@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,978 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Analyze code for Clean Architecture violations and propose refactorings
|
|
3
|
+
argument-hint: [scope] [--strict] [--apply] [--compare]
|
|
4
|
+
allowed-tools: Task, Read, Write, Bash
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Clean Architecture Analysis: $ARGUMENTS
|
|
8
|
+
|
|
9
|
+
**Note**: Clean Architecture and KISS (Keep It Simple, Stupid) principles work together to improve code quality. Clean Architecture ensures proper separation of concerns and testability through interface-based boundaries and dependency injection, while KISS removes unnecessary complexity from the resulting architecture. Use `/architect:clean` to establish clean boundaries, then `/architect:kiss` to simplify implementation. See [KISS Analysis](./kiss.md) for complexity reduction.
|
|
10
|
+
|
|
11
|
+
## Phase 0: Parse Arguments
|
|
12
|
+
|
|
13
|
+
Extract from `$ARGUMENTS`:
|
|
14
|
+
|
|
15
|
+
- **Scope**: Optional with smart defaults
|
|
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
|
+
- `--diff` or empty → Analyze git-changed files only
|
|
20
|
+
- **--strict**: Fail if architecture violations are found
|
|
21
|
+
- **--apply**: Apply suggested refactorings to worktree (requires review)
|
|
22
|
+
- **--compare**: Compare with previous `.clean.local.md` report
|
|
23
|
+
|
|
24
|
+
**Smart scope resolution:**
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
# If no scope provided or --diff flag
|
|
28
|
+
if [[ -z "$SCOPE" ]] || [[ "$SCOPE" == "--diff" ]]; then
|
|
29
|
+
MODE="diff"
|
|
30
|
+
SCOPE=$(git diff --name-only origin/main...HEAD 2>/dev/null | grep -E '\.(ts|js|tsx|jsx)$')
|
|
31
|
+
echo "🔍 Analyzing git-changed files only"
|
|
32
|
+
fi
|
|
33
|
+
|
|
34
|
+
# If scope is a single file
|
|
35
|
+
if [[ -f "$SCOPE" ]]; then
|
|
36
|
+
MODE="file"
|
|
37
|
+
echo "📄 Analyzing single file: $SCOPE"
|
|
38
|
+
fi
|
|
39
|
+
|
|
40
|
+
# If scope is a directory
|
|
41
|
+
if [[ -d "$SCOPE" ]]; then
|
|
42
|
+
MODE="directory"
|
|
43
|
+
echo "📁 Analyzing directory: $SCOPE"
|
|
44
|
+
fi
|
|
45
|
+
|
|
46
|
+
# If scope is a pattern
|
|
47
|
+
if [[ "$SCOPE" == *"*"* ]]; then
|
|
48
|
+
MODE="pattern"
|
|
49
|
+
echo "🔎 Analyzing pattern: $SCOPE"
|
|
50
|
+
fi
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Phase 1: Launch Clean Architecture Agent
|
|
54
|
+
|
|
55
|
+
Invoke a specialized Clean Architecture agent to perform analysis.
|
|
56
|
+
|
|
57
|
+
**Agent invocation:**
|
|
58
|
+
|
|
59
|
+
```typescript
|
|
60
|
+
// Launch agent via Task tool
|
|
61
|
+
await Task({
|
|
62
|
+
subagent_type: "general-purpose",
|
|
63
|
+
description: "Analyze Clean Architecture violations",
|
|
64
|
+
prompt: `Analyze the following scope for Clean Architecture violations:
|
|
65
|
+
|
|
66
|
+
Scope: ${scope}
|
|
67
|
+
Mode: ${mode}
|
|
68
|
+
Strict mode: ${strictMode}
|
|
69
|
+
Apply changes: ${applyChanges}
|
|
70
|
+
|
|
71
|
+
Use Clean Architecture principles from docs/guides/agents.clean.arch.md to identify:
|
|
72
|
+
1. Mixed business logic and system interactions
|
|
73
|
+
2. Missing interfaces for external dependencies
|
|
74
|
+
3. Hardcoded dependencies instead of dependency injection
|
|
75
|
+
4. Missing *.system.ts naming convention for system files
|
|
76
|
+
5. Coverage exclusion issues
|
|
77
|
+
6. Architecture boundary violations
|
|
78
|
+
7. Test coverage gaps from untestable code
|
|
79
|
+
8. Folder organization issues (5+ related files not in module folder)
|
|
80
|
+
|
|
81
|
+
Create a git worktree for proposed refactorings at: .worktree/clean-${timestamp}
|
|
82
|
+
|
|
83
|
+
Report findings with:
|
|
84
|
+
- Issue severity (critical, high, medium, low)
|
|
85
|
+
- Specific code locations
|
|
86
|
+
- Proposed refactorings with interface-based DI
|
|
87
|
+
- File organization improvements
|
|
88
|
+
- Worktree diff summary
|
|
89
|
+
|
|
90
|
+
Return findings in structured format for review.`,
|
|
91
|
+
});
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
**What the agent will do:**
|
|
95
|
+
|
|
96
|
+
1. Read Clean Architecture principles from `docs/guides/agents.clean.arch.md`
|
|
97
|
+
2. Identify code patterns violating clean architecture:
|
|
98
|
+
- **System interactions in business logic** (needs extraction to \*.system.ts)
|
|
99
|
+
- **Missing interfaces** (hardcoded dependencies)
|
|
100
|
+
- **Constructor without DI** (should accept dependencies)
|
|
101
|
+
- **Global singletons** (should use exported singleton pattern)
|
|
102
|
+
- **Test coupling** (unit tests requiring real system access)
|
|
103
|
+
3. Create git worktree at `.worktree/clean-${timestamp}`
|
|
104
|
+
4. Apply proposed refactorings in worktree:
|
|
105
|
+
- Extract interfaces for dependencies
|
|
106
|
+
- Create \*.system.ts files for system interactions
|
|
107
|
+
- Add dependency injection to constructors/functions
|
|
108
|
+
- Create mocks for testing
|
|
109
|
+
- Update test files to use mocks
|
|
110
|
+
5. Generate diff and summary
|
|
111
|
+
6. Report back with structured findings
|
|
112
|
+
|
|
113
|
+
**Agent will NOT:**
|
|
114
|
+
|
|
115
|
+
- Directly modify files in main working tree
|
|
116
|
+
- Commit changes automatically
|
|
117
|
+
- Push changes to remote
|
|
118
|
+
- Delete any code without explicit permission
|
|
119
|
+
- Change business logic behavior (only structure)
|
|
120
|
+
|
|
121
|
+
## Phase 2: Review Agent Findings
|
|
122
|
+
|
|
123
|
+
**Validate findings against Clean Architecture principles:**
|
|
124
|
+
|
|
125
|
+
### 2.1 Parse Agent Report
|
|
126
|
+
|
|
127
|
+
Extract from agent response:
|
|
128
|
+
|
|
129
|
+
- **Violations found**: List of architecture violations with severity
|
|
130
|
+
- **Worktree location**: Path to worktree with proposed refactorings
|
|
131
|
+
- **Diff summary**: Overview of proposed changes
|
|
132
|
+
- **Metrics**: Files refactored, interfaces created, coverage improvement
|
|
133
|
+
|
|
134
|
+
### 2.2 Validate Refactorings
|
|
135
|
+
|
|
136
|
+
Review the proposed refactorings:
|
|
137
|
+
|
|
138
|
+
**Review checklist:**
|
|
139
|
+
|
|
140
|
+
- [ ] Are interfaces properly defined? (Correct contract boundaries)
|
|
141
|
+
- [ ] Is DI implemented correctly? (Constructor or parameter injection)
|
|
142
|
+
- [ ] Are system files named correctly? (\*.system.ts suffix)
|
|
143
|
+
- [ ] Do mocks follow naming convention? (tests/mocks/\*-mock.ts)
|
|
144
|
+
- [ ] Is coverage configuration updated? (\*_/_.system.ts exclusion)
|
|
145
|
+
- [ ] Are tests updated to use mocks? (No real system calls)
|
|
146
|
+
- [ ] Does refactoring preserve behavior? (No logic changes)
|
|
147
|
+
|
|
148
|
+
**If issues found in agent's recommendations:**
|
|
149
|
+
|
|
150
|
+
```text
|
|
151
|
+
Agent proposed interface IUserAPI but it's too broad (God interface).
|
|
152
|
+
→ Request agent to split into focused interfaces
|
|
153
|
+
|
|
154
|
+
Agent suggested *.system.ts but file contains business logic.
|
|
155
|
+
→ Request agent to separate business logic from system calls
|
|
156
|
+
|
|
157
|
+
Agent created mock but it doesn't implement interface correctly.
|
|
158
|
+
→ Request agent to fix mock implementation
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
### 2.3 Request Refinements (if needed)
|
|
162
|
+
|
|
163
|
+
If issues identified with agent's recommendations:
|
|
164
|
+
|
|
165
|
+
```typescript
|
|
166
|
+
// Re-invoke agent with feedback
|
|
167
|
+
await Task({
|
|
168
|
+
subagent_type: "general-purpose",
|
|
169
|
+
description: "Refine Clean Architecture analysis",
|
|
170
|
+
prompt: `Review and refine previous analysis based on feedback:
|
|
171
|
+
|
|
172
|
+
Previous findings: [agent report]
|
|
173
|
+
|
|
174
|
+
Feedback:
|
|
175
|
+
${feedback}
|
|
176
|
+
|
|
177
|
+
Update worktree with refined refactorings and report back.`,
|
|
178
|
+
});
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
Repeat until analysis quality is satisfactory.
|
|
182
|
+
|
|
183
|
+
## Phase 3: Generate Clean Architecture Report
|
|
184
|
+
|
|
185
|
+
**Create `.clean.local.md` with comprehensive findings:**
|
|
186
|
+
|
|
187
|
+
````markdown
|
|
188
|
+
# Clean Architecture Analysis Report
|
|
189
|
+
|
|
190
|
+
**Generated:** [timestamp ISO]
|
|
191
|
+
**Scope:** [analyzed scope]
|
|
192
|
+
**Mode:** [file | directory | pattern | diff]
|
|
193
|
+
**Worktree:** `.worktree/clean-[timestamp]`
|
|
194
|
+
**Agent:** general-purpose
|
|
195
|
+
**Reviewed by:** Claude Code
|
|
196
|
+
|
|
197
|
+
---
|
|
198
|
+
|
|
199
|
+
## Executive Summary
|
|
200
|
+
|
|
201
|
+
**Total Violations:** [count]
|
|
202
|
+
|
|
203
|
+
- 🔴 Critical: [count] (Blocking architecture issues)
|
|
204
|
+
- 🟠 High: [count] (Significant testability problems)
|
|
205
|
+
- 🟡 Medium: [count] (Minor improvements)
|
|
206
|
+
- 🟢 Low: [count] (Nice-to-have)
|
|
207
|
+
|
|
208
|
+
**Potential Impact:**
|
|
209
|
+
|
|
210
|
+
- **Interfaces created:** [count]
|
|
211
|
+
- **System files extracted:** [count] (\*.system.ts)
|
|
212
|
+
- **Mocks created:** [count]
|
|
213
|
+
- **Coverage improvement:** [percentage]% ([count] lines now testable)
|
|
214
|
+
- **Files refactored:** [count]
|
|
215
|
+
|
|
216
|
+
**Overall Assessment:** [summary]
|
|
217
|
+
|
|
218
|
+
---
|
|
219
|
+
|
|
220
|
+
## Detailed Findings
|
|
221
|
+
|
|
222
|
+
### 🔴 Critical Violations (Must Fix)
|
|
223
|
+
|
|
224
|
+
#### 1. [Violation Title] - [File:Line]
|
|
225
|
+
|
|
226
|
+
**Category:** [Mixed Logic | Missing Interface | Hardcoded Dependency | System Naming | Coverage]
|
|
227
|
+
|
|
228
|
+
**Severity:** Critical
|
|
229
|
+
|
|
230
|
+
**Current Code:**
|
|
231
|
+
|
|
232
|
+
```typescript
|
|
233
|
+
// File: src/utils/auth.ts
|
|
234
|
+
export async function authenticate(username: string): Promise<User> {
|
|
235
|
+
// System interaction mixed with business logic
|
|
236
|
+
const { stdout } = await execSync(`ldap-query ${username}`);
|
|
237
|
+
const user = JSON.parse(stdout);
|
|
238
|
+
|
|
239
|
+
// Business logic
|
|
240
|
+
if (!user.active) {
|
|
241
|
+
throw new Error("User inactive");
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
return user;
|
|
245
|
+
}
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
**Problem:**
|
|
249
|
+
|
|
250
|
+
- System interaction (`execSync`) mixed with business logic (user validation)
|
|
251
|
+
- Cannot unit test without executing real LDAP queries
|
|
252
|
+
- No interface for LDAP operations (hardcoded dependency)
|
|
253
|
+
- File excluded from coverage unnecessarily
|
|
254
|
+
|
|
255
|
+
**Proposed Solution:**
|
|
256
|
+
|
|
257
|
+
**Interface:** `src/utils/ldap-interface.ts`
|
|
258
|
+
|
|
259
|
+
```typescript
|
|
260
|
+
export interface ILDAPClient {
|
|
261
|
+
queryUser(username: string): Promise<LDAPUser>;
|
|
262
|
+
}
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
**System Implementation:** `src/utils/ldap.system.ts`
|
|
266
|
+
|
|
267
|
+
```typescript
|
|
268
|
+
import type { ILDAPClient, LDAPUser } from "./ldap-interface.js";
|
|
269
|
+
import { execSync } from "node:child_process";
|
|
270
|
+
|
|
271
|
+
export class LDAPClient implements ILDAPClient {
|
|
272
|
+
async queryUser(username: string): Promise<LDAPUser> {
|
|
273
|
+
const { stdout } = await execSync(`ldap-query ${username}`);
|
|
274
|
+
return JSON.parse(stdout);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
export const defaultLDAP = new LDAPClient();
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
**Business Logic:** `src/utils/auth.ts` (refactored)
|
|
282
|
+
|
|
283
|
+
```typescript
|
|
284
|
+
import type { ILDAPClient } from "./ldap-interface.js";
|
|
285
|
+
import { defaultLDAP } from "./ldap.system.js";
|
|
286
|
+
|
|
287
|
+
export interface AuthDependencies {
|
|
288
|
+
ldap: ILDAPClient;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
export async function authenticate(username: string, deps?: AuthDependencies): Promise<User> {
|
|
292
|
+
const ldap = deps?.ldap ?? defaultLDAP;
|
|
293
|
+
|
|
294
|
+
const user = await ldap.queryUser(username);
|
|
295
|
+
|
|
296
|
+
if (!user.active) {
|
|
297
|
+
throw new Error("User inactive");
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
return user;
|
|
301
|
+
}
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
**Mock:** `tests/mocks/ldap-mock.ts`
|
|
305
|
+
|
|
306
|
+
```typescript
|
|
307
|
+
import type { ILDAPClient, LDAPUser } from "../../src/utils/ldap-interface.js";
|
|
308
|
+
|
|
309
|
+
export class MockLDAPClient implements ILDAPClient {
|
|
310
|
+
private users = new Map<string, LDAPUser>();
|
|
311
|
+
|
|
312
|
+
setUser(username: string, user: LDAPUser): void {
|
|
313
|
+
this.users.set(username, user);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
async queryUser(username: string): Promise<LDAPUser> {
|
|
317
|
+
const user = this.users.get(username);
|
|
318
|
+
if (!user) throw new Error(`User not found: ${username}`);
|
|
319
|
+
return user;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
**Test:** `tests/unit/auth.test.ts` (new)
|
|
325
|
+
|
|
326
|
+
```typescript
|
|
327
|
+
import { authenticate } from "../../src/utils/auth.js";
|
|
328
|
+
import { MockLDAPClient } from "../mocks/ldap-mock.js";
|
|
329
|
+
|
|
330
|
+
describe("authenticate", () => {
|
|
331
|
+
it("should reject inactive users", async () => {
|
|
332
|
+
const mockLDAP = new MockLDAPClient();
|
|
333
|
+
mockLDAP.setUser("john", { username: "john", active: false });
|
|
334
|
+
|
|
335
|
+
await expect(authenticate("john", { ldap: mockLDAP })).rejects.toThrow("User inactive");
|
|
336
|
+
});
|
|
337
|
+
});
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
**Impact:**
|
|
341
|
+
|
|
342
|
+
- **Testability**: Business logic now testable without LDAP access
|
|
343
|
+
- **Coverage**: auth.ts now included in coverage (was previously excluded)
|
|
344
|
+
- **Coverage improvement**: +45 lines testable (ldap.system.ts excluded, auth.ts included)
|
|
345
|
+
- **Files created**: 3 (interface, system, mock)
|
|
346
|
+
- **Tests enabled**: Can now write unit tests for auth logic
|
|
347
|
+
|
|
348
|
+
**Location in worktree:** `.worktree/clean-[timestamp]/src/utils/`
|
|
349
|
+
|
|
350
|
+
**Configuration update required:**
|
|
351
|
+
|
|
352
|
+
```toml
|
|
353
|
+
# bunfig.toml
|
|
354
|
+
coveragePathIgnorePatterns = [
|
|
355
|
+
"**/*.system.ts", # Excludes ldap.system.ts
|
|
356
|
+
# Remove: "src/utils/auth.ts" (now testable)
|
|
357
|
+
]
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
---
|
|
361
|
+
|
|
362
|
+
[Repeat for each critical violation]
|
|
363
|
+
|
|
364
|
+
### 🟠 High Priority Violations
|
|
365
|
+
|
|
366
|
+
[Same structure as critical]
|
|
367
|
+
|
|
368
|
+
### 🟡 Medium Priority Violations
|
|
369
|
+
|
|
370
|
+
[Same structure as critical]
|
|
371
|
+
|
|
372
|
+
### 🟢 Low Priority Violations
|
|
373
|
+
|
|
374
|
+
[Same structure as critical]
|
|
375
|
+
|
|
376
|
+
---
|
|
377
|
+
|
|
378
|
+
## Metrics Summary
|
|
379
|
+
|
|
380
|
+
### Coverage Impact
|
|
381
|
+
|
|
382
|
+
| Metric | Before | After | Improvement |
|
|
383
|
+
| ----------------------- | ------- | ------- | ----------- |
|
|
384
|
+
| Total lines covered | [count] | [count] | +[delta] |
|
|
385
|
+
| Coverage percentage | [pct]% | [pct]% | +[delta]% |
|
|
386
|
+
| Business logic testable | [count] | [count] | +[delta] |
|
|
387
|
+
| System files (excluded) | [count] | [count] | +[delta] |
|
|
388
|
+
|
|
389
|
+
### Refactoring Breakdown
|
|
390
|
+
|
|
391
|
+
- **Interfaces created:** [count]
|
|
392
|
+
- **System files extracted:** [count] (\*.system.ts)
|
|
393
|
+
- **Mocks created:** [count]
|
|
394
|
+
- **Business logic files refactored:** [count]
|
|
395
|
+
- **Test files created/updated:** [count]
|
|
396
|
+
- **Dependencies injected:** [count] classes/functions
|
|
397
|
+
|
|
398
|
+
### Architecture Violations
|
|
399
|
+
|
|
400
|
+
| Violation Type | Count | Resolved | Remaining |
|
|
401
|
+
| --------------------------- | ------- | -------- | --------- |
|
|
402
|
+
| Mixed business/system logic | [count] | [count] | [count] |
|
|
403
|
+
| Hardcoded dependencies | [count] | [count] | [count] |
|
|
404
|
+
| Missing interfaces | [count] | [count] | [count] |
|
|
405
|
+
| Incorrect file naming | [count] | [count] | [count] |
|
|
406
|
+
| Untestable code | [count] | [count] | [count] |
|
|
407
|
+
|
|
408
|
+
---
|
|
409
|
+
|
|
410
|
+
## Worktree Changes Overview
|
|
411
|
+
|
|
412
|
+
**Worktree location:** `.worktree/clean-[timestamp]`
|
|
413
|
+
|
|
414
|
+
**Files created:** [count]
|
|
415
|
+
|
|
416
|
+
- Interfaces: [count]
|
|
417
|
+
- System implementations: [count]
|
|
418
|
+
- Mocks: [count]
|
|
419
|
+
- Tests: [count]
|
|
420
|
+
|
|
421
|
+
**Files modified:** [count]
|
|
422
|
+
|
|
423
|
+
- Business logic refactored: [count]
|
|
424
|
+
- Tests updated: [count]
|
|
425
|
+
- Configuration: [count]
|
|
426
|
+
|
|
427
|
+
**Lines added:** [count]
|
|
428
|
+
**Lines removed:** [count]
|
|
429
|
+
**Net change:** [±X] lines
|
|
430
|
+
|
|
431
|
+
**Diff summary:**
|
|
432
|
+
|
|
433
|
+
```diff
|
|
434
|
+
src/utils/
|
|
435
|
+
+ ldap-interface.ts # Interface definition
|
|
436
|
+
+ ldap.system.ts # System implementation (excluded from coverage)
|
|
437
|
+
~ auth.ts # Refactored with DI (now testable)
|
|
438
|
+
|
|
439
|
+
tests/mocks/
|
|
440
|
+
+ ldap-mock.ts # Mock for testing
|
|
441
|
+
|
|
442
|
+
tests/unit/
|
|
443
|
+
+ auth.test.ts # New unit tests
|
|
444
|
+
|
|
445
|
+
bunfig.toml
|
|
446
|
+
- src/utils/auth.ts # Removed from coverage exclusion
|
|
447
|
+
```
|
|
448
|
+
|
|
449
|
+
**To review changes:**
|
|
450
|
+
|
|
451
|
+
```bash
|
|
452
|
+
# View full diff
|
|
453
|
+
git -C .worktree/clean-[timestamp] diff HEAD
|
|
454
|
+
|
|
455
|
+
# Compare specific refactoring
|
|
456
|
+
git -C .worktree/clean-[timestamp] diff HEAD -- src/utils/
|
|
457
|
+
|
|
458
|
+
# Browse worktree
|
|
459
|
+
cd .worktree/clean-[timestamp]
|
|
460
|
+
```
|
|
461
|
+
|
|
462
|
+
---
|
|
463
|
+
|
|
464
|
+
## Recommendations
|
|
465
|
+
|
|
466
|
+
### Immediate Actions (Critical Violations)
|
|
467
|
+
|
|
468
|
+
1. **Extract system interactions from [module]**
|
|
469
|
+
- Why: Business logic cannot be tested without real system access
|
|
470
|
+
- Impact: +[count] lines of testable code, +[percentage]% coverage
|
|
471
|
+
- Effort: [estimation] (interface + system file + mock + tests)
|
|
472
|
+
|
|
473
|
+
2. **Add dependency injection to [class/function]**
|
|
474
|
+
- Why: Hardcoded dependencies prevent testing and violate DIP
|
|
475
|
+
- Impact: Enables unit testing with mocks
|
|
476
|
+
- Effort: [estimation]
|
|
477
|
+
|
|
478
|
+
### Short-term Improvements (High Priority)
|
|
479
|
+
|
|
480
|
+
[Same structure as immediate actions]
|
|
481
|
+
|
|
482
|
+
### Long-term Enhancements (Medium/Low Priority)
|
|
483
|
+
|
|
484
|
+
[Same structure as immediate actions]
|
|
485
|
+
|
|
486
|
+
---
|
|
487
|
+
|
|
488
|
+
## Next Steps
|
|
489
|
+
|
|
490
|
+
You have several options for proceeding with these findings:
|
|
491
|
+
|
|
492
|
+
### Option 1: Accept Worktree Changes
|
|
493
|
+
|
|
494
|
+
Review and apply refactorings from the worktree:
|
|
495
|
+
|
|
496
|
+
```bash
|
|
497
|
+
# Review changes in worktree
|
|
498
|
+
cd .worktree/clean-[timestamp]
|
|
499
|
+
|
|
500
|
+
# Copy specific files back to main tree
|
|
501
|
+
cp src/utils/ldap-interface.ts ../../src/utils/
|
|
502
|
+
cp src/utils/ldap.system.ts ../../src/utils/
|
|
503
|
+
cp src/utils/auth.ts ../../src/utils/
|
|
504
|
+
|
|
505
|
+
# Or merge all changes
|
|
506
|
+
git -C .worktree/clean-[timestamp] format-patch HEAD~1
|
|
507
|
+
git am < .worktree/clean-[timestamp]/0001-*.patch
|
|
508
|
+
|
|
509
|
+
# Update coverage configuration
|
|
510
|
+
# (bunfig.toml and sonar-project.properties)
|
|
511
|
+
|
|
512
|
+
# Run tests to verify
|
|
513
|
+
bun test
|
|
514
|
+
|
|
515
|
+
# Clean up worktree when done
|
|
516
|
+
git worktree remove .worktree/clean-[timestamp]
|
|
517
|
+
```
|
|
518
|
+
|
|
519
|
+
### Option 2: Debate and Refine
|
|
520
|
+
|
|
521
|
+
If you disagree with any refactorings:
|
|
522
|
+
|
|
523
|
+
```text
|
|
524
|
+
/architect:clean [scope] --compare
|
|
525
|
+
|
|
526
|
+
Review the differences and provide feedback.
|
|
527
|
+
Agent will be re-invoked with your feedback.
|
|
528
|
+
```
|
|
529
|
+
|
|
530
|
+
### Option 3: Convert to Tasks
|
|
531
|
+
|
|
532
|
+
Create Task Master tasks for systematic refactoring:
|
|
533
|
+
|
|
534
|
+
```text
|
|
535
|
+
/task:add "Refactor auth module with Clean Architecture DI"
|
|
536
|
+
- Reference: .clean.local.md#auth-refactoring
|
|
537
|
+
- Priority: High
|
|
538
|
+
- Complexity: Medium
|
|
539
|
+
|
|
540
|
+
/task:add "Create LDAP interface and system implementation"
|
|
541
|
+
- Reference: .clean.local.md#ldap-extraction
|
|
542
|
+
- Priority: High
|
|
543
|
+
- Complexity: Low
|
|
544
|
+
```
|
|
545
|
+
|
|
546
|
+
### Option 4: Convert to Bugs
|
|
547
|
+
|
|
548
|
+
For critical architecture violations blocking development:
|
|
549
|
+
|
|
550
|
+
```text
|
|
551
|
+
/bug "Auth module mixed with system calls, untestable"
|
|
552
|
+
- Reference: .clean.local.md#auth-mixed-logic
|
|
553
|
+
- Priority: Critical
|
|
554
|
+
- Impact: Cannot unit test authentication logic
|
|
555
|
+
|
|
556
|
+
/bug "Database module hardcoded, blocks testing"
|
|
557
|
+
- Reference: .clean.local.md#db-hardcoded
|
|
558
|
+
- Priority: High
|
|
559
|
+
- Impact: Integration tests slow, flaky
|
|
560
|
+
```
|
|
561
|
+
|
|
562
|
+
### Option 5: Staged Approach
|
|
563
|
+
|
|
564
|
+
Combine approaches for large refactorings:
|
|
565
|
+
|
|
566
|
+
1. **Week 1**: Fix critical violations (accept worktree changes for core modules)
|
|
567
|
+
2. **Week 2**: Create tasks for high-priority refactorings
|
|
568
|
+
3. **Week 3**: Update tests and verify coverage improvements
|
|
569
|
+
4. **Week 4**: Review and document exceptions for low-priority items
|
|
570
|
+
|
|
571
|
+
---
|
|
572
|
+
|
|
573
|
+
## Comparison with Previous Report
|
|
574
|
+
|
|
575
|
+
[Only if --compare used]
|
|
576
|
+
|
|
577
|
+
### Changes Since Last Analysis ([date])
|
|
578
|
+
|
|
579
|
+
**New violations identified:** [count]
|
|
580
|
+
**Violations resolved:** [count]
|
|
581
|
+
**Violations regressed:** [count]
|
|
582
|
+
|
|
583
|
+
### Metric Trends
|
|
584
|
+
|
|
585
|
+
| Metric | Previous | Current | Trend |
|
|
586
|
+
| ------------------- | -------- | ------- | ----- |
|
|
587
|
+
| Coverage percentage | [pct]% | [pct]% | [↑↓→] |
|
|
588
|
+
| Testable lines | [count] | [count] | [↑↓→] |
|
|
589
|
+
| System files | [count] | [count] | [↑↓→] |
|
|
590
|
+
| Interfaces | [count] | [count] | [↑↓→] |
|
|
591
|
+
|
|
592
|
+
### Status Changes
|
|
593
|
+
|
|
594
|
+
**Improved:**
|
|
595
|
+
|
|
596
|
+
- [Violation that was fixed]
|
|
597
|
+
|
|
598
|
+
**Regressed:**
|
|
599
|
+
|
|
600
|
+
- [Violation that got worse]
|
|
601
|
+
|
|
602
|
+
**New:**
|
|
603
|
+
|
|
604
|
+
- [Newly identified violation]
|
|
605
|
+
|
|
606
|
+
---
|
|
607
|
+
|
|
608
|
+
## Analysis Configuration
|
|
609
|
+
|
|
610
|
+
**Principles applied:**
|
|
611
|
+
|
|
612
|
+
- Dependency Rule (dependencies point inward)
|
|
613
|
+
- Interface-based boundaries
|
|
614
|
+
- Dependency injection (constructor or parameter)
|
|
615
|
+
- Testability first (unit vs integration)
|
|
616
|
+
|
|
617
|
+
**Naming conventions:**
|
|
618
|
+
|
|
619
|
+
- Interfaces: `I{Name}` (e.g., ILDAPClient)
|
|
620
|
+
- System files: `*.system.ts` (e.g., ldap.system.ts)
|
|
621
|
+
- Mocks: `tests/mocks/{name}-mock.ts`
|
|
622
|
+
|
|
623
|
+
**Coverage patterns:**
|
|
624
|
+
|
|
625
|
+
- Glob exclusion: `**/*.system.ts`
|
|
626
|
+
- System files: Thin wrappers, no business logic
|
|
627
|
+
- Business logic: Fully testable with mocks
|
|
628
|
+
|
|
629
|
+
**Excluded paths:**
|
|
630
|
+
|
|
631
|
+
- `node_modules/**`
|
|
632
|
+
- `dist/**`
|
|
633
|
+
- `**/*.test.ts`
|
|
634
|
+
- `**/*.d.ts`
|
|
635
|
+
- `**/*.system.ts` (system interactions)
|
|
636
|
+
|
|
637
|
+
---
|
|
638
|
+
|
|
639
|
+
## Agent Performance
|
|
640
|
+
|
|
641
|
+
**Analysis time:** [duration]
|
|
642
|
+
**Files analyzed:** [count]
|
|
643
|
+
**Violations found:** [count]
|
|
644
|
+
**Refactorings proposed:** [count] files
|
|
645
|
+
|
|
646
|
+
**Agent effectiveness:**
|
|
647
|
+
|
|
648
|
+
- True positives: [count/count] ([percentage]%)
|
|
649
|
+
- False positives: [count] (refined by Claude Code)
|
|
650
|
+
- Refactorings accepted: [count/count] ([percentage]%)
|
|
651
|
+
|
|
652
|
+
---
|
|
653
|
+
|
|
654
|
+
## References
|
|
655
|
+
|
|
656
|
+
- **Clean Architecture Principles:** `docs/guides/agents.clean.arch.md`
|
|
657
|
+
- **TypeScript Implementation:** `docs/guides/agents.clean.arch.ts.md`
|
|
658
|
+
- **Command Documentation:** `docs/commands/architect/clean.md`
|
|
659
|
+
- **KISS Analysis:** `docs/commands/architect/kiss.md` (Complementary complexity reduction)
|
|
660
|
+
- **Worktree Location:** `.worktree/clean-[timestamp]`
|
|
661
|
+
|
|
662
|
+
---
|
|
663
|
+
|
|
664
|
+
**Report generated by:** General-Purpose Agent (reviewed by Claude Code)
|
|
665
|
+
**Report location:** `.clean.local.md`
|
|
666
|
+
**Execution time:** [total duration]
|
|
667
|
+
````
|
|
668
|
+
|
|
669
|
+
## Phase 4: Present Results to User
|
|
670
|
+
|
|
671
|
+
### 4.1 Write Report to File
|
|
672
|
+
|
|
673
|
+
```bash
|
|
674
|
+
# Write report to .clean.local.md
|
|
675
|
+
cat > .clean.local.md <<EOF
|
|
676
|
+
[Generated report from Phase 3]
|
|
677
|
+
EOF
|
|
678
|
+
```
|
|
679
|
+
|
|
680
|
+
### 4.2 Open in Editor
|
|
681
|
+
|
|
682
|
+
```bash
|
|
683
|
+
# Open report in VS Code
|
|
684
|
+
code .clean.local.md
|
|
685
|
+
```
|
|
686
|
+
|
|
687
|
+
### 4.3 Console Summary
|
|
688
|
+
|
|
689
|
+
Print concise summary to console:
|
|
690
|
+
|
|
691
|
+
```text
|
|
692
|
+
🏛️ Clean Architecture Analysis Complete
|
|
693
|
+
|
|
694
|
+
Scope: [analyzed scope]
|
|
695
|
+
Violations found: [total count]
|
|
696
|
+
🔴 Critical: [count]
|
|
697
|
+
🟠 High: [count]
|
|
698
|
+
🟡 Medium: [count]
|
|
699
|
+
🟢 Low: [count]
|
|
700
|
+
|
|
701
|
+
Refactorings proposed:
|
|
702
|
+
- Create [count] interfaces
|
|
703
|
+
- Extract [count] system files (*.system.ts)
|
|
704
|
+
- Add [count] mocks for testing
|
|
705
|
+
- Improve coverage by [percentage]% (+[count] testable lines)
|
|
706
|
+
|
|
707
|
+
Worktree created: .worktree/clean-[timestamp]
|
|
708
|
+
Report: .clean.local.md (opened in editor)
|
|
709
|
+
|
|
710
|
+
Next steps:
|
|
711
|
+
1. Review findings in .clean.local.md
|
|
712
|
+
2. Check worktree diff: cd .worktree/clean-[timestamp] && git diff HEAD
|
|
713
|
+
3. Choose action:
|
|
714
|
+
- Accept changes (copy from worktree)
|
|
715
|
+
- Debate findings (/architect:clean --compare)
|
|
716
|
+
- Convert to tasks (/task:add <description>)
|
|
717
|
+
- Convert to bugs (/bug <summary>)
|
|
718
|
+
|
|
719
|
+
Questions?
|
|
720
|
+
- View all changes: git -C .worktree/clean-[timestamp] diff HEAD
|
|
721
|
+
- Review specific file: git -C .worktree/clean-[timestamp] show HEAD:[file]
|
|
722
|
+
- Remove worktree: git worktree remove .worktree/clean-[timestamp]
|
|
723
|
+
```
|
|
724
|
+
|
|
725
|
+
### 4.4 Interactive Prompts
|
|
726
|
+
|
|
727
|
+
Ask user for next action:
|
|
728
|
+
|
|
729
|
+
```text
|
|
730
|
+
What would you like to do next?
|
|
731
|
+
|
|
732
|
+
1. Review worktree changes in detail
|
|
733
|
+
2. Accept all worktree changes
|
|
734
|
+
3. Accept specific files from worktree
|
|
735
|
+
4. Debate findings and refine
|
|
736
|
+
5. Convert critical violations to tasks
|
|
737
|
+
6. Convert critical violations to bugs
|
|
738
|
+
7. Clean up worktree and exit
|
|
739
|
+
|
|
740
|
+
Enter choice [1-7]:
|
|
741
|
+
```
|
|
742
|
+
|
|
743
|
+
**Handle user responses:**
|
|
744
|
+
|
|
745
|
+
**Choice 1: Review worktree changes**
|
|
746
|
+
|
|
747
|
+
```bash
|
|
748
|
+
cd .worktree/clean-[timestamp]
|
|
749
|
+
git diff HEAD --stat
|
|
750
|
+
git diff HEAD
|
|
751
|
+
```
|
|
752
|
+
|
|
753
|
+
**Choice 2: Accept all worktree changes**
|
|
754
|
+
|
|
755
|
+
```bash
|
|
756
|
+
# Confirm with user first
|
|
757
|
+
echo "⚠️ This will overwrite files in your main working tree."
|
|
758
|
+
echo " Worktree: .worktree/clean-[timestamp]"
|
|
759
|
+
echo " Files affected: [count]"
|
|
760
|
+
read -p "Continue? [y/N] " confirm
|
|
761
|
+
|
|
762
|
+
if [[ "$confirm" == "y" ]]; then
|
|
763
|
+
# Copy files from worktree
|
|
764
|
+
git -C .worktree/clean-[timestamp] diff --name-only HEAD | while read file; do
|
|
765
|
+
cp ".worktree/clean-[timestamp]/$file" "$file"
|
|
766
|
+
done
|
|
767
|
+
echo "✓ Changes applied. Review with 'git diff'"
|
|
768
|
+
echo "⚠️ Update bunfig.toml and sonar-project.properties coverage exclusions"
|
|
769
|
+
fi
|
|
770
|
+
```
|
|
771
|
+
|
|
772
|
+
**Choice 3: Accept specific files**
|
|
773
|
+
|
|
774
|
+
```bash
|
|
775
|
+
# Show list of changed files
|
|
776
|
+
echo "Select files to apply (space-separated indices):"
|
|
777
|
+
git -C .worktree/clean-[timestamp] diff --name-only HEAD | nl
|
|
778
|
+
read -p "Files: " selections
|
|
779
|
+
|
|
780
|
+
# Copy selected files
|
|
781
|
+
for idx in $selections; do
|
|
782
|
+
file=$(git -C .worktree/clean-[timestamp] diff --name-only HEAD | sed -n "${idx}p")
|
|
783
|
+
cp ".worktree/clean-[timestamp]/$file" "$file"
|
|
784
|
+
echo "✓ Applied: $file"
|
|
785
|
+
done
|
|
786
|
+
```
|
|
787
|
+
|
|
788
|
+
**Choice 4: Debate findings**
|
|
789
|
+
|
|
790
|
+
```bash
|
|
791
|
+
echo "Which findings do you disagree with? (Reference by issue number from report)"
|
|
792
|
+
read -p "Issue numbers: " issues
|
|
793
|
+
echo "What are your concerns?"
|
|
794
|
+
read -p "Feedback: " feedback
|
|
795
|
+
|
|
796
|
+
# Re-invoke agent with feedback (Phase 2.3)
|
|
797
|
+
```
|
|
798
|
+
|
|
799
|
+
**Choice 5: Convert to tasks**
|
|
800
|
+
|
|
801
|
+
```bash
|
|
802
|
+
echo "Converting critical and high-priority violations to Task Master tasks..."
|
|
803
|
+
|
|
804
|
+
# Parse critical violations from report
|
|
805
|
+
# Create tasks using /task:add for each
|
|
806
|
+
|
|
807
|
+
/task:add "Refactor [module] with Clean Architecture DI" \
|
|
808
|
+
--priority high \
|
|
809
|
+
--reference .clean.local.md#issue-1
|
|
810
|
+
|
|
811
|
+
echo "✓ Created [count] tasks. View with /task:status"
|
|
812
|
+
```
|
|
813
|
+
|
|
814
|
+
**Choice 6: Convert to bugs**
|
|
815
|
+
|
|
816
|
+
```bash
|
|
817
|
+
echo "Converting critical violations to bugs..."
|
|
818
|
+
|
|
819
|
+
# Parse critical violations from report
|
|
820
|
+
# Create bugs using /bug for each
|
|
821
|
+
|
|
822
|
+
/bug "Critical: [module] untestable due to mixed logic"
|
|
823
|
+
# Reference: .clean.local.md#issue-1
|
|
824
|
+
|
|
825
|
+
echo "✓ Created [count] bugs. View in .bugs.local.md"
|
|
826
|
+
```
|
|
827
|
+
|
|
828
|
+
**Choice 7: Clean up and exit**
|
|
829
|
+
|
|
830
|
+
```bash
|
|
831
|
+
echo "Cleaning up worktree..."
|
|
832
|
+
git worktree remove .worktree/clean-[timestamp]
|
|
833
|
+
echo "✓ Worktree removed. Report saved to .clean.local.md"
|
|
834
|
+
```
|
|
835
|
+
|
|
836
|
+
## Error Handling
|
|
837
|
+
|
|
838
|
+
**Clean Architecture guide missing:**
|
|
839
|
+
|
|
840
|
+
- Error: "❌ Cannot find docs/guides/agents.clean.arch.md. This file contains Clean Architecture principles for analysis."
|
|
841
|
+
- Exit with status 1
|
|
842
|
+
|
|
843
|
+
**No files in scope:**
|
|
844
|
+
|
|
845
|
+
- Warning: "⚠️ No files found matching scope: [scope]"
|
|
846
|
+
- Exit with status 0
|
|
847
|
+
|
|
848
|
+
**Agent fails to respond:**
|
|
849
|
+
|
|
850
|
+
- Error: "❌ Agent failed to complete analysis."
|
|
851
|
+
- Show agent error message
|
|
852
|
+
- Exit with status 2
|
|
853
|
+
|
|
854
|
+
**Worktree creation fails:**
|
|
855
|
+
|
|
856
|
+
- Error: "❌ Cannot create git worktree. Ensure git is available and working tree is clean."
|
|
857
|
+
- Suggestion: "Run 'git status' to check for conflicts"
|
|
858
|
+
- Exit with status 3
|
|
859
|
+
|
|
860
|
+
**Git not available:**
|
|
861
|
+
|
|
862
|
+
- Error: "❌ Git is required for worktree functionality."
|
|
863
|
+
- Exit with status 4
|
|
864
|
+
|
|
865
|
+
**Invalid comparison:**
|
|
866
|
+
|
|
867
|
+
- Warning: "⚠️ --compare flag used but .clean.local.md not found. Cannot compare."
|
|
868
|
+
- Continue without comparison
|
|
869
|
+
|
|
870
|
+
## Exit Codes
|
|
871
|
+
|
|
872
|
+
- 0: Analysis completed successfully
|
|
873
|
+
- 1: Missing required files (Clean Architecture guide)
|
|
874
|
+
- 2: Agent execution failure
|
|
875
|
+
- 3: Worktree creation failure
|
|
876
|
+
- 4: Git not available
|
|
877
|
+
- 5: User canceled operation
|
|
878
|
+
|
|
879
|
+
## Quick Reference
|
|
880
|
+
|
|
881
|
+
**Common workflows:**
|
|
882
|
+
|
|
883
|
+
```bash
|
|
884
|
+
# Analyze specific module for refactoring
|
|
885
|
+
/architect:clean src/utils/auth.ts
|
|
886
|
+
|
|
887
|
+
# Analyze directory
|
|
888
|
+
/architect:clean src/utils/
|
|
889
|
+
|
|
890
|
+
# Before committing
|
|
891
|
+
/architect:clean # Analyze git-changed files
|
|
892
|
+
/architect:clean --strict # Fail on violations
|
|
893
|
+
|
|
894
|
+
# Review and refine
|
|
895
|
+
/architect:clean --compare # Compare with previous analysis
|
|
896
|
+
|
|
897
|
+
# Apply changes
|
|
898
|
+
/architect:clean --apply # Create worktree and apply refactorings (requires review)
|
|
899
|
+
```
|
|
900
|
+
|
|
901
|
+
**Mode summary:**
|
|
902
|
+
|
|
903
|
+
- File path → Analyze single file
|
|
904
|
+
- Directory path → Analyze all files in directory
|
|
905
|
+
- Pattern → Analyze files matching glob pattern
|
|
906
|
+
- No scope / `--diff` → Analyze git-changed files only
|
|
907
|
+
|
|
908
|
+
**Integration with existing workflows:**
|
|
909
|
+
|
|
910
|
+
```bash
|
|
911
|
+
# Option 1: Accept refactorings directly
|
|
912
|
+
/architect:clean src/
|
|
913
|
+
# Review .clean.local.md
|
|
914
|
+
# Accept changes from worktree
|
|
915
|
+
|
|
916
|
+
# Option 2: Convert to structured work
|
|
917
|
+
/architect:clean src/
|
|
918
|
+
# Review findings
|
|
919
|
+
/task:add "Refactor auth with Clean Architecture"
|
|
920
|
+
/bug "Critical: DB module untestable"
|
|
921
|
+
|
|
922
|
+
# Option 3: Iterative refinement
|
|
923
|
+
/architect:clean src/
|
|
924
|
+
# Review and provide feedback
|
|
925
|
+
/architect:clean src/ --compare # Re-analyze with refinements
|
|
926
|
+
```
|
|
927
|
+
|
|
928
|
+
## Implementation Notes
|
|
929
|
+
|
|
930
|
+
This command focuses on identifying and fixing Clean Architecture violations:
|
|
931
|
+
|
|
932
|
+
**Key violations detected:**
|
|
933
|
+
|
|
934
|
+
1. **Mixed business logic and system interactions**
|
|
935
|
+
- Business logic files containing file I/O, shell execution, network calls
|
|
936
|
+
- Solution: Extract to `*.system.ts` with interface
|
|
937
|
+
|
|
938
|
+
2. **Hardcoded dependencies**
|
|
939
|
+
- Direct imports of concrete implementations
|
|
940
|
+
- Solution: Define interface, use DI
|
|
941
|
+
|
|
942
|
+
3. **Missing dependency injection**
|
|
943
|
+
- Classes/functions with hardcoded dependencies
|
|
944
|
+
- Solution: Constructor or parameter injection with default
|
|
945
|
+
|
|
946
|
+
4. **Incorrect file naming**
|
|
947
|
+
- System files not using `*.system.ts` suffix
|
|
948
|
+
- Solution: Rename and update imports
|
|
949
|
+
|
|
950
|
+
5. **Coverage configuration issues**
|
|
951
|
+
- Business logic excluded from coverage
|
|
952
|
+
- System files not excluded
|
|
953
|
+
- Solution: Update glob patterns in bunfig.toml and sonar-project.properties
|
|
954
|
+
|
|
955
|
+
6. **Poor folder organization**
|
|
956
|
+
- 5+ related files scattered with common prefix instead of in module folder
|
|
957
|
+
- Solution: Create module folder with index.ts for public API
|
|
958
|
+
|
|
959
|
+
**Refactoring patterns applied:**
|
|
960
|
+
|
|
961
|
+
- Interface-based boundaries (IService pattern)
|
|
962
|
+
- Constructor-based DI with exported singleton
|
|
963
|
+
- System file extraction (`*.system.ts`)
|
|
964
|
+
- Mock creation (`tests/mocks/*-mock.ts`)
|
|
965
|
+
- Test updates (use mocks instead of real systems)
|
|
966
|
+
- Coverage configuration updates (glob patterns)
|
|
967
|
+
- Module folder organization (5+ related files → `module/` folder)
|
|
968
|
+
- Public API via `index.ts` re-exports
|
|
969
|
+
|
|
970
|
+
**Clean Architecture layers:**
|
|
971
|
+
|
|
972
|
+
```text
|
|
973
|
+
Business Logic (inner)
|
|
974
|
+
↓ depends on
|
|
975
|
+
Interface (boundary)
|
|
976
|
+
↑ implemented by
|
|
977
|
+
System Implementation (outer) - *.system.ts
|
|
978
|
+
```
|