claude-code-kit 0.7.0__py3-none-any.whl

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.
Files changed (209) hide show
  1. claude_code_kit-0.7.0.dist-info/METADATA +384 -0
  2. claude_code_kit-0.7.0.dist-info/RECORD +209 -0
  3. claude_code_kit-0.7.0.dist-info/WHEEL +4 -0
  4. claude_code_kit-0.7.0.dist-info/entry_points.txt +4 -0
  5. claude_code_kit-0.7.0.dist-info/licenses/LICENSE +21 -0
  6. claude_kit/__init__.py +10 -0
  7. claude_kit/__main__.py +8 -0
  8. claude_kit/_payload/agents/acceptance-reviewer.md +60 -0
  9. claude_kit/_payload/agents/auditor.md +76 -0
  10. claude_kit/_payload/agents/dependency-scanner.md +84 -0
  11. claude_kit/_payload/agents/developer.md +187 -0
  12. claude_kit/_payload/agents/devils-advocate.md +62 -0
  13. claude_kit/_payload/agents/devops-engineer.md +134 -0
  14. claude_kit/_payload/agents/e2e-tester.md +152 -0
  15. claude_kit/_payload/agents/em-reviewer.md +105 -0
  16. claude_kit/_payload/agents/incident-responder.md +64 -0
  17. claude_kit/_payload/agents/merge-reviewer.md +194 -0
  18. claude_kit/_payload/agents/observability-engineer.md +94 -0
  19. claude_kit/_payload/agents/orchestrator.md +551 -0
  20. claude_kit/_payload/agents/owasp-reviewer.md +76 -0
  21. claude_kit/_payload/agents/policy-validator.md +63 -0
  22. claude_kit/_payload/agents/pr-raiser.md +138 -0
  23. claude_kit/_payload/agents/risk-classifier.md +50 -0
  24. claude_kit/_payload/agents/sdlc-code-reviewer.md +196 -0
  25. claude_kit/_payload/agents/secret-scanner.md +70 -0
  26. claude_kit/_payload/agents/security-reviewer.md +80 -0
  27. claude_kit/_payload/agents/senior-backend-dev.md +199 -0
  28. claude_kit/_payload/agents/senior-frontend-dev.md +181 -0
  29. claude_kit/_payload/agents/senior-tester.md +206 -0
  30. claude_kit/_payload/agents/spec-doc-writer.md +331 -0
  31. claude_kit/_payload/agents/story-planner.md +56 -0
  32. claude_kit/_payload/agents/technical-architect.md +139 -0
  33. claude_kit/_payload/agents/tester.md +193 -0
  34. claude_kit/_payload/agents/ui-designer.md +73 -0
  35. claude_kit/_payload/agents/unit-tester.md +119 -0
  36. claude_kit/_payload/catalog/mcp.yaml +54 -0
  37. claude_kit/_payload/catalog/org.yaml +145 -0
  38. claude_kit/_payload/catalog/profiles.yaml +96 -0
  39. claude_kit/_payload/catalog/stacks.yaml +96 -0
  40. claude_kit/_payload/commands/init.md +36 -0
  41. claude_kit/_payload/commands/sdlc.md +18 -0
  42. claude_kit/_payload/commands/status.md +20 -0
  43. claude_kit/_payload/hooks/hooks.json +58 -0
  44. claude_kit/_payload/hooks/scripts/audit-log.sh +18 -0
  45. claude_kit/_payload/hooks/scripts/guard-secrets.sh +26 -0
  46. claude_kit/_payload/hooks/scripts/lint-fix.sh +38 -0
  47. claude_kit/_payload/hooks/scripts/load-continuity.sh +32 -0
  48. claude_kit/_payload/hooks/scripts/load-learnings.sh +40 -0
  49. claude_kit/_payload/hooks/scripts/type-check.sh +23 -0
  50. claude_kit/_payload/hooks/scripts/validate-frontmatter.sh +34 -0
  51. claude_kit/_payload/hooks/scripts/validate-settings.sh +21 -0
  52. claude_kit/_payload/hooks/scripts/warn-large-edits.sh +24 -0
  53. claude_kit/_payload/hooks/scripts/warn-missing-tests.sh +24 -0
  54. claude_kit/_payload/hooks/scripts/warn-sensitive-files.sh +30 -0
  55. claude_kit/_payload/hooks/scripts/warn-shared-modules.sh +33 -0
  56. claude_kit/_payload/rules/agent-guardrails.md +83 -0
  57. claude_kit/_payload/rules/agent-memory.md +106 -0
  58. claude_kit/_payload/rules/agent-resilience.md +61 -0
  59. claude_kit/_payload/rules/autonomy-levels.md +30 -0
  60. claude_kit/_payload/rules/code-organization.md +312 -0
  61. claude_kit/_payload/rules/continuity.md +84 -0
  62. claude_kit/_payload/rules/design-patterns.md +422 -0
  63. claude_kit/_payload/rules/devops-observability.md +57 -0
  64. claude_kit/_payload/rules/documentation.md +326 -0
  65. claude_kit/_payload/rules/evals.md +62 -0
  66. claude_kit/_payload/rules/frontend-best-practices.md +157 -0
  67. claude_kit/_payload/rules/goal-setting-and-monitoring.md +72 -0
  68. claude_kit/_payload/rules/human-in-the-loop.md +64 -0
  69. claude_kit/_payload/rules/linting-and-formatting.md +220 -0
  70. claude_kit/_payload/rules/mandatory-workflow.md +309 -0
  71. claude_kit/_payload/rules/model-tiers.md +34 -0
  72. claude_kit/_payload/rules/quality-gates.md +107 -0
  73. claude_kit/_payload/rules/rarv-cycle.md +31 -0
  74. claude_kit/_payload/rules/reasoning-techniques.md +62 -0
  75. claude_kit/_payload/rules/responsive-and-accessibility.md +353 -0
  76. claude_kit/_payload/rules/risk-classification.md +36 -0
  77. claude_kit/_payload/rules/testing.md +417 -0
  78. claude_kit/_payload/rules/tool-design.md +66 -0
  79. claude_kit/_payload/skills/_references/accessibility-checklist.md +160 -0
  80. claude_kit/_payload/skills/_references/orchestration-patterns.md +405 -0
  81. claude_kit/_payload/skills/_references/performance-checklist.md +153 -0
  82. claude_kit/_payload/skills/_references/security-checklist.md +134 -0
  83. claude_kit/_payload/skills/_references/testing-patterns.md +236 -0
  84. claude_kit/_payload/skills/accessibility-review/SKILL.md +56 -0
  85. claude_kit/_payload/skills/api-and-interface-design/SKILL.md +294 -0
  86. claude_kit/_payload/skills/api-integration/SKILL.md +348 -0
  87. claude_kit/_payload/skills/archive-sprint/SKILL.md +31 -0
  88. claude_kit/_payload/skills/backlog/SKILL.md +41 -0
  89. claude_kit/_payload/skills/backlog/item-template.md +20 -0
  90. claude_kit/_payload/skills/browser-testing-with-devtools/SKILL.md +302 -0
  91. claude_kit/_payload/skills/ci-cd-and-automation/SKILL.md +402 -0
  92. claude_kit/_payload/skills/code-review-and-quality/SKILL.md +347 -0
  93. claude_kit/_payload/skills/code-simplification/SKILL.md +331 -0
  94. claude_kit/_payload/skills/component-design/SKILL.md +171 -0
  95. claude_kit/_payload/skills/consolidate-learnings/SKILL.md +55 -0
  96. claude_kit/_payload/skills/context-engineering/SKILL.md +321 -0
  97. claude_kit/_payload/skills/debugging-and-error-recovery/SKILL.md +300 -0
  98. claude_kit/_payload/skills/decision/SKILL.md +46 -0
  99. claude_kit/_payload/skills/decision/adr-template.md +36 -0
  100. claude_kit/_payload/skills/deprecation-and-migration/SKILL.md +207 -0
  101. claude_kit/_payload/skills/documentation-and-adrs/SKILL.md +299 -0
  102. claude_kit/_payload/skills/doubt-driven-development/SKILL.md +243 -0
  103. claude_kit/_payload/skills/execute/SKILL.md +27 -0
  104. claude_kit/_payload/skills/frontend-ui-engineering/SKILL.md +328 -0
  105. claude_kit/_payload/skills/git-workflow-and-versioning/SKILL.md +300 -0
  106. claude_kit/_payload/skills/idea-refine/SKILL.md +178 -0
  107. claude_kit/_payload/skills/idea-refine/examples.md +238 -0
  108. claude_kit/_payload/skills/idea-refine/frameworks.md +99 -0
  109. claude_kit/_payload/skills/idea-refine/refinement-criteria.md +113 -0
  110. claude_kit/_payload/skills/idea-refine/scripts/idea-refine.sh +15 -0
  111. claude_kit/_payload/skills/incident-postmortem/SKILL.md +74 -0
  112. claude_kit/_payload/skills/incremental-implementation/SKILL.md +245 -0
  113. claude_kit/_payload/skills/interview-me/SKILL.md +221 -0
  114. claude_kit/_payload/skills/load-testing/SKILL.md +83 -0
  115. claude_kit/_payload/skills/manual-test/SKILL.md +516 -0
  116. claude_kit/_payload/skills/performance-optimization/SKILL.md +277 -0
  117. claude_kit/_payload/skills/planning-and-task-breakdown/SKILL.md +223 -0
  118. claude_kit/_payload/skills/playwright-verification/SKILL.md +205 -0
  119. claude_kit/_payload/skills/refresh-docs/SKILL.md +63 -0
  120. claude_kit/_payload/skills/remember/SKILL.md +96 -0
  121. claude_kit/_payload/skills/scope/SKILL.md +52 -0
  122. claude_kit/_payload/skills/scope/scope-template.md +82 -0
  123. claude_kit/_payload/skills/sdlc/SKILL.md +83 -0
  124. claude_kit/_payload/skills/security-and-hardening/SKILL.md +368 -0
  125. claude_kit/_payload/skills/security-verification/SKILL.md +209 -0
  126. claude_kit/_payload/skills/shipping-and-launch/SKILL.md +309 -0
  127. claude_kit/_payload/skills/smoke-test/SKILL.md +78 -0
  128. claude_kit/_payload/skills/source-driven-development/SKILL.md +195 -0
  129. claude_kit/_payload/skills/spec-driven-development/SKILL.md +200 -0
  130. claude_kit/_payload/skills/sprint/SKILL.md +67 -0
  131. claude_kit/_payload/skills/sprint/sprint-template.md +90 -0
  132. claude_kit/_payload/skills/test-driven-development/SKILL.md +383 -0
  133. claude_kit/_payload/skills/threat-model/SKILL.md +60 -0
  134. claude_kit/_payload/skills/triage/SKILL.md +87 -0
  135. claude_kit/_payload/skills/ui-ux-design/SKILL.md +71 -0
  136. claude_kit/_payload/skills/unit-test/SKILL.md +237 -0
  137. claude_kit/_payload/skills/using-agent-skills/SKILL.md +180 -0
  138. claude_kit/_payload/templates/CLAUDE.md +238 -0
  139. claude_kit/_payload/templates/CLAUDE.stack.md.tmpl +53 -0
  140. claude_kit/_payload/templates/CONTINUITY.template.md +35 -0
  141. claude_kit/_payload/templates/README.claude-sdlc.md.tmpl +219 -0
  142. claude_kit/_payload/templates/agent-memory/MEMORY.md +30 -0
  143. claude_kit/_payload/templates/agent-memory/api/.gitkeep +0 -0
  144. claude_kit/_payload/templates/agent-memory/architecture/.gitkeep +0 -0
  145. claude_kit/_payload/templates/agent-memory/debugging/.gitkeep +0 -0
  146. claude_kit/_payload/templates/agent-memory/gotchas/.gitkeep +0 -0
  147. claude_kit/_payload/templates/agent-memory/patterns/.gitkeep +0 -0
  148. claude_kit/_payload/templates/agent-memory/performance/.gitkeep +0 -0
  149. claude_kit/_payload/templates/artifacts/adr.md +18 -0
  150. claude_kit/_payload/templates/artifacts/feature-spec.md +29 -0
  151. claude_kit/_payload/templates/artifacts/release-plan.md +23 -0
  152. claude_kit/_payload/templates/artifacts/runbook.md +24 -0
  153. claude_kit/_payload/templates/artifacts/security-review.md +23 -0
  154. claude_kit/_payload/templates/artifacts/test-plan.md +22 -0
  155. claude_kit/_payload/templates/org/README.md +53 -0
  156. claude_kit/_payload/templates/org/agents/data-workflow-agent.md +59 -0
  157. claude_kit/_payload/templates/org/agents/founder-prototype-agent.md +61 -0
  158. claude_kit/_payload/templates/org/agents/internal-tools-builder.md +63 -0
  159. claude_kit/_payload/templates/org/agents/pm-copilot.md +60 -0
  160. claude_kit/_payload/templates/org/agents/support-ticket-engineer.md +63 -0
  161. claude_kit/_payload/templates/org/packs/devops-and-release/README.md +46 -0
  162. claude_kit/_payload/templates/org/packs/devops-and-release/pack.yaml +32 -0
  163. claude_kit/_payload/templates/org/packs/engineering-core/README.md +46 -0
  164. claude_kit/_payload/templates/org/packs/engineering-core/pack.yaml +44 -0
  165. claude_kit/_payload/templates/org/packs/non-engineer-builder/README.md +53 -0
  166. claude_kit/_payload/templates/org/packs/non-engineer-builder/pack.yaml +39 -0
  167. claude_kit/_payload/templates/org/packs/onboarding-and-docs/README.md +49 -0
  168. claude_kit/_payload/templates/org/packs/onboarding-and-docs/pack.yaml +26 -0
  169. claude_kit/_payload/templates/org/packs/product-to-code/README.md +50 -0
  170. claude_kit/_payload/templates/org/packs/product-to-code/pack.yaml +34 -0
  171. claude_kit/_payload/templates/org/packs/quality-and-review/README.md +53 -0
  172. claude_kit/_payload/templates/org/packs/quality-and-review/pack.yaml +40 -0
  173. claude_kit/_payload/templates/org/packs/security-and-compliance/README.md +50 -0
  174. claude_kit/_payload/templates/org/packs/security-and-compliance/pack.yaml +36 -0
  175. claude_kit/_payload/templates/org/rules/ai-working-agreement.md +45 -0
  176. claude_kit/_payload/templates/org/rules/ambiguity-resolution.md +36 -0
  177. claude_kit/_payload/templates/org/rules/branch-and-pr-policy.md +41 -0
  178. claude_kit/_payload/templates/org/rules/compliance-policy.md +50 -0
  179. claude_kit/_payload/templates/org/rules/non-engineer-safe-coding.md +37 -0
  180. claude_kit/_payload/templates/org/rules/pii-policy.md +46 -0
  181. claude_kit/_payload/templates/org/rules/production-data-policy.md +35 -0
  182. claude_kit/_payload/templates/org/rules/prompt-to-task-conversion.md +30 -0
  183. claude_kit/_payload/templates/org/rules/prototype-boundaries.md +40 -0
  184. claude_kit/_payload/templates/org/rules/secrets-policy.md +34 -0
  185. claude_kit/_payload/templates/org/skills/customer-issue-to-fix/SKILL.md +61 -0
  186. claude_kit/_payload/templates/org/skills/feature-from-idea/SKILL.md +56 -0
  187. claude_kit/_payload/templates/org/skills/prompt-to-safe-task/SKILL.md +59 -0
  188. claude_kit/_payload/templates/org/skills/prototype-to-production/SKILL.md +61 -0
  189. claude_kit/_payload/templates/org/skills/repo-onboarding/SKILL.md +60 -0
  190. claude_kit/_payload/templates/settings.json +53 -0
  191. claude_kit/_payload/templates/stacks/backend/python/fastapi/rules/fastapi-patterns.md +64 -0
  192. claude_kit/_payload/templates/stacks/db/mongodb/agents/migration-specialist.md +61 -0
  193. claude_kit/_payload/templates/stacks/db/mongodb/agents/mongodb-specialist.md +59 -0
  194. claude_kit/_payload/templates/stacks/db/mongodb/rules/mongodb-patterns.md +39 -0
  195. claude_kit/_payload/templates/stacks/db/postgres/agents/db-performance-reviewer.md +66 -0
  196. claude_kit/_payload/templates/stacks/db/postgres/agents/migration-specialist.md +56 -0
  197. claude_kit/_payload/templates/stacks/db/postgres/agents/postgres-specialist.md +58 -0
  198. claude_kit/_payload/templates/stacks/db/postgres/rules/database-performance.md +64 -0
  199. claude_kit/_payload/templates/stacks/db/postgres/rules/postgres-patterns.md +43 -0
  200. claude_kit/_payload/templates/stacks/frontend/react/rules/react-patterns.md +63 -0
  201. claude_kit/catalog.py +476 -0
  202. claude_kit/cli.py +327 -0
  203. claude_kit/hooks.py +246 -0
  204. claude_kit/models.py +205 -0
  205. claude_kit/prompts.py +209 -0
  206. claude_kit/render.py +146 -0
  207. claude_kit/scaffold.py +492 -0
  208. claude_kit/upgrader.py +294 -0
  209. claude_kit/validator.py +197 -0
@@ -0,0 +1,294 @@
1
+ ---
2
+ name: api-and-interface-design
3
+ description: Guides stable API and interface design. Use when designing APIs, module boundaries, or any public interface. Use when creating REST or GraphQL endpoints, defining type contracts between modules, or establishing boundaries between frontend and backend.
4
+ ---
5
+
6
+ # API and Interface Design
7
+
8
+ ## Overview
9
+
10
+ Design stable, well-documented interfaces that are hard to misuse. Good interfaces make the right thing easy and the wrong thing hard. This applies to REST APIs, GraphQL schemas, module boundaries, component props, and any surface where one piece of code talks to another.
11
+
12
+ ## When to Use
13
+
14
+ - Designing new API endpoints
15
+ - Defining module boundaries or contracts between teams
16
+ - Creating component prop interfaces
17
+ - Establishing database schema that informs API shape
18
+ - Changing existing public interfaces
19
+
20
+ ## Core Principles
21
+
22
+ ### Hyrum's Law
23
+
24
+ > With a sufficient number of users of an API, all observable behaviors of your system will be depended on by somebody, regardless of what you promise in the contract.
25
+
26
+ This means: every public behavior — including undocumented quirks, error message text, timing, and ordering — becomes a de facto contract once users depend on it. Design implications:
27
+
28
+ - **Be intentional about what you expose.** Every observable behavior is a potential commitment.
29
+ - **Don't leak implementation details.** If users can observe it, they will depend on it.
30
+ - **Plan for deprecation at design time.** See `deprecation-and-migration` for how to safely remove things users depend on.
31
+ - **Tests are not enough.** Even with perfect contract tests, Hyrum's Law means "safe" changes can break real users who depend on undocumented behavior.
32
+
33
+ ### The One-Version Rule
34
+
35
+ Avoid forcing consumers to choose between multiple versions of the same dependency or API. Diamond dependency problems arise when different consumers need different versions of the same thing. Design for a world where only one version exists at a time — extend rather than fork.
36
+
37
+ ### 1. Contract First
38
+
39
+ Define the interface before implementing it. The contract is the spec — implementation follows.
40
+
41
+ ```typescript
42
+ // Define the contract first
43
+ interface TaskAPI {
44
+ // Creates a task and returns the created task with server-generated fields
45
+ createTask(input: CreateTaskInput): Promise<Task>;
46
+
47
+ // Returns paginated tasks matching filters
48
+ listTasks(params: ListTasksParams): Promise<PaginatedResult<Task>>;
49
+
50
+ // Returns a single task or throws NotFoundError
51
+ getTask(id: string): Promise<Task>;
52
+
53
+ // Partial update — only provided fields change
54
+ updateTask(id: string, input: UpdateTaskInput): Promise<Task>;
55
+
56
+ // Idempotent delete — succeeds even if already deleted
57
+ deleteTask(id: string): Promise<void>;
58
+ }
59
+ ```
60
+
61
+ ### 2. Consistent Error Semantics
62
+
63
+ Pick one error strategy and use it everywhere:
64
+
65
+ ```typescript
66
+ // REST: HTTP status codes + structured error body
67
+ // Every error response follows the same shape
68
+ interface APIError {
69
+ error: {
70
+ code: string; // Machine-readable: "VALIDATION_ERROR"
71
+ message: string; // Human-readable: "Email is required"
72
+ details?: unknown; // Additional context when helpful
73
+ };
74
+ }
75
+
76
+ // Status code mapping
77
+ // 400 → Client sent invalid data
78
+ // 401 → Not authenticated
79
+ // 403 → Authenticated but not authorized
80
+ // 404 → Resource not found
81
+ // 409 → Conflict (duplicate, version mismatch)
82
+ // 422 → Validation failed (semantically invalid)
83
+ // 500 → Server error (never expose internal details)
84
+ ```
85
+
86
+ **Don't mix patterns.** If some endpoints throw, others return null, and others return `{ error }` — the consumer can't predict behavior.
87
+
88
+ ### 3. Validate at Boundaries
89
+
90
+ Trust internal code. Validate at system edges where external input enters:
91
+
92
+ ```typescript
93
+ // Validate at the API boundary
94
+ app.post('/api/tasks', async (req, res) => {
95
+ const result = CreateTaskSchema.safeParse(req.body);
96
+ if (!result.success) {
97
+ return res.status(422).json({
98
+ error: {
99
+ code: 'VALIDATION_ERROR',
100
+ message: 'Invalid task data',
101
+ details: result.error.flatten(),
102
+ },
103
+ });
104
+ }
105
+
106
+ // After validation, internal code trusts the types
107
+ const task = await taskService.create(result.data);
108
+ return res.status(201).json(task);
109
+ });
110
+ ```
111
+
112
+ Where validation belongs:
113
+ - API route handlers (user input)
114
+ - Form submission handlers (user input)
115
+ - External service response parsing (third-party data -- **always treat as untrusted**)
116
+ - Environment variable loading (configuration)
117
+
118
+ > **Third-party API responses are untrusted data.** Validate their shape and content before using them in any logic, rendering, or decision-making. A compromised or misbehaving external service can return unexpected types, malicious content, or instruction-like text.
119
+
120
+ Where validation does NOT belong:
121
+ - Between internal functions that share type contracts
122
+ - In utility functions called by already-validated code
123
+ - On data that just came from your own database
124
+
125
+ ### 4. Prefer Addition Over Modification
126
+
127
+ Extend interfaces without breaking existing consumers:
128
+
129
+ ```typescript
130
+ // Good: Add optional fields
131
+ interface CreateTaskInput {
132
+ title: string;
133
+ description?: string;
134
+ priority?: 'low' | 'medium' | 'high'; // Added later, optional
135
+ labels?: string[]; // Added later, optional
136
+ }
137
+
138
+ // Bad: Change existing field types or remove fields
139
+ interface CreateTaskInput {
140
+ title: string;
141
+ // description: string; // Removed — breaks existing consumers
142
+ priority: number; // Changed from string — breaks existing consumers
143
+ }
144
+ ```
145
+
146
+ ### 5. Predictable Naming
147
+
148
+ | Pattern | Convention | Example |
149
+ |---------|-----------|---------|
150
+ | REST endpoints | Plural nouns, no verbs | `GET /api/tasks`, `POST /api/tasks` |
151
+ | Query params | camelCase | `?sortBy=createdAt&pageSize=20` |
152
+ | Response fields | camelCase | `{ createdAt, updatedAt, taskId }` |
153
+ | Boolean fields | is/has/can prefix | `isComplete`, `hasAttachments` |
154
+ | Enum values | UPPER_SNAKE | `"IN_PROGRESS"`, `"COMPLETED"` |
155
+
156
+ ## REST API Patterns
157
+
158
+ ### Resource Design
159
+
160
+ ```
161
+ GET /api/tasks → List tasks (with query params for filtering)
162
+ POST /api/tasks → Create a task
163
+ GET /api/tasks/:id → Get a single task
164
+ PATCH /api/tasks/:id → Update a task (partial)
165
+ DELETE /api/tasks/:id → Delete a task
166
+
167
+ GET /api/tasks/:id/comments → List comments for a task (sub-resource)
168
+ POST /api/tasks/:id/comments → Add a comment to a task
169
+ ```
170
+
171
+ ### Pagination
172
+
173
+ Paginate list endpoints:
174
+
175
+ ```typescript
176
+ // Request
177
+ GET /api/tasks?page=1&pageSize=20&sortBy=createdAt&sortOrder=desc
178
+
179
+ // Response
180
+ {
181
+ "data": [...],
182
+ "pagination": {
183
+ "page": 1,
184
+ "pageSize": 20,
185
+ "totalItems": 142,
186
+ "totalPages": 8
187
+ }
188
+ }
189
+ ```
190
+
191
+ ### Filtering
192
+
193
+ Use query parameters for filters:
194
+
195
+ ```
196
+ GET /api/tasks?status=in_progress&assignee=user123&createdAfter=2025-01-01
197
+ ```
198
+
199
+ ### Partial Updates (PATCH)
200
+
201
+ Accept partial objects — only update what's provided:
202
+
203
+ ```typescript
204
+ // Only title changes, everything else preserved
205
+ PATCH /api/tasks/123
206
+ { "title": "Updated title" }
207
+ ```
208
+
209
+ ## Type-Safe Interface Patterns
210
+
211
+ ### Use Discriminated Unions for Variants
212
+
213
+ ```typescript
214
+ // Good: Each variant is explicit
215
+ type TaskStatus =
216
+ | { type: 'pending' }
217
+ | { type: 'in_progress'; assignee: string; startedAt: Date }
218
+ | { type: 'completed'; completedAt: Date; completedBy: string }
219
+ | { type: 'cancelled'; reason: string; cancelledAt: Date };
220
+
221
+ // Consumer gets type narrowing
222
+ function getStatusLabel(status: TaskStatus): string {
223
+ switch (status.type) {
224
+ case 'pending': return 'Pending';
225
+ case 'in_progress': return `In progress (${status.assignee})`;
226
+ case 'completed': return `Done on ${status.completedAt}`;
227
+ case 'cancelled': return `Cancelled: ${status.reason}`;
228
+ }
229
+ }
230
+ ```
231
+
232
+ ### Input/Output Separation
233
+
234
+ ```typescript
235
+ // Input: what the caller provides
236
+ interface CreateTaskInput {
237
+ title: string;
238
+ description?: string;
239
+ }
240
+
241
+ // Output: what the system returns (includes server-generated fields)
242
+ interface Task {
243
+ id: string;
244
+ title: string;
245
+ description: string | null;
246
+ createdAt: Date;
247
+ updatedAt: Date;
248
+ createdBy: string;
249
+ }
250
+ ```
251
+
252
+ ### Use Branded Types for IDs
253
+
254
+ ```typescript
255
+ type TaskId = string & { readonly __brand: 'TaskId' };
256
+ type UserId = string & { readonly __brand: 'UserId' };
257
+
258
+ // Prevents accidentally passing a UserId where a TaskId is expected
259
+ function getTask(id: TaskId): Promise<Task> { ... }
260
+ ```
261
+
262
+ ## Common Rationalizations
263
+
264
+ | Rationalization | Reality |
265
+ |---|---|
266
+ | "We'll document the API later" | The types ARE the documentation. Define them first. |
267
+ | "We don't need pagination for now" | You will the moment someone has 100+ items. Add it from the start. |
268
+ | "PATCH is complicated, let's just use PUT" | PUT requires the full object every time. PATCH is what clients actually want. |
269
+ | "We'll version the API when we need to" | Breaking changes without versioning break consumers. Design for extension from the start. |
270
+ | "Nobody uses that undocumented behavior" | Hyrum's Law: if it's observable, somebody depends on it. Treat every public behavior as a commitment. |
271
+ | "We can just maintain two versions" | Multiple versions multiply maintenance cost and create diamond dependency problems. Prefer the One-Version Rule. |
272
+ | "Internal APIs don't need contracts" | Internal consumers are still consumers. Contracts prevent coupling and enable parallel work. |
273
+
274
+ ## Red Flags
275
+
276
+ - Endpoints that return different shapes depending on conditions
277
+ - Inconsistent error formats across endpoints
278
+ - Validation scattered throughout internal code instead of at boundaries
279
+ - Breaking changes to existing fields (type changes, removals)
280
+ - List endpoints without pagination
281
+ - Verbs in REST URLs (`/api/createTask`, `/api/getUsers`)
282
+ - Third-party API responses used without validation or sanitization
283
+
284
+ ## Verification
285
+
286
+ After designing an API:
287
+
288
+ - [ ] Every endpoint has typed input and output schemas
289
+ - [ ] Error responses follow a single consistent format
290
+ - [ ] Validation happens at system boundaries only
291
+ - [ ] List endpoints support pagination
292
+ - [ ] New fields are additive and optional (backward compatible)
293
+ - [ ] Naming follows consistent conventions across all endpoints
294
+ - [ ] API documentation or types are committed alongside the implementation
@@ -0,0 +1,348 @@
1
+ ---
2
+ name: api-integration
3
+ description: Integrate APIs with proper caching, error handling, type safety, and loading states using the project's data-fetching patterns.
4
+ argument-hint: [API endpoint or feature name]
5
+ disable-model-invocation: true
6
+ ---
7
+
8
+ Integrate API for: $ARGUMENTS.
9
+
10
+ ## Steps
11
+
12
+ 1. **Identify the API**: Determine the endpoint(s), HTTP method(s), request/response shapes, and authentication requirements for $ARGUMENTS.
13
+
14
+ 2. **Define types**: Create typed interfaces for request and response payloads. Co-locate types with the API client module according to the project's conventions.
15
+
16
+ ```typescript
17
+ // TypeScript example
18
+ export interface GetItemsParams {
19
+ page: number;
20
+ limit: number;
21
+ status?: 'open' | 'resolved' | 'escalated';
22
+ }
23
+
24
+ export interface ItemResponse {
25
+ data: Item[];
26
+ total: number;
27
+ page: number;
28
+ }
29
+ ```
30
+
31
+ ```python
32
+ # Python example (Pydantic)
33
+ from pydantic import BaseModel
34
+
35
+ class GetItemsParams(BaseModel):
36
+ page: int
37
+ limit: int
38
+ status: str | None = None
39
+
40
+ class ItemResponse(BaseModel):
41
+ data: list[Item]
42
+ total: int
43
+ page: int
44
+ ```
45
+
46
+ 3. **Create API client functions**: Place in the project's designated API layer as pure async functions. Use the project's HTTP client.
47
+
48
+ ```typescript
49
+ // TypeScript example
50
+ import { httpClient } from '@/lib/httpClient';
51
+ import type { GetItemsParams, ItemResponse } from './types/items';
52
+
53
+ export async function getItems(params: GetItemsParams): Promise<ItemResponse> {
54
+ const { data } = await httpClient.get<ItemResponse>('/items', { params });
55
+ return data;
56
+ }
57
+
58
+ export async function resolveItem(id: string, resolution: string): Promise<void> {
59
+ await httpClient.post(`/items/${encodeURIComponent(id)}/resolve`, { resolution });
60
+ }
61
+ ```
62
+
63
+ ```python
64
+ # Python example (httpx)
65
+ import httpx
66
+ from .schemas import GetItemsParams, ItemResponse
67
+
68
+ async def get_items(params: GetItemsParams) -> ItemResponse:
69
+ async with httpx.AsyncClient() as client:
70
+ response = await client.get('/items', params=params.model_dump())
71
+ return ItemResponse.model_validate(response.json())
72
+
73
+ async def resolve_item(id: str, resolution: str) -> None:
74
+ async with httpx.AsyncClient() as client:
75
+ await client.post(f'/items/{id}/resolve', json={'resolution': resolution})
76
+ ```
77
+
78
+ 4. **Create data-fetching hooks/functions**: Wrap API calls with the project's caching/state management layer.
79
+
80
+ ### Query Pattern (React Query example)
81
+ ```typescript
82
+ import { useQuery } from '@tanstack/react-query';
83
+ import { getItems } from '@/api/items';
84
+ import type { GetItemsParams } from '@/api/types/items';
85
+
86
+ export const itemKeys = {
87
+ all: ['items'] as const,
88
+ lists: () => [...itemKeys.all, 'list'] as const,
89
+ list: (params: GetItemsParams) => [...itemKeys.lists(), params] as const,
90
+ details: () => [...itemKeys.all, 'detail'] as const,
91
+ detail: (id: string) => [...itemKeys.details(), id] as const,
92
+ };
93
+
94
+ export function useItems(params: GetItemsParams) {
95
+ return useQuery({
96
+ queryKey: itemKeys.list(params),
97
+ queryFn: () => getItems(params),
98
+ staleTime: 5 * 60 * 1000, // 5 minutes
99
+ placeholderData: keepPreviousData,
100
+ });
101
+ }
102
+ ```
103
+
104
+ ### Mutation Pattern (React Query example)
105
+ ```typescript
106
+ import { useMutation, useQueryClient } from '@tanstack/react-query';
107
+ import { resolveItem } from '@/api/items';
108
+
109
+ export function useResolveItem() {
110
+ const queryClient = useQueryClient();
111
+
112
+ return useMutation({
113
+ mutationFn: ({ id, resolution }: { id: string; resolution: string }) =>
114
+ resolveItem(id, resolution),
115
+ onSuccess: () => {
116
+ queryClient.invalidateQueries({ queryKey: itemKeys.all });
117
+ },
118
+ });
119
+ }
120
+ ```
121
+
122
+ ### Alternative: Service Layer Pattern (backend or Vue/Angular)
123
+ ```python
124
+ # Python service layer
125
+ from .repository import ItemRepository
126
+ from .schemas import GetItemsParams, ItemResponse
127
+
128
+ class ItemService:
129
+ def __init__(self, repo: ItemRepository):
130
+ self.repo = repo
131
+
132
+ async def get_items(self, params: GetItemsParams) -> ItemResponse:
133
+ items = await self.repo.find_all(params)
134
+ total = await self.repo.count(params)
135
+ return ItemResponse(data=items, total=total, page=params.page)
136
+ ```
137
+
138
+ 5. **Validate responses at the boundary**: Use a validation library to ensure API responses match expected shapes.
139
+
140
+ ```typescript
141
+ // TypeScript with Zod
142
+ import { z } from 'zod';
143
+
144
+ const itemResponseSchema = z.object({
145
+ data: z.array(itemSchema),
146
+ total: z.number(),
147
+ page: z.number(),
148
+ });
149
+
150
+ export async function getItems(params: GetItemsParams) {
151
+ const { data } = await httpClient.get('/items', { params });
152
+ return itemResponseSchema.parse(data);
153
+ }
154
+ ```
155
+
156
+ ```python
157
+ # Python with Pydantic (validation built-in)
158
+ from pydantic import BaseModel, field_validator
159
+
160
+ class ItemResponse(BaseModel):
161
+ data: list[Item]
162
+ total: int
163
+ page: int
164
+
165
+ @field_validator('total')
166
+ @classmethod
167
+ def total_non_negative(cls, v: int) -> int:
168
+ if v < 0:
169
+ raise ValueError('total must be non-negative')
170
+ return v
171
+ ```
172
+
173
+ 6. **Use in components/views**: Follow the loading/empty/error state pattern.
174
+
175
+ ```tsx
176
+ // React example
177
+ function ItemList() {
178
+ const { data, isLoading, error } = useItems({ page: 1, limit: 20 });
179
+
180
+ if (isLoading) return <Spinner />;
181
+ if (error) return <EmptyState title="Failed to load items" />;
182
+ if (!data?.data.length) return <EmptyState title="No items found" />;
183
+
184
+ return (
185
+ <div className="space-y-3">
186
+ {data.data.map((item) => (
187
+ <ItemCard key={item.id} item={item} />
188
+ ))}
189
+ </div>
190
+ );
191
+ }
192
+ ```
193
+
194
+ ```python
195
+ # Python (FastAPI) example
196
+ from fastapi import APIRouter, Depends, HTTPException, status
197
+
198
+ @router.get('/items', response_model=ItemResponse)
199
+ async def list_items(
200
+ params: GetItemsParams = Depends(),
201
+ service: ItemService = Depends(),
202
+ ) -> ItemResponse:
203
+ try:
204
+ return await service.get_items(params)
205
+ except Exception as e:
206
+ raise HTTPException(
207
+ status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
208
+ detail='Failed to load items'
209
+ )
210
+ ```
211
+
212
+ 7. **Verify**: Run the project's linter, type checker, and build to confirm all checks pass.
213
+
214
+ ## Data-Fetching Conventions
215
+
216
+ ### Cache Key Factory
217
+ Every feature should have a key factory object for consistent cache management (applies to client-side caching libraries like TanStack Query, SWR, Apollo):
218
+
219
+ ```typescript
220
+ export const featureKeys = {
221
+ all: ['feature'] as const,
222
+ lists: () => [...featureKeys.all, 'list'] as const,
223
+ list: (params: Params) => [...featureKeys.lists(), params] as const,
224
+ details: () => [...featureKeys.all, 'detail'] as const,
225
+ detail: (id: string) => [...featureKeys.details(), id] as const,
226
+ };
227
+ ```
228
+
229
+ ### Stale Time Defaults (Client-Side Caching)
230
+ | Data Type | Stale Time | Rationale |
231
+ |-----------|-----------|-----------|
232
+ | Reference data (categories, roles) | 30 minutes | Rarely changes |
233
+ | Dashboard KPIs | 5 minutes | Moderate freshness |
234
+ | Real-time feeds (notifications, alerts) | 1 minute | Needs frequent updates |
235
+ | User-specific (preferences) | Infinity | Only changes on mutation |
236
+
237
+ ### Error Handling
238
+ - Use the data-fetching layer's built-in error state — avoid wrapping in try/catch at the component level
239
+ - Global error handler for auth errors (401 → redirect to login)
240
+ - Show empty/error state UI for query failures
241
+ - Show toast/notification for mutation failures
242
+
243
+ ### Optimistic Updates (Client-Side)
244
+ Use for operations where the user expects instant feedback:
245
+
246
+ ```typescript
247
+ // TanStack Query example
248
+ onMutate: async (newData) => {
249
+ await queryClient.cancelQueries({ queryKey });
250
+ const previous = queryClient.getQueryData(queryKey);
251
+ queryClient.setQueryData(queryKey, (old) => /* optimistic update */);
252
+ return { previous };
253
+ },
254
+ onError: (_err, _new, context) => {
255
+ queryClient.setQueryData(queryKey, context?.previous);
256
+ },
257
+ onSettled: () => {
258
+ queryClient.invalidateQueries({ queryKey });
259
+ },
260
+ ```
261
+
262
+ ```python
263
+ # Backend optimistic approach (return before commit)
264
+ async def update_item(db: AsyncSession, id: str, update: ItemUpdate) -> Item:
265
+ item = await repo.get_by_id(db, id)
266
+ if not item:
267
+ raise HTTPException(status_code=404)
268
+
269
+ # Apply changes
270
+ for field, value in update.model_dump(exclude_unset=True).items():
271
+ setattr(item, field, value)
272
+
273
+ # Flush to get updated state, but don't commit yet
274
+ await db.flush()
275
+ await db.refresh(item)
276
+
277
+ # Return optimistically (commit happens at end of request)
278
+ return item
279
+ ```
280
+
281
+ ## Directory Structure
282
+
283
+ Adapt to your project's conventions. Common patterns:
284
+
285
+ ### Frontend (React/Vue/Angular)
286
+ ```
287
+ src/
288
+ lib/
289
+ httpClient.ts # Shared HTTP client (Axios/Fetch)
290
+ queryKeys.ts # Shared query key factories (if using client-side caching)
291
+ providers/
292
+ QueryProvider.tsx # Data-fetching provider (TanStack Query, SWR, Apollo)
293
+ modules/ (or features/)
294
+ <feature>/
295
+ api/<feature>Api.ts # Plain async API functions
296
+ hooks/use<Feature>Queries.ts # Data-fetching hooks wrapping API functions
297
+ types/<feature>.ts # Request/response types
298
+ ```
299
+
300
+ ### Backend (Python/Node/Go/etc.)
301
+ ```
302
+ app/
303
+ api/ # HTTP route handlers
304
+ v1/
305
+ <feature>/
306
+ router.py (or routes.ts) # Route definitions
307
+ schemas.py (or dtos.ts) # Request/response schemas
308
+ service.py (or service.ts) # Business logic
309
+ repository.py (or repository.ts) # Data access
310
+ ```
311
+
312
+ **Key rules:**
313
+ - API client functions (plain async) live in the project's designated API layer
314
+ - Data-fetching hooks/wrappers live alongside the module or in a dedicated hooks folder
315
+ - Key factories can be co-located or centralized depending on the project's conventions
316
+ - Validation happens at system boundaries (API responses in frontend, request payloads in backend)
317
+
318
+ ## Common Patterns by Stack
319
+
320
+ ### React + TanStack Query
321
+ - Query hooks: `useQuery` for reads, `useMutation` for writes
322
+ - Key factories for cache management
323
+ - `invalidateQueries` after mutations
324
+ - `placeholderData: keepPreviousData` for pagination
325
+
326
+ ### Vue + Pinia
327
+ - API functions in composables (`useItems`)
328
+ - Pinia store for caching if needed
329
+ - Loading/error state in composable return
330
+
331
+ ### Angular + RxJS
332
+ - API functions return Observables
333
+ - Service layer manages HTTP calls
334
+ - `catchError` for error handling
335
+ - `shareReplay` for caching
336
+
337
+ ### Backend (FastAPI/Express/Spring Boot)
338
+ - Repository pattern for data access
339
+ - Service layer for business logic
340
+ - Route handlers delegate to services
341
+ - Typed request/response schemas
342
+
343
+ ## References
344
+
345
+ - HTTP client: Check the project's configuration (Axios, Fetch, httpx, requests)
346
+ - Data-fetching library: TanStack Query, SWR, Apollo (frontend), or service/repository pattern (backend)
347
+ - Validation: Zod, Yup, io-ts (TypeScript), Pydantic (Python), Joi (Node.js)
348
+ - Loading/error patterns: Check `code-organization.md` for the project's UI component conventions
@@ -0,0 +1,31 @@
1
+ ---
2
+ name: archive-sprint
3
+ description: Archive a completed sprint's planning docs and update the backlog status.
4
+ argument-hint: [backlog item number]
5
+ disable-model-invocation: true
6
+ ---
7
+
8
+ Archive the completed sprint for backlog item #$ARGUMENTS.
9
+
10
+ ## Steps
11
+
12
+ 1. **Find the planning folder**: Look in `docs/planning/` for the directory corresponding to backlog item #$ARGUMENTS.
13
+
14
+ 2. **Verify completion**: Check that the work is actually done:
15
+ - Read the sprint plan and verify tasks are complete
16
+ - Verify the Sprint Report section is filled in (Results, Metrics, What went well/wrong, Learnings, Unresolved). If missing, tell the user to write the post-sprint report first — do not archive without it.
17
+ - Check if any new learnings should be added to `docs/reference/post-sprint-learnings.md`. If the sprint report has learnings not already captured there, append them.
18
+ - Optionally run the project's build to confirm nothing is broken
19
+
20
+ 3. **Move to archive**: Use `git mv` to move:
21
+ - The scope doc → `docs/archive/plans/{slug}-scope.md`
22
+ - The sprint plan → `docs/archive/sprints/{slug}-sprint.md`
23
+ - Any other planning docs in the folder → `docs/archive/plans/`
24
+
25
+ 4. **Update backlog**: Find the item in its horizon file (`docs/backlog/now.md`, `next.md`, or `later.md`) and move it to `docs/backlog/completed.md` with `Completed` status and the date. Update the item counts in `docs/backlog/README.md`.
26
+
27
+ 5. **Clean up**: Remove the now-empty planning directory.
28
+
29
+ 6. **Commit**: Stage all moved/modified files and commit with message: `backlog: complete #N — {Title}`
30
+
31
+ 7. **Summarize**: Tell the user what was archived and confirm the backlog was updated.