@intentsolutionsio/code-cleanup 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.
@@ -0,0 +1,105 @@
1
+ # Safety Protocol
2
+
3
+ Rules for safe code cleanup. Every cleanup session follows this protocol.
4
+
5
+ ---
6
+
7
+ ## Pre-Cleanup Checklist
8
+
9
+ 1. **Clean git state** — `git status --porcelain` must be empty
10
+ 2. **Record baseline** — save `git rev-parse HEAD` for rollback
11
+ 3. **Green tests** — run existing test suite, confirm passing
12
+ 4. **Backup branch** — `git branch cleanup-backup` before starting
13
+
14
+ If any check fails, stop and ask the user before proceeding.
15
+
16
+ ## Confidence Scoring
17
+
18
+ Every finding gets a confidence score:
19
+
20
+ | Level | Criteria | Action |
21
+ |-------|----------|--------|
22
+ | **HIGH** | Tool confirms unused, type system proves safe, tests pass after removal | Auto-apply (if dimension allows) |
23
+ | **MEDIUM** | Pattern match is strong, but dynamic usage possible | Flag with suggested fix |
24
+ | **LOW** | Heuristic match only, could be intentional | Flag with explanation only |
25
+
26
+ **Scoring rules:**
27
+ - Tool verification (knip, madge, tsc) → +1 confidence level
28
+ - Multiple signals pointing to same issue → +1 confidence level
29
+ - Dynamic usage possible (reflection, eval, metaprogramming) → -1 confidence level
30
+ - Code is in test/fixture directory → -1 confidence level
31
+ - Code has comments explaining why it exists → -1 confidence level
32
+
33
+ ## Revert Procedures
34
+
35
+ ### Revert Single Dimension
36
+ ```bash
37
+ # Undo all unstaged changes
38
+ git checkout -- .
39
+
40
+ # Or selectively revert specific files
41
+ git checkout -- src/path/to/file.ts
42
+ ```
43
+
44
+ ### Revert Everything
45
+ ```bash
46
+ # Reset to pre-cleanup state
47
+ git reset --hard <baseline-commit-hash>
48
+ ```
49
+
50
+ ### Partial Revert (Keep Some Changes)
51
+ ```bash
52
+ # Interactive: review each hunk
53
+ git add -p # Stage only the changes you want to keep
54
+ git checkout -- . # Discard the rest
55
+ ```
56
+
57
+ ## Dimension Risk Matrix
58
+
59
+ | Risk Level | Dimensions | Auto-Apply Policy |
60
+ |------------|-----------|-------------------|
61
+ | **LOW** | dead, slop | Apply after build verification |
62
+ | **MEDIUM** | types, security, legacy, typecons, defensive, perf | Varies — see dimension table in SKILL.md |
63
+ | **HIGH** | dry, async, circular | Flag only — never auto-apply |
64
+
65
+ ## Never Auto-Apply Rules
66
+
67
+ These findings are ALWAYS flagged, never auto-applied:
68
+
69
+ 1. **Security findings** — hardcoded secrets, injection vectors
70
+ 2. **Async pattern changes** — risk of introducing race conditions
71
+ 3. **Circular dependency restructuring** — architectural change
72
+ 4. **DRY extractions** — premature abstraction risk
73
+ 5. **Defensive code removal** — might guard against runtime edge cases
74
+ 6. **Performance optimizations** — need benchmarking evidence
75
+
76
+ ## Build Verification Gate
77
+
78
+ After every auto-applied dimension:
79
+
80
+ 1. Run type checker (`tsc --noEmit`, `mypy`, etc.)
81
+ 2. Run test suite (`npm test`, `pytest`, `go test`, etc.)
82
+ 3. Run linter (`eslint`, `ruff`, `golangci-lint`, etc.)
83
+
84
+ **If any step fails:**
85
+ 1. Immediately revert: `git checkout -- .`
86
+ 2. Log which changes caused the failure
87
+ 3. Re-apply only the safe subset
88
+ 4. Move failed items to "Flagged for Review"
89
+
90
+ ## Common False Positive Patterns
91
+
92
+ Be cautious when encountering:
93
+
94
+ | Pattern | Why It's Tricky |
95
+ |---------|----------------|
96
+ | Dynamic `require()`/`import()` | Static analysis can't see usage |
97
+ | Reflection / `Object.keys()` | Properties accessed dynamically |
98
+ | Dependency injection | Usage is in config, not in code |
99
+ | Event emitters | Listeners registered elsewhere |
100
+ | Plugin systems | Entry points called by framework |
101
+ | Test utilities | Used in test files, not source |
102
+ | CLI entry points | Called by shell, not by code |
103
+ | Webpack/Vite magic | Loaders transform at build time |
104
+
105
+ When in doubt, **flag** rather than **apply**.
@@ -0,0 +1,185 @@
1
+ # Cleanup Tools Reference
2
+
3
+ Language-specific tools for each cleanup dimension. Always fall back to grep patterns
4
+ (see [patterns.md](patterns.md)) when tools aren't installed.
5
+
6
+ ---
7
+
8
+ ## JavaScript / TypeScript
9
+
10
+ ### Dead Code
11
+ ```bash
12
+ # knip — finds unused files, exports, dependencies, and types
13
+ npx knip # Full report
14
+ npx knip --reporter compact # Compact output
15
+ npx knip --include files # Unused files only
16
+ npx knip --include exports # Unused exports only
17
+ npx knip --include dependencies # Unused dependencies only
18
+ ```
19
+
20
+ ### Circular Dependencies
21
+ ```bash
22
+ # madge — dependency graph and circular detection
23
+ npx madge --circular src/ # Find circular deps
24
+ npx madge --circular --extensions ts src/ # TS only
25
+ npx madge --image graph.svg src/ # Visual dependency graph
26
+
27
+ # dependency-cruiser — configurable dependency analysis
28
+ npx depcruise --output-type err src/ # Error report
29
+ npx depcruise --output-type dot src/ | dot -T svg > deps.svg # Visual
30
+ ```
31
+
32
+ ### Duplication
33
+ ```bash
34
+ # jscpd — copy/paste detector
35
+ npx jscpd src/ --min-lines 10 --min-tokens 50
36
+ npx jscpd src/ --reporters console --format "typescript,javascript"
37
+ npx jscpd src/ --output report/ # HTML report
38
+ ```
39
+
40
+ ### Type Safety
41
+ ```bash
42
+ # TypeScript strict checks
43
+ npx tsc --noEmit --strict # Full strict mode
44
+ npx tsc --noEmit 2>&1 | grep "any" # Find any-related issues
45
+ ```
46
+
47
+ ### Security
48
+ ```bash
49
+ # npm audit for dependency vulnerabilities
50
+ npm audit --json | head -50
51
+ npm audit fix --dry-run
52
+
53
+ # eslint security plugins
54
+ npx eslint --rule '{"no-eval": "error", "no-implied-eval": "error"}' src/
55
+ ```
56
+
57
+ ### Performance
58
+ ```bash
59
+ # Bundle analysis
60
+ npx webpack-bundle-analyzer stats.json # Webpack
61
+ npx vite-bundle-visualizer # Vite
62
+ npx source-map-explorer dist/bundle.js # Generic
63
+
64
+ # Import cost estimation
65
+ npx import-cost src/index.ts
66
+ ```
67
+
68
+ ---
69
+
70
+ ## Python
71
+
72
+ ### Dead Code
73
+ ```bash
74
+ # vulture — find unused code
75
+ vulture src/ --min-confidence 80
76
+ vulture src/ --make-whitelist > whitelist.py # Generate whitelist
77
+
78
+ # autoflake — remove unused imports
79
+ autoflake --check --remove-all-unused-imports -r src/
80
+ autoflake --in-place --remove-all-unused-imports -r src/ # Apply
81
+ ```
82
+
83
+ ### Code Quality
84
+ ```bash
85
+ # ruff — fast linter and formatter (replaces flake8, isort, pyupgrade)
86
+ ruff check src/ # Lint
87
+ ruff check src/ --fix # Auto-fix
88
+ ruff check src/ --select F841 # Unused variables only
89
+ ruff check src/ --select UP # Pyupgrade rules (legacy patterns)
90
+
91
+ # pylint unused detection
92
+ pylint src/ --disable=all --enable=W0611,W0612,W0613 # Unused imports/vars/args
93
+ ```
94
+
95
+ ### Security
96
+ ```bash
97
+ # bandit — security linter
98
+ bandit -r src/ -ll # Medium+ severity
99
+ bandit -r src/ --format json # JSON output
100
+ bandit -r src/ -t B101,B105,B106 # Specific checks (assert, hardcoded password)
101
+
102
+ # safety — dependency vulnerability check
103
+ safety check --json
104
+ ```
105
+
106
+ ### Duplication
107
+ ```bash
108
+ # pylint duplicate detection
109
+ pylint src/ --disable=all --enable=R0801 # Duplicate code
110
+
111
+ # jscpd works for Python too
112
+ npx jscpd src/ --format python --min-lines 10
113
+ ```
114
+
115
+ ---
116
+
117
+ ## Go
118
+
119
+ ### Dead Code
120
+ ```bash
121
+ # deadcode — find unreachable functions
122
+ go install golang.org/x/tools/cmd/deadcode@latest
123
+ deadcode ./...
124
+
125
+ # staticcheck — comprehensive analysis
126
+ staticcheck ./...
127
+ staticcheck -checks U1000 ./... # Unused code specifically
128
+ ```
129
+
130
+ ### Code Quality
131
+ ```bash
132
+ # golangci-lint — meta-linter
133
+ golangci-lint run
134
+ golangci-lint run --enable-all
135
+ golangci-lint run --enable unused,deadcode,ineffassign
136
+ ```
137
+
138
+ ---
139
+
140
+ ## Rust
141
+
142
+ ### Dead Code
143
+ ```bash
144
+ # Compiler warnings
145
+ cargo build 2>&1 | grep "dead_code\|unused"
146
+ RUSTFLAGS="-W dead-code" cargo build
147
+
148
+ # cargo-udeps — unused dependencies
149
+ cargo install cargo-udeps
150
+ cargo udeps
151
+ ```
152
+
153
+ ### Code Quality
154
+ ```bash
155
+ # clippy — comprehensive linting
156
+ cargo clippy -- -W clippy::all
157
+ cargo clippy --fix # Auto-fix
158
+ ```
159
+
160
+ ---
161
+
162
+ ## Universal Tools
163
+
164
+ ### Duplication (Any Language)
165
+ ```bash
166
+ npx jscpd . --min-lines 10 --min-tokens 50 \
167
+ --format "typescript,javascript,python,go,rust,java"
168
+ ```
169
+
170
+ ### Secret Scanning
171
+ ```bash
172
+ # gitleaks — scan for hardcoded secrets
173
+ gitleaks detect --source . --verbose
174
+ gitleaks detect --source . --report-format json --report-path leaks.json
175
+
176
+ # trufflehog — entropy-based secret detection
177
+ trufflehog filesystem . --only-verified
178
+ ```
179
+
180
+ ### Dependency Analysis
181
+ ```bash
182
+ # depcheck (Node.js) — unused dependencies
183
+ npx depcheck
184
+ npx depcheck --ignores="@types/*" # Ignore type packages
185
+ ```