bros-harness 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/CHANGELOG.md +7 -0
- package/LICENSE +21 -0
- package/README.md +183 -0
- package/SECURITY.md +16 -0
- package/assets/agents.manifest.json +55 -0
- package/assets/commands.manifest.json +35 -0
- package/assets/docs.manifest.json +20 -0
- package/assets/import-report.md +25 -0
- package/assets/manifest.json +799 -0
- package/assets/opencode/agents/README.md +3 -0
- package/assets/opencode/agents/bro-build.md +256 -0
- package/assets/opencode/agents/bro-design.md +77 -0
- package/assets/opencode/agents/bro-docs.md +72 -0
- package/assets/opencode/agents/bro-explore.md +143 -0
- package/assets/opencode/agents/bro-ops.md +195 -0
- package/assets/opencode/agents/bro-shield.md +77 -0
- package/assets/opencode/agents/bro-test.md +204 -0
- package/assets/opencode/agents/bro-ui.md +135 -0
- package/assets/opencode/agents/mighty-bro.md +252 -0
- package/assets/opencode/commands/README.md +3 -0
- package/assets/opencode/commands/bros-assemble.md +32 -0
- package/assets/opencode/commands/bros-build.md +58 -0
- package/assets/opencode/commands/bros-plan.md +83 -0
- package/assets/opencode/commands/bros-review.md +38 -0
- package/assets/opencode/commands/bros-status.md +26 -0
- package/assets/opencode/docs/README.md +3 -0
- package/assets/opencode/docs/bros-builtin-skills.md +63 -0
- package/assets/opencode/docs/bros-harness.md +194 -0
- package/assets/opencode/skills/README.md +3 -0
- package/assets/opencode/skills/agent-architecture-audit/SKILL.md +256 -0
- package/assets/opencode/skills/agent-harness-construction/.openskills.json +7 -0
- package/assets/opencode/skills/agent-harness-construction/SKILL.md +73 -0
- package/assets/opencode/skills/agent-introspection-debugging/.openskills.json +7 -0
- package/assets/opencode/skills/agent-introspection-debugging/SKILL.md +153 -0
- package/assets/opencode/skills/api-design/.openskills.json +7 -0
- package/assets/opencode/skills/api-design/agents/openai.yaml +7 -0
- package/assets/opencode/skills/architecture-decision-records/.openskills.json +7 -0
- package/assets/opencode/skills/architecture-decision-records/SKILL.md +179 -0
- package/assets/opencode/skills/article-writing/.openskills.json +7 -0
- package/assets/opencode/skills/article-writing/SKILL.md +79 -0
- package/assets/opencode/skills/article-writing/agents/openai.yaml +7 -0
- package/assets/opencode/skills/automation-audit-ops/.openskills.json +7 -0
- package/assets/opencode/skills/automation-audit-ops/SKILL.md +142 -0
- package/assets/opencode/skills/backend-patterns/.openskills.json +7 -0
- package/assets/opencode/skills/backend-patterns/SKILL.md +561 -0
- package/assets/opencode/skills/backend-patterns/agents/openai.yaml +7 -0
- package/assets/opencode/skills/benchmark/.openskills.json +7 -0
- package/assets/opencode/skills/benchmark/SKILL.md +93 -0
- package/assets/opencode/skills/bros-orchestrate/SKILL.md +455 -0
- package/assets/opencode/skills/browser-qa/.openskills.json +7 -0
- package/assets/opencode/skills/browser-qa/SKILL.md +87 -0
- package/assets/opencode/skills/canary-watch/.openskills.json +7 -0
- package/assets/opencode/skills/canary-watch/SKILL.md +107 -0
- package/assets/opencode/skills/code-review-expert/SKILL.md +155 -0
- package/assets/opencode/skills/code-review-expert/agents/agent.yaml +7 -0
- package/assets/opencode/skills/code-review-expert/references/code-quality-checklist.md +130 -0
- package/assets/opencode/skills/code-review-expert/references/removal-plan.md +52 -0
- package/assets/opencode/skills/code-review-expert/references/security-checklist.md +118 -0
- package/assets/opencode/skills/code-review-expert/references/solid-checklist.md +65 -0
- package/assets/opencode/skills/code-tour/.openskills.json +7 -0
- package/assets/opencode/skills/code-tour/SKILL.md +236 -0
- package/assets/opencode/skills/coding-standards/.openskills.json +7 -0
- package/assets/opencode/skills/coding-standards/SKILL.md +549 -0
- package/assets/opencode/skills/coding-standards/agents/openai.yaml +7 -0
- package/assets/opencode/skills/context-budget/.openskills.json +7 -0
- package/assets/opencode/skills/context-budget/SKILL.md +135 -0
- package/assets/opencode/skills/database-migrations/.openskills.json +7 -0
- package/assets/opencode/skills/database-migrations/SKILL.md +429 -0
- package/assets/opencode/skills/deployment-patterns/.openskills.json +7 -0
- package/assets/opencode/skills/deployment-patterns/SKILL.md +427 -0
- package/assets/opencode/skills/design-system/.openskills.json +7 -0
- package/assets/opencode/skills/design-system/SKILL.md +82 -0
- package/assets/opencode/skills/docker-patterns/.openskills.json +7 -0
- package/assets/opencode/skills/docker-patterns/SKILL.md +364 -0
- package/assets/opencode/skills/documentation-lookup/.openskills.json +7 -0
- package/assets/opencode/skills/documentation-lookup/SKILL.md +90 -0
- package/assets/opencode/skills/documentation-lookup/agents/openai.yaml +7 -0
- package/assets/opencode/skills/e2e-testing/.openskills.json +7 -0
- package/assets/opencode/skills/e2e-testing/SKILL.md +326 -0
- package/assets/opencode/skills/e2e-testing/agents/openai.yaml +7 -0
- package/assets/opencode/skills/error-handling/SKILL.md +376 -0
- package/assets/opencode/skills/frontend-design/.openskills.json +7 -0
- package/assets/opencode/skills/frontend-design/SKILL.md +145 -0
- package/assets/opencode/skills/frontend-design-direction/SKILL.md +92 -0
- package/assets/opencode/skills/frontend-patterns/.openskills.json +7 -0
- package/assets/opencode/skills/frontend-patterns/SKILL.md +642 -0
- package/assets/opencode/skills/frontend-patterns/agents/openai.yaml +7 -0
- package/assets/opencode/skills/gateguard/.openskills.json +7 -0
- package/assets/opencode/skills/gateguard/SKILL.md +125 -0
- package/assets/opencode/skills/git-master/SKILL.md +60 -0
- package/assets/opencode/skills/golang-patterns/.openskills.json +7 -0
- package/assets/opencode/skills/golang-patterns/SKILL.md +674 -0
- package/assets/opencode/skills/golang-testing/.openskills.json +7 -0
- package/assets/opencode/skills/golang-testing/SKILL.md +720 -0
- package/assets/opencode/skills/grafana-dashboard-design/SKILL.md +65 -0
- package/assets/opencode/skills/hexagonal-architecture/.openskills.json +7 -0
- package/assets/opencode/skills/hexagonal-architecture/SKILL.md +276 -0
- package/assets/opencode/skills/java-coding-standards/.openskills.json +7 -0
- package/assets/opencode/skills/java-coding-standards/SKILL.md +383 -0
- package/assets/opencode/skills/jpa-patterns/.openskills.json +7 -0
- package/assets/opencode/skills/jpa-patterns/SKILL.md +151 -0
- package/assets/opencode/skills/knowledge-ops/.openskills.json +7 -0
- package/assets/opencode/skills/knowledge-ops/SKILL.md +154 -0
- package/assets/opencode/skills/make-interfaces-feel-better/SKILL.md +151 -0
- package/assets/opencode/skills/mysql-patterns/SKILL.md +412 -0
- package/assets/opencode/skills/nestjs-patterns/.openskills.json +7 -0
- package/assets/opencode/skills/nestjs-patterns/SKILL.md +230 -0
- package/assets/opencode/skills/nextjs-turbopack/.openskills.json +7 -0
- package/assets/opencode/skills/nextjs-turbopack/SKILL.md +57 -0
- package/assets/opencode/skills/nextjs-turbopack/agents/openai.yaml +7 -0
- package/assets/opencode/skills/parallel-execution-optimizer/SKILL.md +72 -0
- package/assets/opencode/skills/postgres-patterns/.openskills.json +7 -0
- package/assets/opencode/skills/postgres-patterns/SKILL.md +147 -0
- package/assets/opencode/skills/prisma-patterns/SKILL.md +371 -0
- package/assets/opencode/skills/product-capability/.openskills.json +7 -0
- package/assets/opencode/skills/product-capability/SKILL.md +141 -0
- package/assets/opencode/skills/product-lens/.openskills.json +7 -0
- package/assets/opencode/skills/product-lens/SKILL.md +92 -0
- package/assets/opencode/skills/production-audit/SKILL.md +206 -0
- package/assets/opencode/skills/python-patterns/.openskills.json +7 -0
- package/assets/opencode/skills/python-patterns/SKILL.md +750 -0
- package/assets/opencode/skills/python-testing/.openskills.json +7 -0
- package/assets/opencode/skills/python-testing/SKILL.md +816 -0
- package/assets/opencode/skills/redis-patterns/SKILL.md +403 -0
- package/assets/opencode/skills/requirements-clarity/README.md +260 -0
- package/assets/opencode/skills/requirements-clarity/SKILL.md +324 -0
- package/assets/opencode/skills/rust-patterns/.openskills.json +7 -0
- package/assets/opencode/skills/rust-patterns/SKILL.md +499 -0
- package/assets/opencode/skills/rust-testing/.openskills.json +7 -0
- package/assets/opencode/skills/rust-testing/SKILL.md +500 -0
- package/assets/opencode/skills/safety-guard/.openskills.json +7 -0
- package/assets/opencode/skills/safety-guard/SKILL.md +75 -0
- package/assets/opencode/skills/search-first/.openskills.json +7 -0
- package/assets/opencode/skills/search-first/SKILL.md +181 -0
- package/assets/opencode/skills/security-review/.openskills.json +7 -0
- package/assets/opencode/skills/security-review/agents/openai.yaml +7 -0
- package/assets/opencode/skills/security-review/cloud-infrastructure-security.md +361 -0
- package/assets/opencode/skills/security-scan/.openskills.json +7 -0
- package/assets/opencode/skills/security-scan/SKILL.md +165 -0
- package/assets/opencode/skills/springboot-patterns/.openskills.json +7 -0
- package/assets/opencode/skills/springboot-patterns/SKILL.md +314 -0
- package/assets/opencode/skills/springboot-tdd/.openskills.json +7 -0
- package/assets/opencode/skills/springboot-tdd/SKILL.md +158 -0
- package/assets/opencode/skills/springboot-verification/.openskills.json +7 -0
- package/assets/opencode/skills/springboot-verification/SKILL.md +231 -0
- package/assets/opencode/skills/strategic-compact/.openskills.json +7 -0
- package/assets/opencode/skills/strategic-compact/SKILL.md +131 -0
- package/assets/opencode/skills/strategic-compact/agents/openai.yaml +7 -0
- package/assets/opencode/skills/strategic-compact/suggest-compact.sh +54 -0
- package/assets/opencode/skills/tdd-workflow/.openskills.json +7 -0
- package/assets/opencode/skills/tdd-workflow/SKILL.md +463 -0
- package/assets/opencode/skills/tdd-workflow/agents/openai.yaml +7 -0
- package/assets/opencode/skills/verification-loop/.openskills.json +7 -0
- package/assets/opencode/skills/verification-loop/SKILL.md +126 -0
- package/assets/opencode/skills/verification-loop/agents/openai.yaml +7 -0
- package/assets/opencode/skills/vite-patterns/SKILL.md +449 -0
- package/assets/opencode/skills/web-doc-search/SKILL.md +51 -0
- package/assets/opencode/templates/README.md +3 -0
- package/assets/opencode/templates/bros/adr.md +39 -0
- package/assets/opencode/templates/bros/delivery-report.md +71 -0
- package/assets/opencode/templates/bros/explorer-evidence-packet.md +51 -0
- package/assets/opencode/templates/bros/prd.md +72 -0
- package/assets/opencode/templates/bros/security-review.md +48 -0
- package/assets/opencode/templates/bros/status-board.md +33 -0
- package/assets/opencode/templates/bros/task-packet.md +94 -0
- package/assets/opencode/templates/bros/test-strategy.md +57 -0
- package/assets/opencode/templates/bros/ui-implementation-packet.md +64 -0
- package/assets/skills.manifest.json +650 -0
- package/assets/templates.manifest.json +55 -0
- package/bin/bros.mjs +122 -0
- package/docs/compatibility.md +9 -0
- package/docs/installation.md +66 -0
- package/docs/integrations/claude.md +5 -0
- package/docs/integrations/codex.md +5 -0
- package/docs/integrations/opencode.md +39 -0
- package/docs/migration/from-local-opencode-config.md +10 -0
- package/docs/release-process.md +11 -0
- package/docs/repository-structure.md +15 -0
- package/docs/roadmap.md +20 -0
- package/docs/security.md +18 -0
- package/docs/testing.md +9 -0
- package/examples/opencode/README.md +11 -0
- package/examples/opencode/opencode.example.jsonc +4 -0
- package/package.json +43 -0
- package/scripts/validate-assets.mjs +22 -0
- package/scripts/verify-no-secrets.mjs +38 -0
- package/src/plugin.mjs +98 -0
|
@@ -0,0 +1,549 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: coding-standards
|
|
3
|
+
description: Baseline cross-project coding conventions for naming, readability, immutability, and code-quality review. Use detailed frontend or backend skills for framework-specific patterns.
|
|
4
|
+
origin: ECC
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Coding Standards & Best Practices
|
|
8
|
+
|
|
9
|
+
Baseline coding conventions applicable across projects.
|
|
10
|
+
|
|
11
|
+
This skill is the shared floor, not the detailed framework playbook.
|
|
12
|
+
|
|
13
|
+
- Use `frontend-patterns` for React, state, forms, rendering, and UI architecture.
|
|
14
|
+
- Use `backend-patterns` or `api-design` for repository/service layers, endpoint design, validation, and server-specific concerns.
|
|
15
|
+
- Use `rules/common/coding-style.md` when you need the shortest reusable rule layer instead of a full skill walkthrough.
|
|
16
|
+
|
|
17
|
+
## When to Activate
|
|
18
|
+
|
|
19
|
+
- Starting a new project or module
|
|
20
|
+
- Reviewing code for quality and maintainability
|
|
21
|
+
- Refactoring existing code to follow conventions
|
|
22
|
+
- Enforcing naming, formatting, or structural consistency
|
|
23
|
+
- Setting up linting, formatting, or type-checking rules
|
|
24
|
+
- Onboarding new contributors to coding conventions
|
|
25
|
+
|
|
26
|
+
## Scope Boundaries
|
|
27
|
+
|
|
28
|
+
Activate this skill for:
|
|
29
|
+
- descriptive naming
|
|
30
|
+
- immutability defaults
|
|
31
|
+
- readability, KISS, DRY, and YAGNI enforcement
|
|
32
|
+
- error-handling expectations and code-smell review
|
|
33
|
+
|
|
34
|
+
Do not use this skill as the primary source for:
|
|
35
|
+
- React composition, hooks, or rendering patterns
|
|
36
|
+
- backend architecture, API design, or database layering
|
|
37
|
+
- domain-specific framework guidance when a narrower ECC skill already exists
|
|
38
|
+
|
|
39
|
+
## Code Quality Principles
|
|
40
|
+
|
|
41
|
+
### 1. Readability First
|
|
42
|
+
- Code is read more than written
|
|
43
|
+
- Clear variable and function names
|
|
44
|
+
- Self-documenting code preferred over comments
|
|
45
|
+
- Consistent formatting
|
|
46
|
+
|
|
47
|
+
### 2. KISS (Keep It Simple, Stupid)
|
|
48
|
+
- Simplest solution that works
|
|
49
|
+
- Avoid over-engineering
|
|
50
|
+
- No premature optimization
|
|
51
|
+
- Easy to understand > clever code
|
|
52
|
+
|
|
53
|
+
### 3. DRY (Don't Repeat Yourself)
|
|
54
|
+
- Extract common logic into functions
|
|
55
|
+
- Create reusable components
|
|
56
|
+
- Share utilities across modules
|
|
57
|
+
- Avoid copy-paste programming
|
|
58
|
+
|
|
59
|
+
### 4. YAGNI (You Aren't Gonna Need It)
|
|
60
|
+
- Don't build features before they're needed
|
|
61
|
+
- Avoid speculative generality
|
|
62
|
+
- Add complexity only when required
|
|
63
|
+
- Start simple, refactor when needed
|
|
64
|
+
|
|
65
|
+
## TypeScript/JavaScript Standards
|
|
66
|
+
|
|
67
|
+
### Variable Naming
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
// PASS: GOOD: Descriptive names
|
|
71
|
+
const marketSearchQuery = 'election'
|
|
72
|
+
const isUserAuthenticated = true
|
|
73
|
+
const totalRevenue = 1000
|
|
74
|
+
|
|
75
|
+
// FAIL: BAD: Unclear names
|
|
76
|
+
const q = 'election'
|
|
77
|
+
const flag = true
|
|
78
|
+
const x = 1000
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Function Naming
|
|
82
|
+
|
|
83
|
+
```typescript
|
|
84
|
+
// PASS: GOOD: Verb-noun pattern
|
|
85
|
+
async function fetchMarketData(marketId: string) { }
|
|
86
|
+
function calculateSimilarity(a: number[], b: number[]) { }
|
|
87
|
+
function isValidEmail(email: string): boolean { }
|
|
88
|
+
|
|
89
|
+
// FAIL: BAD: Unclear or noun-only
|
|
90
|
+
async function market(id: string) { }
|
|
91
|
+
function similarity(a, b) { }
|
|
92
|
+
function email(e) { }
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### Immutability Pattern (CRITICAL)
|
|
96
|
+
|
|
97
|
+
```typescript
|
|
98
|
+
// PASS: ALWAYS use spread operator
|
|
99
|
+
const updatedUser = {
|
|
100
|
+
...user,
|
|
101
|
+
name: 'New Name'
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const updatedArray = [...items, newItem]
|
|
105
|
+
|
|
106
|
+
// FAIL: NEVER mutate directly
|
|
107
|
+
user.name = 'New Name' // BAD
|
|
108
|
+
items.push(newItem) // BAD
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### Error Handling
|
|
112
|
+
|
|
113
|
+
```typescript
|
|
114
|
+
// PASS: GOOD: Comprehensive error handling
|
|
115
|
+
async function fetchData(url: string) {
|
|
116
|
+
try {
|
|
117
|
+
const response = await fetch(url)
|
|
118
|
+
|
|
119
|
+
if (!response.ok) {
|
|
120
|
+
throw new Error(`HTTP ${response.status}: ${response.statusText}`)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return await response.json()
|
|
124
|
+
} catch (error) {
|
|
125
|
+
console.error('Fetch failed:', error)
|
|
126
|
+
throw new Error('Failed to fetch data')
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// FAIL: BAD: No error handling
|
|
131
|
+
async function fetchData(url) {
|
|
132
|
+
const response = await fetch(url)
|
|
133
|
+
return response.json()
|
|
134
|
+
}
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### Async/Await Best Practices
|
|
138
|
+
|
|
139
|
+
```typescript
|
|
140
|
+
// PASS: GOOD: Parallel execution when possible
|
|
141
|
+
const [users, markets, stats] = await Promise.all([
|
|
142
|
+
fetchUsers(),
|
|
143
|
+
fetchMarkets(),
|
|
144
|
+
fetchStats()
|
|
145
|
+
])
|
|
146
|
+
|
|
147
|
+
// FAIL: BAD: Sequential when unnecessary
|
|
148
|
+
const users = await fetchUsers()
|
|
149
|
+
const markets = await fetchMarkets()
|
|
150
|
+
const stats = await fetchStats()
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### Type Safety
|
|
154
|
+
|
|
155
|
+
```typescript
|
|
156
|
+
// PASS: GOOD: Proper types
|
|
157
|
+
interface Market {
|
|
158
|
+
id: string
|
|
159
|
+
name: string
|
|
160
|
+
status: 'active' | 'resolved' | 'closed'
|
|
161
|
+
created_at: Date
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function getMarket(id: string): Promise<Market> {
|
|
165
|
+
// Implementation
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// FAIL: BAD: Using 'any'
|
|
169
|
+
function getMarket(id: any): Promise<any> {
|
|
170
|
+
// Implementation
|
|
171
|
+
}
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
## React Best Practices
|
|
175
|
+
|
|
176
|
+
### Component Structure
|
|
177
|
+
|
|
178
|
+
```typescript
|
|
179
|
+
// PASS: GOOD: Functional component with types
|
|
180
|
+
interface ButtonProps {
|
|
181
|
+
children: React.ReactNode
|
|
182
|
+
onClick: () => void
|
|
183
|
+
disabled?: boolean
|
|
184
|
+
variant?: 'primary' | 'secondary'
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export function Button({
|
|
188
|
+
children,
|
|
189
|
+
onClick,
|
|
190
|
+
disabled = false,
|
|
191
|
+
variant = 'primary'
|
|
192
|
+
}: ButtonProps) {
|
|
193
|
+
return (
|
|
194
|
+
<button
|
|
195
|
+
onClick={onClick}
|
|
196
|
+
disabled={disabled}
|
|
197
|
+
className={`btn btn-${variant}`}
|
|
198
|
+
>
|
|
199
|
+
{children}
|
|
200
|
+
</button>
|
|
201
|
+
)
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// FAIL: BAD: No types, unclear structure
|
|
205
|
+
export function Button(props) {
|
|
206
|
+
return <button onClick={props.onClick}>{props.children}</button>
|
|
207
|
+
}
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
### Custom Hooks
|
|
211
|
+
|
|
212
|
+
```typescript
|
|
213
|
+
// PASS: GOOD: Reusable custom hook
|
|
214
|
+
export function useDebounce<T>(value: T, delay: number): T {
|
|
215
|
+
const [debouncedValue, setDebouncedValue] = useState<T>(value)
|
|
216
|
+
|
|
217
|
+
useEffect(() => {
|
|
218
|
+
const handler = setTimeout(() => {
|
|
219
|
+
setDebouncedValue(value)
|
|
220
|
+
}, delay)
|
|
221
|
+
|
|
222
|
+
return () => clearTimeout(handler)
|
|
223
|
+
}, [value, delay])
|
|
224
|
+
|
|
225
|
+
return debouncedValue
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// Usage
|
|
229
|
+
const debouncedQuery = useDebounce(searchQuery, 500)
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
### State Management
|
|
233
|
+
|
|
234
|
+
```typescript
|
|
235
|
+
// PASS: GOOD: Proper state updates
|
|
236
|
+
const [count, setCount] = useState(0)
|
|
237
|
+
|
|
238
|
+
// Functional update for state based on previous state
|
|
239
|
+
setCount(prev => prev + 1)
|
|
240
|
+
|
|
241
|
+
// FAIL: BAD: Direct state reference
|
|
242
|
+
setCount(count + 1) // Can be stale in async scenarios
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
### Conditional Rendering
|
|
246
|
+
|
|
247
|
+
```typescript
|
|
248
|
+
// PASS: GOOD: Clear conditional rendering
|
|
249
|
+
{isLoading && <Spinner />}
|
|
250
|
+
{error && <ErrorMessage error={error} />}
|
|
251
|
+
{data && <DataDisplay data={data} />}
|
|
252
|
+
|
|
253
|
+
// FAIL: BAD: Ternary hell
|
|
254
|
+
{isLoading ? <Spinner /> : error ? <ErrorMessage error={error} /> : data ? <DataDisplay data={data} /> : null}
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
## API Design Standards
|
|
258
|
+
|
|
259
|
+
### REST API Conventions
|
|
260
|
+
|
|
261
|
+
```
|
|
262
|
+
GET /api/markets # List all markets
|
|
263
|
+
GET /api/markets/:id # Get specific market
|
|
264
|
+
POST /api/markets # Create new market
|
|
265
|
+
PUT /api/markets/:id # Update market (full)
|
|
266
|
+
PATCH /api/markets/:id # Update market (partial)
|
|
267
|
+
DELETE /api/markets/:id # Delete market
|
|
268
|
+
|
|
269
|
+
# Query parameters for filtering
|
|
270
|
+
GET /api/markets?status=active&limit=10&offset=0
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
### Response Format
|
|
274
|
+
|
|
275
|
+
```typescript
|
|
276
|
+
// PASS: GOOD: Consistent response structure
|
|
277
|
+
interface ApiResponse<T> {
|
|
278
|
+
success: boolean
|
|
279
|
+
data?: T
|
|
280
|
+
error?: string
|
|
281
|
+
meta?: {
|
|
282
|
+
total: number
|
|
283
|
+
page: number
|
|
284
|
+
limit: number
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// Success response
|
|
289
|
+
return NextResponse.json({
|
|
290
|
+
success: true,
|
|
291
|
+
data: markets,
|
|
292
|
+
meta: { total: 100, page: 1, limit: 10 }
|
|
293
|
+
})
|
|
294
|
+
|
|
295
|
+
// Error response
|
|
296
|
+
return NextResponse.json({
|
|
297
|
+
success: false,
|
|
298
|
+
error: 'Invalid request'
|
|
299
|
+
}, { status: 400 })
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
### Input Validation
|
|
303
|
+
|
|
304
|
+
```typescript
|
|
305
|
+
import { z } from 'zod'
|
|
306
|
+
|
|
307
|
+
// PASS: GOOD: Schema validation
|
|
308
|
+
const CreateMarketSchema = z.object({
|
|
309
|
+
name: z.string().min(1).max(200),
|
|
310
|
+
description: z.string().min(1).max(2000),
|
|
311
|
+
endDate: z.string().datetime(),
|
|
312
|
+
categories: z.array(z.string()).min(1)
|
|
313
|
+
})
|
|
314
|
+
|
|
315
|
+
export async function POST(request: Request) {
|
|
316
|
+
const body = await request.json()
|
|
317
|
+
|
|
318
|
+
try {
|
|
319
|
+
const validated = CreateMarketSchema.parse(body)
|
|
320
|
+
// Proceed with validated data
|
|
321
|
+
} catch (error) {
|
|
322
|
+
if (error instanceof z.ZodError) {
|
|
323
|
+
return NextResponse.json({
|
|
324
|
+
success: false,
|
|
325
|
+
error: 'Validation failed',
|
|
326
|
+
details: error.errors
|
|
327
|
+
}, { status: 400 })
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
## File Organization
|
|
334
|
+
|
|
335
|
+
### Project Structure
|
|
336
|
+
|
|
337
|
+
```
|
|
338
|
+
src/
|
|
339
|
+
├── app/ # Next.js App Router
|
|
340
|
+
│ ├── api/ # API routes
|
|
341
|
+
│ ├── markets/ # Market pages
|
|
342
|
+
│ └── (auth)/ # Auth pages (route groups)
|
|
343
|
+
├── components/ # React components
|
|
344
|
+
│ ├── ui/ # Generic UI components
|
|
345
|
+
│ ├── forms/ # Form components
|
|
346
|
+
│ └── layouts/ # Layout components
|
|
347
|
+
├── hooks/ # Custom React hooks
|
|
348
|
+
├── lib/ # Utilities and configs
|
|
349
|
+
│ ├── api/ # API clients
|
|
350
|
+
│ ├── utils/ # Helper functions
|
|
351
|
+
│ └── constants/ # Constants
|
|
352
|
+
├── types/ # TypeScript types
|
|
353
|
+
└── styles/ # Global styles
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
### File Naming
|
|
357
|
+
|
|
358
|
+
```
|
|
359
|
+
components/Button.tsx # PascalCase for components
|
|
360
|
+
hooks/useAuth.ts # camelCase with 'use' prefix
|
|
361
|
+
lib/formatDate.ts # camelCase for utilities
|
|
362
|
+
types/market.types.ts # camelCase with .types suffix
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
## Comments & Documentation
|
|
366
|
+
|
|
367
|
+
### When to Comment
|
|
368
|
+
|
|
369
|
+
```typescript
|
|
370
|
+
// PASS: GOOD: Explain WHY, not WHAT
|
|
371
|
+
// Use exponential backoff to avoid overwhelming the API during outages
|
|
372
|
+
const delay = Math.min(1000 * Math.pow(2, retryCount), 30000)
|
|
373
|
+
|
|
374
|
+
// Deliberately using mutation here for performance with large arrays
|
|
375
|
+
items.push(newItem)
|
|
376
|
+
|
|
377
|
+
// FAIL: BAD: Stating the obvious
|
|
378
|
+
// Increment counter by 1
|
|
379
|
+
count++
|
|
380
|
+
|
|
381
|
+
// Set name to user's name
|
|
382
|
+
name = user.name
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
### JSDoc for Public APIs
|
|
386
|
+
|
|
387
|
+
```typescript
|
|
388
|
+
/**
|
|
389
|
+
* Searches markets using semantic similarity.
|
|
390
|
+
*
|
|
391
|
+
* @param query - Natural language search query
|
|
392
|
+
* @param limit - Maximum number of results (default: 10)
|
|
393
|
+
* @returns Array of markets sorted by similarity score
|
|
394
|
+
* @throws {Error} If OpenAI API fails or Redis unavailable
|
|
395
|
+
*
|
|
396
|
+
* @example
|
|
397
|
+
* ```typescript
|
|
398
|
+
* const results = await searchMarkets('election', 5)
|
|
399
|
+
* console.log(results[0].name) // "Trump vs Biden"
|
|
400
|
+
* ```
|
|
401
|
+
*/
|
|
402
|
+
export async function searchMarkets(
|
|
403
|
+
query: string,
|
|
404
|
+
limit: number = 10
|
|
405
|
+
): Promise<Market[]> {
|
|
406
|
+
// Implementation
|
|
407
|
+
}
|
|
408
|
+
```
|
|
409
|
+
|
|
410
|
+
## Performance Best Practices
|
|
411
|
+
|
|
412
|
+
### Memoization
|
|
413
|
+
|
|
414
|
+
```typescript
|
|
415
|
+
import { useMemo, useCallback } from 'react'
|
|
416
|
+
|
|
417
|
+
// PASS: GOOD: Memoize expensive computations
|
|
418
|
+
const sortedMarkets = useMemo(() => {
|
|
419
|
+
return markets.sort((a, b) => b.volume - a.volume)
|
|
420
|
+
}, [markets])
|
|
421
|
+
|
|
422
|
+
// PASS: GOOD: Memoize callbacks
|
|
423
|
+
const handleSearch = useCallback((query: string) => {
|
|
424
|
+
setSearchQuery(query)
|
|
425
|
+
}, [])
|
|
426
|
+
```
|
|
427
|
+
|
|
428
|
+
### Lazy Loading
|
|
429
|
+
|
|
430
|
+
```typescript
|
|
431
|
+
import { lazy, Suspense } from 'react'
|
|
432
|
+
|
|
433
|
+
// PASS: GOOD: Lazy load heavy components
|
|
434
|
+
const HeavyChart = lazy(() => import('./HeavyChart'))
|
|
435
|
+
|
|
436
|
+
export function Dashboard() {
|
|
437
|
+
return (
|
|
438
|
+
<Suspense fallback={<Spinner />}>
|
|
439
|
+
<HeavyChart />
|
|
440
|
+
</Suspense>
|
|
441
|
+
)
|
|
442
|
+
}
|
|
443
|
+
```
|
|
444
|
+
|
|
445
|
+
### Database Queries
|
|
446
|
+
|
|
447
|
+
```typescript
|
|
448
|
+
// PASS: GOOD: Select only needed columns
|
|
449
|
+
const { data } = await supabase
|
|
450
|
+
.from('markets')
|
|
451
|
+
.select('id, name, status')
|
|
452
|
+
.limit(10)
|
|
453
|
+
|
|
454
|
+
// FAIL: BAD: Select everything
|
|
455
|
+
const { data } = await supabase
|
|
456
|
+
.from('markets')
|
|
457
|
+
.select('*')
|
|
458
|
+
```
|
|
459
|
+
|
|
460
|
+
## Testing Standards
|
|
461
|
+
|
|
462
|
+
### Test Structure (AAA Pattern)
|
|
463
|
+
|
|
464
|
+
```typescript
|
|
465
|
+
test('calculates similarity correctly', () => {
|
|
466
|
+
// Arrange
|
|
467
|
+
const vector1 = [1, 0, 0]
|
|
468
|
+
const vector2 = [0, 1, 0]
|
|
469
|
+
|
|
470
|
+
// Act
|
|
471
|
+
const similarity = calculateCosineSimilarity(vector1, vector2)
|
|
472
|
+
|
|
473
|
+
// Assert
|
|
474
|
+
expect(similarity).toBe(0)
|
|
475
|
+
})
|
|
476
|
+
```
|
|
477
|
+
|
|
478
|
+
### Test Naming
|
|
479
|
+
|
|
480
|
+
```typescript
|
|
481
|
+
// PASS: GOOD: Descriptive test names
|
|
482
|
+
test('returns empty array when no markets match query', () => { })
|
|
483
|
+
test('throws error when OpenAI API key is missing', () => { })
|
|
484
|
+
test('falls back to substring search when Redis unavailable', () => { })
|
|
485
|
+
|
|
486
|
+
// FAIL: BAD: Vague test names
|
|
487
|
+
test('works', () => { })
|
|
488
|
+
test('test search', () => { })
|
|
489
|
+
```
|
|
490
|
+
|
|
491
|
+
## Code Smell Detection
|
|
492
|
+
|
|
493
|
+
Watch for these anti-patterns:
|
|
494
|
+
|
|
495
|
+
### 1. Long Functions
|
|
496
|
+
```typescript
|
|
497
|
+
// FAIL: BAD: Function > 50 lines
|
|
498
|
+
function processMarketData() {
|
|
499
|
+
// 100 lines of code
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
// PASS: GOOD: Split into smaller functions
|
|
503
|
+
function processMarketData() {
|
|
504
|
+
const validated = validateData()
|
|
505
|
+
const transformed = transformData(validated)
|
|
506
|
+
return saveData(transformed)
|
|
507
|
+
}
|
|
508
|
+
```
|
|
509
|
+
|
|
510
|
+
### 2. Deep Nesting
|
|
511
|
+
```typescript
|
|
512
|
+
// FAIL: BAD: 5+ levels of nesting
|
|
513
|
+
if (user) {
|
|
514
|
+
if (user.isAdmin) {
|
|
515
|
+
if (market) {
|
|
516
|
+
if (market.isActive) {
|
|
517
|
+
if (hasPermission) {
|
|
518
|
+
// Do something
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
// PASS: GOOD: Early returns
|
|
526
|
+
if (!user) return
|
|
527
|
+
if (!user.isAdmin) return
|
|
528
|
+
if (!market) return
|
|
529
|
+
if (!market.isActive) return
|
|
530
|
+
if (!hasPermission) return
|
|
531
|
+
|
|
532
|
+
// Do something
|
|
533
|
+
```
|
|
534
|
+
|
|
535
|
+
### 3. Magic Numbers
|
|
536
|
+
```typescript
|
|
537
|
+
// FAIL: BAD: Unexplained numbers
|
|
538
|
+
if (retryCount > 3) { }
|
|
539
|
+
setTimeout(callback, 500)
|
|
540
|
+
|
|
541
|
+
// PASS: GOOD: Named constants
|
|
542
|
+
const MAX_RETRIES = 3
|
|
543
|
+
const DEBOUNCE_DELAY_MS = 500
|
|
544
|
+
|
|
545
|
+
if (retryCount > MAX_RETRIES) { }
|
|
546
|
+
setTimeout(callback, DEBOUNCE_DELAY_MS)
|
|
547
|
+
```
|
|
548
|
+
|
|
549
|
+
**Remember**: Code quality is not negotiable. Clear, maintainable code enables rapid development and confident refactoring.
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: context-budget
|
|
3
|
+
description: Audits Claude Code context window consumption across agents, skills, MCP servers, and rules. Identifies bloat, redundant components, and produces prioritized token-savings recommendations.
|
|
4
|
+
origin: ECC
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Context Budget
|
|
8
|
+
|
|
9
|
+
Analyze token overhead across every loaded component in a Claude Code session and surface actionable optimizations to reclaim context space.
|
|
10
|
+
|
|
11
|
+
## When to Use
|
|
12
|
+
|
|
13
|
+
- Session performance feels sluggish or output quality is degrading
|
|
14
|
+
- You've recently added many skills, agents, or MCP servers
|
|
15
|
+
- You want to know how much context headroom you actually have
|
|
16
|
+
- Planning to add more components and need to know if there's room
|
|
17
|
+
- Running `/context-budget` command (this skill backs it)
|
|
18
|
+
|
|
19
|
+
## How It Works
|
|
20
|
+
|
|
21
|
+
### Phase 1: Inventory
|
|
22
|
+
|
|
23
|
+
Scan all component directories and estimate token consumption:
|
|
24
|
+
|
|
25
|
+
**Agents** (`agents/*.md`)
|
|
26
|
+
- Count lines and tokens per file (words × 1.3)
|
|
27
|
+
- Extract `description` frontmatter length
|
|
28
|
+
- Flag: files >200 lines (heavy), description >30 words (bloated frontmatter)
|
|
29
|
+
|
|
30
|
+
**Skills** (`skills/*/SKILL.md`)
|
|
31
|
+
- Count tokens per SKILL.md
|
|
32
|
+
- Flag: files >400 lines
|
|
33
|
+
- Check for duplicate copies in `.agents/skills/` — skip identical copies to avoid double-counting
|
|
34
|
+
|
|
35
|
+
**Rules** (`rules/**/*.md`)
|
|
36
|
+
- Count tokens per file
|
|
37
|
+
- Flag: files >100 lines
|
|
38
|
+
- Detect content overlap between rule files in the same language module
|
|
39
|
+
|
|
40
|
+
**MCP Servers** (`.mcp.json` or active MCP config)
|
|
41
|
+
- Count configured servers and total tool count
|
|
42
|
+
- Estimate schema overhead at ~500 tokens per tool
|
|
43
|
+
- Flag: servers with >20 tools, servers that wrap simple CLI commands (`gh`, `git`, `npm`, `supabase`, `vercel`)
|
|
44
|
+
|
|
45
|
+
**CLAUDE.md** (project + user-level)
|
|
46
|
+
- Count tokens per file in the CLAUDE.md chain
|
|
47
|
+
- Flag: combined total >300 lines
|
|
48
|
+
|
|
49
|
+
### Phase 2: Classify
|
|
50
|
+
|
|
51
|
+
Sort every component into a bucket:
|
|
52
|
+
|
|
53
|
+
| Bucket | Criteria | Action |
|
|
54
|
+
|--------|----------|--------|
|
|
55
|
+
| **Always needed** | Referenced in CLAUDE.md, backs an active command, or matches current project type | Keep |
|
|
56
|
+
| **Sometimes needed** | Domain-specific (e.g. language patterns), not referenced in CLAUDE.md | Consider on-demand activation |
|
|
57
|
+
| **Rarely needed** | No command reference, overlapping content, or no obvious project match | Remove or lazy-load |
|
|
58
|
+
|
|
59
|
+
### Phase 3: Detect Issues
|
|
60
|
+
|
|
61
|
+
Identify the following problem patterns:
|
|
62
|
+
|
|
63
|
+
- **Bloated agent descriptions** — description >30 words in frontmatter loads into every Task tool invocation
|
|
64
|
+
- **Heavy agents** — files >200 lines inflate Task tool context on every spawn
|
|
65
|
+
- **Redundant components** — skills that duplicate agent logic, rules that duplicate CLAUDE.md
|
|
66
|
+
- **MCP over-subscription** — >10 servers, or servers wrapping CLI tools available for free
|
|
67
|
+
- **CLAUDE.md bloat** — verbose explanations, outdated sections, instructions that should be rules
|
|
68
|
+
|
|
69
|
+
### Phase 4: Report
|
|
70
|
+
|
|
71
|
+
Produce the context budget report:
|
|
72
|
+
|
|
73
|
+
```
|
|
74
|
+
Context Budget Report
|
|
75
|
+
═══════════════════════════════════════
|
|
76
|
+
|
|
77
|
+
Total estimated overhead: ~XX,XXX tokens
|
|
78
|
+
Context model: Claude Sonnet (200K window)
|
|
79
|
+
Effective available context: ~XXX,XXX tokens (XX%)
|
|
80
|
+
|
|
81
|
+
Component Breakdown:
|
|
82
|
+
┌─────────────────┬────────┬───────────┐
|
|
83
|
+
│ Component │ Count │ Tokens │
|
|
84
|
+
├─────────────────┼────────┼───────────┤
|
|
85
|
+
│ Agents │ N │ ~X,XXX │
|
|
86
|
+
│ Skills │ N │ ~X,XXX │
|
|
87
|
+
│ Rules │ N │ ~X,XXX │
|
|
88
|
+
│ MCP tools │ N │ ~XX,XXX │
|
|
89
|
+
│ CLAUDE.md │ N │ ~X,XXX │
|
|
90
|
+
└─────────────────┴────────┴───────────┘
|
|
91
|
+
|
|
92
|
+
WARNING: Issues Found (N):
|
|
93
|
+
[ranked by token savings]
|
|
94
|
+
|
|
95
|
+
Top 3 Optimizations:
|
|
96
|
+
1. [action] → save ~X,XXX tokens
|
|
97
|
+
2. [action] → save ~X,XXX tokens
|
|
98
|
+
3. [action] → save ~X,XXX tokens
|
|
99
|
+
|
|
100
|
+
Potential savings: ~XX,XXX tokens (XX% of current overhead)
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
In verbose mode, additionally output per-file token counts, line-by-line breakdown of the heaviest files, specific redundant lines between overlapping components, and MCP tool list with per-tool schema size estimates.
|
|
104
|
+
|
|
105
|
+
## Examples
|
|
106
|
+
|
|
107
|
+
**Basic audit**
|
|
108
|
+
```
|
|
109
|
+
User: /context-budget
|
|
110
|
+
Skill: Scans setup → 16 agents (12,400 tokens), 28 skills (6,200), 87 MCP tools (43,500), 2 CLAUDE.md (1,200)
|
|
111
|
+
Flags: 3 heavy agents, 14 MCP servers (3 CLI-replaceable)
|
|
112
|
+
Top saving: remove 3 MCP servers → -27,500 tokens (47% overhead reduction)
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
**Verbose mode**
|
|
116
|
+
```
|
|
117
|
+
User: /context-budget --verbose
|
|
118
|
+
Skill: Full report + per-file breakdown showing planner.md (213 lines, 1,840 tokens),
|
|
119
|
+
MCP tool list with per-tool sizes, duplicated rule lines side by side
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
**Pre-expansion check**
|
|
123
|
+
```
|
|
124
|
+
User: I want to add 5 more MCP servers, do I have room?
|
|
125
|
+
Skill: Current overhead 33% → adding 5 servers (~50 tools) would add ~25,000 tokens → pushes to 45% overhead
|
|
126
|
+
Recommendation: remove 2 CLI-replaceable servers first to stay under 40%
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## Best Practices
|
|
130
|
+
|
|
131
|
+
- **Token estimation**: use `words × 1.3` for prose, `chars / 4` for code-heavy files
|
|
132
|
+
- **MCP is the biggest lever**: each tool schema costs ~500 tokens; a 30-tool server costs more than all your skills combined
|
|
133
|
+
- **Agent descriptions are loaded always**: even if the agent is never invoked, its description field is present in every Task tool context
|
|
134
|
+
- **Verbose mode for debugging**: use when you need to pinpoint the exact files driving overhead, not for regular audits
|
|
135
|
+
- **Audit after changes**: run after adding any agent, skill, or MCP server to catch creep early
|