opencode-code-archaeology 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +98 -0
- package/LICENSE +24 -0
- package/README.md +128 -0
- package/VERSION +1 -0
- package/commands/code-archaeology-excavate.md +51 -0
- package/commands/code-archaeology-restore.md +62 -0
- package/commands/code-archaeology-survey.md +48 -0
- package/commands/code-archaeology.md +105 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +258 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +17 -0
- package/dist/types.js.map +1 -0
- package/hooks/opencode/init.sh +84 -0
- package/hooks/opencode/revert-phase.sh +17 -0
- package/hooks/opencode/update-expedition.sh +46 -0
- package/hooks/opencode/verify-phase.sh +31 -0
- package/package.json +61 -0
- package/plugins/code-archaeology.ts +8 -0
- package/schema/expedition-report.json +99 -0
- package/skills/code-archaeology/SKILL.md +141 -0
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: code-archaeology
|
|
3
|
+
description: Use when a codebase has accumulated technical debt including dead code, legacy fallbacks, circular dependencies, duplicate types, weak typing, defensive programming slop, or error handling anti-patterns that need systematic excavation and cataloging before restoration.
|
|
4
|
+
platform: opencode
|
|
5
|
+
tools: ["Bash", "Agent", "Read", "Write", "Edit", "Glob", "Grep", "Skill", "TaskCreate", "TaskUpdate"]
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Code Archaeology
|
|
9
|
+
|
|
10
|
+
Systematic excavation of a codebase to remove accumulated sediment—dead code, legacy fallbacks, circular dependencies, weak types, and defensive programming slop—while producing human-reviewable site reports before any artifacts are disturbed. Non-destructive by default.
|
|
11
|
+
|
|
12
|
+
## Overview
|
|
13
|
+
|
|
14
|
+
Code Archaeology treats a codebase like an archaeological site. Each expedition removes a specific class of technical debt in a fixed order (stratigraphic dependencies). Reports are generated at every phase. In `survey` mode, zero files are modified. In `excavate` mode, mock patches are produced for human review. In `restore` mode, approved changes are executed.
|
|
15
|
+
|
|
16
|
+
## When to Use
|
|
17
|
+
|
|
18
|
+
- Codebase has grown over years with unclear ownership
|
|
19
|
+
- Large amounts of commented-out, unused, or unreachable code exist
|
|
20
|
+
- Legacy polyfills, shims, or compatibility layers remain for EOL environments
|
|
21
|
+
- Circular dependencies block tree-shaking or slow builds
|
|
22
|
+
- Types are duplicated across files or use `any`/`unknown` excessively
|
|
23
|
+
- Error handling suppresses or swallows exceptions
|
|
24
|
+
- DRY violations create maintenance burden
|
|
25
|
+
- Team wants a full audit before refactoring
|
|
26
|
+
|
|
27
|
+
## When NOT to Use
|
|
28
|
+
|
|
29
|
+
- Greenfield project with minimal code
|
|
30
|
+
- Codebase already has active refactoring in progress
|
|
31
|
+
- No test suite exists (baseline verification requires passing tests)
|
|
32
|
+
- Team cannot review generated reports before restoration
|
|
33
|
+
|
|
34
|
+
## Expedition Order (Fixed)
|
|
35
|
+
|
|
36
|
+
The expeditions MUST run in this order due to stratigraphic dependencies:
|
|
37
|
+
|
|
38
|
+
1. **Site Survey & Baseline** — inventory, metrics, baseline capture
|
|
39
|
+
2. **Dead Code Excavation** — unused exports, unreachable functions, orphans
|
|
40
|
+
3. **Legacy Stratum Removal** — deprecated APIs, polyfills, shims
|
|
41
|
+
4. **Circular Dependency Cartography** — map and break cycles
|
|
42
|
+
5. **Type Catalog Consolidation** — deduplicate types
|
|
43
|
+
6. **Type Restoration & Hardening** — replace weak types
|
|
44
|
+
7. **DRY Stratification** — extract semantic duplications
|
|
45
|
+
8. **Error Handling Stratigraphy** — fix suppression/empty catch
|
|
46
|
+
9. **Artifact Cleaning & Documentation** — remove slop, update docs
|
|
47
|
+
10. **Site Preservation & Final Catalog** — verify, preserve records
|
|
48
|
+
|
|
49
|
+
**Why this order:** You cannot consolidate types before removing dead code (you might catalog code that should be discarded). You cannot DRY before untangling cycles (abstractions over cyclic deps create worse stratification).
|
|
50
|
+
|
|
51
|
+
## Modes
|
|
52
|
+
|
|
53
|
+
| Mode | File Changes | Reports | Use Case |
|
|
54
|
+
|------|-------------|---------|----------|
|
|
55
|
+
| `survey` | Zero | All | Initial audit, management review |
|
|
56
|
+
| `excavate` | Zero | All + mock patches | Pre-approval, team review |
|
|
57
|
+
| `restore` | Yes (HIGH confidence) | All | Executing approved changes |
|
|
58
|
+
|
|
59
|
+
With `strict_mode: true`, restore also applies MEDIUM confidence findings.
|
|
60
|
+
|
|
61
|
+
## Constraints
|
|
62
|
+
|
|
63
|
+
- NEVER commit directly to main or master
|
|
64
|
+
- NEVER remove or modify code without writing a site report first
|
|
65
|
+
- NEVER guess types; flag uncertain replacements for human review
|
|
66
|
+
- ALWAYS run tests between phases; stop immediately on failure
|
|
67
|
+
- ALWAYS revert changes if a phase introduces test failures
|
|
68
|
+
- NEVER consolidate types before dead code and legacy removal
|
|
69
|
+
- NEVER remove try/catch from I/O or external input boundaries
|
|
70
|
+
|
|
71
|
+
## Parameters
|
|
72
|
+
|
|
73
|
+
| Parameter | Default | Description |
|
|
74
|
+
|-----------|---------|-------------|
|
|
75
|
+
| `repo_path` | `.` | Target repository |
|
|
76
|
+
| `language` | `typescript` | Primary language |
|
|
77
|
+
| `mode` | `survey` | `survey`, `excavate`, or `restore` |
|
|
78
|
+
| `strict_mode` | `false` | Auto-restore medium-confidence findings |
|
|
79
|
+
| `test_command` | `npm test` | Test runner command |
|
|
80
|
+
| `typecheck_command` | `npx tsc --noEmit` | Type check command |
|
|
81
|
+
| `branch_name` | `refactor/archaeology` | Git branch to create |
|
|
82
|
+
|
|
83
|
+
## Language-Specific Tooling
|
|
84
|
+
|
|
85
|
+
| Language | Dead Code | Dependencies | Types | DRY |
|
|
86
|
+
|----------|-----------|--------------|-------|-----|
|
|
87
|
+
| TypeScript | `knip`, `unimported` | `madge` | `tsc` | `jscpd` |
|
|
88
|
+
| JavaScript | `knip`, `depcheck` | `madge` | N/A | `jscpd` |
|
|
89
|
+
| Python | `vulture` | `pydeps` | `mypy` | `pylint` |
|
|
90
|
+
| Go | `deadcode`, `staticcheck` | `godepgraph` | `go vet` | `golangci-lint` |
|
|
91
|
+
| Rust | `cargo-udeps`, `rustc` | `cargo-deps` | `rustc` | `clippy` |
|
|
92
|
+
|
|
93
|
+
If tools are missing, the skill falls back to AST-based manual analysis.
|
|
94
|
+
|
|
95
|
+
## Quick Reference
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
# Survey only (zero changes)
|
|
99
|
+
opencode run code-archaeology --mode survey
|
|
100
|
+
|
|
101
|
+
# Generate mock patches for review
|
|
102
|
+
opencode run code-archaeology --mode excavate
|
|
103
|
+
|
|
104
|
+
# Restore high-confidence findings
|
|
105
|
+
opencode run code-archaeology --mode restore
|
|
106
|
+
|
|
107
|
+
# Restore with medium confidence too
|
|
108
|
+
opencode run code-archaeology --mode restore --strict_mode true
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## Output Artifacts
|
|
112
|
+
|
|
113
|
+
All artifacts are written to `.archaeology/`:
|
|
114
|
+
|
|
115
|
+
- `site_survey.md` — baseline inventory and stratum graph
|
|
116
|
+
- `expedition1-report.md` through `expedition8-report.md` — per-expedition findings
|
|
117
|
+
- `FINAL_CATALOG.md` — completed excavation metrics and recommendations
|
|
118
|
+
- `excavation_log.txt` — `git diff --stat`
|
|
119
|
+
|
|
120
|
+
## Expedition Prompts
|
|
121
|
+
|
|
122
|
+
Detailed instructions for each expedition are in the plugin's `prompts/` directory:
|
|
123
|
+
|
|
124
|
+
- `discovery.md` — Phase 0: Site Survey
|
|
125
|
+
- `dead_code.md` — Expedition 1
|
|
126
|
+
- `legacy.md` — Expedition 2
|
|
127
|
+
- `dependencies.md` — Expedition 3
|
|
128
|
+
- `types_consolidate.md` — Expedition 4
|
|
129
|
+
- `types_harden.md` — Expedition 5
|
|
130
|
+
- `dry.md` — Expedition 6
|
|
131
|
+
- `errors.md` — Expedition 7
|
|
132
|
+
- `polish.md` — Expedition 8
|
|
133
|
+
- `final_verify.md` — Phase 9
|
|
134
|
+
|
|
135
|
+
## Common Mistakes
|
|
136
|
+
|
|
137
|
+
- Running `restore` before reviewing `survey` reports — always review first
|
|
138
|
+
- Skipping test runs between phases — failures must be caught immediately
|
|
139
|
+
- Consolidating types before removing dead code — creates cataloging work for discarded code
|
|
140
|
+
- Removing I/O boundary try/catch blocks — these protect against external failures
|
|
141
|
+
- Guessing types during hardening — flag uncertain replacements for review instead
|