@northbridge-security/secureai 0.1.13
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/.claude/README.md +122 -0
- package/.claude/commands/architect/clean.md +978 -0
- package/.claude/commands/architect/kiss.md +762 -0
- package/.claude/commands/architect/review.md +704 -0
- package/.claude/commands/catchup.md +90 -0
- package/.claude/commands/code.md +115 -0
- package/.claude/commands/commit.md +1218 -0
- package/.claude/commands/cover.md +1298 -0
- package/.claude/commands/fmea.md +275 -0
- package/.claude/commands/kaizen.md +312 -0
- package/.claude/commands/pr.md +503 -0
- package/.claude/commands/todo.md +99 -0
- package/.claude/commands/worktree.md +738 -0
- package/.claude/commands/wrapup.md +103 -0
- package/LICENSE +183 -0
- package/README.md +108 -0
- package/dist/cli.js +75634 -0
- package/docs/agents/devops-reviewer.md +889 -0
- package/docs/agents/kiss-simplifier.md +1088 -0
- package/docs/agents/typescript.md +8 -0
- package/docs/guides/README.md +109 -0
- package/docs/guides/agents.clean.arch.md +244 -0
- package/docs/guides/agents.clean.arch.ts.md +1314 -0
- package/docs/guides/agents.gotask.md +1037 -0
- package/docs/guides/agents.markdown.md +1209 -0
- package/docs/guides/agents.onepassword.md +285 -0
- package/docs/guides/agents.sonar.md +857 -0
- package/docs/guides/agents.tdd.md +838 -0
- package/docs/guides/agents.tdd.ts.md +1062 -0
- package/docs/guides/agents.typesript.md +1389 -0
- package/docs/guides/github-mcp.md +1075 -0
- package/package.json +130 -0
- package/packages/secureai-cli/src/cli.ts +21 -0
- package/tasks/README.md +880 -0
- package/tasks/aws.yml +64 -0
- package/tasks/bash.yml +118 -0
- package/tasks/bun.yml +738 -0
- package/tasks/claude.yml +183 -0
- package/tasks/docker.yml +420 -0
- package/tasks/docs.yml +127 -0
- package/tasks/git.yml +1336 -0
- package/tasks/gotask.yml +132 -0
- package/tasks/json.yml +77 -0
- package/tasks/markdown.yml +95 -0
- package/tasks/onepassword.yml +350 -0
- package/tasks/security.yml +102 -0
- package/tasks/sonar.yml +437 -0
- package/tasks/template.yml +74 -0
- package/tasks/vscode.yml +103 -0
- package/tasks/yaml.yml +121 -0
|
@@ -0,0 +1,704 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Review code against best practices and guidelines with specific checks
|
|
3
|
+
argument-hint: [path] [--duplication] [--prefer-classes] [--all] [--strict] [--compare]
|
|
4
|
+
allowed-tools: Task, Read, Write, Bash, Grep, Glob
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Best Practices Review: $ARGUMENTS
|
|
8
|
+
|
|
9
|
+
**Note**: This command reviews code against language-specific best practices from `~/.claude/guides/`. It complements `/architect:clean` (architecture violations) and `/architect:kiss` (complexity reduction) by focusing on coding standards and design patterns. Use together for comprehensive code quality analysis.
|
|
10
|
+
|
|
11
|
+
## Phase 0: Parse Arguments
|
|
12
|
+
|
|
13
|
+
Extract from `$ARGUMENTS`:
|
|
14
|
+
|
|
15
|
+
- **Path** (first positional argument): Optional scope for analysis
|
|
16
|
+
- File path (e.g., `src/utils/auth.ts`) → Analyze specific file
|
|
17
|
+
- Directory path (e.g., `src/`) → Analyze all files in directory
|
|
18
|
+
- Pattern (e.g., `src/**/*.ts`) → Analyze matching files
|
|
19
|
+
- Empty or `--diff` → Analyze git-changed files only
|
|
20
|
+
- **Checks** (flags): Specific checks to run
|
|
21
|
+
- `--duplication`: Check for code duplication opportunities
|
|
22
|
+
- `--prefer-classes`: Check for functions that should be class methods
|
|
23
|
+
- `--all`: Run all available checks (default if no specific checks)
|
|
24
|
+
- **Options**:
|
|
25
|
+
- `--strict`: Fail if violations exceed threshold
|
|
26
|
+
- `--compare`: Compare with previous `.architect.review.local.md` report
|
|
27
|
+
|
|
28
|
+
**Smart scope resolution:**
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
# Parse arguments
|
|
32
|
+
SCOPE=""
|
|
33
|
+
CHECKS=()
|
|
34
|
+
OPTIONS=()
|
|
35
|
+
|
|
36
|
+
for arg in $ARGUMENTS; do
|
|
37
|
+
case "$arg" in
|
|
38
|
+
--duplication|--prefer-classes|--all)
|
|
39
|
+
CHECKS+=("$arg")
|
|
40
|
+
;;
|
|
41
|
+
--strict|--compare|--diff)
|
|
42
|
+
OPTIONS+=("$arg")
|
|
43
|
+
;;
|
|
44
|
+
*)
|
|
45
|
+
# First non-flag argument is the scope
|
|
46
|
+
if [[ -z "$SCOPE" ]]; then
|
|
47
|
+
SCOPE="$arg"
|
|
48
|
+
fi
|
|
49
|
+
;;
|
|
50
|
+
esac
|
|
51
|
+
done
|
|
52
|
+
|
|
53
|
+
# Default to --all if no specific checks
|
|
54
|
+
if [[ ${#CHECKS[@]} -eq 0 ]]; then
|
|
55
|
+
CHECKS=("--all")
|
|
56
|
+
fi
|
|
57
|
+
|
|
58
|
+
# Determine mode
|
|
59
|
+
if [[ -z "$SCOPE" ]] || [[ " ${OPTIONS[*]} " =~ " --diff " ]]; then
|
|
60
|
+
MODE="diff"
|
|
61
|
+
SCOPE=$(git diff --name-only origin/main...HEAD 2>/dev/null | grep -E '\.(ts|js|tsx|jsx|py|go|rb)$')
|
|
62
|
+
echo "Analyzing git-changed files only"
|
|
63
|
+
elif [[ -f "$SCOPE" ]]; then
|
|
64
|
+
MODE="file"
|
|
65
|
+
echo "Analyzing single file: $SCOPE"
|
|
66
|
+
elif [[ -d "$SCOPE" ]]; then
|
|
67
|
+
MODE="directory"
|
|
68
|
+
echo "Analyzing directory: $SCOPE"
|
|
69
|
+
elif [[ "$SCOPE" == *"*"* ]]; then
|
|
70
|
+
MODE="pattern"
|
|
71
|
+
echo "Analyzing pattern: $SCOPE"
|
|
72
|
+
fi
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Phase 1: Detect Language and Load Guidelines
|
|
76
|
+
|
|
77
|
+
### 1.1 Detect Primary Language
|
|
78
|
+
|
|
79
|
+
Analyze files in scope to determine primary language:
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
// Language detection logic
|
|
83
|
+
interface LanguageStats {
|
|
84
|
+
language: string;
|
|
85
|
+
fileCount: number;
|
|
86
|
+
extension: string;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const languageMap: Record<string, string> = {
|
|
90
|
+
".ts": "typescript",
|
|
91
|
+
".tsx": "typescript",
|
|
92
|
+
".js": "javascript",
|
|
93
|
+
".jsx": "javascript",
|
|
94
|
+
".py": "python",
|
|
95
|
+
".go": "go",
|
|
96
|
+
".rb": "ruby",
|
|
97
|
+
".rs": "rust",
|
|
98
|
+
".java": "java",
|
|
99
|
+
".cs": "csharp",
|
|
100
|
+
".php": "php",
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
// Count files by extension in scope
|
|
104
|
+
const stats = countFilesByExtension(scopeFiles);
|
|
105
|
+
const primaryLanguage = stats[0].language; // Most common
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### 1.2 Load Language Guidelines
|
|
109
|
+
|
|
110
|
+
Fetch guidelines from `~/.claude/guides/`:
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
# Check for language-specific guidelines
|
|
114
|
+
GUIDES_DIR="$HOME/.claude/guides"
|
|
115
|
+
LANGUAGE="typescript" # Detected from Phase 1.1
|
|
116
|
+
|
|
117
|
+
# Look for guidelines in order of specificity
|
|
118
|
+
GUIDELINES_FILES=(
|
|
119
|
+
"$GUIDES_DIR/agents.${LANGUAGE}.best-practices.md"
|
|
120
|
+
"$GUIDES_DIR/agents.${LANGUAGE}.md"
|
|
121
|
+
"$GUIDES_DIR/agents.clean.arch.${LANGUAGE}.md"
|
|
122
|
+
"$GUIDES_DIR/agents.tdd.${LANGUAGE}.md"
|
|
123
|
+
)
|
|
124
|
+
|
|
125
|
+
LOADED_GUIDELINES=()
|
|
126
|
+
for file in "${GUIDELINES_FILES[@]}"; do
|
|
127
|
+
if [[ -f "$file" ]]; then
|
|
128
|
+
LOADED_GUIDELINES+=("$file")
|
|
129
|
+
echo "Loaded guidelines: $file"
|
|
130
|
+
fi
|
|
131
|
+
done
|
|
132
|
+
|
|
133
|
+
if [[ ${#LOADED_GUIDELINES[@]} -eq 0 ]]; then
|
|
134
|
+
echo "Warning: No language-specific guidelines found for $LANGUAGE"
|
|
135
|
+
echo "Using generic best practices"
|
|
136
|
+
fi
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## Phase 2: Run Specific Checks
|
|
140
|
+
|
|
141
|
+
### 2.1 Duplication Check (`--duplication`)
|
|
142
|
+
|
|
143
|
+
**Purpose**: Identify code duplication and suggest base class extraction or shared utilities.
|
|
144
|
+
|
|
145
|
+
**What it checks:**
|
|
146
|
+
|
|
147
|
+
1. **Similar code blocks** - Functions/methods with >70% similarity
|
|
148
|
+
2. **Copy-paste patterns** - Identical code in multiple files
|
|
149
|
+
3. **Extractable base classes** - Classes with duplicate methods
|
|
150
|
+
4. **Shared utility candidates** - Repeated logic across modules
|
|
151
|
+
|
|
152
|
+
**Analysis approach:**
|
|
153
|
+
|
|
154
|
+
```typescript
|
|
155
|
+
// Launch duplication analysis agent
|
|
156
|
+
await Task({
|
|
157
|
+
subagent_type: "code-reviewer",
|
|
158
|
+
description: "Check code duplication",
|
|
159
|
+
prompt: `Analyze for code duplication in scope: ${scope}
|
|
160
|
+
|
|
161
|
+
Guidelines loaded: ${loadedGuidelines.join(", ")}
|
|
162
|
+
|
|
163
|
+
Check for:
|
|
164
|
+
1. Functions/methods with similar logic (>70% overlap)
|
|
165
|
+
2. Copy-paste code blocks (identical or near-identical)
|
|
166
|
+
3. Classes that should share a base class
|
|
167
|
+
4. Repeated patterns that should be utility functions
|
|
168
|
+
5. Similar error handling that could be centralized
|
|
169
|
+
|
|
170
|
+
For each duplication found, suggest:
|
|
171
|
+
- Whether to extract base class (OOP approach)
|
|
172
|
+
- Whether to create shared utility (functional approach)
|
|
173
|
+
- Whether to use composition over inheritance
|
|
174
|
+
- How to maintain clean architecture principles
|
|
175
|
+
|
|
176
|
+
Output format:
|
|
177
|
+
- File locations with line numbers
|
|
178
|
+
- Similarity percentage
|
|
179
|
+
- Recommended refactoring approach
|
|
180
|
+
- Code example of suggested extraction`,
|
|
181
|
+
});
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
**Duplication severity levels:**
|
|
185
|
+
|
|
186
|
+
| Similarity | Severity | Recommendation |
|
|
187
|
+
| ---------- | -------- | --------------------------------------- |
|
|
188
|
+
| >90% | Critical | Immediate extraction required |
|
|
189
|
+
| 70-90% | High | Extract to shared utility/base class |
|
|
190
|
+
| 50-70% | Medium | Consider abstraction |
|
|
191
|
+
| <50% | Low | May be intentional, document if keeping |
|
|
192
|
+
|
|
193
|
+
### 2.2 Prefer Classes Check (`--prefer-classes`)
|
|
194
|
+
|
|
195
|
+
**Purpose**: Identify exported functions that should be organized into classes with static methods for cleaner barrel exports.
|
|
196
|
+
|
|
197
|
+
**What it checks:**
|
|
198
|
+
|
|
199
|
+
1. **Function groups with common prefix** - Functions like `createUser`, `updateUser`, `deleteUser` → `UserService` class
|
|
200
|
+
2. **Stateless utility functions** - Related functions that could be static class methods
|
|
201
|
+
3. **Factory functions** - Functions returning objects that could be class constructors
|
|
202
|
+
4. **Namespace-like exports** - Multiple exports that logically belong together
|
|
203
|
+
|
|
204
|
+
**Analysis approach:**
|
|
205
|
+
|
|
206
|
+
```typescript
|
|
207
|
+
// Launch class extraction analysis agent
|
|
208
|
+
await Task({
|
|
209
|
+
subagent_type: "code-reviewer",
|
|
210
|
+
description: "Check function-to-class opportunities",
|
|
211
|
+
prompt: `Analyze for functions that should be class methods in scope: ${scope}
|
|
212
|
+
|
|
213
|
+
Guidelines loaded: ${loadedGuidelines.join(", ")}
|
|
214
|
+
|
|
215
|
+
Check for:
|
|
216
|
+
1. Functions with common prefix (e.g., userCreate, userUpdate, userDelete)
|
|
217
|
+
2. Groups of 3+ related exported functions
|
|
218
|
+
3. Functions that share common dependencies
|
|
219
|
+
4. Functions that would benefit from static method organization
|
|
220
|
+
5. Files with many standalone exports that complicate barrel files
|
|
221
|
+
|
|
222
|
+
For each opportunity found:
|
|
223
|
+
- Current: Multiple exported functions
|
|
224
|
+
- Suggested: Class with static methods OR instance class with DI
|
|
225
|
+
- Rationale: Why class organization is cleaner
|
|
226
|
+
- Barrel impact: How it simplifies index.ts exports
|
|
227
|
+
|
|
228
|
+
Example transformation:
|
|
229
|
+
// Before (function exports)
|
|
230
|
+
export function createUser(data: UserData): User { ... }
|
|
231
|
+
export function updateUser(id: string, data: Partial<UserData>): User { ... }
|
|
232
|
+
export function deleteUser(id: string): void { ... }
|
|
233
|
+
export function getUserById(id: string): User | null { ... }
|
|
234
|
+
|
|
235
|
+
// After (class with static methods)
|
|
236
|
+
export class UserService {
|
|
237
|
+
static create(data: UserData): User { ... }
|
|
238
|
+
static update(id: string, data: Partial<UserData>): User { ... }
|
|
239
|
+
static delete(id: string): void { ... }
|
|
240
|
+
static getById(id: string): User | null { ... }
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// OR (class with DI for dependencies)
|
|
244
|
+
export class UserService {
|
|
245
|
+
constructor(private readonly db: IDatabase) {}
|
|
246
|
+
create(data: UserData): User { ... }
|
|
247
|
+
update(id: string, data: Partial<UserData>): User { ... }
|
|
248
|
+
// ...
|
|
249
|
+
}
|
|
250
|
+
export const defaultUserService = new UserService(defaultDatabase);
|
|
251
|
+
|
|
252
|
+
Benefits:
|
|
253
|
+
- Cleaner barrel: export { UserService } vs export { createUser, updateUser, ... }
|
|
254
|
+
- Logical grouping: Related functionality in one class
|
|
255
|
+
- Easier mocking: Mock entire class vs individual functions
|
|
256
|
+
- Better IDE support: Autocomplete shows all related methods`,
|
|
257
|
+
});
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
**Prefer-classes severity levels:**
|
|
261
|
+
|
|
262
|
+
| Pattern | Severity | Recommendation |
|
|
263
|
+
| -------------------------- | -------- | ------------------------- |
|
|
264
|
+
| 5+ related functions | High | Extract to class |
|
|
265
|
+
| 3-4 related functions | Medium | Consider class extraction |
|
|
266
|
+
| Functions with shared deps | High | Use class with DI |
|
|
267
|
+
| Common prefix pattern | Medium | Group into service class |
|
|
268
|
+
|
|
269
|
+
## Phase 3: Generate Review Report
|
|
270
|
+
|
|
271
|
+
**Create `.tmp/agent/.architect.review.local.md` with findings:**
|
|
272
|
+
|
|
273
|
+
````markdown
|
|
274
|
+
# Best Practices Review Report
|
|
275
|
+
|
|
276
|
+
**Generated:** [timestamp ISO]
|
|
277
|
+
**Scope:** [analyzed scope]
|
|
278
|
+
**Mode:** [file | directory | pattern | diff]
|
|
279
|
+
**Language:** [detected language]
|
|
280
|
+
**Checks run:** [list of checks]
|
|
281
|
+
**Guidelines loaded:** [list of guideline files]
|
|
282
|
+
|
|
283
|
+
---
|
|
284
|
+
|
|
285
|
+
## Executive Summary
|
|
286
|
+
|
|
287
|
+
**Total Issues:** [count]
|
|
288
|
+
|
|
289
|
+
- Critical: [count] (Must fix before merge)
|
|
290
|
+
- High: [count] (Should fix soon)
|
|
291
|
+
- Medium: [count] (Improve when possible)
|
|
292
|
+
- Low: [count] (Nice-to-have)
|
|
293
|
+
|
|
294
|
+
**Checks Summary:**
|
|
295
|
+
|
|
296
|
+
| Check | Issues | Critical | High | Medium | Low |
|
|
297
|
+
| -------------- | ------- | -------- | ------- | ------- | ------- |
|
|
298
|
+
| Duplication | [count] | [count] | [count] | [count] | [count] |
|
|
299
|
+
| Prefer Classes | [count] | [count] | [count] | [count] | [count] |
|
|
300
|
+
|
|
301
|
+
**Overall Assessment:** [summary]
|
|
302
|
+
|
|
303
|
+
---
|
|
304
|
+
|
|
305
|
+
## Duplication Analysis
|
|
306
|
+
|
|
307
|
+
### Critical Duplication (>90% Similarity)
|
|
308
|
+
|
|
309
|
+
#### 1. [Description] - [File1] ↔ [File2]
|
|
310
|
+
|
|
311
|
+
**Similarity:** [percentage]%
|
|
312
|
+
|
|
313
|
+
**Location 1:** `[file1:line-start:line-end]`
|
|
314
|
+
|
|
315
|
+
```[language]
|
|
316
|
+
[code snippet 1]
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
**Location 2:** `[file2:line-start:line-end]`
|
|
320
|
+
|
|
321
|
+
```[language]
|
|
322
|
+
[code snippet 2]
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
**Recommendation:** Extract to base class / shared utility
|
|
326
|
+
|
|
327
|
+
**Suggested extraction:**
|
|
328
|
+
|
|
329
|
+
```[language]
|
|
330
|
+
// New file: src/shared/[name].ts
|
|
331
|
+
[extracted code with proper abstraction]
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
**Refactored usage:**
|
|
335
|
+
|
|
336
|
+
```[language]
|
|
337
|
+
// In file1
|
|
338
|
+
import { ExtractedClass } from '../shared/[name]';
|
|
339
|
+
// ... usage
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
---
|
|
343
|
+
|
|
344
|
+
[Repeat for each duplication issue]
|
|
345
|
+
|
|
346
|
+
### High Priority Duplication (70-90%)
|
|
347
|
+
|
|
348
|
+
[Same structure as critical]
|
|
349
|
+
|
|
350
|
+
### Medium Priority Duplication (50-70%)
|
|
351
|
+
|
|
352
|
+
[Same structure as critical]
|
|
353
|
+
|
|
354
|
+
---
|
|
355
|
+
|
|
356
|
+
## Prefer Classes Analysis
|
|
357
|
+
|
|
358
|
+
### High Priority - Multiple Related Functions
|
|
359
|
+
|
|
360
|
+
#### 1. [File] - [Count] related functions found
|
|
361
|
+
|
|
362
|
+
**Current exports:**
|
|
363
|
+
|
|
364
|
+
```[language]
|
|
365
|
+
// [file]
|
|
366
|
+
export function [prefix]Create(...) { ... }
|
|
367
|
+
export function [prefix]Update(...) { ... }
|
|
368
|
+
export function [prefix]Delete(...) { ... }
|
|
369
|
+
export function [prefix]GetById(...) { ... }
|
|
370
|
+
export function [prefix]List(...) { ... }
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
**Problem:**
|
|
374
|
+
|
|
375
|
+
- [count] functions with common prefix `[prefix]`
|
|
376
|
+
- Barrel file (`index.ts`) requires [count] individual exports
|
|
377
|
+
- Related functionality scattered across file
|
|
378
|
+
- Harder to mock in tests (mock each function)
|
|
379
|
+
|
|
380
|
+
**Recommended refactoring:**
|
|
381
|
+
|
|
382
|
+
**Option A: Static methods (stateless operations)**
|
|
383
|
+
|
|
384
|
+
```[language]
|
|
385
|
+
// [file] - refactored
|
|
386
|
+
export class [PrefixService] {
|
|
387
|
+
static create(...): [Type] { ... }
|
|
388
|
+
static update(...): [Type] { ... }
|
|
389
|
+
static delete(...): void { ... }
|
|
390
|
+
static getById(...): [Type] | null { ... }
|
|
391
|
+
static list(...): [Type][] { ... }
|
|
392
|
+
}
|
|
393
|
+
```
|
|
394
|
+
|
|
395
|
+
**Option B: Instance class with DI (has dependencies)**
|
|
396
|
+
|
|
397
|
+
```[language]
|
|
398
|
+
// [file] - refactored
|
|
399
|
+
export class [PrefixService] {
|
|
400
|
+
constructor(
|
|
401
|
+
private readonly [dep1]: I[Dep1],
|
|
402
|
+
private readonly [dep2]: I[Dep2]
|
|
403
|
+
) {}
|
|
404
|
+
|
|
405
|
+
create(...): [Type] { ... }
|
|
406
|
+
update(...): [Type] { ... }
|
|
407
|
+
// ...
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
// Exported singleton with default dependencies
|
|
411
|
+
export const default[PrefixService] = new [PrefixService](
|
|
412
|
+
default[Dep1],
|
|
413
|
+
default[Dep2]
|
|
414
|
+
);
|
|
415
|
+
```
|
|
416
|
+
|
|
417
|
+
**Barrel simplification:**
|
|
418
|
+
|
|
419
|
+
```[language]
|
|
420
|
+
// Before: index.ts
|
|
421
|
+
export {
|
|
422
|
+
[prefix]Create,
|
|
423
|
+
[prefix]Update,
|
|
424
|
+
[prefix]Delete,
|
|
425
|
+
[prefix]GetById,
|
|
426
|
+
[prefix]List,
|
|
427
|
+
} from './[file]';
|
|
428
|
+
|
|
429
|
+
// After: index.ts
|
|
430
|
+
export { [PrefixService] } from './[file]';
|
|
431
|
+
// OR
|
|
432
|
+
export { [PrefixService], default[PrefixService] } from './[file]';
|
|
433
|
+
```
|
|
434
|
+
|
|
435
|
+
**Impact:**
|
|
436
|
+
|
|
437
|
+
- Exports reduced: [before] → [after]
|
|
438
|
+
- Test mocking simplified
|
|
439
|
+
- Related code grouped logically
|
|
440
|
+
|
|
441
|
+
---
|
|
442
|
+
|
|
443
|
+
[Repeat for each prefer-classes issue]
|
|
444
|
+
|
|
445
|
+
---
|
|
446
|
+
|
|
447
|
+
## Guidelines Applied
|
|
448
|
+
|
|
449
|
+
### Loaded Guidelines
|
|
450
|
+
|
|
451
|
+
| Guideline File | Principles Applied |
|
|
452
|
+
| -------------- | -------------------- |
|
|
453
|
+
| [file1] | [list of principles] |
|
|
454
|
+
| [file2] | [list of principles] |
|
|
455
|
+
|
|
456
|
+
### Key Principles Referenced
|
|
457
|
+
|
|
458
|
+
1. **[Principle 1]**: [How it was applied]
|
|
459
|
+
2. **[Principle 2]**: [How it was applied]
|
|
460
|
+
3. **[Principle 3]**: [How it was applied]
|
|
461
|
+
|
|
462
|
+
---
|
|
463
|
+
|
|
464
|
+
## Recommendations
|
|
465
|
+
|
|
466
|
+
### Immediate Actions (Critical Issues)
|
|
467
|
+
|
|
468
|
+
1. **[Action 1]**
|
|
469
|
+
- Files affected: [list]
|
|
470
|
+
- Effort: [low/medium/high]
|
|
471
|
+
- Impact: [description]
|
|
472
|
+
|
|
473
|
+
### Short-term Improvements (High Priority)
|
|
474
|
+
|
|
475
|
+
[Same structure]
|
|
476
|
+
|
|
477
|
+
### Long-term Enhancements (Medium/Low Priority)
|
|
478
|
+
|
|
479
|
+
[Same structure]
|
|
480
|
+
|
|
481
|
+
---
|
|
482
|
+
|
|
483
|
+
## Next Steps
|
|
484
|
+
|
|
485
|
+
### Option 1: Fix Issues Individually
|
|
486
|
+
|
|
487
|
+
```bash
|
|
488
|
+
# Open report and address issues one by one
|
|
489
|
+
# For each issue, follow the suggested refactoring
|
|
490
|
+
```
|
|
491
|
+
|
|
492
|
+
### Option 2: Convert to Tasks
|
|
493
|
+
|
|
494
|
+
```bash
|
|
495
|
+
/task:add "Extract duplicate code in [module]"
|
|
496
|
+
/task:add "Refactor [functions] to [Service] class"
|
|
497
|
+
```
|
|
498
|
+
|
|
499
|
+
### Option 3: Run with --strict in CI
|
|
500
|
+
|
|
501
|
+
```bash
|
|
502
|
+
# Add to pre-commit or CI
|
|
503
|
+
/architect:review --strict
|
|
504
|
+
# Fails if critical or high issues found
|
|
505
|
+
```
|
|
506
|
+
|
|
507
|
+
### Option 4: Compare Over Time
|
|
508
|
+
|
|
509
|
+
```bash
|
|
510
|
+
# Run again after fixes
|
|
511
|
+
/architect:review --compare
|
|
512
|
+
# Shows improvement metrics
|
|
513
|
+
```
|
|
514
|
+
|
|
515
|
+
---
|
|
516
|
+
|
|
517
|
+
## Comparison with Previous Report
|
|
518
|
+
|
|
519
|
+
[Only if --compare used]
|
|
520
|
+
|
|
521
|
+
### Changes Since Last Analysis ([date])
|
|
522
|
+
|
|
523
|
+
**Issues resolved:** [count]
|
|
524
|
+
**New issues:** [count]
|
|
525
|
+
**Net change:** [±count]
|
|
526
|
+
|
|
527
|
+
### Metric Trends
|
|
528
|
+
|
|
529
|
+
| Metric | Previous | Current | Trend |
|
|
530
|
+
| ------------- | -------- | ------- | ----- |
|
|
531
|
+
| Total issues | [count] | [count] | [↑↓→] |
|
|
532
|
+
| Critical | [count] | [count] | [↑↓→] |
|
|
533
|
+
| Duplication % | [pct] | [pct] | [↑↓→] |
|
|
534
|
+
|
|
535
|
+
---
|
|
536
|
+
|
|
537
|
+
## Configuration
|
|
538
|
+
|
|
539
|
+
**Checks run:**
|
|
540
|
+
|
|
541
|
+
- `--duplication`: [enabled/disabled]
|
|
542
|
+
- `--prefer-classes`: [enabled/disabled]
|
|
543
|
+
|
|
544
|
+
**Thresholds:**
|
|
545
|
+
|
|
546
|
+
- Duplication similarity: 50%+ (warning), 70%+ (high), 90%+ (critical)
|
|
547
|
+
- Related functions: 3+ (medium), 5+ (high)
|
|
548
|
+
|
|
549
|
+
**Excluded paths:**
|
|
550
|
+
|
|
551
|
+
- `node_modules/**`
|
|
552
|
+
- `dist/**`
|
|
553
|
+
- `**/*.test.ts`
|
|
554
|
+
- `**/*.d.ts`
|
|
555
|
+
|
|
556
|
+
---
|
|
557
|
+
|
|
558
|
+
**Report generated by:** Best Practices Review
|
|
559
|
+
**Report location:** `.tmp/agent/.architect.review.local.md`
|
|
560
|
+
**Execution time:** [duration]
|
|
561
|
+
````
|
|
562
|
+
|
|
563
|
+
## Phase 4: Present Results to User
|
|
564
|
+
|
|
565
|
+
### 4.1 Ensure Output Directory
|
|
566
|
+
|
|
567
|
+
```bash
|
|
568
|
+
# Create output directory
|
|
569
|
+
mkdir -p .tmp/agent
|
|
570
|
+
```
|
|
571
|
+
|
|
572
|
+
### 4.2 Write Report to File
|
|
573
|
+
|
|
574
|
+
```bash
|
|
575
|
+
# Write report to .tmp/agent/.architect.review.local.md
|
|
576
|
+
cat > .tmp/agent/.architect.review.local.md <<EOF
|
|
577
|
+
[Generated report from Phase 3]
|
|
578
|
+
EOF
|
|
579
|
+
```
|
|
580
|
+
|
|
581
|
+
### 4.3 Console Summary
|
|
582
|
+
|
|
583
|
+
Print concise summary to console:
|
|
584
|
+
|
|
585
|
+
```text
|
|
586
|
+
Best Practices Review Complete
|
|
587
|
+
|
|
588
|
+
Scope: [analyzed scope]
|
|
589
|
+
Language: [detected language]
|
|
590
|
+
Checks: [list of checks run]
|
|
591
|
+
|
|
592
|
+
Issues found: [total count]
|
|
593
|
+
Critical: [count]
|
|
594
|
+
High: [count]
|
|
595
|
+
Medium: [count]
|
|
596
|
+
Low: [count]
|
|
597
|
+
|
|
598
|
+
Duplication:
|
|
599
|
+
- [count] code blocks with >70% similarity
|
|
600
|
+
- [count] extraction opportunities
|
|
601
|
+
|
|
602
|
+
Prefer Classes:
|
|
603
|
+
- [count] function groups could be classes
|
|
604
|
+
- [count] barrel exports could be simplified
|
|
605
|
+
|
|
606
|
+
Guidelines applied: [count] from ~/.claude/guides/
|
|
607
|
+
|
|
608
|
+
Report: .tmp/agent/.architect.review.local.md
|
|
609
|
+
|
|
610
|
+
Next steps:
|
|
611
|
+
1. Review findings in report
|
|
612
|
+
2. Address critical issues first
|
|
613
|
+
3. Run /architect:review --compare after fixes
|
|
614
|
+
```
|
|
615
|
+
|
|
616
|
+
### 4.4 Strict Mode Check
|
|
617
|
+
|
|
618
|
+
```bash
|
|
619
|
+
if [[ " ${OPTIONS[*]} " =~ " --strict " ]]; then
|
|
620
|
+
if [[ $CRITICAL_COUNT -gt 0 ]] || [[ $HIGH_COUNT -gt 0 ]]; then
|
|
621
|
+
echo "STRICT MODE: Found $CRITICAL_COUNT critical and $HIGH_COUNT high issues"
|
|
622
|
+
exit 1
|
|
623
|
+
fi
|
|
624
|
+
fi
|
|
625
|
+
```
|
|
626
|
+
|
|
627
|
+
## Error Handling
|
|
628
|
+
|
|
629
|
+
**No files in scope:**
|
|
630
|
+
|
|
631
|
+
- Warning: "No files found matching scope: [scope]"
|
|
632
|
+
- Exit with status 0
|
|
633
|
+
|
|
634
|
+
**No guidelines found:**
|
|
635
|
+
|
|
636
|
+
- Warning: "No language-specific guidelines found for [language]"
|
|
637
|
+
- Continue with generic best practices
|
|
638
|
+
- Exit with status 0
|
|
639
|
+
|
|
640
|
+
**Invalid check flag:**
|
|
641
|
+
|
|
642
|
+
- Error: "Unknown check flag: [flag]"
|
|
643
|
+
- Show available flags: `--duplication`, `--prefer-classes`, `--all`
|
|
644
|
+
- Exit with status 1
|
|
645
|
+
|
|
646
|
+
**Analysis failure:**
|
|
647
|
+
|
|
648
|
+
- Error: "Analysis failed: [reason]"
|
|
649
|
+
- Exit with status 2
|
|
650
|
+
|
|
651
|
+
## Exit Codes
|
|
652
|
+
|
|
653
|
+
- 0: Analysis completed successfully
|
|
654
|
+
- 1: Invalid arguments or configuration
|
|
655
|
+
- 2: Analysis execution failure
|
|
656
|
+
- 3: Strict mode violations found
|
|
657
|
+
|
|
658
|
+
## Quick Reference
|
|
659
|
+
|
|
660
|
+
**Common workflows:**
|
|
661
|
+
|
|
662
|
+
```bash
|
|
663
|
+
# Full review with all checks (default)
|
|
664
|
+
/architect:review
|
|
665
|
+
|
|
666
|
+
# Review specific directory
|
|
667
|
+
/architect:review src/utils/
|
|
668
|
+
|
|
669
|
+
# Run specific checks only
|
|
670
|
+
/architect:review --duplication
|
|
671
|
+
/architect:review --prefer-classes
|
|
672
|
+
/architect:review src/ --duplication --prefer-classes
|
|
673
|
+
|
|
674
|
+
# Strict mode for CI/pre-commit
|
|
675
|
+
/architect:review --strict
|
|
676
|
+
|
|
677
|
+
# Compare with previous analysis
|
|
678
|
+
/architect:review --compare
|
|
679
|
+
|
|
680
|
+
# Review git-changed files only
|
|
681
|
+
/architect:review --diff
|
|
682
|
+
```
|
|
683
|
+
|
|
684
|
+
**Available checks:**
|
|
685
|
+
|
|
686
|
+
| Flag | Description |
|
|
687
|
+
| ------------------ | ----------------------------------------------- |
|
|
688
|
+
| `--duplication` | Find code duplication, suggest extractions |
|
|
689
|
+
| `--prefer-classes` | Find function groups, suggest class refactoring |
|
|
690
|
+
| `--all` | Run all checks (default if no specific checks) |
|
|
691
|
+
|
|
692
|
+
**Integration with other commands:**
|
|
693
|
+
|
|
694
|
+
```bash
|
|
695
|
+
# Full architecture review workflow
|
|
696
|
+
/architect:clean src/ # Fix architecture violations
|
|
697
|
+
/architect:kiss src/ # Reduce complexity
|
|
698
|
+
/architect:review src/ # Apply best practices
|
|
699
|
+
|
|
700
|
+
# Convert findings to tasks
|
|
701
|
+
/architect:review src/
|
|
702
|
+
/task:add "Extract duplicate validation logic"
|
|
703
|
+
/task:add "Refactor user functions to UserService class"
|
|
704
|
+
```
|