devtronic 1.0.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 +61 -0
- package/dist/chunk-B6Q6YVID.js +728 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +4214 -0
- package/dist/plugin-JTDPHWUF.js +18 -0
- package/package.json +70 -0
- package/templates/antigravity/.agents/rules/architecture.md +31 -0
- package/templates/antigravity/.agents/rules/quality.md +44 -0
- package/templates/claude-code/.claude/agents/architecture-checker.md +142 -0
- package/templates/claude-code/.claude/agents/code-reviewer.md +73 -0
- package/templates/claude-code/.claude/agents/commit-changes.md +74 -0
- package/templates/claude-code/.claude/agents/dependency-checker.md +112 -0
- package/templates/claude-code/.claude/agents/doc-sync.md +99 -0
- package/templates/claude-code/.claude/agents/error-investigator.md +142 -0
- package/templates/claude-code/.claude/agents/quality-runner.md +123 -0
- package/templates/claude-code/.claude/agents/test-generator.md +114 -0
- package/templates/claude-code/.claude/rules/architecture.md +257 -0
- package/templates/claude-code/.claude/rules/quality.md +103 -0
- package/templates/claude-code/.claude/skills/audit/SKILL.md +426 -0
- package/templates/claude-code/.claude/skills/audit/report-template.md +137 -0
- package/templates/claude-code/.claude/skills/backlog/SKILL.md +231 -0
- package/templates/claude-code/.claude/skills/brief/SKILL.md +425 -0
- package/templates/claude-code/.claude/skills/briefing/SKILL.md +172 -0
- package/templates/claude-code/.claude/skills/checkpoint/SKILL.md +284 -0
- package/templates/claude-code/.claude/skills/create-plan/SKILL.md +446 -0
- package/templates/claude-code/.claude/skills/create-skill/SKILL.md +245 -0
- package/templates/claude-code/.claude/skills/execute-plan/SKILL.md +398 -0
- package/templates/claude-code/.claude/skills/generate-tests/SKILL.md +358 -0
- package/templates/claude-code/.claude/skills/generate-tests/test-patterns.md +349 -0
- package/templates/claude-code/.claude/skills/handoff/SKILL.md +178 -0
- package/templates/claude-code/.claude/skills/investigate/SKILL.md +376 -0
- package/templates/claude-code/.claude/skills/learn/SKILL.md +231 -0
- package/templates/claude-code/.claude/skills/opensrc/SKILL.md +104 -0
- package/templates/claude-code/.claude/skills/post-review/SKILL.md +437 -0
- package/templates/claude-code/.claude/skills/quick/SKILL.md +188 -0
- package/templates/claude-code/.claude/skills/recap/SKILL.md +190 -0
- package/templates/claude-code/.claude/skills/research/SKILL.md +450 -0
- package/templates/claude-code/.claude/skills/scaffold/SKILL.md +281 -0
- package/templates/claude-code/.claude/skills/scaffold/bootstrap-commands.md +104 -0
- package/templates/claude-code/.claude/skills/scaffold/examples-backend.md +105 -0
- package/templates/claude-code/.claude/skills/scaffold/examples-frontend.md +197 -0
- package/templates/claude-code/.claude/skills/scaffold/examples-spa-ddd.md +667 -0
- package/templates/claude-code/.claude/skills/scaffold/structures.md +236 -0
- package/templates/claude-code/.claude/skills/setup/SKILL.md +227 -0
- package/templates/claude-code/.claude/skills/spec/SKILL.md +235 -0
- package/templates/claude-code/.claude/skills/summary/SKILL.md +279 -0
- package/templates/claude-code/.claude/skills/worktree/SKILL.md +266 -0
- package/templates/cursor/.cursor/rules/architecture.mdc +36 -0
- package/templates/cursor/.cursor/rules/quality.mdc +49 -0
- package/templates/github-copilot/.github/copilot-instructions.md +40 -0
- package/templates/opencode/.opencode/rules/architecture.md +31 -0
- package/templates/opencode/.opencode/rules/quality.md +44 -0
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# Code Quality Checks
|
|
2
|
+
|
|
3
|
+
After implementing a new feature or modifying existing code, **always run the following checks** before considering the task complete.
|
|
4
|
+
|
|
5
|
+
## Package Manager Detection
|
|
6
|
+
|
|
7
|
+
Before running any commands, detect the project's package manager by checking for lockfiles:
|
|
8
|
+
- `pnpm-lock.yaml` → Use `pnpm`
|
|
9
|
+
- `yarn.lock` → Use `yarn`
|
|
10
|
+
- `bun.lockb` → Use `bun`
|
|
11
|
+
- `package-lock.json` or none → Use `npm`
|
|
12
|
+
|
|
13
|
+
Use the detected PM for all commands below (examples show npm but adapt accordingly).
|
|
14
|
+
|
|
15
|
+
## Required Validation Steps
|
|
16
|
+
|
|
17
|
+
### 1. Type Checking
|
|
18
|
+
|
|
19
|
+
<!-- CUSTOMIZE: Update command for your project -->
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm run typecheck
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
- Fix any type errors before proceeding
|
|
26
|
+
- Do not use `any` to bypass errors—find the correct type
|
|
27
|
+
|
|
28
|
+
### 2. Linting
|
|
29
|
+
|
|
30
|
+
<!-- CUSTOMIZE: Update command for your project -->
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
npm run lint
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
- Fix all linting errors and warnings
|
|
37
|
+
- Use `npm run lint:fix` for auto-fixable issues
|
|
38
|
+
- For unused variables that are intentional (destructuring), prefix with `_`
|
|
39
|
+
|
|
40
|
+
### 3. Formatting
|
|
41
|
+
|
|
42
|
+
<!-- CUSTOMIZE: Update command for your project -->
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
npm run format
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
- Run this to ensure consistent code style
|
|
49
|
+
- Use `npm run format:check` to verify without modifying
|
|
50
|
+
|
|
51
|
+
## Order of Operations
|
|
52
|
+
|
|
53
|
+
```
|
|
54
|
+
1. typecheck → catches type errors early
|
|
55
|
+
2. lint → enforces code quality rules
|
|
56
|
+
3. format → ensures consistent styling
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Quick Reference
|
|
60
|
+
|
|
61
|
+
<!-- CUSTOMIZE: Update for your project -->
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
# All checks in sequence
|
|
65
|
+
npm run typecheck && npm run lint && npm run format
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## When to Skip
|
|
69
|
+
|
|
70
|
+
Only skip these checks if:
|
|
71
|
+
- The user explicitly says the change is WIP/draft
|
|
72
|
+
- The user specifically asks to skip validation
|
|
73
|
+
|
|
74
|
+
## Project-Specific Checks
|
|
75
|
+
|
|
76
|
+
<!-- CUSTOMIZE: Add checks specific to your project -->
|
|
77
|
+
|
|
78
|
+
Examples to add:
|
|
79
|
+
- i18n consistency: `npm run i18n:check`
|
|
80
|
+
- Database migrations: `npm run db:check`
|
|
81
|
+
- API schema: `npm run api:validate`
|
|
82
|
+
- Bundle size: `npm run analyze`
|
|
83
|
+
|
|
84
|
+
## Pre-Commit Hook (Recommended)
|
|
85
|
+
|
|
86
|
+
Consider adding a pre-commit hook to automate these checks:
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
# Using husky + lint-staged
|
|
90
|
+
npx husky install
|
|
91
|
+
npm pkg set scripts.prepare="husky install"
|
|
92
|
+
npx husky add .husky/pre-commit "npx lint-staged"
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
```json
|
|
96
|
+
// package.json
|
|
97
|
+
{
|
|
98
|
+
"lint-staged": {
|
|
99
|
+
"*.{ts,tsx}": ["eslint --fix", "prettier --write"],
|
|
100
|
+
"*.{json,md}": ["prettier --write"]
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
```
|
|
@@ -0,0 +1,426 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: audit
|
|
3
|
+
description: "Comprehensive codebase audit (SonarQube lite): architecture, code smells, complexity, security, coverage, and technical debt."
|
|
4
|
+
allowed-tools: Read, Grep, Glob, Bash, Task, Write, AskUserQuestion
|
|
5
|
+
argument-hint: "[--architecture|--code|--complexity|--security|--quick|directory]"
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Audit - Comprehensive Codebase Scanner
|
|
9
|
+
|
|
10
|
+
One-stop skill for auditing codebase health: architecture, code quality, code smells, complexity, security, test coverage, and technical debt. Parse `$ARGUMENTS` for mode flags (--architecture, --code, --complexity, --security, --quick) or a specific directory to scope the audit.
|
|
11
|
+
|
|
12
|
+
## Modes
|
|
13
|
+
|
|
14
|
+
| Mode | Command | What it checks |
|
|
15
|
+
|------|---------|----------------|
|
|
16
|
+
| **Full** | `/audit` | Everything (architecture + code + smells + complexity + security + coverage) |
|
|
17
|
+
| **Architecture** | `/audit --architecture` | Layer violations, dependency direction |
|
|
18
|
+
| **Code** | `/audit --code` | TODOs, unused code, duplicates, consistency, code smells |
|
|
19
|
+
| **Complexity** | `/audit --complexity` | Cyclomatic + cognitive complexity per function |
|
|
20
|
+
| **Security** | `/audit --security` | Secrets, vulnerable deps, OWASP basics |
|
|
21
|
+
| **Quick** | `/audit --quick` | Critical issues only + functions >20 complexity + god files >800 lines (fast) |
|
|
22
|
+
| **Scoped** | `/audit src/features/auth` | Audit specific directory only |
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## When to Use
|
|
27
|
+
|
|
28
|
+
- Periodically (weekly/monthly) to maintain codebase health
|
|
29
|
+
- Before major refactoring
|
|
30
|
+
- Before releases
|
|
31
|
+
- Onboarding to assess codebase quality
|
|
32
|
+
- After rapid development sprints
|
|
33
|
+
|
|
34
|
+
**Different from `/post-review`**: That checks recent changes only. This scans the full codebase.
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
## Full Audit Workflow
|
|
39
|
+
|
|
40
|
+
```
|
|
41
|
+
┌─────────────────────────────────────────────────────────────────┐
|
|
42
|
+
│ FULL AUDIT WORKFLOW │
|
|
43
|
+
├─────────────────────────────────────────────────────────────────┤
|
|
44
|
+
│ │
|
|
45
|
+
│ 1. DETECT ARCHITECTURE │
|
|
46
|
+
│ └── Read docs/ARCHITECTURE.md or auto-detect │
|
|
47
|
+
│ └── Detect PM (lockfiles), find coverage reports │
|
|
48
|
+
│ │
|
|
49
|
+
│ 2. PARALLEL SCANS (5 Task agents) │
|
|
50
|
+
│ ├── A: Architecture violations │
|
|
51
|
+
│ ├── B: Code quality grep (TODOs, console.logs, commented) │
|
|
52
|
+
│ ├── C: Code smells + duplication (file analysis) │
|
|
53
|
+
│ ├── D: Complexity analysis (per directory) │
|
|
54
|
+
│ └── E: Security checks │
|
|
55
|
+
│ │
|
|
56
|
+
│ 3. COVERAGE INTEGRATION │
|
|
57
|
+
│ └── Parse coverage report if exists │
|
|
58
|
+
│ │
|
|
59
|
+
│ 4. ANALYZE & CATEGORIZE │
|
|
60
|
+
│ └── Critical > Major > Minor │
|
|
61
|
+
│ │
|
|
62
|
+
│ 5. CALCULATE TECHNICAL DEBT │
|
|
63
|
+
│ └── Hours estimate per severity │
|
|
64
|
+
│ │
|
|
65
|
+
│ 6. GENERATE REPORT │
|
|
66
|
+
│ └── Save to thoughts/audit/YYYY-MM-DD_audit.md │
|
|
67
|
+
│ │
|
|
68
|
+
│ 7. CALCULATE HEALTH SCORE │
|
|
69
|
+
│ └── 0-100 rating (with complexity + coverage penalties) │
|
|
70
|
+
│ │
|
|
71
|
+
└─────────────────────────────────────────────────────────────────┘
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
---
|
|
75
|
+
|
|
76
|
+
## Architecture Audit (`--architecture`)
|
|
77
|
+
|
|
78
|
+
### What It Checks
|
|
79
|
+
|
|
80
|
+
| Violation | Example | Severity |
|
|
81
|
+
|-----------|---------|----------|
|
|
82
|
+
| Domain importing infrastructure | `@prisma/client` in domain | Critical |
|
|
83
|
+
| UI accessing database | Component importing DB client | Critical |
|
|
84
|
+
| Application importing presentation | Use case importing React | Major |
|
|
85
|
+
| Business logic in API routes | Complex validation in route | Major |
|
|
86
|
+
| Wrong dependency direction | Infrastructure -> Presentation | Major |
|
|
87
|
+
|
|
88
|
+
### Detection Rules by Pattern
|
|
89
|
+
|
|
90
|
+
| Pattern | Indicators | Layer Rules |
|
|
91
|
+
|---------|------------|-------------|
|
|
92
|
+
| **clean** | `src/domain`, `src/application`, `src/infrastructure` | Domain -> nothing, App -> Domain, Infra -> Domain+App |
|
|
93
|
+
| **feature-based** | `src/features/*/domain` | Same as clean, per feature |
|
|
94
|
+
| **mvc** | `src/models`, `src/views`, `src/controllers` | Models -> nothing |
|
|
95
|
+
|
|
96
|
+
### Parallel Scans
|
|
97
|
+
|
|
98
|
+
Launch 4 Explore agents simultaneously:
|
|
99
|
+
|
|
100
|
+
1. **Domain Layer**: Check for infrastructure/presentation imports
|
|
101
|
+
2. **Application Layer**: Check for presentation imports
|
|
102
|
+
3. **Presentation Layer**: Check for direct DB access
|
|
103
|
+
4. **Business Logic**: Find misplaced logic in routes/components
|
|
104
|
+
|
|
105
|
+
---
|
|
106
|
+
|
|
107
|
+
## Code Quality Audit (`--code`)
|
|
108
|
+
|
|
109
|
+
### What It Checks
|
|
110
|
+
|
|
111
|
+
| Issue | How Detected | Severity |
|
|
112
|
+
|-------|--------------|----------|
|
|
113
|
+
| FIXME/HACK comments | Grep | Critical |
|
|
114
|
+
| TODO comments | Grep | Normal |
|
|
115
|
+
| Unused imports | Lint/Grep | Minor |
|
|
116
|
+
| Console.logs | Grep | Minor |
|
|
117
|
+
| Duplicated code | Pattern matching | Major |
|
|
118
|
+
| Naming inconsistency | Manual review | Minor |
|
|
119
|
+
|
|
120
|
+
### Scans
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
# TODOs and FIXMEs
|
|
124
|
+
Grep "TODO|FIXME|HACK|XXX|TEMP" --type ts -C 1
|
|
125
|
+
|
|
126
|
+
# Console.logs left behind
|
|
127
|
+
Grep "console\.(log|debug|info)" --type ts
|
|
128
|
+
|
|
129
|
+
# Commented out code (potential dead code)
|
|
130
|
+
Grep "^\\s*//.*function|^\\s*//.*const|^\\s*//.*class" --type ts
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### Categorization
|
|
134
|
+
|
|
135
|
+
- **Critical**: FIXME, HACK (immediate attention)
|
|
136
|
+
- **Normal**: TODO (should plan)
|
|
137
|
+
- **Low**: XXX, TEMP, minor style issues
|
|
138
|
+
|
|
139
|
+
### Code Smells Detection
|
|
140
|
+
|
|
141
|
+
Launch a Task agent (subagent_type: general-purpose) to detect code smells by reading source files:
|
|
142
|
+
|
|
143
|
+
| Smell | Warning | Critical | Detection |
|
|
144
|
+
|-------|---------|----------|-----------|
|
|
145
|
+
| God Files | >500 lines | >800 lines | Count lines per file (exclude tests, generated) |
|
|
146
|
+
| Long Functions | >50 lines | >100 lines | Find function/method bodies, count lines |
|
|
147
|
+
| Deep Nesting | >4 levels | >6 levels | Count nested `if/for/while/switch` depth |
|
|
148
|
+
| Too Many Params | >5 params | >8 params | Check function signatures |
|
|
149
|
+
| Large Classes | >300 lines / >20 methods | >500 lines / >30 methods | Analyze class definitions |
|
|
150
|
+
| Semantic Duplication | 2-3 similar blocks | 4+ similar blocks | Compare functions >10 lines with similar structure |
|
|
151
|
+
|
|
152
|
+
**Duplication detection strategy**: Agent reads functions of 10+ lines, groups by similar line count (within 20%), compares structure (stripping names/literals). >70% structural similarity = duplicate.
|
|
153
|
+
|
|
154
|
+
---
|
|
155
|
+
|
|
156
|
+
## Complexity Audit (`--complexity`)
|
|
157
|
+
|
|
158
|
+
### Cyclomatic Complexity
|
|
159
|
+
|
|
160
|
+
Starting at 1, add 1 for each decision point:
|
|
161
|
+
|
|
162
|
+
| Construct | Count |
|
|
163
|
+
|-----------|-------|
|
|
164
|
+
| `if` | +1 |
|
|
165
|
+
| `else if` | +1 |
|
|
166
|
+
| `for` / `for...of` / `for...in` | +1 |
|
|
167
|
+
| `while` / `do...while` | +1 |
|
|
168
|
+
| `case` (in switch) | +1 |
|
|
169
|
+
| `catch` | +1 |
|
|
170
|
+
| `&&` | +1 |
|
|
171
|
+
| `\|\|` | +1 |
|
|
172
|
+
| `??` | +1 |
|
|
173
|
+
| `? :` (ternary) | +1 |
|
|
174
|
+
|
|
175
|
+
**Thresholds**:
|
|
176
|
+
- OK: 1-10
|
|
177
|
+
- Warning: 11-20
|
|
178
|
+
- Critical: >20
|
|
179
|
+
|
|
180
|
+
### Cognitive Complexity
|
|
181
|
+
|
|
182
|
+
Like cyclomatic, but nesting depth acts as a multiplier:
|
|
183
|
+
|
|
184
|
+
```
|
|
185
|
+
cognitive_increment = base_increment * (1 + nesting_depth)
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
Each `if/for/while/switch/catch` at nesting level N adds (1 + N) instead of 1.
|
|
189
|
+
`else if` adds 1 (no nesting penalty). `else` adds 1 (no nesting penalty).
|
|
190
|
+
`&&`, `||`, `??` add 1 (no nesting penalty, but sequences of the same operator count as 1).
|
|
191
|
+
|
|
192
|
+
**Thresholds**:
|
|
193
|
+
- OK: 1-15
|
|
194
|
+
- Warning: 16-25
|
|
195
|
+
- Critical: >25
|
|
196
|
+
|
|
197
|
+
### Analysis Strategy
|
|
198
|
+
|
|
199
|
+
Launch up to 5 Task agents in parallel (subagent_type: general-purpose), one per top-level source directory. Each agent:
|
|
200
|
+
|
|
201
|
+
1. Reads source files in its directory (skip `node_modules`, `dist`, `build`, `coverage`, `.next`, generated files)
|
|
202
|
+
2. Identifies functions/methods (named functions, arrow functions assigned to variables, class methods)
|
|
203
|
+
3. Counts cyclomatic and cognitive complexity
|
|
204
|
+
4. Reports ONLY functions that exceed warning threshold (cyclomatic >10 OR cognitive >15)
|
|
205
|
+
|
|
206
|
+
---
|
|
207
|
+
|
|
208
|
+
## Security Audit (`--security`)
|
|
209
|
+
|
|
210
|
+
### What It Checks
|
|
211
|
+
|
|
212
|
+
| Issue | How Detected | Severity |
|
|
213
|
+
|-------|--------------|----------|
|
|
214
|
+
| Hardcoded secrets | Grep patterns | Critical |
|
|
215
|
+
| Vulnerable dependencies | npm audit | Critical/Major |
|
|
216
|
+
| SQL injection vectors | Pattern matching | Critical |
|
|
217
|
+
| Missing input validation | Code review | Major |
|
|
218
|
+
| Exposed sensitive data | Grep | Critical |
|
|
219
|
+
|
|
220
|
+
### Package Manager Detection
|
|
221
|
+
|
|
222
|
+
Before running audit commands, detect the PM by checking lockfiles:
|
|
223
|
+
- `pnpm-lock.yaml` -> Use `pnpm audit`
|
|
224
|
+
- `yarn.lock` -> Use `yarn audit`
|
|
225
|
+
- `bun.lockb` -> Use `bunx npm-audit`
|
|
226
|
+
- `package-lock.json` or none -> Use `npm audit`
|
|
227
|
+
|
|
228
|
+
### Scans
|
|
229
|
+
|
|
230
|
+
```bash
|
|
231
|
+
# Hardcoded secrets
|
|
232
|
+
Grep "password\s*=\s*['\"]|api_key\s*=\s*['\"]|secret\s*=\s*['\"]" --type ts -i
|
|
233
|
+
|
|
234
|
+
# Private keys or tokens
|
|
235
|
+
Grep "-----BEGIN|sk_live_|pk_live_|ghp_|AKIA" --type ts
|
|
236
|
+
|
|
237
|
+
# Environment variables in code (should be in .env)
|
|
238
|
+
Grep "process\.env\." --type ts
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
### Dependency Audit
|
|
242
|
+
|
|
243
|
+
Invoke the **dependency-checker** agent for the dependency-related checks (vulnerabilities, outdated packages, unused deps, licenses). It produces a structured report that you integrate into the security section of the audit output.
|
|
244
|
+
|
|
245
|
+
If the dependency-checker agent is not available, fall back to:
|
|
246
|
+
```bash
|
|
247
|
+
<pm> audit --audit-level=moderate 2>/dev/null || echo "Run audit manually"
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
### OWASP Quick Check
|
|
251
|
+
|
|
252
|
+
- [ ] Input validation on all user inputs
|
|
253
|
+
- [ ] No SQL string concatenation
|
|
254
|
+
- [ ] Authentication on protected routes
|
|
255
|
+
- [ ] No sensitive data in logs
|
|
256
|
+
- [ ] HTTPS enforced
|
|
257
|
+
|
|
258
|
+
---
|
|
259
|
+
|
|
260
|
+
## Test Coverage Integration
|
|
261
|
+
|
|
262
|
+
### Finding Coverage Reports
|
|
263
|
+
|
|
264
|
+
Search for existing coverage reports in this order:
|
|
265
|
+
1. `**/coverage-summary.json` (Jest/Istanbul JSON summary)
|
|
266
|
+
2. `**/lcov.info` (LCOV format)
|
|
267
|
+
3. `**/coverage-final.json` (Istanbul detailed)
|
|
268
|
+
|
|
269
|
+
Use Glob to find them. Skip `node_modules`.
|
|
270
|
+
|
|
271
|
+
### Parsing
|
|
272
|
+
|
|
273
|
+
**coverage-summary.json**: Read the `total` key for line/branch/function percentages.
|
|
274
|
+
|
|
275
|
+
**lcov.info**: Parse `LF:` (lines found) and `LH:` (lines hit) entries, calculate `(total_LH / total_LF) * 100`.
|
|
276
|
+
|
|
277
|
+
**coverage-final.json**: Aggregate statement coverage across all files.
|
|
278
|
+
|
|
279
|
+
### Coverage Thresholds
|
|
280
|
+
|
|
281
|
+
| Coverage | Severity | Action |
|
|
282
|
+
|----------|----------|--------|
|
|
283
|
+
| < 20% | Critical | Urgent: add tests for critical paths |
|
|
284
|
+
| 20-49% | Major | Plan test sprint |
|
|
285
|
+
| 50-79% | Minor | Gradually improve |
|
|
286
|
+
| >= 80% | OK | Maintain |
|
|
287
|
+
|
|
288
|
+
### No Coverage Report
|
|
289
|
+
|
|
290
|
+
If no coverage report is found, output an informational note:
|
|
291
|
+
|
|
292
|
+
```
|
|
293
|
+
> No coverage report found. Run your test suite with coverage enabled
|
|
294
|
+
> (e.g., `npm test -- --coverage`) to include coverage in the audit.
|
|
295
|
+
> No coverage penalty applied to health score.
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
**No penalty is applied to the health score when coverage data is unavailable.**
|
|
299
|
+
|
|
300
|
+
---
|
|
301
|
+
|
|
302
|
+
## Technical Debt Estimation
|
|
303
|
+
|
|
304
|
+
Always included in the audit report summary. Calculated from all findings.
|
|
305
|
+
|
|
306
|
+
### Calculation
|
|
307
|
+
|
|
308
|
+
```
|
|
309
|
+
debt_hours = (critical_count * 4h) + (major_count * 1h) + (minor_count * 0.25h)
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
### Debt Rating
|
|
313
|
+
|
|
314
|
+
| Debt (hours) | Rating | Interpretation |
|
|
315
|
+
|--------------|--------|----------------|
|
|
316
|
+
| 0-8h | Low | Healthy codebase |
|
|
317
|
+
| 9-40h | Moderate | 1-2 sprint allocation recommended |
|
|
318
|
+
| 41-160h | High | Dedicated tech debt initiative needed |
|
|
319
|
+
| >160h | Very High | Systemic issues, consider major refactor |
|
|
320
|
+
|
|
321
|
+
### Trend Comparison
|
|
322
|
+
|
|
323
|
+
If a previous audit exists in `thoughts/audit/`, compare:
|
|
324
|
+
|
|
325
|
+
```markdown
|
|
326
|
+
### Debt Trend
|
|
327
|
+
|
|
328
|
+
| Metric | Previous (YYYY-MM-DD) | Current | Delta |
|
|
329
|
+
|--------|----------------------|---------|-------|
|
|
330
|
+
| Critical | 5 | 3 | -2 (improved) |
|
|
331
|
+
| Major | 12 | 14 | +2 (regressed) |
|
|
332
|
+
| Minor | 30 | 25 | -5 (improved) |
|
|
333
|
+
| Debt Hours | 52h | 41h | -11h (improved) |
|
|
334
|
+
| Health Score | 55 | 68 | +13 (improved) |
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
---
|
|
338
|
+
|
|
339
|
+
## Quick Mode (`--quick`)
|
|
340
|
+
|
|
341
|
+
Fast check for critical issues only:
|
|
342
|
+
|
|
343
|
+
1. Domain importing infrastructure packages
|
|
344
|
+
2. UI importing database clients
|
|
345
|
+
3. Hardcoded secrets
|
|
346
|
+
4. FIXME/HACK comments
|
|
347
|
+
5. npm audit critical vulnerabilities
|
|
348
|
+
6. **Functions with cyclomatic complexity >20**
|
|
349
|
+
7. **God files >800 lines**
|
|
350
|
+
|
|
351
|
+
Uses single agent, completes in ~30 seconds.
|
|
352
|
+
|
|
353
|
+
---
|
|
354
|
+
|
|
355
|
+
## Report Template
|
|
356
|
+
|
|
357
|
+
Save to: `thoughts/audit/YYYY-MM-DD_audit.md`
|
|
358
|
+
|
|
359
|
+
Use the full template from [report-template.md](report-template.md). Key sections: Summary table, Technical Debt Summary (with trend), Complexity Report (top 10 + distribution), Code Smells table, Test Coverage, Issues by severity, Recommendations, Next Steps.
|
|
360
|
+
|
|
361
|
+
---
|
|
362
|
+
|
|
363
|
+
## Health Score Calculation
|
|
364
|
+
|
|
365
|
+
```
|
|
366
|
+
base = 100 - (critical * 15) - (major * 5) - (minor * 1)
|
|
367
|
+
|
|
368
|
+
# Complexity penalty: up to 20 points
|
|
369
|
+
complexity_penalty = min(20, critical_complexity_functions * 3)
|
|
370
|
+
|
|
371
|
+
# Coverage penalty: only if coverage data exists
|
|
372
|
+
# 0 if no report, otherwise penalize low coverage (max 20 points)
|
|
373
|
+
coverage_penalty = 0 (if no coverage data)
|
|
374
|
+
coverage_penalty = max(0, (50 - avg_coverage%) / 2.5) (if data exists)
|
|
375
|
+
|
|
376
|
+
score = max(0, min(100, base - complexity_penalty - coverage_penalty))
|
|
377
|
+
```
|
|
378
|
+
|
|
379
|
+
| Score | Rating |
|
|
380
|
+
|-------|--------|
|
|
381
|
+
| 90-100 | Excellent |
|
|
382
|
+
| 70-89 | Good |
|
|
383
|
+
| 50-69 | Needs Attention |
|
|
384
|
+
| < 50 | Critical |
|
|
385
|
+
|
|
386
|
+
---
|
|
387
|
+
|
|
388
|
+
## Edge Cases
|
|
389
|
+
|
|
390
|
+
- **No source files found**: Skip analysis, report informational note
|
|
391
|
+
- **Monorepo**: Detect multiple `package.json`, run per-package where applicable
|
|
392
|
+
- **No `docs/ARCHITECTURE.md`**: Auto-detect pattern from directory structure
|
|
393
|
+
- **Previous audit missing**: Skip trend comparison, note "first audit"
|
|
394
|
+
- **Coverage report stale** (>30 days old): Warn but still parse
|
|
395
|
+
- **Very large codebase** (>10k files): Increase agent count, limit depth per agent
|
|
396
|
+
- **No package manager lockfile**: Default to `npm`, note in report
|
|
397
|
+
|
|
398
|
+
---
|
|
399
|
+
|
|
400
|
+
## Examples
|
|
401
|
+
|
|
402
|
+
```bash
|
|
403
|
+
/audit # Full audit (all checks including complexity + coverage)
|
|
404
|
+
/audit --architecture # Only layer violations
|
|
405
|
+
/audit --code # TODOs, duplicates, code smells
|
|
406
|
+
/audit --complexity # Cyclomatic + cognitive complexity analysis
|
|
407
|
+
/audit --security # Only security checks
|
|
408
|
+
/audit --quick # Fast critical-only scan (includes complexity >20, god files)
|
|
409
|
+
/audit src/features/auth # Audit specific directory
|
|
410
|
+
/audit --architecture --code # Combine modes
|
|
411
|
+
/audit --complexity --code # Complexity + code smells together
|
|
412
|
+
```
|
|
413
|
+
|
|
414
|
+
---
|
|
415
|
+
|
|
416
|
+
## Tips
|
|
417
|
+
|
|
418
|
+
1. **Run monthly** to catch drift early
|
|
419
|
+
2. **Fix critical first** - they compound
|
|
420
|
+
3. **Track score over time** to measure improvement
|
|
421
|
+
4. **Before releases**, run full audit
|
|
422
|
+
5. **After major refactors**, always audit
|
|
423
|
+
6. **Use scoped mode** for faster feedback during development
|
|
424
|
+
7. **Compare debt trends** between audits to validate improvement efforts
|
|
425
|
+
8. **Address complexity hotspots** first - they cause the most bugs
|
|
426
|
+
9. **Enable coverage** in your test suite to get the full health picture
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
# Audit Report Template
|
|
2
|
+
|
|
3
|
+
Save to: `thoughts/audit/YYYY-MM-DD_audit.md`
|
|
4
|
+
|
|
5
|
+
```markdown
|
|
6
|
+
# Codebase Audit Report
|
|
7
|
+
|
|
8
|
+
**Date**: YYYY-MM-DD
|
|
9
|
+
**Mode**: [full|architecture|code|complexity|security|quick]
|
|
10
|
+
**Scope**: [full codebase | specific directory]
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## Summary
|
|
15
|
+
|
|
16
|
+
| Category | Critical | Major | Minor |
|
|
17
|
+
|----------|----------|-------|-------|
|
|
18
|
+
| Architecture | X | Y | Z |
|
|
19
|
+
| Code Quality | X | Y | Z |
|
|
20
|
+
| Code Smells | X | Y | Z |
|
|
21
|
+
| Complexity | X | Y | Z |
|
|
22
|
+
| Security | X | Y | Z |
|
|
23
|
+
| **Total** | **X** | **Y** | **Z** |
|
|
24
|
+
|
|
25
|
+
**Health Score**: XX/100 ([Excellent|Good|Needs Attention|Critical])
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## Technical Debt Summary
|
|
30
|
+
|
|
31
|
+
| Severity | Count | Estimated Effort |
|
|
32
|
+
|----------|-------|-----------------|
|
|
33
|
+
| Critical | X | X * 4h = Xh |
|
|
34
|
+
| Major | X | X * 1h = Xh |
|
|
35
|
+
| Minor | X | X * 0.25h = Xh |
|
|
36
|
+
| **Total** | **X** | **Xh** |
|
|
37
|
+
|
|
38
|
+
**Debt Rating**: [Low|Moderate|High|Very High]
|
|
39
|
+
|
|
40
|
+
[If previous audit exists]
|
|
41
|
+
### Trend vs Previous Audit (YYYY-MM-DD)
|
|
42
|
+
| Metric | Previous | Current | Delta |
|
|
43
|
+
|--------|----------|---------|-------|
|
|
44
|
+
| Health Score | X | Y | +/-Z |
|
|
45
|
+
| Debt Hours | Xh | Yh | +/-Zh |
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
## Complexity Report
|
|
50
|
+
|
|
51
|
+
### Most Complex Functions (Top 10)
|
|
52
|
+
|
|
53
|
+
| Function | File | Cyclomatic | Cognitive | Rating |
|
|
54
|
+
|----------|------|------------|-----------|--------|
|
|
55
|
+
| `functionName()` | `path/to/file.ts:line` | X | Y | [Warning|Critical] |
|
|
56
|
+
|
|
57
|
+
### Complexity Distribution
|
|
58
|
+
|
|
59
|
+
| Range | Count | % |
|
|
60
|
+
|-------|-------|---|
|
|
61
|
+
| 1-10 (OK) | X | X% |
|
|
62
|
+
| 11-20 (Warning) | X | X% |
|
|
63
|
+
| >20 (Critical) | X | X% |
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
## Code Smells
|
|
68
|
+
|
|
69
|
+
| Smell | Count | Severity | Worst Offenders |
|
|
70
|
+
|-------|-------|----------|-----------------|
|
|
71
|
+
| God Files | X | [Warning|Critical] | `file.ts` (X lines), ... |
|
|
72
|
+
| Long Functions | X | [Warning|Critical] | `func()` (X lines), ... |
|
|
73
|
+
| Deep Nesting | X | [Warning|Critical] | `func()` (X levels), ... |
|
|
74
|
+
| Too Many Params | X | [Warning|Critical] | `func(a,b,c,d,e,f)`, ... |
|
|
75
|
+
| Large Classes | X | [Warning|Critical] | `ClassName` (X lines), ... |
|
|
76
|
+
| Duplication | X | [Warning|Critical] | `funcA()` ~ `funcB()`, ... |
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
## Test Coverage
|
|
81
|
+
|
|
82
|
+
[If coverage report found]
|
|
83
|
+
|
|
84
|
+
| Metric | Value | Rating |
|
|
85
|
+
|--------|-------|--------|
|
|
86
|
+
| Line Coverage | X% | [OK|Minor|Major|Critical] |
|
|
87
|
+
| Branch Coverage | X% | [OK|Minor|Major|Critical] |
|
|
88
|
+
| Function Coverage | X% | [OK|Minor|Major|Critical] |
|
|
89
|
+
|
|
90
|
+
### Low Coverage Files (Bottom 5)
|
|
91
|
+
|
|
92
|
+
| File | Line % | Branch % |
|
|
93
|
+
|------|--------|----------|
|
|
94
|
+
| `path/to/file.ts` | X% | Y% |
|
|
95
|
+
|
|
96
|
+
[If no coverage report]
|
|
97
|
+
> No coverage report found. Run tests with `--coverage` to include in audit.
|
|
98
|
+
|
|
99
|
+
---
|
|
100
|
+
|
|
101
|
+
## Critical Issues (Fix Immediately)
|
|
102
|
+
|
|
103
|
+
### [Issue Title]
|
|
104
|
+
- **File**: `path/to/file.ts:line`
|
|
105
|
+
- **Category**: [Architecture|Code Quality|Complexity|Security|Code Smell]
|
|
106
|
+
- **Issue**: [Description]
|
|
107
|
+
- **Fix**: [Specific action]
|
|
108
|
+
|
|
109
|
+
---
|
|
110
|
+
|
|
111
|
+
## Major Issues (Fix Soon)
|
|
112
|
+
|
|
113
|
+
[Same format]
|
|
114
|
+
|
|
115
|
+
---
|
|
116
|
+
|
|
117
|
+
## Minor Issues (Consider)
|
|
118
|
+
|
|
119
|
+
[Same format]
|
|
120
|
+
|
|
121
|
+
---
|
|
122
|
+
|
|
123
|
+
## Recommendations
|
|
124
|
+
|
|
125
|
+
1. [Most impactful fix first]
|
|
126
|
+
2. [Second priority]
|
|
127
|
+
3. [...]
|
|
128
|
+
|
|
129
|
+
---
|
|
130
|
+
|
|
131
|
+
## Next Steps
|
|
132
|
+
|
|
133
|
+
- [ ] Fix critical issues before next release
|
|
134
|
+
- [ ] Address major issues in next sprint
|
|
135
|
+
- [ ] Schedule minor fixes for tech debt sessions
|
|
136
|
+
- [ ] Re-run `/audit` after fixes
|
|
137
|
+
```
|