@harness-engineering/cli 1.7.0 → 1.8.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/dist/agents/personas/documentation-maintainer.yaml +3 -1
- package/dist/agents/personas/performance-guardian.yaml +23 -0
- package/dist/agents/skills/claude-code/align-documentation/SKILL.md +13 -0
- package/dist/agents/skills/claude-code/cleanup-dead-code/SKILL.md +25 -1
- package/dist/agents/skills/claude-code/cleanup-dead-code/skill.yaml +5 -2
- package/dist/agents/skills/claude-code/detect-doc-drift/SKILL.md +12 -0
- package/dist/agents/skills/claude-code/enforce-architecture/SKILL.md +48 -1
- package/dist/agents/skills/claude-code/enforce-architecture/skill.yaml +5 -2
- package/dist/agents/skills/claude-code/harness-accessibility/SKILL.md +7 -0
- package/dist/agents/skills/claude-code/harness-autopilot/SKILL.md +9 -1
- package/dist/agents/skills/claude-code/harness-brainstorming/SKILL.md +76 -4
- package/dist/agents/skills/claude-code/harness-brainstorming/skill.yaml +2 -0
- package/dist/agents/skills/claude-code/harness-code-review/SKILL.md +487 -234
- package/dist/agents/skills/claude-code/harness-code-review/skill.yaml +15 -2
- package/dist/agents/skills/claude-code/harness-codebase-cleanup/SKILL.md +226 -0
- package/dist/agents/skills/claude-code/harness-codebase-cleanup/skill.yaml +64 -0
- package/dist/agents/skills/claude-code/harness-dependency-health/SKILL.md +35 -6
- package/dist/agents/skills/claude-code/harness-docs-pipeline/SKILL.md +460 -0
- package/dist/agents/skills/claude-code/harness-docs-pipeline/skill.yaml +69 -0
- package/dist/agents/skills/claude-code/harness-execution/SKILL.md +73 -8
- package/dist/agents/skills/claude-code/harness-execution/skill.yaml +1 -0
- package/dist/agents/skills/claude-code/harness-hotspot-detector/SKILL.md +32 -6
- package/dist/agents/skills/claude-code/harness-i18n/SKILL.md +484 -0
- package/dist/agents/skills/claude-code/harness-i18n/skill.yaml +54 -0
- package/dist/agents/skills/claude-code/harness-i18n-process/SKILL.md +388 -0
- package/dist/agents/skills/claude-code/harness-i18n-process/skill.yaml +43 -0
- package/dist/agents/skills/claude-code/harness-i18n-workflow/SKILL.md +512 -0
- package/dist/agents/skills/claude-code/harness-i18n-workflow/skill.yaml +53 -0
- package/dist/agents/skills/claude-code/harness-impact-analysis/SKILL.md +35 -6
- package/dist/agents/skills/claude-code/harness-integrity/SKILL.md +17 -1
- package/dist/agents/skills/claude-code/harness-knowledge-mapper/SKILL.md +46 -5
- package/dist/agents/skills/claude-code/harness-perf/SKILL.md +37 -8
- package/dist/agents/skills/claude-code/harness-perf/skill.yaml +3 -0
- package/dist/agents/skills/claude-code/harness-perf-tdd/SKILL.md +17 -4
- package/dist/agents/skills/claude-code/harness-planning/SKILL.md +57 -3
- package/dist/agents/skills/claude-code/harness-planning/skill.yaml +2 -0
- package/dist/agents/skills/claude-code/harness-release-readiness/SKILL.md +16 -0
- package/dist/agents/skills/claude-code/harness-roadmap/SKILL.md +562 -0
- package/dist/agents/skills/claude-code/harness-roadmap/skill.yaml +43 -0
- package/dist/agents/skills/claude-code/harness-security-review/SKILL.md +36 -2
- package/dist/agents/skills/claude-code/harness-security-review/skill.yaml +8 -6
- package/dist/agents/skills/claude-code/harness-soundness-review/SKILL.md +1267 -0
- package/dist/agents/skills/claude-code/harness-soundness-review/skill.yaml +48 -0
- package/dist/agents/skills/claude-code/harness-test-advisor/SKILL.md +35 -6
- package/dist/agents/skills/claude-code/harness-verification/SKILL.md +66 -0
- package/dist/agents/skills/claude-code/harness-verification/skill.yaml +1 -0
- package/dist/agents/skills/claude-code/harness-verify/SKILL.md +11 -0
- package/dist/agents/skills/claude-code/initialize-harness-project/SKILL.md +15 -1
- package/dist/agents/skills/claude-code/validate-context-engineering/SKILL.md +12 -0
- package/dist/agents/skills/gemini-cli/harness-accessibility/SKILL.md +7 -0
- package/dist/agents/skills/gemini-cli/harness-autopilot/SKILL.md +9 -1
- package/dist/agents/skills/gemini-cli/harness-codebase-cleanup/SKILL.md +226 -0
- package/dist/agents/skills/gemini-cli/harness-codebase-cleanup/skill.yaml +64 -0
- package/dist/agents/skills/gemini-cli/harness-dependency-health/SKILL.md +35 -6
- package/dist/agents/skills/gemini-cli/harness-docs-pipeline/SKILL.md +460 -0
- package/dist/agents/skills/gemini-cli/harness-docs-pipeline/skill.yaml +69 -0
- package/dist/agents/skills/gemini-cli/harness-hotspot-detector/SKILL.md +32 -6
- package/dist/agents/skills/gemini-cli/harness-i18n/SKILL.md +484 -0
- package/dist/agents/skills/gemini-cli/harness-i18n/skill.yaml +54 -0
- package/dist/agents/skills/gemini-cli/harness-i18n-process/SKILL.md +388 -0
- package/dist/agents/skills/gemini-cli/harness-i18n-process/skill.yaml +43 -0
- package/dist/agents/skills/gemini-cli/harness-i18n-workflow/SKILL.md +512 -0
- package/dist/agents/skills/gemini-cli/harness-i18n-workflow/skill.yaml +53 -0
- package/dist/agents/skills/gemini-cli/harness-impact-analysis/SKILL.md +35 -6
- package/dist/agents/skills/gemini-cli/harness-knowledge-mapper/SKILL.md +46 -5
- package/dist/agents/skills/gemini-cli/harness-perf/SKILL.md +37 -8
- package/dist/agents/skills/gemini-cli/harness-perf/skill.yaml +3 -0
- package/dist/agents/skills/gemini-cli/harness-perf-tdd/SKILL.md +17 -4
- package/dist/agents/skills/gemini-cli/harness-release-readiness/SKILL.md +16 -0
- package/dist/agents/skills/gemini-cli/harness-roadmap/SKILL.md +562 -0
- package/dist/agents/skills/gemini-cli/harness-roadmap/skill.yaml +43 -0
- package/dist/agents/skills/gemini-cli/harness-security-review/skill.yaml +8 -6
- package/dist/agents/skills/gemini-cli/harness-soundness-review/SKILL.md +1267 -0
- package/dist/agents/skills/gemini-cli/harness-soundness-review/skill.yaml +48 -0
- package/dist/agents/skills/gemini-cli/harness-test-advisor/SKILL.md +35 -6
- package/dist/agents/skills/shared/i18n-knowledge/accessibility/intersection.yaml +142 -0
- package/dist/agents/skills/shared/i18n-knowledge/anti-patterns/encoding.yaml +67 -0
- package/dist/agents/skills/shared/i18n-knowledge/anti-patterns/formatting.yaml +106 -0
- package/dist/agents/skills/shared/i18n-knowledge/anti-patterns/layout.yaml +80 -0
- package/dist/agents/skills/shared/i18n-knowledge/anti-patterns/pluralization.yaml +80 -0
- package/dist/agents/skills/shared/i18n-knowledge/anti-patterns/string-handling.yaml +106 -0
- package/dist/agents/skills/shared/i18n-knowledge/frameworks/android-resources.yaml +47 -0
- package/dist/agents/skills/shared/i18n-knowledge/frameworks/apple-strings.yaml +47 -0
- package/dist/agents/skills/shared/i18n-knowledge/frameworks/backend-patterns.yaml +50 -0
- package/dist/agents/skills/shared/i18n-knowledge/frameworks/flutter-intl.yaml +47 -0
- package/dist/agents/skills/shared/i18n-knowledge/frameworks/i18next.yaml +47 -0
- package/dist/agents/skills/shared/i18n-knowledge/frameworks/react-intl.yaml +47 -0
- package/dist/agents/skills/shared/i18n-knowledge/frameworks/vue-i18n.yaml +47 -0
- package/dist/agents/skills/shared/i18n-knowledge/industries/ecommerce.yaml +66 -0
- package/dist/agents/skills/shared/i18n-knowledge/industries/fintech.yaml +66 -0
- package/dist/agents/skills/shared/i18n-knowledge/industries/gaming.yaml +69 -0
- package/dist/agents/skills/shared/i18n-knowledge/industries/healthcare.yaml +66 -0
- package/dist/agents/skills/shared/i18n-knowledge/industries/legal.yaml +66 -0
- package/dist/agents/skills/shared/i18n-knowledge/locales/ar.yaml +41 -0
- package/dist/agents/skills/shared/i18n-knowledge/locales/de.yaml +35 -0
- package/dist/agents/skills/shared/i18n-knowledge/locales/en.yaml +32 -0
- package/dist/agents/skills/shared/i18n-knowledge/locales/es.yaml +35 -0
- package/dist/agents/skills/shared/i18n-knowledge/locales/fi.yaml +35 -0
- package/dist/agents/skills/shared/i18n-knowledge/locales/fr.yaml +35 -0
- package/dist/agents/skills/shared/i18n-knowledge/locales/he.yaml +41 -0
- package/dist/agents/skills/shared/i18n-knowledge/locales/hi.yaml +35 -0
- package/dist/agents/skills/shared/i18n-knowledge/locales/it.yaml +32 -0
- package/dist/agents/skills/shared/i18n-knowledge/locales/ja.yaml +38 -0
- package/dist/agents/skills/shared/i18n-knowledge/locales/ko.yaml +38 -0
- package/dist/agents/skills/shared/i18n-knowledge/locales/nl.yaml +32 -0
- package/dist/agents/skills/shared/i18n-knowledge/locales/pl.yaml +35 -0
- package/dist/agents/skills/shared/i18n-knowledge/locales/pt.yaml +32 -0
- package/dist/agents/skills/shared/i18n-knowledge/locales/ru.yaml +35 -0
- package/dist/agents/skills/shared/i18n-knowledge/locales/sv.yaml +32 -0
- package/dist/agents/skills/shared/i18n-knowledge/locales/th.yaml +35 -0
- package/dist/agents/skills/shared/i18n-knowledge/locales/tr.yaml +35 -0
- package/dist/agents/skills/shared/i18n-knowledge/locales/zh-Hans.yaml +38 -0
- package/dist/agents/skills/shared/i18n-knowledge/locales/zh-Hant.yaml +35 -0
- package/dist/agents/skills/shared/i18n-knowledge/mcp-interop/i18next-mcp.yaml +56 -0
- package/dist/agents/skills/shared/i18n-knowledge/mcp-interop/lingo-dev.yaml +56 -0
- package/dist/agents/skills/shared/i18n-knowledge/mcp-interop/lokalise.yaml +60 -0
- package/dist/agents/skills/shared/i18n-knowledge/mcp-interop/tolgee.yaml +60 -0
- package/dist/agents/skills/shared/i18n-knowledge/testing/locale-testing.yaml +107 -0
- package/dist/agents/skills/shared/i18n-knowledge/testing/pseudo-localization.yaml +86 -0
- package/dist/bin/harness.js +64 -4
- package/dist/{chunk-4WUGOJQ7.js → chunk-3JWCBVUZ.js} +1 -1
- package/dist/{chunk-FFIX3QVG.js → chunk-LNI4T7R6.js} +131 -41
- package/dist/{chunk-GA6GN5J2.js → chunk-SJECMKSS.js} +2244 -34
- package/dist/{dist-N4D4QWFV.js → dist-BDO5GFEM.js} +1 -1
- package/dist/{dist-C4J67MPP.js → dist-NT3GXHQZ.js} +95 -1
- package/dist/index.d.ts +187 -7
- package/dist/index.js +7 -3
- package/dist/validate-cross-check-2OPGCGGU.js +7 -0
- package/package.json +7 -7
- package/dist/validate-cross-check-WGXQ7K62.js +0 -7
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
name: harness-code-review
|
|
2
|
-
version: "
|
|
3
|
-
description:
|
|
2
|
+
version: "2.0.0"
|
|
3
|
+
description: Multi-phase code review pipeline with mechanical checks, graph-scoped context, and parallel review agents
|
|
4
4
|
cognitive_mode: adversarial-reviewer
|
|
5
5
|
triggers:
|
|
6
6
|
- manual
|
|
@@ -14,12 +14,25 @@ tools:
|
|
|
14
14
|
- Read
|
|
15
15
|
- Glob
|
|
16
16
|
- Grep
|
|
17
|
+
- emit_interaction
|
|
17
18
|
cli:
|
|
18
19
|
command: harness skill run harness-code-review
|
|
19
20
|
args:
|
|
20
21
|
- name: path
|
|
21
22
|
description: Project root path
|
|
22
23
|
required: false
|
|
24
|
+
- name: --comment
|
|
25
|
+
description: Post inline comments to GitHub PR
|
|
26
|
+
required: false
|
|
27
|
+
- name: --deep
|
|
28
|
+
description: Add threat modeling pass (invokes security-review --deep)
|
|
29
|
+
required: false
|
|
30
|
+
- name: --no-mechanical
|
|
31
|
+
description: Skip mechanical checks (useful if already run)
|
|
32
|
+
required: false
|
|
33
|
+
- name: --ci
|
|
34
|
+
description: Enable eligibility gate, non-interactive output
|
|
35
|
+
required: false
|
|
23
36
|
mcp:
|
|
24
37
|
tool: run_skill
|
|
25
38
|
input:
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
# Harness Codebase Cleanup
|
|
2
|
+
|
|
3
|
+
> Orchestrate dead code removal and architecture violation fixes with a shared convergence loop. Catches cross-concern cascades that individual skills miss.
|
|
4
|
+
|
|
5
|
+
## When to Use
|
|
6
|
+
|
|
7
|
+
- After a major refactoring or feature removal when both dead code and architecture violations are likely
|
|
8
|
+
- As a periodic comprehensive codebase hygiene task
|
|
9
|
+
- When `cleanup-dead-code` or `enforce-architecture` individually are not catching cascading issues
|
|
10
|
+
- When you want hotspot-aware safety classification
|
|
11
|
+
- NOT for quick single-concern checks -- use `cleanup-dead-code` or `enforce-architecture` directly
|
|
12
|
+
- NOT when tests are failing -- fix tests first
|
|
13
|
+
- NOT during active feature development
|
|
14
|
+
|
|
15
|
+
## Flags
|
|
16
|
+
|
|
17
|
+
| Flag | Effect |
|
|
18
|
+
| --------------------- | ----------------------------------------------------------------- |
|
|
19
|
+
| `--fix` | Enable convergence-based auto-fix (default: detect + report only) |
|
|
20
|
+
| `--dead-code-only` | Skip architecture checks |
|
|
21
|
+
| `--architecture-only` | Skip dead code checks |
|
|
22
|
+
| `--dry-run` | Show what would be fixed without applying |
|
|
23
|
+
| `--ci` | Non-interactive: apply safe fixes only, report everything else |
|
|
24
|
+
|
|
25
|
+
## Process
|
|
26
|
+
|
|
27
|
+
### Phase 1: CONTEXT -- Build Hotspot Map
|
|
28
|
+
|
|
29
|
+
1. **Run hotspot detection** via `harness skill run harness-hotspot-detector` or equivalent git log analysis:
|
|
30
|
+
```bash
|
|
31
|
+
git log --format=format: --name-only --since="6 months ago" | sort | uniq -c | sort -rn | head -50
|
|
32
|
+
```
|
|
33
|
+
2. **Build churn map.** Parse output into a `file -> commit count` mapping.
|
|
34
|
+
3. **Compute top 10% threshold.** Sort all files by commit count. The file at the 90th percentile defines the threshold. Files above this threshold are "high churn."
|
|
35
|
+
4. **Store as HotspotContext** for use in Phase 3 (CLASSIFY).
|
|
36
|
+
|
|
37
|
+
### Phase 2: DETECT -- Run Both Concerns in Parallel
|
|
38
|
+
|
|
39
|
+
1. **Dead code detection** (skip if `--architecture-only`):
|
|
40
|
+
- Run `harness cleanup --type dead-code --json`
|
|
41
|
+
- Or use the `detect_entropy` MCP tool with `type: 'dead-code'`
|
|
42
|
+
- Captures: dead files, dead exports, unused imports, dead internals, commented-out code blocks, orphaned dependencies
|
|
43
|
+
|
|
44
|
+
2. **Architecture detection** (skip if `--dead-code-only`):
|
|
45
|
+
- Run `harness check-deps --json`
|
|
46
|
+
- Captures: layer violations, forbidden imports, circular dependencies, import ordering issues
|
|
47
|
+
|
|
48
|
+
3. **Merge findings.** Convert all raw findings into `CleanupFinding` objects using `classifyFinding()`. This normalizes both concerns into a shared schema.
|
|
49
|
+
|
|
50
|
+
### Phase 3: CLASSIFY -- Safety Classification and Dedup
|
|
51
|
+
|
|
52
|
+
1. **Apply safety classification.** Each `CleanupFinding` already has a safety level from `classifyFinding()`. Review the classification rules:
|
|
53
|
+
|
|
54
|
+
**Dead code safety:**
|
|
55
|
+
|
|
56
|
+
| Finding | Safety | Condition |
|
|
57
|
+
| ------------------------- | ------------- | ------------------------------------------- |
|
|
58
|
+
| Dead files | Safe | Not entry point, no side effects |
|
|
59
|
+
| Unused imports | Safe | Zero references |
|
|
60
|
+
| Dead exports (non-public) | Safe | Zero importers, not in package entry point |
|
|
61
|
+
| Dead exports (public API) | Unsafe | In package entry point or published package |
|
|
62
|
+
| Commented-out code | Safe | Always (code is in git history) |
|
|
63
|
+
| Orphaned npm deps | Probably safe | Needs install + test verification |
|
|
64
|
+
| Dead internals | Unsafe | Cannot reliably determine all callers |
|
|
65
|
+
|
|
66
|
+
**Architecture safety:**
|
|
67
|
+
|
|
68
|
+
| Violation | Safety | Condition |
|
|
69
|
+
| ----------------------------------- | ------------- | -------------------------- |
|
|
70
|
+
| Import ordering | Safe | Mechanical reorder |
|
|
71
|
+
| Forbidden import (with alternative) | Probably safe | 1:1 replacement configured |
|
|
72
|
+
| Forbidden import (no alternative) | Unsafe | Requires restructuring |
|
|
73
|
+
| Design token (unambiguous) | Probably safe | Single token match |
|
|
74
|
+
| Design token (ambiguous) | Unsafe | Multiple candidates |
|
|
75
|
+
| Upward dependency | Unsafe | Always |
|
|
76
|
+
| Skip-layer dependency | Unsafe | Always |
|
|
77
|
+
| Circular dependency | Unsafe | Always |
|
|
78
|
+
|
|
79
|
+
2. **Apply hotspot downgrade.** For each finding, check if the file is in the top 10% by churn (from Phase 1 HotspotContext). If so, downgrade `safe` to `probably-safe`. Do not downgrade `unsafe` findings.
|
|
80
|
+
|
|
81
|
+
3. **Cross-concern dedup.** Call `deduplicateFindings()` to merge overlapping findings:
|
|
82
|
+
- A dead import from a forbidden layer = one finding (dead-code concern, noting architecture overlap)
|
|
83
|
+
- A dead file that has architecture violations = one finding (dead-code, noting violations resolved by deletion)
|
|
84
|
+
|
|
85
|
+
### Phase 4: FIX -- Convergence Loop
|
|
86
|
+
|
|
87
|
+
**Only runs when `--fix` flag is set.** Without `--fix`, skip to Phase 5 (REPORT).
|
|
88
|
+
|
|
89
|
+
```
|
|
90
|
+
findings = classified findings from Phase 3
|
|
91
|
+
previousCount = findings.length
|
|
92
|
+
iteration = 0
|
|
93
|
+
|
|
94
|
+
while iteration < 5:
|
|
95
|
+
iteration++
|
|
96
|
+
|
|
97
|
+
# Batch 1: Apply safe fixes silently
|
|
98
|
+
safeFixes = findings.filter(f => f.safety === 'safe')
|
|
99
|
+
apply(safeFixes)
|
|
100
|
+
|
|
101
|
+
# Batch 2: Present probably-safe fixes
|
|
102
|
+
if --ci mode:
|
|
103
|
+
skip probably-safe fixes (report only)
|
|
104
|
+
else:
|
|
105
|
+
probablySafeFixes = findings.filter(f => f.safety === 'probably-safe')
|
|
106
|
+
presentAsDiffs(probablySafeFixes)
|
|
107
|
+
apply(approved fixes)
|
|
108
|
+
|
|
109
|
+
# Verify: lint + typecheck + test
|
|
110
|
+
verifyResult = run("pnpm lint && pnpm tsc --noEmit && pnpm test")
|
|
111
|
+
|
|
112
|
+
if verifyResult.failed:
|
|
113
|
+
revertBatch()
|
|
114
|
+
reclassify failed fixes as unsafe
|
|
115
|
+
continue
|
|
116
|
+
|
|
117
|
+
# Re-detect both concerns
|
|
118
|
+
newFindings = runDetection() # Phase 2 again
|
|
119
|
+
newFindings = classify(newFindings) # Phase 3 again
|
|
120
|
+
|
|
121
|
+
if newFindings.length >= previousCount:
|
|
122
|
+
break # No progress, stop
|
|
123
|
+
|
|
124
|
+
previousCount = newFindings.length
|
|
125
|
+
findings = newFindings
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
**Verification gate:** Every fix batch must pass lint + typecheck + test. If verification fails:
|
|
129
|
+
|
|
130
|
+
1. Revert the entire batch (use git: `git checkout -- .`)
|
|
131
|
+
2. Reclassify all findings in the batch as `unsafe`
|
|
132
|
+
3. Continue the loop with remaining findings
|
|
133
|
+
|
|
134
|
+
**Cross-concern cascade examples:**
|
|
135
|
+
|
|
136
|
+
- Dead import from forbidden layer: removing the dead import also resolves the architecture violation. Single fix, both resolved.
|
|
137
|
+
- Architecture fix creates dead code: replacing a forbidden import makes the old module's export dead. Next detect cycle catches it.
|
|
138
|
+
- Dead file resolves multiple violations: deleting a dead file that imports from wrong layers resolves those violations too.
|
|
139
|
+
|
|
140
|
+
### Phase 5: REPORT -- Actionable Output
|
|
141
|
+
|
|
142
|
+
Generate a structured report with two sections:
|
|
143
|
+
|
|
144
|
+
**1. Fixes Applied:**
|
|
145
|
+
For each fix that was applied:
|
|
146
|
+
|
|
147
|
+
- File and line
|
|
148
|
+
- What was fixed (finding type and description)
|
|
149
|
+
- What action was taken (delete, replace, reorder)
|
|
150
|
+
- Verification status (pass/fail)
|
|
151
|
+
|
|
152
|
+
**2. Remaining Findings (requires human action):**
|
|
153
|
+
For each unsafe finding that was not auto-fixed:
|
|
154
|
+
|
|
155
|
+
- **What is wrong:** The finding type, file, line, and description
|
|
156
|
+
- **Why it cannot be auto-fixed:** The safety reason and classification logic
|
|
157
|
+
- **Suggested approach:** Concrete next steps for manual resolution
|
|
158
|
+
|
|
159
|
+
Example report output:
|
|
160
|
+
|
|
161
|
+
```
|
|
162
|
+
=== HARNESS CODEBASE CLEANUP REPORT ===
|
|
163
|
+
|
|
164
|
+
Fixes applied: 12
|
|
165
|
+
- 5 unused imports removed (safe)
|
|
166
|
+
- 3 dead exports de-exported (safe)
|
|
167
|
+
- 2 commented-out code blocks deleted (safe)
|
|
168
|
+
- 1 forbidden import replaced (probably-safe, approved)
|
|
169
|
+
- 1 orphaned dependency removed (probably-safe, approved)
|
|
170
|
+
|
|
171
|
+
Convergence: 3 iterations, 12 → 8 → 3 → 3 (stopped)
|
|
172
|
+
|
|
173
|
+
Remaining findings: 3 (require human action)
|
|
174
|
+
|
|
175
|
+
1. UNSAFE: Circular dependency
|
|
176
|
+
File: src/services/order-service.ts <-> src/services/inventory-service.ts
|
|
177
|
+
Why: Circular dependencies require structural refactoring
|
|
178
|
+
Suggested: Extract shared logic into src/services/stock-calculator.ts
|
|
179
|
+
|
|
180
|
+
2. UNSAFE: Dead internal function
|
|
181
|
+
File: src/utils/legacy.ts:45 — processLegacyFormat()
|
|
182
|
+
Why: Cannot reliably determine all callers (possible dynamic usage)
|
|
183
|
+
Suggested: Search for string references, check config files, then delete if confirmed unused
|
|
184
|
+
|
|
185
|
+
3. UNSAFE: Public API dead export
|
|
186
|
+
File: packages/core/src/index.ts — legacyHelper
|
|
187
|
+
Why: Export is in package entry point; external consumers may depend on it
|
|
188
|
+
Suggested: Deprecate with @deprecated JSDoc tag, remove in next major version
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
## Examples
|
|
192
|
+
|
|
193
|
+
### Example: Post-Refactoring Cleanup
|
|
194
|
+
|
|
195
|
+
After removing the `legacy-auth` module:
|
|
196
|
+
|
|
197
|
+
1. **Phase 1 (CONTEXT):** Hotspot analysis shows `src/services/auth.ts` has 42 commits (top 5%).
|
|
198
|
+
2. **Phase 2 (DETECT):** Dead code detects 3 dead exports in `src/utils/token.ts` (were only used by legacy-auth). Architecture detects 1 forbidden import in `src/services/session.ts` (still importing from removed module's location).
|
|
199
|
+
3. **Phase 3 (CLASSIFY):** Dead exports classified as `safe` but downgraded to `probably-safe` because `token.ts` is in a high-churn file. Forbidden import classified as `unsafe` (no alternative configured).
|
|
200
|
+
4. **Phase 4 (FIX):** First iteration removes 3 dead exports (approved as probably-safe). Re-detect finds `token.ts` now has zero exports and becomes a dead file. Second iteration deletes the dead file. Convergence stops -- the forbidden import requires manual restructuring.
|
|
201
|
+
5. **Phase 5 (REPORT):** 4 fixes applied (3 dead exports + 1 dead file), 1 remaining finding (forbidden import requiring restructuring).
|
|
202
|
+
|
|
203
|
+
## Harness Integration
|
|
204
|
+
|
|
205
|
+
- **`harness cleanup --type dead-code --json`** -- Dead code detection input
|
|
206
|
+
- **`harness check-deps --json`** -- Architecture violation detection input
|
|
207
|
+
- **`harness skill run harness-hotspot-detector`** -- Hotspot context for safety classification
|
|
208
|
+
- **`apply_fixes` MCP tool** -- Applies safe fixes via the MCP server
|
|
209
|
+
- **`harness validate`** -- Final validation after all fixes
|
|
210
|
+
- **`harness check-deps`** -- Final architecture check after all fixes
|
|
211
|
+
|
|
212
|
+
## Success Criteria
|
|
213
|
+
|
|
214
|
+
- All safe fixes are applied without test failures
|
|
215
|
+
- Probably-safe fixes are presented as diffs for approval (or skipped in CI mode)
|
|
216
|
+
- Unsafe findings are never auto-fixed
|
|
217
|
+
- Convergence loop catches cross-concern cascades
|
|
218
|
+
- Report includes actionable guidance for every remaining finding
|
|
219
|
+
- `harness validate` passes after cleanup
|
|
220
|
+
|
|
221
|
+
## Escalation
|
|
222
|
+
|
|
223
|
+
- **When convergence loop does not converge after 5 iterations:** The codebase has deeply tangled issues. Stop and report all remaining findings. Consider breaking the cleanup into focused sessions.
|
|
224
|
+
- **When a safe fix causes test failures:** The classification was wrong. Revert, reclassify as unsafe, and investigate the hidden dependency. Document the false positive for future improvement.
|
|
225
|
+
- **When the hotspot detector is unavailable:** Skip the hotspot downgrade. All safety classifications use their base level without churn context.
|
|
226
|
+
- **When dead code and architecture fixes conflict:** The convergence loop handles this naturally. If removing dead code creates an architecture issue (rare), the next detection cycle catches it.
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
name: harness-codebase-cleanup
|
|
2
|
+
version: "1.0.0"
|
|
3
|
+
description: Orchestrate dead code removal and architecture violation fixes with shared convergence loop
|
|
4
|
+
cognitive_mode: systematic-orchestrator
|
|
5
|
+
triggers:
|
|
6
|
+
- manual
|
|
7
|
+
platforms:
|
|
8
|
+
- claude-code
|
|
9
|
+
- gemini-cli
|
|
10
|
+
tools:
|
|
11
|
+
- Bash
|
|
12
|
+
- Read
|
|
13
|
+
- Glob
|
|
14
|
+
- Grep
|
|
15
|
+
cli:
|
|
16
|
+
command: harness skill run harness-codebase-cleanup
|
|
17
|
+
args:
|
|
18
|
+
- name: path
|
|
19
|
+
description: Project root path
|
|
20
|
+
required: false
|
|
21
|
+
- name: fix
|
|
22
|
+
description: Enable convergence-based auto-fix (default detect+report only)
|
|
23
|
+
required: false
|
|
24
|
+
- name: dead-code-only
|
|
25
|
+
description: Skip architecture checks
|
|
26
|
+
required: false
|
|
27
|
+
- name: architecture-only
|
|
28
|
+
description: Skip dead code checks
|
|
29
|
+
required: false
|
|
30
|
+
- name: dry-run
|
|
31
|
+
description: Show what would be fixed without applying
|
|
32
|
+
required: false
|
|
33
|
+
- name: ci
|
|
34
|
+
description: Non-interactive mode (safe fixes only, report everything else)
|
|
35
|
+
required: false
|
|
36
|
+
mcp:
|
|
37
|
+
tool: run_skill
|
|
38
|
+
input:
|
|
39
|
+
skill: harness-codebase-cleanup
|
|
40
|
+
path: string
|
|
41
|
+
type: flexible
|
|
42
|
+
phases:
|
|
43
|
+
- name: context
|
|
44
|
+
description: Run hotspot detection, build churn map
|
|
45
|
+
required: true
|
|
46
|
+
- name: detect
|
|
47
|
+
description: Run dead code and architecture detection in parallel
|
|
48
|
+
required: true
|
|
49
|
+
- name: classify
|
|
50
|
+
description: Classify findings, apply hotspot downgrade, cross-concern dedup
|
|
51
|
+
required: true
|
|
52
|
+
- name: fix
|
|
53
|
+
description: Convergence loop - apply safe fixes, verify, re-detect
|
|
54
|
+
required: false
|
|
55
|
+
- name: report
|
|
56
|
+
description: Generate actionable report of fixes applied and remaining findings
|
|
57
|
+
required: true
|
|
58
|
+
state:
|
|
59
|
+
persistent: false
|
|
60
|
+
files: []
|
|
61
|
+
depends_on:
|
|
62
|
+
- cleanup-dead-code
|
|
63
|
+
- enforce-architecture
|
|
64
|
+
- harness-hotspot-detector
|
|
@@ -12,8 +12,23 @@
|
|
|
12
12
|
|
|
13
13
|
## Prerequisites
|
|
14
14
|
|
|
15
|
-
A knowledge graph
|
|
16
|
-
|
|
15
|
+
A knowledge graph at `.harness/graph/` enables full analysis. If no graph exists,
|
|
16
|
+
the skill uses static analysis fallbacks (see Graph Availability section).
|
|
17
|
+
Run `harness scan` to enable graph-enhanced analysis.
|
|
18
|
+
|
|
19
|
+
### Graph Availability
|
|
20
|
+
|
|
21
|
+
Before starting, check if `.harness/graph/graph.json` exists.
|
|
22
|
+
|
|
23
|
+
**If graph exists:** Check staleness — compare `.harness/graph/metadata.json`
|
|
24
|
+
scanTimestamp against `git log -1 --format=%ct` (latest commit timestamp).
|
|
25
|
+
If graph is more than 2 commits behind (`git log --oneline <scanTimestamp>..HEAD | wc -l`),
|
|
26
|
+
run `harness scan` to refresh before proceeding. (Staleness sensitivity: **High**)
|
|
27
|
+
|
|
28
|
+
**If graph exists and is fresh (or refreshed):** Use graph tools as primary strategy.
|
|
29
|
+
|
|
30
|
+
**If no graph exists:** Output "Running without graph (run `harness scan` to
|
|
31
|
+
enable full analysis)" and use fallback strategies for all subsequent steps.
|
|
17
32
|
|
|
18
33
|
## Process
|
|
19
34
|
|
|
@@ -50,6 +65,20 @@ Query the graph for five key structural indicators:
|
|
|
50
65
|
|
|
51
66
|
5. **Module cohesion**: For each module (directory), count internal vs external edges. Low internal cohesion (many external edges, few internal) suggests misplaced code.
|
|
52
67
|
|
|
68
|
+
#### Fallback (without graph)
|
|
69
|
+
|
|
70
|
+
When no graph is available, use static analysis to approximate structural metrics:
|
|
71
|
+
|
|
72
|
+
1. **Build adjacency list**: Grep all source files for `import`/`require` statements. Parse each to extract the imported path. Build an adjacency list mapping each file to its imports.
|
|
73
|
+
2. **Hub detection**: From the adjacency list, count inbound edges per file. Files with >10 importers are hubs.
|
|
74
|
+
3. **Orphan detection**: Files with zero inbound edges that are not entry points (not `index.*`, not in `package.json` main/exports). Use glob to find all source files, then subtract those that appear as import targets.
|
|
75
|
+
4. **Cycle detection**: Run DFS on the adjacency list. When a back-edge is found, report the cycle path.
|
|
76
|
+
5. **Deep chain detection**: From entry points, DFS to find the longest import chain. Report chains exceeding 7 hops.
|
|
77
|
+
6. **Module cohesion (approximate)**: For each directory, count imports that stay within the directory (internal) vs imports that leave it (external). Cohesion = internal / (internal + external).
|
|
78
|
+
7. **Run `check_dependencies` CLI** — this works without a graph and can detect layer violations.
|
|
79
|
+
|
|
80
|
+
> Fallback completeness: ~60% — cannot compute transitive depth beyond what import parsing reveals; coupling metrics are approximate.
|
|
81
|
+
|
|
53
82
|
### Phase 2: SCORE — Calculate Health Score
|
|
54
83
|
|
|
55
84
|
Compute a weighted health score (0-100):
|
|
@@ -104,7 +133,7 @@ For each problem found, generate a specific, actionable recommendation:
|
|
|
104
133
|
|
|
105
134
|
## Harness Integration
|
|
106
135
|
|
|
107
|
-
- **`harness scan`** —
|
|
136
|
+
- **`harness scan`** — Recommended before this skill for full graph-enhanced analysis. If graph is missing, skill uses static analysis fallbacks.
|
|
108
137
|
- **`harness validate`** — Run after acting on findings to verify project health.
|
|
109
138
|
- **Graph tools** — This skill uses `query_graph`, `get_relationships`, and `check_dependencies` MCP tools.
|
|
110
139
|
|
|
@@ -114,7 +143,7 @@ For each problem found, generate a specific, actionable recommendation:
|
|
|
114
143
|
- All five structural metrics gathered (hubs, orphans, cycles, deep chains, cohesion)
|
|
115
144
|
- Recommendations are specific and actionable (name files, suggest concrete fixes)
|
|
116
145
|
- Report follows the structured output format
|
|
117
|
-
- All findings are backed by graph query evidence
|
|
146
|
+
- All findings are backed by graph query evidence (with graph) or systematic static analysis (without graph)
|
|
118
147
|
|
|
119
148
|
## Examples
|
|
120
149
|
|
|
@@ -141,8 +170,8 @@ Output:
|
|
|
141
170
|
|
|
142
171
|
## Gates
|
|
143
172
|
|
|
144
|
-
- **
|
|
145
|
-
- **
|
|
173
|
+
- **Graph preferred, fallback available.** If no graph exists, use fallback strategies (import parsing, DFS cycle detection, hub/orphan identification). Do not stop — produce the best analysis possible.
|
|
174
|
+
- **Systematic analysis required.** All metrics must come from graph queries (with graph) or systematic import parsing (without graph). Do not guess — parse actual import statements.
|
|
146
175
|
|
|
147
176
|
## Escalation
|
|
148
177
|
|