@harness-engineering/cli 1.3.0 → 1.6.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/architecture-enforcer.yaml +1 -0
- package/dist/agents/personas/code-reviewer.yaml +41 -0
- package/dist/agents/personas/codebase-health-analyst.yaml +27 -0
- package/dist/agents/personas/documentation-maintainer.yaml +2 -0
- package/dist/agents/personas/entropy-cleaner.yaml +3 -0
- package/dist/agents/personas/graph-maintainer.yaml +27 -0
- package/dist/agents/personas/parallel-coordinator.yaml +29 -0
- package/dist/agents/personas/task-executor.yaml +41 -0
- package/dist/agents/skills/README.md +8 -0
- package/dist/agents/skills/claude-code/add-harness-component/SKILL.md +10 -0
- package/dist/agents/skills/claude-code/align-documentation/SKILL.md +19 -0
- package/dist/agents/skills/claude-code/cleanup-dead-code/SKILL.md +19 -0
- package/dist/agents/skills/claude-code/detect-doc-drift/SKILL.md +8 -0
- package/dist/agents/skills/claude-code/enforce-architecture/SKILL.md +9 -0
- package/dist/agents/skills/claude-code/harness-architecture-advisor/SKILL.md +9 -0
- package/dist/agents/skills/claude-code/harness-code-review/SKILL.md +10 -0
- package/dist/agents/skills/claude-code/harness-debugging/SKILL.md +10 -0
- package/dist/agents/skills/claude-code/harness-dependency-health/SKILL.md +150 -0
- package/dist/agents/skills/claude-code/harness-dependency-health/skill.yaml +41 -0
- package/dist/agents/skills/claude-code/harness-execution/SKILL.md +19 -0
- package/dist/agents/skills/claude-code/harness-hotspot-detector/SKILL.md +135 -0
- package/dist/agents/skills/claude-code/harness-hotspot-detector/skill.yaml +44 -0
- package/dist/agents/skills/claude-code/harness-impact-analysis/SKILL.md +139 -0
- package/dist/agents/skills/claude-code/harness-impact-analysis/skill.yaml +44 -0
- package/dist/agents/skills/claude-code/harness-knowledge-mapper/SKILL.md +154 -0
- package/dist/agents/skills/claude-code/harness-knowledge-mapper/skill.yaml +49 -0
- package/dist/agents/skills/claude-code/harness-onboarding/SKILL.md +10 -0
- package/dist/agents/skills/claude-code/harness-parallel-agents/SKILL.md +9 -0
- package/dist/agents/skills/claude-code/harness-planning/SKILL.md +9 -0
- package/dist/agents/skills/claude-code/harness-pre-commit-review/SKILL.md +6 -0
- package/dist/agents/skills/claude-code/harness-refactoring/SKILL.md +19 -0
- package/dist/agents/skills/claude-code/harness-tdd/SKILL.md +10 -0
- package/dist/agents/skills/claude-code/harness-test-advisor/SKILL.md +131 -0
- package/dist/agents/skills/claude-code/harness-test-advisor/skill.yaml +44 -0
- package/dist/agents/skills/claude-code/initialize-harness-project/SKILL.md +10 -0
- package/dist/agents/skills/claude-code/validate-context-engineering/SKILL.md +9 -0
- package/dist/agents/skills/gemini-cli/harness-dependency-health/SKILL.md +150 -0
- package/dist/agents/skills/gemini-cli/harness-dependency-health/skill.yaml +41 -0
- package/dist/agents/skills/gemini-cli/harness-hotspot-detector/SKILL.md +135 -0
- package/dist/agents/skills/gemini-cli/harness-hotspot-detector/skill.yaml +44 -0
- package/dist/agents/skills/gemini-cli/harness-impact-analysis/SKILL.md +139 -0
- package/dist/agents/skills/gemini-cli/harness-impact-analysis/skill.yaml +44 -0
- package/dist/agents/skills/gemini-cli/harness-knowledge-mapper/SKILL.md +154 -0
- package/dist/agents/skills/gemini-cli/harness-knowledge-mapper/skill.yaml +49 -0
- package/dist/agents/skills/gemini-cli/harness-test-advisor/SKILL.md +131 -0
- package/dist/agents/skills/gemini-cli/harness-test-advisor/skill.yaml +44 -0
- package/dist/agents/skills/tests/platform-parity.test.ts +131 -0
- package/dist/agents/skills/tests/schema.ts +2 -0
- package/dist/bin/harness.js +2 -2
- package/dist/{chunk-EFZOLZFB.js → chunk-ACMDUQJG.js} +4 -2
- package/dist/{chunk-APYEWOCR.js → chunk-VS4OTOKZ.js} +1393 -350
- package/dist/{create-skill-4GKJZB5R.js → create-skill-NZDLMMR6.js} +1 -1
- package/dist/index.d.ts +265 -143
- package/dist/index.js +30 -4
- package/package.json +3 -2
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
# Harness Test Advisor
|
|
2
|
+
|
|
3
|
+
> Graph-based test selection. Answers: "I changed these files — what tests should I run?"
|
|
4
|
+
|
|
5
|
+
## When to Use
|
|
6
|
+
|
|
7
|
+
- Before pushing code — run only the tests that matter
|
|
8
|
+
- In CI — optimize test suite execution order
|
|
9
|
+
- When a test fails — understand which changes could have caused it
|
|
10
|
+
- When `on_pr` triggers fire
|
|
11
|
+
- NOT for writing tests (use harness-tdd)
|
|
12
|
+
- NOT for test quality analysis (out of scope)
|
|
13
|
+
|
|
14
|
+
## Prerequisites
|
|
15
|
+
|
|
16
|
+
A knowledge graph must exist at `.harness/graph/`. Run `harness scan` if no graph is available.
|
|
17
|
+
If the graph exists but code has changed since the last scan, re-run `harness scan` first — stale graph data leads to inaccurate results.
|
|
18
|
+
|
|
19
|
+
## Process
|
|
20
|
+
|
|
21
|
+
### Phase 1: PARSE — Identify Changed Files
|
|
22
|
+
|
|
23
|
+
1. **From diff**: Parse `git diff --name-only` to get changed file paths.
|
|
24
|
+
2. **From input**: Accept comma-separated file paths.
|
|
25
|
+
3. **Filter**: Only consider `.ts`, `.tsx`, `.js`, `.jsx` files (skip docs, config).
|
|
26
|
+
|
|
27
|
+
### Phase 2: DISCOVER — Find Related Tests via Graph
|
|
28
|
+
|
|
29
|
+
For each changed file, use graph traversal to find test files:
|
|
30
|
+
|
|
31
|
+
1. **Direct test coverage**: Use `get_impact` to find test files that import the changed file.
|
|
32
|
+
|
|
33
|
+
```
|
|
34
|
+
get_impact(filePath="src/services/auth.ts")
|
|
35
|
+
→ tests: ["tests/services/auth.test.ts", "tests/integration/auth-flow.test.ts"]
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
2. **Transitive test coverage**: Use `query_graph` with depth 2 to find tests that import files that import the changed file.
|
|
39
|
+
|
|
40
|
+
```
|
|
41
|
+
query_graph(rootNodeIds=["file:src/services/auth.ts"], maxDepth=2, includeEdges=["imports"], bidirectional=true)
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
3. **Co-change tests**: Check `co_changes_with` edges for test files that historically change alongside the modified files.
|
|
45
|
+
|
|
46
|
+
### Phase 3: PRIORITIZE — Rank and Generate Commands
|
|
47
|
+
|
|
48
|
+
Organize tests into three tiers:
|
|
49
|
+
|
|
50
|
+
**Tier 1 — Must Run** (direct coverage):
|
|
51
|
+
Tests that directly import or test the changed files. These are most likely to catch regressions.
|
|
52
|
+
|
|
53
|
+
**Tier 2 — Should Run** (transitive coverage):
|
|
54
|
+
Tests that cover code one hop away from the changed files. These catch indirect breakage.
|
|
55
|
+
|
|
56
|
+
**Tier 3 — Could Run** (related):
|
|
57
|
+
Tests in the same module or that co-change with the modified files. Lower probability of failure but worth running if time permits.
|
|
58
|
+
|
|
59
|
+
### Output
|
|
60
|
+
|
|
61
|
+
```
|
|
62
|
+
## Test Advisor Report
|
|
63
|
+
|
|
64
|
+
### Changed Files
|
|
65
|
+
- src/services/auth.ts (modified)
|
|
66
|
+
- src/types/user.ts (modified)
|
|
67
|
+
|
|
68
|
+
### Tier 1 — Must Run (direct coverage)
|
|
69
|
+
1. tests/services/auth.test.ts — imports auth.ts
|
|
70
|
+
2. tests/types/user.test.ts — imports user.ts
|
|
71
|
+
|
|
72
|
+
### Tier 2 — Should Run (transitive)
|
|
73
|
+
3. tests/routes/login.test.ts — imports routes/login.ts → imports auth.ts
|
|
74
|
+
4. tests/middleware/verify.test.ts — imports middleware/verify.ts → imports auth.ts
|
|
75
|
+
|
|
76
|
+
### Tier 3 — Could Run (related)
|
|
77
|
+
5. tests/integration/auth-flow.test.ts — same module, co-changes with auth.ts
|
|
78
|
+
|
|
79
|
+
### Quick Run Command
|
|
80
|
+
npx vitest run tests/services/auth.test.ts tests/types/user.test.ts tests/routes/login.test.ts tests/middleware/verify.test.ts
|
|
81
|
+
|
|
82
|
+
### Full Run Command (all tiers)
|
|
83
|
+
npx vitest run tests/services/auth.test.ts tests/types/user.test.ts tests/routes/login.test.ts tests/middleware/verify.test.ts tests/integration/auth-flow.test.ts
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Harness Integration
|
|
87
|
+
|
|
88
|
+
- **`harness scan`** — Must run before this skill to ensure graph is current.
|
|
89
|
+
- **`harness validate`** — Run after acting on findings to verify project health.
|
|
90
|
+
- **Graph tools** — This skill uses `query_graph`, `get_impact`, and `get_relationships` MCP tools.
|
|
91
|
+
|
|
92
|
+
## Success Criteria
|
|
93
|
+
|
|
94
|
+
- Tests prioritized into 3 tiers (Must Run, Should Run, Could Run)
|
|
95
|
+
- Executable run commands generated for quick and full test runs
|
|
96
|
+
- Coverage gaps flagged for changed files with no test coverage
|
|
97
|
+
- Report follows the structured output format
|
|
98
|
+
- All findings are backed by graph query evidence, not heuristics
|
|
99
|
+
|
|
100
|
+
## Examples
|
|
101
|
+
|
|
102
|
+
### Example: Selecting Tests for a Services Change
|
|
103
|
+
|
|
104
|
+
```
|
|
105
|
+
Input: git diff shows src/services/auth.ts and src/types/user.ts modified
|
|
106
|
+
|
|
107
|
+
1. PARSE — 2 changed files identified (both .ts)
|
|
108
|
+
2. DISCOVER — get_impact(filePath="src/services/auth.ts")
|
|
109
|
+
query_graph with depth 2 for transitive tests
|
|
110
|
+
Tier 1: auth.test.ts, user.test.ts (direct imports)
|
|
111
|
+
Tier 2: login.test.ts, verify.test.ts (one hop away)
|
|
112
|
+
Tier 3: auth-flow.test.ts (co-change history)
|
|
113
|
+
3. PRIORITIZE — 5 tests across 3 tiers
|
|
114
|
+
|
|
115
|
+
Output:
|
|
116
|
+
Tier 1 (must run): 2 tests
|
|
117
|
+
Tier 2 (should run): 2 tests
|
|
118
|
+
Tier 3 (could run): 1 test
|
|
119
|
+
Quick command: npx vitest run auth.test.ts user.test.ts login.test.ts verify.test.ts
|
|
120
|
+
Coverage gaps: none
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## Gates
|
|
124
|
+
|
|
125
|
+
- **No advice without graph.** If no graph exists, fall back to: "Run all tests in the same directory as changed files."
|
|
126
|
+
- **Always include Tier 1.** Direct test coverage is non-negotiable — always recommend running these.
|
|
127
|
+
|
|
128
|
+
## Escalation
|
|
129
|
+
|
|
130
|
+
- **When changed file has no test coverage**: Flag as a gap: "No tests found for src/services/auth.ts — consider adding tests before merging."
|
|
131
|
+
- **When Tier 1 has >20 tests**: The changed file may be a hub. Suggest running Tier 1 in parallel or splitting the file.
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
name: harness-test-advisor
|
|
2
|
+
version: "1.0.0"
|
|
3
|
+
description: Graph-based test selection — answers "what tests should I run?"
|
|
4
|
+
cognitive_mode: advisory-guide
|
|
5
|
+
triggers:
|
|
6
|
+
- manual
|
|
7
|
+
- on_pr
|
|
8
|
+
platforms:
|
|
9
|
+
- claude-code
|
|
10
|
+
- gemini-cli
|
|
11
|
+
tools:
|
|
12
|
+
- Bash
|
|
13
|
+
- Read
|
|
14
|
+
- Glob
|
|
15
|
+
- Grep
|
|
16
|
+
cli:
|
|
17
|
+
command: harness skill run harness-test-advisor
|
|
18
|
+
args:
|
|
19
|
+
- name: path
|
|
20
|
+
description: Project root path
|
|
21
|
+
required: false
|
|
22
|
+
- name: files
|
|
23
|
+
description: Comma-separated list of changed files
|
|
24
|
+
required: false
|
|
25
|
+
mcp:
|
|
26
|
+
tool: run_skill
|
|
27
|
+
input:
|
|
28
|
+
skill: harness-test-advisor
|
|
29
|
+
path: string
|
|
30
|
+
type: flexible
|
|
31
|
+
phases:
|
|
32
|
+
- name: parse
|
|
33
|
+
description: Identify changed files from diff or input
|
|
34
|
+
required: true
|
|
35
|
+
- name: discover
|
|
36
|
+
description: Find related tests via graph traversal
|
|
37
|
+
required: true
|
|
38
|
+
- name: prioritize
|
|
39
|
+
description: Rank tests by relevance and generate commands
|
|
40
|
+
required: true
|
|
41
|
+
state:
|
|
42
|
+
persistent: false
|
|
43
|
+
files: []
|
|
44
|
+
depends_on: []
|
|
@@ -72,6 +72,16 @@
|
|
|
72
72
|
|
|
73
73
|
3. **Run `harness check-deps`** (intermediate and above) to verify dependency constraints match the actual codebase. If there are violations, decide with the human: update the constraints or fix the code.
|
|
74
74
|
|
|
75
|
+
### Build the Initial Knowledge Graph
|
|
76
|
+
|
|
77
|
+
If the project will use graph-based queries, build the initial knowledge graph now:
|
|
78
|
+
|
|
79
|
+
```
|
|
80
|
+
harness scan [path]
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
This creates the `.harness/graph/` directory and populates it with the project's dependency and relationship data. Subsequent graph queries (impact analysis, dependency health, test advisor) depend on this initial scan.
|
|
84
|
+
|
|
75
85
|
4. **Commit the initialization.** All generated and configured files in a single commit.
|
|
76
86
|
|
|
77
87
|
## Harness Integration
|
|
@@ -23,6 +23,15 @@
|
|
|
23
23
|
|
|
24
24
|
3. **Review AGENTS.md manually.** Automated tools catch structural issues but miss semantic drift. Read each section and ask: "Is this still true?"
|
|
25
25
|
|
|
26
|
+
### Graph-Enhanced Context (when available)
|
|
27
|
+
|
|
28
|
+
When a knowledge graph exists at `.harness/graph/`, use graph queries for faster, more accurate auditing:
|
|
29
|
+
|
|
30
|
+
- `query_graph` — find all undocumented code nodes (file nodes without `documents` edges), replacing manual cross-referencing
|
|
31
|
+
- `search_similar` — detect stale references in AGENTS.md by matching section text against current code entities
|
|
32
|
+
|
|
33
|
+
When a graph is available, it IS the source of truth for documentation coverage. Drift = stale or missing edges between code and doc nodes. Fall back to file-based commands if no graph is available.
|
|
34
|
+
|
|
26
35
|
### Phase 2: Detect Gaps
|
|
27
36
|
|
|
28
37
|
Categorize findings into four types:
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
# Harness Dependency Health
|
|
2
|
+
|
|
3
|
+
> Analyze structural health of the codebase and surface problems before they become incidents.
|
|
4
|
+
|
|
5
|
+
## When to Use
|
|
6
|
+
|
|
7
|
+
- Weekly scheduled health check on the codebase
|
|
8
|
+
- Before major refactoring — understand current structural health
|
|
9
|
+
- When onboarding to a new project — assess codebase quality
|
|
10
|
+
- NOT for checking layer violations (use enforce-architecture)
|
|
11
|
+
- NOT for finding dead code (use cleanup-dead-code)
|
|
12
|
+
|
|
13
|
+
## Prerequisites
|
|
14
|
+
|
|
15
|
+
A knowledge graph must exist at `.harness/graph/`. Run `harness scan` if no graph is available.
|
|
16
|
+
If the graph exists but code has changed since the last scan, re-run `harness scan` first — stale graph data leads to inaccurate results.
|
|
17
|
+
|
|
18
|
+
## Process
|
|
19
|
+
|
|
20
|
+
### Phase 1: METRICS — Compute Graph Structural Metrics
|
|
21
|
+
|
|
22
|
+
Query the graph for five key structural indicators:
|
|
23
|
+
|
|
24
|
+
1. **Hub detection**: Find nodes with high fan-in (>10 inbound `imports` edges).
|
|
25
|
+
|
|
26
|
+
```
|
|
27
|
+
query_graph(rootNodeIds=[all file nodes], includeEdges=["imports"])
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Hubs are single points of failure — changes to them have outsized blast radius.
|
|
31
|
+
|
|
32
|
+
2. **Orphan detection**: Find file nodes with zero inbound `imports` edges that are not entry points.
|
|
33
|
+
|
|
34
|
+
```
|
|
35
|
+
get_relationships(nodeId=<file>, direction="inbound")
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Orphans may be dead code or missing from the module system.
|
|
39
|
+
|
|
40
|
+
3. **Cycle detection**: Use `check_dependencies` to find circular import chains.
|
|
41
|
+
Cycles create fragile coupling — any change in the cycle affects all members.
|
|
42
|
+
|
|
43
|
+
4. **Deep chain detection**: Find import chains longer than N hops (default: 7).
|
|
44
|
+
|
|
45
|
+
```
|
|
46
|
+
query_graph(rootNodeIds=[entry points], maxDepth=10, includeEdges=["imports"])
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Deep chains are fragile — a change at the bottom propagates unpredictably.
|
|
50
|
+
|
|
51
|
+
5. **Module cohesion**: For each module (directory), count internal vs external edges. Low internal cohesion (many external edges, few internal) suggests misplaced code.
|
|
52
|
+
|
|
53
|
+
### Phase 2: SCORE — Calculate Health Score
|
|
54
|
+
|
|
55
|
+
Compute a weighted health score (0-100):
|
|
56
|
+
|
|
57
|
+
| Metric | Weight | Scoring |
|
|
58
|
+
| ----------------- | ------ | ----------------------------------------- |
|
|
59
|
+
| Hubs (>10 fan-in) | 25% | 0 hubs = 100, 1-3 = 70, 4-6 = 40, >6 = 10 |
|
|
60
|
+
| Orphans | 20% | 0 = 100, 1-5 = 80, 6-15 = 50, >15 = 20 |
|
|
61
|
+
| Cycles | 25% | 0 = 100, 1 = 60, 2-3 = 30, >3 = 0 |
|
|
62
|
+
| Deep chains (>7) | 15% | 0 = 100, 1-3 = 70, >3 = 30 |
|
|
63
|
+
| Cohesion (avg) | 15% | >0.7 = 100, 0.5-0.7 = 70, <0.5 = 30 |
|
|
64
|
+
|
|
65
|
+
**Grades**: A (90-100), B (75-89), C (60-74), D (40-59), F (<40)
|
|
66
|
+
|
|
67
|
+
### Phase 3: RECOMMEND — Generate Recommendations
|
|
68
|
+
|
|
69
|
+
For each problem found, generate a specific, actionable recommendation:
|
|
70
|
+
|
|
71
|
+
- **Hubs**: "Split `src/utils/helpers.ts` (14 importers) into domain-specific utilities"
|
|
72
|
+
- **Orphans**: "Remove `src/legacy/old-parser.ts` (0 importers, not an entry point)"
|
|
73
|
+
- **Cycles**: "Break cycle A→B→C→A by extracting shared types to `src/types/shared.ts`"
|
|
74
|
+
- **Deep chains**: "Consider flattening chain: entry→A→B→C→D→E→F→G (8 hops)"
|
|
75
|
+
- **Low cohesion**: "Module `src/services/` has 80% external edges — consider splitting"
|
|
76
|
+
|
|
77
|
+
### Output
|
|
78
|
+
|
|
79
|
+
```
|
|
80
|
+
## Dependency Health Report
|
|
81
|
+
|
|
82
|
+
### Score: B (78/100)
|
|
83
|
+
|
|
84
|
+
### Metrics
|
|
85
|
+
| Metric | Count | Score |
|
|
86
|
+
|--------|-------|-------|
|
|
87
|
+
| Hubs (>10 fan-in) | 2 | 70/100 |
|
|
88
|
+
| Orphans | 3 | 80/100 |
|
|
89
|
+
| Cycles | 0 | 100/100 |
|
|
90
|
+
| Deep chains (>7) | 1 | 70/100 |
|
|
91
|
+
| Module cohesion | 0.62 avg | 70/100 |
|
|
92
|
+
|
|
93
|
+
### Top Issues
|
|
94
|
+
1. **Hub**: src/utils/helpers.ts — 14 importers (split recommended)
|
|
95
|
+
2. **Hub**: src/types/index.ts — 12 importers (acceptable for type barrel)
|
|
96
|
+
3. **Orphan**: src/legacy/old-parser.ts — 0 importers
|
|
97
|
+
4. **Deep chain**: entry→auth→user→db→pool→config→env→loader (8 hops)
|
|
98
|
+
|
|
99
|
+
### Recommendations
|
|
100
|
+
1. Split src/utils/helpers.ts into domain-specific modules
|
|
101
|
+
2. Investigate src/legacy/old-parser.ts for removal
|
|
102
|
+
3. Flatten auth chain by having auth import db directly
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## Harness Integration
|
|
106
|
+
|
|
107
|
+
- **`harness scan`** — Must run before this skill to ensure graph is current.
|
|
108
|
+
- **`harness validate`** — Run after acting on findings to verify project health.
|
|
109
|
+
- **Graph tools** — This skill uses `query_graph`, `get_relationships`, and `check_dependencies` MCP tools.
|
|
110
|
+
|
|
111
|
+
## Success Criteria
|
|
112
|
+
|
|
113
|
+
- Health score computed on 0-100 scale with letter grade (A-F)
|
|
114
|
+
- All five structural metrics gathered (hubs, orphans, cycles, deep chains, cohesion)
|
|
115
|
+
- Recommendations are specific and actionable (name files, suggest concrete fixes)
|
|
116
|
+
- Report follows the structured output format
|
|
117
|
+
- All findings are backed by graph query evidence, not heuristics
|
|
118
|
+
|
|
119
|
+
## Examples
|
|
120
|
+
|
|
121
|
+
### Example: Weekly Health Check on Monorepo
|
|
122
|
+
|
|
123
|
+
```
|
|
124
|
+
Input: Scheduled weekly run on project root
|
|
125
|
+
|
|
126
|
+
1. METRICS — query_graph for hubs: 2 found (helpers.ts, index.ts)
|
|
127
|
+
get_relationships for orphans: 3 found
|
|
128
|
+
check_dependencies for cycles: 0 found
|
|
129
|
+
query_graph for deep chains: 1 found (8 hops)
|
|
130
|
+
Module cohesion average: 0.62
|
|
131
|
+
2. SCORE — Weighted score: 78/100 (Grade: B)
|
|
132
|
+
3. RECOMMEND — "Split helpers.ts (14 importers) into domain modules"
|
|
133
|
+
"Investigate old-parser.ts for removal (0 importers)"
|
|
134
|
+
"Flatten auth chain — 8 hops exceeds threshold"
|
|
135
|
+
|
|
136
|
+
Output:
|
|
137
|
+
Score: B (78/100)
|
|
138
|
+
Top issues: 2 hubs, 3 orphans, 1 deep chain
|
|
139
|
+
3 actionable recommendations generated
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
## Gates
|
|
143
|
+
|
|
144
|
+
- **No analysis without graph.** If no graph exists, stop and instruct to run `harness scan`.
|
|
145
|
+
- **No guessing.** All metrics must come from graph queries, not heuristics.
|
|
146
|
+
|
|
147
|
+
## Escalation
|
|
148
|
+
|
|
149
|
+
- **When score is F (<40)**: Flag as critical and recommend immediate architectural review.
|
|
150
|
+
- **When graph is stale**: Warn and suggest re-scanning before trusting results.
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
name: harness-dependency-health
|
|
2
|
+
version: "1.0.0"
|
|
3
|
+
description: Analyze structural health of the codebase using graph metrics
|
|
4
|
+
cognitive_mode: analytical-reporter
|
|
5
|
+
triggers:
|
|
6
|
+
- manual
|
|
7
|
+
- scheduled
|
|
8
|
+
platforms:
|
|
9
|
+
- claude-code
|
|
10
|
+
- gemini-cli
|
|
11
|
+
tools:
|
|
12
|
+
- Bash
|
|
13
|
+
- Read
|
|
14
|
+
- Glob
|
|
15
|
+
- Grep
|
|
16
|
+
cli:
|
|
17
|
+
command: harness skill run harness-dependency-health
|
|
18
|
+
args:
|
|
19
|
+
- name: path
|
|
20
|
+
description: Project root path
|
|
21
|
+
required: false
|
|
22
|
+
mcp:
|
|
23
|
+
tool: run_skill
|
|
24
|
+
input:
|
|
25
|
+
skill: harness-dependency-health
|
|
26
|
+
path: string
|
|
27
|
+
type: rigid
|
|
28
|
+
phases:
|
|
29
|
+
- name: metrics
|
|
30
|
+
description: Compute graph structural metrics
|
|
31
|
+
required: true
|
|
32
|
+
- name: score
|
|
33
|
+
description: Calculate health score and identify problems
|
|
34
|
+
required: true
|
|
35
|
+
- name: recommend
|
|
36
|
+
description: Generate specific remediation recommendations
|
|
37
|
+
required: true
|
|
38
|
+
state:
|
|
39
|
+
persistent: false
|
|
40
|
+
files: []
|
|
41
|
+
depends_on: []
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
# Harness Hotspot Detector
|
|
2
|
+
|
|
3
|
+
> Identify modules that represent structural risk via co-change and churn analysis.
|
|
4
|
+
|
|
5
|
+
## When to Use
|
|
6
|
+
|
|
7
|
+
- Weekly scheduled analysis to track codebase risk
|
|
8
|
+
- Before major refactoring — find the riskiest areas
|
|
9
|
+
- When investigating why changes keep breaking unrelated features
|
|
10
|
+
- NOT for finding dead code (use cleanup-dead-code)
|
|
11
|
+
- NOT for checking architecture rules (use enforce-architecture)
|
|
12
|
+
|
|
13
|
+
## Prerequisites
|
|
14
|
+
|
|
15
|
+
A knowledge graph must exist at `.harness/graph/` with git history ingested. Run `harness scan` if no graph is available.
|
|
16
|
+
If the graph exists but code has changed since the last scan, re-run `harness scan` first — stale graph data leads to inaccurate results.
|
|
17
|
+
|
|
18
|
+
## Process
|
|
19
|
+
|
|
20
|
+
### Phase 1: CO-CHANGE — Analyze Co-Change Patterns
|
|
21
|
+
|
|
22
|
+
Query the graph for `co_changes_with` edges (created by GitIngestor):
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
query_graph(rootNodeIds=[all file nodes], includeEdges=["co_changes_with"])
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Identify file pairs that frequently change together:
|
|
29
|
+
|
|
30
|
+
- **Co-located pairs** (same directory): Normal — they share a concern.
|
|
31
|
+
- **Distant pairs** (different modules): Suspicious — may indicate hidden coupling.
|
|
32
|
+
|
|
33
|
+
Flag distant co-change pairs as potential hotspots.
|
|
34
|
+
|
|
35
|
+
### Phase 2: CHURN — Identify High-Churn Files
|
|
36
|
+
|
|
37
|
+
Query commit nodes to find files with the highest change frequency:
|
|
38
|
+
|
|
39
|
+
```
|
|
40
|
+
query_graph(rootNodeIds=[commit nodes], includeTypes=["commit", "file"], includeEdges=["co_changes_with"])
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Rank files by:
|
|
44
|
+
|
|
45
|
+
- Total commit count touching the file
|
|
46
|
+
- Recent velocity (commits in last 30 days vs prior 30 days)
|
|
47
|
+
- Change size (total lines added + deleted)
|
|
48
|
+
|
|
49
|
+
High churn in shared utilities or core modules = high risk.
|
|
50
|
+
|
|
51
|
+
### Phase 3: COUPLING — Detect Hidden Dependencies
|
|
52
|
+
|
|
53
|
+
Cross-reference co-change data with structural data:
|
|
54
|
+
|
|
55
|
+
1. **High logical coupling, low structural coupling**: Files that always change together but have no `imports` edge between them. This indicates a hidden dependency — changing one requires changing the other, but the code doesn't express this relationship.
|
|
56
|
+
|
|
57
|
+
2. **High structural coupling, low logical coupling**: Files with `imports` edges but that rarely change together. This may indicate over-coupling — the import exists but the relationship is weak.
|
|
58
|
+
|
|
59
|
+
Use `get_relationships` to check structural edges between co-change pairs.
|
|
60
|
+
|
|
61
|
+
### Phase 4: REPORT — Generate Ranked Hotspot Report
|
|
62
|
+
|
|
63
|
+
```
|
|
64
|
+
## Hotspot Analysis Report
|
|
65
|
+
|
|
66
|
+
### Risk Hotspots (ranked by risk score)
|
|
67
|
+
|
|
68
|
+
1. **src/services/billing.ts** — Risk: HIGH
|
|
69
|
+
- Churn: 23 commits (last 30 days: 8)
|
|
70
|
+
- Co-changes with: src/types/invoice.ts (distant, 15 co-changes)
|
|
71
|
+
- Hidden dependency: no imports edge to invoice.ts
|
|
72
|
+
- Recommendation: Extract shared billing types or add explicit dependency
|
|
73
|
+
|
|
74
|
+
2. **src/utils/helpers.ts** — Risk: HIGH
|
|
75
|
+
- Churn: 45 commits (highest in codebase)
|
|
76
|
+
- Co-changes with: 12 different files across 4 modules
|
|
77
|
+
- Recommendation: Split into domain-specific utilities to reduce blast radius
|
|
78
|
+
|
|
79
|
+
3. **src/middleware/auth.ts** — Risk: MEDIUM
|
|
80
|
+
- Churn: 15 commits
|
|
81
|
+
- Co-changes with: src/routes/login.ts (co-located, expected)
|
|
82
|
+
- No hidden dependencies detected
|
|
83
|
+
|
|
84
|
+
### Summary
|
|
85
|
+
- Total hotspots detected: 5
|
|
86
|
+
- High risk: 2
|
|
87
|
+
- Medium risk: 3
|
|
88
|
+
- Hidden dependencies: 1
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Harness Integration
|
|
92
|
+
|
|
93
|
+
- **`harness scan`** — Must run before this skill to ensure graph is current.
|
|
94
|
+
- **`harness validate`** — Run after acting on findings to verify project health.
|
|
95
|
+
- **Graph tools** — This skill uses `query_graph`, `get_impact`, and `get_relationships` MCP tools.
|
|
96
|
+
|
|
97
|
+
## Success Criteria
|
|
98
|
+
|
|
99
|
+
- Hotspots ranked by composite risk score (churn + coupling)
|
|
100
|
+
- Hidden dependencies identified (high co-change, no structural edge)
|
|
101
|
+
- Co-change patterns detected and classified (co-located vs distant)
|
|
102
|
+
- Report follows the structured output format
|
|
103
|
+
- All findings are backed by graph query evidence, not heuristics
|
|
104
|
+
|
|
105
|
+
## Examples
|
|
106
|
+
|
|
107
|
+
### Example: Detecting Hotspots in a Growing Codebase
|
|
108
|
+
|
|
109
|
+
```
|
|
110
|
+
Input: Scheduled weekly analysis on project root
|
|
111
|
+
|
|
112
|
+
1. CO-CHANGE — query_graph for co_changes_with edges
|
|
113
|
+
Found 4 distant co-change pairs
|
|
114
|
+
2. CHURN — Ranked files by commit frequency
|
|
115
|
+
billing.ts: 23 commits, helpers.ts: 45 commits
|
|
116
|
+
3. COUPLING — Cross-referenced co-change vs imports edges
|
|
117
|
+
billing.ts <-> invoice.ts: 15 co-changes, no imports edge
|
|
118
|
+
(hidden dependency detected)
|
|
119
|
+
4. REPORT — Ranked hotspots by risk score
|
|
120
|
+
|
|
121
|
+
Output:
|
|
122
|
+
Hotspots: 5 total (2 high, 3 medium)
|
|
123
|
+
Hidden dependencies: 1 (billing.ts <-> invoice.ts)
|
|
124
|
+
Top recommendation: Extract shared billing types
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## Gates
|
|
128
|
+
|
|
129
|
+
- **No analysis without graph + git data.** Both code structure and git history must be ingested.
|
|
130
|
+
- **No guessing at co-change patterns.** Use graph `co_changes_with` edges, not manual git log parsing.
|
|
131
|
+
|
|
132
|
+
## Escalation
|
|
133
|
+
|
|
134
|
+
- **When hidden dependencies found**: Recommend making the dependency explicit (add import) or extracting shared code.
|
|
135
|
+
- **When a single file has >30 commits**: Flag as critical hotspot requiring architectural attention.
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
name: harness-hotspot-detector
|
|
2
|
+
version: "1.0.0"
|
|
3
|
+
description: Identify structural risk hotspots via co-change and churn analysis
|
|
4
|
+
cognitive_mode: analytical-reporter
|
|
5
|
+
triggers:
|
|
6
|
+
- manual
|
|
7
|
+
- scheduled
|
|
8
|
+
platforms:
|
|
9
|
+
- claude-code
|
|
10
|
+
- gemini-cli
|
|
11
|
+
tools:
|
|
12
|
+
- Bash
|
|
13
|
+
- Read
|
|
14
|
+
- Glob
|
|
15
|
+
- Grep
|
|
16
|
+
cli:
|
|
17
|
+
command: harness skill run harness-hotspot-detector
|
|
18
|
+
args:
|
|
19
|
+
- name: path
|
|
20
|
+
description: Project root path
|
|
21
|
+
required: false
|
|
22
|
+
mcp:
|
|
23
|
+
tool: run_skill
|
|
24
|
+
input:
|
|
25
|
+
skill: harness-hotspot-detector
|
|
26
|
+
path: string
|
|
27
|
+
type: rigid
|
|
28
|
+
phases:
|
|
29
|
+
- name: co-change
|
|
30
|
+
description: Analyze co-change patterns from git history
|
|
31
|
+
required: true
|
|
32
|
+
- name: churn
|
|
33
|
+
description: Identify high-churn files and modules
|
|
34
|
+
required: true
|
|
35
|
+
- name: coupling
|
|
36
|
+
description: Detect hidden dependencies via logical coupling
|
|
37
|
+
required: true
|
|
38
|
+
- name: report
|
|
39
|
+
description: Generate ranked hotspot report
|
|
40
|
+
required: true
|
|
41
|
+
state:
|
|
42
|
+
persistent: false
|
|
43
|
+
files: []
|
|
44
|
+
depends_on: []
|