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
package/AGENTS.md
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# Code Archaeology Agent Guide
|
|
2
|
+
|
|
3
|
+
Code Archaeology is an OpenCode plugin for systematic codebase excavation, cataloging, and restoration.
|
|
4
|
+
|
|
5
|
+
## Runtime Policy
|
|
6
|
+
|
|
7
|
+
- OpenCode is the only supported worker runtime.
|
|
8
|
+
- The plugin operates entirely within the target repository.
|
|
9
|
+
- All changes are isolated to a configurable branch (`refactor/archaeology` by default).
|
|
10
|
+
|
|
11
|
+
## Available Hooks
|
|
12
|
+
|
|
13
|
+
Core hooks in `hooks/opencode/`:
|
|
14
|
+
- `init.sh` — Initialize `.archaeology/` directory and session state
|
|
15
|
+
- `verify-phase.sh` — Run tests and typecheck between phases
|
|
16
|
+
- `revert-phase.sh` — Revert changes if a phase fails verification
|
|
17
|
+
- `update-expedition.sh` — Update expedition status in session.json
|
|
18
|
+
|
|
19
|
+
## Safety Hooks
|
|
20
|
+
|
|
21
|
+
- `verify-phase.sh` — Mandatory test/typecheck gate between expeditions
|
|
22
|
+
- `revert-phase.sh` — Automatic rollback on failure
|
|
23
|
+
|
|
24
|
+
## Workflow
|
|
25
|
+
|
|
26
|
+
1. Run `hooks/opencode/init.sh` to initialize the session
|
|
27
|
+
2. For each expedition:
|
|
28
|
+
a. Run the expedition (generate reports or apply changes)
|
|
29
|
+
b. Run `hooks/opencode/verify-phase.sh <phase>` to verify
|
|
30
|
+
c. If verification fails, run `hooks/opencode/revert-phase.sh <phase>`
|
|
31
|
+
d. Run `hooks/opencode/update-expedition.sh <phase> <status> [findings]`
|
|
32
|
+
3. Final verification runs all checks and generates `FINAL_CATALOG.md`
|
|
33
|
+
|
|
34
|
+
## Local State
|
|
35
|
+
|
|
36
|
+
`.archaeology/` is runtime state and must not be committed.
|
|
37
|
+
|
|
38
|
+
Key files:
|
|
39
|
+
- `session.json` — Expedition progress and configuration
|
|
40
|
+
- `site_survey.md` — Baseline inventory
|
|
41
|
+
- `expedition1-report.md` through `expedition8-report.md` — Per-expedition findings
|
|
42
|
+
- `FINAL_CATALOG.md` — Completed excavation summary
|
|
43
|
+
- `excavation_log.txt` — `git diff --stat`
|
|
44
|
+
- `patches/` — Mock patches (excavate mode)
|
|
45
|
+
|
|
46
|
+
## Modes
|
|
47
|
+
|
|
48
|
+
| Mode | Behavior |
|
|
49
|
+
|------|----------|
|
|
50
|
+
| `survey` | Reports only, zero file changes |
|
|
51
|
+
| `excavate` | Reports + mock patches, zero file changes |
|
|
52
|
+
| `restore` | Apply approved changes, test-gated |
|
|
53
|
+
|
|
54
|
+
## Constraints
|
|
55
|
+
|
|
56
|
+
- NEVER commit directly to main or master
|
|
57
|
+
- NEVER remove or modify code without writing a site report first
|
|
58
|
+
- NEVER guess types; flag uncertain replacements for human review
|
|
59
|
+
- ALWAYS run tests between phases; stop immediately on failure
|
|
60
|
+
- ALWAYS revert changes if a phase introduces test failures
|
|
61
|
+
- NEVER consolidate types before dead code and legacy removal
|
|
62
|
+
- NEVER remove try/catch from I/O or external input boundaries
|
|
63
|
+
|
|
64
|
+
## Verification
|
|
65
|
+
|
|
66
|
+
Before claiming work is complete:
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
bash hooks/opencode/verify-phase.sh final_verify
|
|
70
|
+
bash -n hooks/opencode/*.sh
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Language Support
|
|
74
|
+
|
|
75
|
+
| Language | Dead Code | Dependencies | Types | DRY |
|
|
76
|
+
|----------|-----------|--------------|-------|-----|
|
|
77
|
+
| TypeScript | `knip` | `madge` | `tsc` | `jscpd` |
|
|
78
|
+
| JavaScript | `knip` | `madge` | N/A | `jscpd` |
|
|
79
|
+
| Python | `vulture` | `pydeps` | `mypy` | `pylint` |
|
|
80
|
+
| Go | `deadcode` | `godepgraph` | `go vet` | `golangci-lint` |
|
|
81
|
+
| Rust | `cargo-udeps` | `cargo-deps` | `rustc` | `clippy` |
|
|
82
|
+
|
|
83
|
+
If tools are missing, the skill falls back to AST-based manual analysis.
|
|
84
|
+
|
|
85
|
+
## Expedition Order
|
|
86
|
+
|
|
87
|
+
The expeditions MUST run in this fixed order:
|
|
88
|
+
|
|
89
|
+
1. Site Survey & Baseline
|
|
90
|
+
2. Dead Code Excavation
|
|
91
|
+
3. Legacy Stratum Removal
|
|
92
|
+
4. Circular Dependency Cartography
|
|
93
|
+
5. Type Catalog Consolidation
|
|
94
|
+
6. Type Restoration & Hardening
|
|
95
|
+
7. DRY Stratification
|
|
96
|
+
8. Error Handling Stratigraphy
|
|
97
|
+
9. Artifact Cleaning & Documentation
|
|
98
|
+
10. Site Preservation & Final Catalog
|
package/LICENSE
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
This is free and unencumbered software released into the public domain.
|
|
2
|
+
|
|
3
|
+
Anyone is free to copy, modify, publish, use, compile, sell, or
|
|
4
|
+
distribute this software, either in source code form or as a compiled
|
|
5
|
+
binary, for any purpose, commercial or non-commercial, and by any
|
|
6
|
+
means.
|
|
7
|
+
|
|
8
|
+
In jurisdictions that recognize copyright laws, the author or authors
|
|
9
|
+
of this software dedicate any and all copyright interest in the
|
|
10
|
+
software to the public domain. We make this dedication for the benefit
|
|
11
|
+
of the public at large and to the detriment of our heirs and
|
|
12
|
+
successors. We intend this dedication to be an overt act of
|
|
13
|
+
relinquishment in perpetuity of all present and future rights to this
|
|
14
|
+
software under copyright law.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
19
|
+
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
20
|
+
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
21
|
+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
|
23
|
+
|
|
24
|
+
For more information, please refer to <https://unlicense.org>
|
package/README.md
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
# Code Archaeology
|
|
2
|
+
|
|
3
|
+
A systematic excavation plugin for OpenCode. Removes accumulated sediment from a codebase—dead code, legacy fallbacks, circular dependencies, weak types, and defensive programming slop—to restore the original architecture.
|
|
4
|
+
|
|
5
|
+
## ⚠️ Site Safety
|
|
6
|
+
|
|
7
|
+
This plugin modifies code. By default it runs in **survey** mode, producing site reports only. Review these before switching to `restore` mode.
|
|
8
|
+
|
|
9
|
+
## Prerequisites
|
|
10
|
+
|
|
11
|
+
- Git repo with clean working tree
|
|
12
|
+
- Passing test suite (even if minimal)
|
|
13
|
+
- Type checker / linter installed
|
|
14
|
+
- `opencode` CLI available
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
# As an OpenCode plugin
|
|
20
|
+
npm install -g opencode-code-archaeology
|
|
21
|
+
|
|
22
|
+
# Or clone and link
|
|
23
|
+
git clone https://github.com/Maleick/Code-Archaeology.git
|
|
24
|
+
cd Code-Archaeology
|
|
25
|
+
npm link
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Usage
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
# 1. Survey — catalog artifacts, zero changes
|
|
32
|
+
opencode run code-archaeology --mode survey
|
|
33
|
+
|
|
34
|
+
# 2. Review reports in .archaeology/
|
|
35
|
+
cat .archaeology/expedition1-report.md
|
|
36
|
+
# ... etc
|
|
37
|
+
|
|
38
|
+
# 3. Restore high-confidence findings only
|
|
39
|
+
opencode run code-archaeology --mode restore --strict_mode false
|
|
40
|
+
|
|
41
|
+
# 4. Or restore medium+high confidence
|
|
42
|
+
opencode run code-archaeology --mode restore --strict_mode true
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Parameters
|
|
46
|
+
|
|
47
|
+
| Parameter | Default | Description |
|
|
48
|
+
|-----------|---------|-------------|
|
|
49
|
+
| `repo_path` | `.` | Target repository |
|
|
50
|
+
| `language` | `typescript` | Primary language |
|
|
51
|
+
| `mode` | `survey` | `survey`, `excavate`, or `restore` |
|
|
52
|
+
| `strict_mode` | `false` | Auto-restore medium-confidence findings |
|
|
53
|
+
| `test_command` | `npm test` | Test runner command |
|
|
54
|
+
| `typecheck_command` | `npx tsc --noEmit` | Type check command |
|
|
55
|
+
| `branch_name` | `refactor/archaeology` | Git branch to create |
|
|
56
|
+
|
|
57
|
+
## Output Artifacts
|
|
58
|
+
|
|
59
|
+
All artifacts are written to `.archaeology/`:
|
|
60
|
+
|
|
61
|
+
- `site_survey.md` — baseline inventory and stratum graph
|
|
62
|
+
- `expedition1-report.md` through `expedition8-report.md` — per-expedition findings
|
|
63
|
+
- `FINAL_CATALOG.md` — completed excavation metrics and recommendations
|
|
64
|
+
- `excavation_log.txt` — `git diff --stat`
|
|
65
|
+
|
|
66
|
+
## Expedition Order (Fixed)
|
|
67
|
+
|
|
68
|
+
The expeditions MUST run in this order due to stratigraphic dependencies:
|
|
69
|
+
|
|
70
|
+
1. Site Survey & Baseline
|
|
71
|
+
2. Dead Code Excavation
|
|
72
|
+
3. Legacy Stratum Removal
|
|
73
|
+
4. Circular Dependency Cartography
|
|
74
|
+
5. Type Catalog Consolidation
|
|
75
|
+
6. Type Restoration & Hardening
|
|
76
|
+
7. DRY Stratification
|
|
77
|
+
8. Error Handling Stratigraphy
|
|
78
|
+
9. Artifact Cleaning & Documentation
|
|
79
|
+
10. Site Preservation & Final Catalog
|
|
80
|
+
|
|
81
|
+
**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).
|
|
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
|
+
## Architecture
|
|
96
|
+
|
|
97
|
+
```
|
|
98
|
+
Code-Archaeology/
|
|
99
|
+
├── src/ # TypeScript source (plugin entry, types)
|
|
100
|
+
├── plugins/ # OpenCode plugin entry point
|
|
101
|
+
├── skills/ # Agent skill definitions (SKILL.md)
|
|
102
|
+
├── commands/ # CLI command documentation
|
|
103
|
+
├── hooks/ # Shell scripts for expedition workflow
|
|
104
|
+
├── prompts/ # Detailed expedition prompts
|
|
105
|
+
├── schema/ # JSON schemas for reports
|
|
106
|
+
├── AGENTS.md # Agent runtime guide
|
|
107
|
+
└── README.md # This file
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Development
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
# Install dependencies
|
|
114
|
+
npm install
|
|
115
|
+
|
|
116
|
+
# Build
|
|
117
|
+
npm run build
|
|
118
|
+
|
|
119
|
+
# Type check
|
|
120
|
+
npm run typecheck
|
|
121
|
+
|
|
122
|
+
# Verify package
|
|
123
|
+
npm run verify:pack
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## License
|
|
127
|
+
|
|
128
|
+
MIT
|
package/VERSION
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
2.0.0
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: code-archaeology-excavate
|
|
3
|
+
description: Run Code Archaeology in excavate mode — generate reports and mock patches for human review
|
|
4
|
+
trigger:
|
|
5
|
+
- "archaeology excavate"
|
|
6
|
+
- "code archaeology excavate"
|
|
7
|
+
- "/archaeology-excavate"
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# Code Archaeology — Excavate Mode
|
|
11
|
+
|
|
12
|
+
Generate reports AND mock patch files for human review. Still zero actual file changes — this produces the patches you would apply.
|
|
13
|
+
|
|
14
|
+
## Usage
|
|
15
|
+
|
|
16
|
+
```
|
|
17
|
+
Run: /code-archaeology-excavate
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## What It Does
|
|
21
|
+
|
|
22
|
+
Runs all 10 expeditions in excavate mode:
|
|
23
|
+
- Catalogs every artifact found (same as survey)
|
|
24
|
+
- Generates mock `.patch` files showing proposed changes
|
|
25
|
+
- Labels each patch with confidence level (HIGH/MEDIUM/LOW)
|
|
26
|
+
- Proposes specific line-by-line changes
|
|
27
|
+
- Does NOT apply any patches
|
|
28
|
+
|
|
29
|
+
## When to Use
|
|
30
|
+
|
|
31
|
+
- After survey reports show promising findings
|
|
32
|
+
- Team wants to review exact changes before applying
|
|
33
|
+
- Need to estimate review effort
|
|
34
|
+
- Want to batch-review multiple expeditions
|
|
35
|
+
|
|
36
|
+
## Output
|
|
37
|
+
|
|
38
|
+
- All survey reports in `.archaeology/`
|
|
39
|
+
- Mock patch files in `.archaeology/patches/`
|
|
40
|
+
- Patch index in `.archaeology/patch-index.json`
|
|
41
|
+
|
|
42
|
+
## Review Process
|
|
43
|
+
|
|
44
|
+
1. Read `expeditionN-report.md` files
|
|
45
|
+
2. Review `.archaeology/patches/*.patch` files
|
|
46
|
+
3. Approve/reject individual patches
|
|
47
|
+
4. Run `/code-archaeology-restore` to apply approved patches
|
|
48
|
+
|
|
49
|
+
## Parameters
|
|
50
|
+
|
|
51
|
+
Same as `/code-archaeology`, defaults to `mode: excavate`.
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: code-archaeology-restore
|
|
3
|
+
description: Run Code Archaeology in restore mode — execute approved changes after survey/excavate review
|
|
4
|
+
trigger:
|
|
5
|
+
- "archaeology restore"
|
|
6
|
+
- "code archaeology restore"
|
|
7
|
+
- "/archaeology-restore"
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# Code Archaeology — Restore Mode
|
|
11
|
+
|
|
12
|
+
Execute approved changes. Applies HIGH confidence findings by default. With `strict_mode: true`, also applies MEDIUM confidence findings.
|
|
13
|
+
|
|
14
|
+
## Usage
|
|
15
|
+
|
|
16
|
+
```
|
|
17
|
+
Run: /code-archaeology-restore
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## What It Does
|
|
21
|
+
|
|
22
|
+
Runs all 10 expeditions in restore mode:
|
|
23
|
+
- Applies HIGH confidence changes automatically
|
|
24
|
+
- Applies MEDIUM confidence changes only if `strict_mode: true`
|
|
25
|
+
- NEVER applies LOW confidence changes (flagged for manual review)
|
|
26
|
+
- Runs tests after each expedition phase
|
|
27
|
+
- Reverts immediately if tests fail
|
|
28
|
+
- Generates final report with metrics
|
|
29
|
+
|
|
30
|
+
## When to Use
|
|
31
|
+
|
|
32
|
+
- Survey and excavate phases are complete
|
|
33
|
+
- Team has reviewed and approved findings
|
|
34
|
+
- You want automated cleanup of obvious issues
|
|
35
|
+
- You have good test coverage to catch regressions
|
|
36
|
+
|
|
37
|
+
## Safety
|
|
38
|
+
|
|
39
|
+
- Creates `refactor/archaeology` branch (configurable)
|
|
40
|
+
- Tests run between every phase
|
|
41
|
+
- Automatic revert on test failure
|
|
42
|
+
- LOW confidence findings never auto-applied
|
|
43
|
+
- I/O boundary error handling never removed
|
|
44
|
+
|
|
45
|
+
## Parameters
|
|
46
|
+
|
|
47
|
+
| Parameter | Default | Description |
|
|
48
|
+
|-----------|---------|-------------|
|
|
49
|
+
| `strict_mode` | `false` | If `true`, also applies MEDIUM confidence findings |
|
|
50
|
+
|
|
51
|
+
## Output
|
|
52
|
+
|
|
53
|
+
- Applied changes on `refactor/archaeology` branch
|
|
54
|
+
- `FINAL_CATALOG.md` with before/after metrics
|
|
55
|
+
- `excavation_log.txt` with `git diff --stat`
|
|
56
|
+
|
|
57
|
+
## Next Steps
|
|
58
|
+
|
|
59
|
+
1. Review the branch: `git diff main..refactor/archaeology`
|
|
60
|
+
2. Run full test suite
|
|
61
|
+
3. Create PR for team review
|
|
62
|
+
4. Merge when approved
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: code-archaeology-survey
|
|
3
|
+
description: Run Code Archaeology in survey mode — catalog artifacts only, zero file changes
|
|
4
|
+
trigger:
|
|
5
|
+
- "archaeology survey"
|
|
6
|
+
- "code archaeology survey"
|
|
7
|
+
- "/archaeology-survey"
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# Code Archaeology — Survey Mode
|
|
11
|
+
|
|
12
|
+
Generate site reports only. Zero file changes. Use this for initial audits and management review.
|
|
13
|
+
|
|
14
|
+
## Usage
|
|
15
|
+
|
|
16
|
+
```
|
|
17
|
+
Run: /code-archaeology-survey
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## What It Does
|
|
21
|
+
|
|
22
|
+
Runs all 10 expeditions in survey mode:
|
|
23
|
+
- Catalogs every artifact found
|
|
24
|
+
- Generates `.archaeology/expeditionN-report.md` for each phase
|
|
25
|
+
- Produces `.archaeology/site_survey.md` baseline
|
|
26
|
+
- Produces `.archaeology/FINAL_CATALOG.md` summary
|
|
27
|
+
- Does NOT modify any source files
|
|
28
|
+
|
|
29
|
+
## When to Use
|
|
30
|
+
|
|
31
|
+
- First-time codebase audit
|
|
32
|
+
- Management wants a technical debt report
|
|
33
|
+
- Team is deciding whether to refactor
|
|
34
|
+
- You want to know the scope before committing resources
|
|
35
|
+
|
|
36
|
+
## Output
|
|
37
|
+
|
|
38
|
+
All reports in `.archaeology/`:
|
|
39
|
+
- `site_survey.md`
|
|
40
|
+
- `expedition1-report.md` through `expedition8-report.md`
|
|
41
|
+
- `FINAL_CATALOG.md`
|
|
42
|
+
|
|
43
|
+
## Next Steps
|
|
44
|
+
|
|
45
|
+
After reviewing reports:
|
|
46
|
+
1. Decide which findings to address
|
|
47
|
+
2. Run `/code-archaeology-excavate` to generate mock patches
|
|
48
|
+
3. Or run `/code-archaeology-restore` to apply high-confidence fixes
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: code-archaeology
|
|
3
|
+
description: Start a Code Archaeology expedition to excavate, catalog, and restore a codebase by removing technical debt systematically
|
|
4
|
+
trigger:
|
|
5
|
+
- "start archaeology"
|
|
6
|
+
- "run archaeology"
|
|
7
|
+
- "code archaeology"
|
|
8
|
+
- "/archaeology"
|
|
9
|
+
- "/code-archaeology"
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
# Code Archaeology — Systematic Codebase Excavation
|
|
13
|
+
|
|
14
|
+
Excavate, catalog, and restore a codebase by removing accumulated sediment: dead code, legacy fallbacks, circular dependencies, weak types, and defensive programming slop. Produces human-reviewable site reports before any artifacts are disturbed. Non-destructive by default.
|
|
15
|
+
|
|
16
|
+
## Quick Start
|
|
17
|
+
|
|
18
|
+
```
|
|
19
|
+
Run: /code-archaeology
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## What It Does
|
|
23
|
+
|
|
24
|
+
1. **Surveys** the codebase — inventory, metrics, baseline
|
|
25
|
+
2. **Excavates** dead code — unused exports, unreachable functions
|
|
26
|
+
3. **Removes** legacy stratum — deprecated APIs, polyfills, shims
|
|
27
|
+
4. **Maps** circular dependencies — cartography and remediation
|
|
28
|
+
5. **Consolidates** types — deduplicate type definitions
|
|
29
|
+
6. **Hardens** types — replace `any`/`unknown` with precise types
|
|
30
|
+
7. **Enforces** DRY — extract semantic duplications
|
|
31
|
+
8. **Fixes** error handling — remove suppression, add proper handling
|
|
32
|
+
9. **Cleans** artifacts — documentation, formatting, remaining slop
|
|
33
|
+
10. **Preserves** the site — final verification and catalog
|
|
34
|
+
|
|
35
|
+
## Available Commands
|
|
36
|
+
|
|
37
|
+
| Command | Description |
|
|
38
|
+
|---------|-------------|
|
|
39
|
+
| `/code-archaeology` | Start full expedition (default: survey mode) |
|
|
40
|
+
| `/code-archaeology-survey` | Site survey only — zero file changes |
|
|
41
|
+
| `/code-archaeology-excavate` | Generate reports + mock patches for review |
|
|
42
|
+
| `/code-archaeology-restore` | Execute approved changes after review |
|
|
43
|
+
|
|
44
|
+
## Parameters
|
|
45
|
+
|
|
46
|
+
| Parameter | Default | Description |
|
|
47
|
+
|-----------|---------|-------------|
|
|
48
|
+
| `repo_path` | `.` | Target repository |
|
|
49
|
+
| `language` | `typescript` | Primary language |
|
|
50
|
+
| `mode` | `survey` | `survey`, `excavate`, or `restore` |
|
|
51
|
+
| `strict_mode` | `false` | Auto-restore medium-confidence findings |
|
|
52
|
+
| `test_command` | `npm test` | Test runner command |
|
|
53
|
+
| `typecheck_command` | `npx tsc --noEmit` | Type check command |
|
|
54
|
+
| `branch_name` | `refactor/archaeology` | Git branch to create |
|
|
55
|
+
|
|
56
|
+
## Requirements
|
|
57
|
+
|
|
58
|
+
- Git repo with clean working tree
|
|
59
|
+
- Passing test suite (even if minimal)
|
|
60
|
+
- Type checker / linter installed
|
|
61
|
+
- `opencode` CLI available
|
|
62
|
+
|
|
63
|
+
## Safety
|
|
64
|
+
|
|
65
|
+
- **Survey mode (default)**: Zero file changes. Only reports generated.
|
|
66
|
+
- **Excavate mode**: Mock patches for human review. No actual modifications.
|
|
67
|
+
- **Restore mode**: Applies approved changes. Always runs tests between phases.
|
|
68
|
+
- **Branch isolation**: All work happens on `refactor/archaeology` (configurable).
|
|
69
|
+
- **Test gating**: Any phase that breaks tests is automatically reverted.
|
|
70
|
+
|
|
71
|
+
## Output Artifacts
|
|
72
|
+
|
|
73
|
+
All artifacts are written to `.archaeology/`:
|
|
74
|
+
|
|
75
|
+
- `site_survey.md` — baseline inventory and stratum graph
|
|
76
|
+
- `expedition1-report.md` through `expedition8-report.md` — per-expedition findings
|
|
77
|
+
- `FINAL_CATALOG.md` — completed excavation metrics and recommendations
|
|
78
|
+
- `excavation_log.txt` — `git diff --stat`
|
|
79
|
+
|
|
80
|
+
## Expedition Order (Fixed)
|
|
81
|
+
|
|
82
|
+
The expeditions MUST run in this order due to stratigraphic dependencies:
|
|
83
|
+
|
|
84
|
+
1. Site Survey & Baseline
|
|
85
|
+
2. Dead Code Excavation
|
|
86
|
+
3. Legacy Stratum Removal
|
|
87
|
+
4. Circular Dependency Cartography
|
|
88
|
+
5. Type Catalog Consolidation
|
|
89
|
+
6. Type Restoration & Hardening
|
|
90
|
+
7. DRY Stratification
|
|
91
|
+
8. Error Handling Stratigraphy
|
|
92
|
+
9. Artifact Cleaning & Documentation
|
|
93
|
+
10. Site Preservation & Final Catalog
|
|
94
|
+
|
|
95
|
+
## Language Support
|
|
96
|
+
|
|
97
|
+
| Language | Dead Code | Dependencies | Types | DRY |
|
|
98
|
+
|----------|-----------|--------------|-------|-----|
|
|
99
|
+
| TypeScript | `knip` | `madge` | `tsc` | `jscpd` |
|
|
100
|
+
| JavaScript | `knip` | `madge` | N/A | `jscpd` |
|
|
101
|
+
| Python | `vulture` | `pydeps` | `mypy` | `pylint` |
|
|
102
|
+
| Go | `deadcode` | `godepgraph` | `go vet` | `golangci-lint` |
|
|
103
|
+
| Rust | `cargo-udeps` | `cargo-deps` | `rustc` | `clippy` |
|
|
104
|
+
|
|
105
|
+
If tools are missing, falls back to AST-based manual analysis.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { PluginServer } from "./types.js";
|
|
2
|
+
export declare const id = "code-archaeology";
|
|
3
|
+
export declare const repoRoot: string;
|
|
4
|
+
export declare const version: string;
|
|
5
|
+
export declare function server(): Promise<PluginServer>;
|
|
6
|
+
export * from "./types.js";
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAO/C,eAAO,MAAM,EAAE,qBAAqB,CAAC;AACrC,eAAO,MAAM,QAAQ,QAAc,CAAC;AAGpC,eAAO,MAAM,OAAO,QAA2C,CAAC;AAEhE,wBAAsB,MAAM,IAAI,OAAO,CAAC,YAAY,CAAC,CAMpD;AAED,cAAc,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { fileURLToPath } from "node:url";
|
|
2
|
+
import { dirname, resolve } from "node:path";
|
|
3
|
+
import { readFileSync } from "node:fs";
|
|
4
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
5
|
+
const __dirname = dirname(__filename);
|
|
6
|
+
const packageRoot = resolve(__dirname, "..");
|
|
7
|
+
export const id = "code-archaeology";
|
|
8
|
+
export const repoRoot = packageRoot;
|
|
9
|
+
const versionPath = resolve(packageRoot, "VERSION");
|
|
10
|
+
export const version = readFileSync(versionPath, "utf8").trim();
|
|
11
|
+
export async function server() {
|
|
12
|
+
return {
|
|
13
|
+
event() {
|
|
14
|
+
return undefined;
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export * from "./types.js";
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAGvC,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAClD,MAAM,SAAS,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AAEtC,MAAM,WAAW,GAAG,OAAO,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;AAE7C,MAAM,CAAC,MAAM,EAAE,GAAG,kBAAkB,CAAC;AACrC,MAAM,CAAC,MAAM,QAAQ,GAAG,WAAW,CAAC;AAEpC,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC;AACpD,MAAM,CAAC,MAAM,OAAO,GAAG,YAAY,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC,IAAI,EAAE,CAAC;AAEhE,MAAM,CAAC,KAAK,UAAU,MAAM;IAC1B,OAAO;QACL,KAAK;YACH,OAAO,SAAS,CAAC;QACnB,CAAC;KACF,CAAC;AACJ,CAAC;AAED,cAAc,YAAY,CAAC"}
|