@harness-engineering/cli 1.6.2 → 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/personas/planner.yaml +27 -0
- package/dist/agents/personas/verifier.yaml +30 -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 +67 -1
- package/dist/agents/skills/claude-code/enforce-architecture/skill.yaml +5 -2
- package/dist/agents/skills/claude-code/harness-accessibility/SKILL.md +281 -0
- package/dist/agents/skills/claude-code/harness-accessibility/skill.yaml +51 -0
- package/dist/agents/skills/claude-code/harness-autopilot/SKILL.md +119 -72
- package/dist/agents/skills/claude-code/harness-autopilot/skill.yaml +4 -2
- 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-dependency-health/skill.yaml +1 -1
- package/dist/agents/skills/claude-code/harness-design/SKILL.md +265 -0
- package/dist/agents/skills/claude-code/harness-design/skill.yaml +53 -0
- package/dist/agents/skills/claude-code/harness-design-mobile/SKILL.md +336 -0
- package/dist/agents/skills/claude-code/harness-design-mobile/skill.yaml +49 -0
- package/dist/agents/skills/claude-code/harness-design-system/SKILL.md +282 -0
- package/dist/agents/skills/claude-code/harness-design-system/skill.yaml +50 -0
- package/dist/agents/skills/claude-code/harness-design-web/SKILL.md +360 -0
- package/dist/agents/skills/claude-code/harness-design-web/skill.yaml +52 -0
- 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-hotspot-detector/skill.yaml +1 -1
- 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 +51 -6
- package/dist/agents/skills/claude-code/harness-integrity/SKILL.md +35 -1
- package/dist/agents/skills/claude-code/harness-knowledge-mapper/SKILL.md +46 -5
- package/dist/agents/skills/claude-code/harness-knowledge-mapper/skill.yaml +1 -1
- package/dist/agents/skills/claude-code/harness-onboarding/SKILL.md +19 -1
- 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 +29 -9
- 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-security-scan/skill.yaml +1 -1
- 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 +37 -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 +281 -0
- package/dist/agents/skills/gemini-cli/harness-accessibility/skill.yaml +51 -0
- package/dist/agents/skills/gemini-cli/harness-autopilot/SKILL.md +119 -72
- package/dist/agents/skills/gemini-cli/harness-autopilot/skill.yaml +4 -2
- 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-dependency-health/skill.yaml +1 -1
- package/dist/agents/skills/gemini-cli/harness-design/SKILL.md +265 -0
- package/dist/agents/skills/gemini-cli/harness-design/skill.yaml +53 -0
- package/dist/agents/skills/gemini-cli/harness-design-mobile/SKILL.md +336 -0
- package/dist/agents/skills/gemini-cli/harness-design-mobile/skill.yaml +49 -0
- package/dist/agents/skills/gemini-cli/harness-design-system/SKILL.md +282 -0
- package/dist/agents/skills/gemini-cli/harness-design-system/skill.yaml +50 -0
- package/dist/agents/skills/gemini-cli/harness-design-web/SKILL.md +360 -0
- package/dist/agents/skills/gemini-cli/harness-design-web/skill.yaml +52 -0
- 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-hotspot-detector/skill.yaml +1 -1
- 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 +51 -6
- package/dist/agents/skills/gemini-cli/harness-knowledge-mapper/SKILL.md +46 -5
- package/dist/agents/skills/gemini-cli/harness-knowledge-mapper/skill.yaml +1 -1
- 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 +29 -9
- 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-security-scan/skill.yaml +1 -1
- 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/node_modules/.bin/vitest +2 -2
- package/dist/agents/skills/shared/design-knowledge/anti-patterns/color.yaml +106 -0
- package/dist/agents/skills/shared/design-knowledge/anti-patterns/layout.yaml +109 -0
- package/dist/agents/skills/shared/design-knowledge/anti-patterns/motion.yaml +109 -0
- package/dist/agents/skills/shared/design-knowledge/anti-patterns/typography.yaml +112 -0
- package/dist/agents/skills/shared/design-knowledge/industries/creative.yaml +80 -0
- package/dist/agents/skills/shared/design-knowledge/industries/ecommerce.yaml +80 -0
- package/dist/agents/skills/shared/design-knowledge/industries/emerging-tech.yaml +83 -0
- package/dist/agents/skills/shared/design-knowledge/industries/fintech.yaml +80 -0
- package/dist/agents/skills/shared/design-knowledge/industries/healthcare.yaml +80 -0
- package/dist/agents/skills/shared/design-knowledge/industries/lifestyle.yaml +80 -0
- package/dist/agents/skills/shared/design-knowledge/industries/saas.yaml +80 -0
- package/dist/agents/skills/shared/design-knowledge/industries/services.yaml +80 -0
- package/dist/agents/skills/shared/design-knowledge/palettes/curated.yaml +234 -0
- package/dist/agents/skills/shared/design-knowledge/platform-rules/android.yaml +125 -0
- package/dist/agents/skills/shared/design-knowledge/platform-rules/flutter.yaml +144 -0
- package/dist/agents/skills/shared/design-knowledge/platform-rules/ios.yaml +106 -0
- package/dist/agents/skills/shared/design-knowledge/platform-rules/web.yaml +102 -0
- package/dist/agents/skills/shared/design-knowledge/typography/pairings.yaml +274 -0
- 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-UDWGSL3T.js → chunk-3JWCBVUZ.js} +3 -3
- package/dist/{chunk-IUFFBBYV.js → chunk-LNI4T7R6.js} +179 -61
- package/dist/{chunk-USEYPS7F.js → chunk-SJECMKSS.js} +2250 -40
- package/dist/{dist-4MYPT3OE.js → dist-BDO5GFEM.js} +295 -14
- package/dist/{dist-RBZXXJHG.js → dist-NT3GXHQZ.js} +95 -1
- package/dist/index.d.ts +266 -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-CPEPNLOD.js +0 -7
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
name: harness-accessibility
|
|
2
|
+
version: "1.0.0"
|
|
3
|
+
description: WCAG accessibility scanning, contrast checking, ARIA validation, and remediation
|
|
4
|
+
cognitive_mode: meticulous-verifier
|
|
5
|
+
triggers:
|
|
6
|
+
- manual
|
|
7
|
+
- on_new_feature
|
|
8
|
+
- on_project_init
|
|
9
|
+
platforms:
|
|
10
|
+
- claude-code
|
|
11
|
+
- gemini-cli
|
|
12
|
+
tools:
|
|
13
|
+
- Bash
|
|
14
|
+
- Read
|
|
15
|
+
- Write
|
|
16
|
+
- Edit
|
|
17
|
+
- Glob
|
|
18
|
+
- Grep
|
|
19
|
+
cli:
|
|
20
|
+
command: harness skill run harness-accessibility
|
|
21
|
+
args:
|
|
22
|
+
- name: path
|
|
23
|
+
description: Project root path
|
|
24
|
+
required: false
|
|
25
|
+
- name: scope
|
|
26
|
+
description: Scope of scan (full, component, page)
|
|
27
|
+
required: false
|
|
28
|
+
mcp:
|
|
29
|
+
tool: run_skill
|
|
30
|
+
input:
|
|
31
|
+
skill: harness-accessibility
|
|
32
|
+
path: string
|
|
33
|
+
type: rigid
|
|
34
|
+
phases:
|
|
35
|
+
- name: scan
|
|
36
|
+
description: Scan codebase for accessibility issues (WCAG AA baseline)
|
|
37
|
+
required: true
|
|
38
|
+
- name: evaluate
|
|
39
|
+
description: Evaluate severity and categorize findings
|
|
40
|
+
required: true
|
|
41
|
+
- name: report
|
|
42
|
+
description: Generate structured accessibility report
|
|
43
|
+
required: true
|
|
44
|
+
- name: fix
|
|
45
|
+
description: Apply automated fixes for mechanical issues
|
|
46
|
+
required: false
|
|
47
|
+
state:
|
|
48
|
+
persistent: false
|
|
49
|
+
files: []
|
|
50
|
+
depends_on:
|
|
51
|
+
- harness-design-system
|
|
@@ -13,18 +13,23 @@
|
|
|
13
13
|
|
|
14
14
|
## Relationship to Other Skills
|
|
15
15
|
|
|
16
|
-
| Skill | Role in Autopilot |
|
|
17
|
-
| -------------------- | -------------------------------------------- |
|
|
18
|
-
| harness-planning | Delegated to for phase plan creation |
|
|
19
|
-
| harness-execution | Delegated to for task-by-task implementation |
|
|
20
|
-
| harness-verification | Delegated to for post-execution validation |
|
|
21
|
-
| harness-code-review | Delegated to for post-verification review |
|
|
16
|
+
| Skill | Persona Agent (`subagent_type`) | Role in Autopilot |
|
|
17
|
+
| -------------------- | ------------------------------- | -------------------------------------------- |
|
|
18
|
+
| harness-planning | `harness-planner` | Delegated to for phase plan creation |
|
|
19
|
+
| harness-execution | `harness-task-executor` | Delegated to for task-by-task implementation |
|
|
20
|
+
| harness-verification | `harness-verifier` | Delegated to for post-execution validation |
|
|
21
|
+
| harness-code-review | `harness-code-reviewer` | Delegated to for post-verification review |
|
|
22
22
|
|
|
23
|
-
Autopilot orchestrates these
|
|
23
|
+
Autopilot orchestrates these persona agents — it never reimplements their logic. Each agent is dispatched via the Agent tool with the corresponding `subagent_type`, which isolates it to the harness methodology and prevents it from using unrelated skills.
|
|
24
24
|
|
|
25
25
|
## Iron Law
|
|
26
26
|
|
|
27
|
-
**Autopilot delegates, never reimplements.** If you find yourself writing planning logic, execution logic, or review logic inside the autopilot loop, STOP. Delegate to the
|
|
27
|
+
**Autopilot delegates, never reimplements.** If you find yourself writing planning logic, execution logic, or review logic inside the autopilot loop, STOP. Delegate to the dedicated persona agent.
|
|
28
|
+
|
|
29
|
+
**Always use dedicated persona agents, never general-purpose agents.** Every dispatch MUST target the specific harness persona (`harness-planner`, `harness-task-executor`, `harness-verifier`, `harness-code-reviewer`). General-purpose agents see all globally registered skills and may use unrelated workflows instead of the harness methodology.
|
|
30
|
+
|
|
31
|
+
- **Claude Code:** Use the Agent tool with `subagent_type` set to the persona name.
|
|
32
|
+
- **Gemini CLI:** Use the `run_agent` tool targeting the persona by name, or dispatch via `harness persona run <name>`.
|
|
28
33
|
|
|
29
34
|
**Human always approves plans.** No plan executes without explicit human sign-off, regardless of complexity level. The difference is whether autopilot generates the plan automatically or asks the human to drive planning interactively.
|
|
30
35
|
|
|
@@ -44,20 +49,32 @@ INIT → ASSESS → PLAN → APPROVE_PLAN → EXECUTE → VERIFY → REVIEW →
|
|
|
44
49
|
|
|
45
50
|
### Phase 1: INIT — Load Spec and Restore State
|
|
46
51
|
|
|
47
|
-
1. **
|
|
52
|
+
1. **Resolve spec path.** The spec file is provided as an argument, or ask the user for the spec path.
|
|
53
|
+
|
|
54
|
+
2. **Derive session slug and directory:**
|
|
55
|
+
- Derive the session slug from the spec path:
|
|
56
|
+
1. If the path starts with `docs/`, strip the `docs/` prefix. Otherwise, use the full relative path.
|
|
57
|
+
2. Drop the trailing `.md` extension
|
|
58
|
+
3. Replace all `/` and `.` characters with `--`
|
|
59
|
+
4. Lowercase the result
|
|
60
|
+
- Set `sessionDir = .harness/sessions/<slug>/`
|
|
61
|
+
- Create the session directory if it does not exist
|
|
62
|
+
|
|
63
|
+
3. **Check for existing state.** Read `{sessionDir}/autopilot-state.json`. If it exists and `currentState` is not `DONE`:
|
|
48
64
|
- Report: "Resuming autopilot from state `{currentState}`, phase {currentPhase}: {phaseName}."
|
|
49
65
|
- Skip to the recorded `currentState` and continue from there.
|
|
50
66
|
|
|
51
|
-
|
|
52
|
-
- Read the spec file
|
|
67
|
+
4. **If no existing state (fresh start):**
|
|
68
|
+
- Read the spec file.
|
|
53
69
|
- Parse the `## Implementation Order` section to extract phases.
|
|
54
70
|
- For each phase heading (`### Phase N: Name`), extract:
|
|
55
71
|
- Phase name
|
|
56
72
|
- Complexity annotation (`<!-- complexity: low|medium|high -->`, default: `medium`)
|
|
57
|
-
- Create
|
|
73
|
+
- Create `{sessionDir}/autopilot-state.json`:
|
|
58
74
|
```json
|
|
59
75
|
{
|
|
60
|
-
"schemaVersion":
|
|
76
|
+
"schemaVersion": 2,
|
|
77
|
+
"sessionDir": ".harness/sessions/<slug>",
|
|
61
78
|
"specPath": "<path to spec>",
|
|
62
79
|
"currentState": "ASSESS",
|
|
63
80
|
"currentPhase": 0,
|
|
@@ -78,15 +95,22 @@ INIT → ASSESS → PLAN → APPROVE_PLAN → EXECUTE → VERIFY → REVIEW →
|
|
|
78
95
|
}
|
|
79
96
|
```
|
|
80
97
|
|
|
81
|
-
|
|
98
|
+
5. **Load context.** Read `.harness/learnings.md` and `.harness/failures.md` (global, at `.harness/` root) if they exist. Note any relevant learnings or known dead ends for the current phase.
|
|
99
|
+
|
|
100
|
+
6. **Load roadmap context.** If `docs/roadmap.md` exists, read it to understand:
|
|
101
|
+
- Current project priorities (which features are `in-progress`)
|
|
102
|
+
- Blockers that may affect the upcoming phases
|
|
103
|
+
- Overall project status and milestone progress
|
|
104
|
+
|
|
105
|
+
This provides the autopilot with project-level context beyond the individual spec being executed. If the roadmap does not exist, skip this step — the autopilot operates normally without it.
|
|
82
106
|
|
|
83
|
-
|
|
107
|
+
7. **Transition to ASSESS.**
|
|
84
108
|
|
|
85
109
|
---
|
|
86
110
|
|
|
87
111
|
### ASSESS — Determine Phase Approach
|
|
88
112
|
|
|
89
|
-
1. **Read the current phase** from `autopilot-state.json` at index `currentPhase`.
|
|
113
|
+
1. **Read the current phase** from `{sessionDir}/autopilot-state.json` at index `currentPhase`.
|
|
90
114
|
|
|
91
115
|
2. **Check if plan already exists.** If `planPath` is set and the file exists, skip to `APPROVE_PLAN`.
|
|
92
116
|
|
|
@@ -97,8 +121,8 @@ INIT → ASSESS → PLAN → APPROVE_PLAN → EXECUTE → VERIFY → REVIEW →
|
|
|
97
121
|
|
|
98
122
|
| Effective Complexity | Action |
|
|
99
123
|
| -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
100
|
-
| `low` | Auto-plan via
|
|
101
|
-
| `medium` | Auto-plan via
|
|
124
|
+
| `low` | Auto-plan via `harness-planner` agent. Proceed to PLAN. |
|
|
125
|
+
| `medium` | Auto-plan via `harness-planner` agent. Proceed to PLAN. Present with extra scrutiny note. |
|
|
102
126
|
| `high` | Pause. Tell the user: "Phase {N}: {name} is marked high-complexity. Run `/harness:planning` interactively for this phase, then re-invoke `/harness:autopilot` to continue." Transition to PLAN with `awaitingInteractivePlan: true`. |
|
|
103
127
|
|
|
104
128
|
4. **Update state** with `currentState: "PLAN"` and save.
|
|
@@ -109,22 +133,27 @@ INIT → ASSESS → PLAN → APPROVE_PLAN → EXECUTE → VERIFY → REVIEW →
|
|
|
109
133
|
|
|
110
134
|
**If auto-planning (low/medium complexity):**
|
|
111
135
|
|
|
112
|
-
1. Dispatch a
|
|
136
|
+
1. Dispatch a planning agent using the Agent tool:
|
|
113
137
|
|
|
114
138
|
```
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
139
|
+
Agent tool parameters:
|
|
140
|
+
subagent_type: "harness-planner"
|
|
141
|
+
description: "Plan phase {N}: {name}"
|
|
142
|
+
prompt: |
|
|
143
|
+
You are running harness-planning for phase {N}: {name}.
|
|
144
|
+
|
|
145
|
+
Spec: {specPath}
|
|
146
|
+
Session directory: {sessionDir}
|
|
147
|
+
Phase description: {phase description from spec}
|
|
148
|
+
Previous phase learnings (global): {relevant learnings from .harness/learnings.md}
|
|
149
|
+
Known failures to avoid (global): {relevant entries from .harness/failures.md}
|
|
150
|
+
|
|
151
|
+
Follow the harness-planning skill process exactly. Write the plan to
|
|
152
|
+
docs/plans/{date}-{phase-name}-plan.md. Write {sessionDir}/handoff.json when done.
|
|
124
153
|
```
|
|
125
154
|
|
|
126
|
-
2. When the
|
|
127
|
-
- Read the generated plan path from
|
|
155
|
+
2. When the agent returns:
|
|
156
|
+
- Read the generated plan path from `{sessionDir}/handoff.json`.
|
|
128
157
|
- **Apply complexity override check:**
|
|
129
158
|
- Count tasks in the plan.
|
|
130
159
|
- Count `[checkpoint:*]` markers.
|
|
@@ -138,7 +167,7 @@ INIT → ASSESS → PLAN → APPROVE_PLAN → EXECUTE → VERIFY → REVIEW →
|
|
|
138
167
|
**If awaiting interactive plan (high complexity):**
|
|
139
168
|
|
|
140
169
|
1. Check if a plan file now exists for this phase (user ran planning separately).
|
|
141
|
-
- Look for files matching `docs/plans/*{phase-name}*` or check
|
|
170
|
+
- Look for files matching `docs/plans/*{phase-name}*` or check `{sessionDir}/handoff.json` for a planning handoff.
|
|
142
171
|
2. If found: update `planPath` in state, transition to `APPROVE_PLAN`.
|
|
143
172
|
3. If not found: remind the user and wait.
|
|
144
173
|
|
|
@@ -170,27 +199,32 @@ INIT → ASSESS → PLAN → APPROVE_PLAN → EXECUTE → VERIFY → REVIEW →
|
|
|
170
199
|
|
|
171
200
|
### EXECUTE — Run the Plan
|
|
172
201
|
|
|
173
|
-
1. **Dispatch execution
|
|
202
|
+
1. **Dispatch execution agent using the Agent tool:**
|
|
174
203
|
|
|
175
204
|
```
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
205
|
+
Agent tool parameters:
|
|
206
|
+
subagent_type: "harness-task-executor"
|
|
207
|
+
description: "Execute phase {N}: {name}"
|
|
208
|
+
prompt: |
|
|
209
|
+
You are running harness-execution for phase {N}: {name}.
|
|
210
|
+
|
|
211
|
+
Plan: {planPath}
|
|
212
|
+
Session directory: {sessionDir}
|
|
213
|
+
State: {sessionDir}/state.json
|
|
214
|
+
Learnings (global): .harness/learnings.md
|
|
215
|
+
Failures (global): .harness/failures.md
|
|
216
|
+
|
|
217
|
+
Follow the harness-execution skill process exactly.
|
|
218
|
+
Update {sessionDir}/state.json after each task.
|
|
219
|
+
Write {sessionDir}/handoff.json when done or when blocked.
|
|
186
220
|
```
|
|
187
221
|
|
|
188
|
-
2. **When the
|
|
222
|
+
2. **When the agent returns, check the outcome:**
|
|
189
223
|
- **All tasks complete:** Transition to VERIFY.
|
|
190
224
|
- **Checkpoint reached:** Surface the checkpoint to the user in the main conversation. Handle the checkpoint type:
|
|
191
|
-
- `[checkpoint:human-verify]` — Show output, ask for confirmation, then resume execution
|
|
192
|
-
- `[checkpoint:decision]` — Present options, record choice, resume execution
|
|
193
|
-
- `[checkpoint:human-action]` — Instruct user, wait for confirmation, resume execution
|
|
225
|
+
- `[checkpoint:human-verify]` — Show output, ask for confirmation, then resume execution agent.
|
|
226
|
+
- `[checkpoint:decision]` — Present options, record choice, resume execution agent.
|
|
227
|
+
- `[checkpoint:human-action]` — Instruct user, wait for confirmation, resume execution agent.
|
|
194
228
|
- **Task failed:** Enter retry logic (see below).
|
|
195
229
|
|
|
196
230
|
3. **Retry logic on failure:**
|
|
@@ -198,7 +232,7 @@ INIT → ASSESS → PLAN → APPROVE_PLAN → EXECUTE → VERIFY → REVIEW →
|
|
|
198
232
|
- If `attemptsUsed < maxAttempts`:
|
|
199
233
|
- Increment `attemptsUsed`.
|
|
200
234
|
- Record the attempt (timestamp, error, fix attempted, result).
|
|
201
|
-
- **Attempt 1:** Read error output, apply obvious fix, re-dispatch execution
|
|
235
|
+
- **Attempt 1:** Read error output, apply obvious fix, re-dispatch execution agent for the failed task only.
|
|
202
236
|
- **Attempt 2:** Expand context — read related files, check `learnings.md` for similar failures, re-dispatch with additional context.
|
|
203
237
|
- **Attempt 3:** Full context gather — read test output, imports, plan instructions for ambiguity. Re-dispatch with maximum context.
|
|
204
238
|
- If budget exhausted:
|
|
@@ -213,16 +247,22 @@ INIT → ASSESS → PLAN → APPROVE_PLAN → EXECUTE → VERIFY → REVIEW →
|
|
|
213
247
|
|
|
214
248
|
### VERIFY — Post-Execution Validation
|
|
215
249
|
|
|
216
|
-
1. **Dispatch verification
|
|
250
|
+
1. **Dispatch verification agent using the Agent tool:**
|
|
217
251
|
|
|
218
252
|
```
|
|
219
|
-
|
|
253
|
+
Agent tool parameters:
|
|
254
|
+
subagent_type: "harness-verifier"
|
|
255
|
+
description: "Verify phase {N}: {name}"
|
|
256
|
+
prompt: |
|
|
257
|
+
You are running harness-verification for phase {N}: {name}.
|
|
258
|
+
|
|
259
|
+
Session directory: {sessionDir}
|
|
220
260
|
|
|
221
|
-
|
|
222
|
-
|
|
261
|
+
Follow the harness-verification skill process exactly.
|
|
262
|
+
Report pass/fail with findings.
|
|
223
263
|
```
|
|
224
264
|
|
|
225
|
-
2. **When the
|
|
265
|
+
2. **When the agent returns:**
|
|
226
266
|
- **All checks pass:** Transition to REVIEW.
|
|
227
267
|
- **Failures found:** Surface findings to the user. Ask: "Fix these issues before review? (yes / skip verification / stop)"
|
|
228
268
|
- **yes** — Re-enter EXECUTE with targeted fixes (retry budget resets for verification fixes).
|
|
@@ -235,16 +275,22 @@ INIT → ASSESS → PLAN → APPROVE_PLAN → EXECUTE → VERIFY → REVIEW →
|
|
|
235
275
|
|
|
236
276
|
### REVIEW — Code Review
|
|
237
277
|
|
|
238
|
-
1. **Dispatch review
|
|
278
|
+
1. **Dispatch review agent using the Agent tool:**
|
|
239
279
|
|
|
240
280
|
```
|
|
241
|
-
|
|
281
|
+
Agent tool parameters:
|
|
282
|
+
subagent_type: "harness-code-reviewer"
|
|
283
|
+
description: "Review phase {N}: {name}"
|
|
284
|
+
prompt: |
|
|
285
|
+
You are running harness-code-review for phase {N}: {name}.
|
|
286
|
+
|
|
287
|
+
Session directory: {sessionDir}
|
|
242
288
|
|
|
243
|
-
|
|
244
|
-
|
|
289
|
+
Follow the harness-code-review skill process exactly.
|
|
290
|
+
Report findings with severity (blocking / warning / note).
|
|
245
291
|
```
|
|
246
292
|
|
|
247
|
-
2. **When the
|
|
293
|
+
2. **When the agent returns:**
|
|
248
294
|
- **No blocking findings:** Report summary, transition to PHASE_COMPLETE.
|
|
249
295
|
- **Blocking findings:** Surface to user. Ask: "Address blocking findings before completing this phase? (yes / override / stop)"
|
|
250
296
|
- **yes** — Re-enter EXECUTE with review fixes.
|
|
@@ -303,7 +349,7 @@ INIT → ASSESS → PLAN → APPROVE_PLAN → EXECUTE → VERIFY → REVIEW →
|
|
|
303
349
|
- "Create a PR? (yes / no)"
|
|
304
350
|
- If yes: assemble commit history, suggest PR title and description.
|
|
305
351
|
|
|
306
|
-
3. **Write final handoff
|
|
352
|
+
3. **Write final handoff** to `{sessionDir}/handoff.json`:
|
|
307
353
|
|
|
308
354
|
```json
|
|
309
355
|
{
|
|
@@ -326,20 +372,21 @@ INIT → ASSESS → PLAN → APPROVE_PLAN → EXECUTE → VERIFY → REVIEW →
|
|
|
326
372
|
- [skill:harness-autopilot] [outcome:observation] {any notable patterns from the run}
|
|
327
373
|
```
|
|
328
374
|
|
|
329
|
-
5. **Clean up state:** Set `currentState: "DONE"` in `autopilot-state.json`. Do not delete the file — it serves as a record.
|
|
375
|
+
5. **Clean up state:** Set `currentState: "DONE"` in `{sessionDir}/autopilot-state.json`. Do not delete the file — it serves as a record.
|
|
330
376
|
|
|
331
377
|
## Harness Integration
|
|
332
378
|
|
|
333
379
|
- **`harness validate`** — Run during INIT to verify project health. Included in every execution task via harness-execution delegation.
|
|
334
380
|
- **`harness check-deps`** — Delegated to harness-execution (included in task steps).
|
|
335
|
-
- **State file** — `.harness/autopilot-state.json` tracks the orchestration state machine. `.harness/state.json` tracks task-level execution state (managed by harness-execution).
|
|
336
|
-
- **Handoff** — `.harness/handoff.json` is written by each delegated skill and read by the next. Autopilot writes a final handoff on DONE.
|
|
337
|
-
- **Learnings** — `.harness/learnings.md` is appended by both delegated skills and autopilot itself.
|
|
381
|
+
- **State file** — `.harness/sessions/<slug>/autopilot-state.json` tracks the orchestration state machine. `.harness/sessions/<slug>/state.json` tracks task-level execution state (managed by harness-execution). The slug is derived from the spec path during INIT.
|
|
382
|
+
- **Handoff** — `.harness/sessions/<slug>/handoff.json` is written by each delegated skill and read by the next. Autopilot writes a final handoff on DONE.
|
|
383
|
+
- **Learnings** — `.harness/learnings.md` (global) is appended by both delegated skills and autopilot itself.
|
|
384
|
+
- **Roadmap context** — During INIT, reads `docs/roadmap.md` (if present) for project-level priorities, blockers, and milestone status. Provides broader context for phase execution decisions.
|
|
338
385
|
|
|
339
386
|
## Success Criteria
|
|
340
387
|
|
|
341
388
|
- Single `/harness:autopilot` invocation executes all phases through to completion
|
|
342
|
-
- Resume from any state after context reset via
|
|
389
|
+
- Resume from any state after context reset via session-scoped `autopilot-state.json`
|
|
343
390
|
- Low-complexity phases auto-plan; high-complexity phases pause for interactive planning
|
|
344
391
|
- Planning override bumps complexity upward when task signals disagree
|
|
345
392
|
- Retry budget (3 attempts) with escalating context before surfacing failures
|
|
@@ -360,7 +407,7 @@ Read spec — found 3 phases:
|
|
|
360
407
|
Phase 1: Core Scanner (complexity: low)
|
|
361
408
|
Phase 2: Rule Engine (complexity: high)
|
|
362
409
|
Phase 3: CLI Integration (complexity: low)
|
|
363
|
-
Created .harness/autopilot-state.json. Starting Phase 1.
|
|
410
|
+
Created .harness/sessions/specs--2026-03-19-security-scanner/autopilot-state.json. Starting Phase 1.
|
|
364
411
|
```
|
|
365
412
|
|
|
366
413
|
**Phase 1 — ASSESS:**
|
|
@@ -372,7 +419,7 @@ Phase 1: Core Scanner — complexity: low. Auto-planning.
|
|
|
372
419
|
**Phase 1 — PLAN:**
|
|
373
420
|
|
|
374
421
|
```
|
|
375
|
-
[
|
|
422
|
+
[harness-planner agent runs harness-planning]
|
|
376
423
|
Plan generated: docs/plans/2026-03-19-core-scanner-plan.md (8 tasks, ~24 min)
|
|
377
424
|
```
|
|
378
425
|
|
|
@@ -388,9 +435,9 @@ Approve this plan and begin execution? (yes / revise / skip / stop)
|
|
|
388
435
|
**Phase 1 — EXECUTE → VERIFY → REVIEW:**
|
|
389
436
|
|
|
390
437
|
```
|
|
391
|
-
[
|
|
392
|
-
[
|
|
393
|
-
[
|
|
438
|
+
[harness-task-executor agent executes 8 tasks... all pass]
|
|
439
|
+
[harness-verifier agent runs verification... pass]
|
|
440
|
+
[harness-code-reviewer agent runs code review... 0 blocking, 2 notes]
|
|
394
441
|
```
|
|
395
442
|
|
|
396
443
|
**Phase 1 — PHASE_COMPLETE:**
|
|
@@ -479,16 +526,16 @@ How should we proceed? (fix manually and continue / revise plan / stop)
|
|
|
479
526
|
|
|
480
527
|
## Gates
|
|
481
528
|
|
|
482
|
-
- **No reimplementing delegated skills.** Autopilot orchestrates. If you are writing planning logic, execution logic, verification logic, or review logic, STOP. Delegate to the appropriate
|
|
529
|
+
- **No reimplementing delegated skills.** Autopilot orchestrates. If you are writing planning logic, execution logic, verification logic, or review logic, STOP. Delegate to the appropriate persona agent via `subagent_type`.
|
|
483
530
|
- **No executing without plan approval.** Every plan must be explicitly approved by the human before execution begins. No exceptions, regardless of complexity level.
|
|
484
531
|
- **No skipping VERIFY or REVIEW.** Every phase goes through verification and review. The human can override findings, but the steps cannot be skipped.
|
|
485
532
|
- **No infinite retries.** The retry budget is 3 attempts. If exhausted, STOP and surface to the human. Do not extend the budget without explicit human instruction.
|
|
486
|
-
- **No modifying
|
|
533
|
+
- **No modifying session state files manually.** The session state files are managed by the skill. If the state appears corrupted, start fresh rather than patching it.
|
|
487
534
|
|
|
488
535
|
## Escalation
|
|
489
536
|
|
|
490
537
|
- **When the spec has no Implementation Order section:** Cannot identify phases. Ask the user to add phase annotations to the spec or provide a roadmap file.
|
|
491
|
-
- **When a delegated skill fails to produce expected output:** Check that handoff.json was written correctly. If the
|
|
492
|
-
- **When the user wants to reorder phases mid-run:** Update the phases array in autopilot-state.json (mark skipped phases, adjust currentPhase). Do not re-run completed phases.
|
|
538
|
+
- **When a delegated skill fails to produce expected output:** Check that `{sessionDir}/handoff.json` was written correctly. If the agent failed, report the failure and ask the user whether to retry the entire phase step or stop.
|
|
539
|
+
- **When the user wants to reorder phases mid-run:** Update the phases array in the session-scoped `autopilot-state.json` (mark skipped phases, adjust currentPhase). Do not re-run completed phases.
|
|
493
540
|
- **When context limits are approaching:** Persist state immediately and inform the user: "Context limit approaching. State saved. Re-invoke /harness:autopilot to continue from this point."
|
|
494
541
|
- **When multiple phases fail in sequence:** After 2 consecutive phase failures (retry budget exhausted in both), suggest the user review the spec for systemic issues rather than continuing.
|
|
@@ -42,9 +42,11 @@ phases:
|
|
|
42
42
|
state:
|
|
43
43
|
persistent: true
|
|
44
44
|
files:
|
|
45
|
-
- .harness/autopilot-state.json
|
|
46
|
-
- .harness/state.json
|
|
45
|
+
- .harness/sessions/*/autopilot-state.json
|
|
46
|
+
- .harness/sessions/*/state.json
|
|
47
|
+
- .harness/sessions/*/handoff.json
|
|
47
48
|
- .harness/learnings.md
|
|
49
|
+
- .harness/failures.md
|
|
48
50
|
depends_on:
|
|
49
51
|
- harness-planning
|
|
50
52
|
- harness-execution
|
|
@@ -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.
|