opencode-code-archaeology 2.0.0 → 2.0.2
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/.github/ISSUE_TEMPLATE/bug_report.yml +63 -0
- package/.github/ISSUE_TEMPLATE/feature_request.yml +48 -0
- package/.github/pull_request_template.md +26 -0
- package/.github/workflows/ci.yml +45 -0
- package/CHANGELOG.md +20 -0
- package/CONTRIBUTING.md +48 -0
- package/INSTALL.md +141 -0
- package/README.md +194 -71
- package/SECURITY.md +20 -0
- package/VERSION +1 -1
- package/assets/code-archaeology-banner.svg +66 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +111 -0
- package/dist/cli.js.map +1 -0
- package/dist/plugin.d.ts +3 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +2 -0
- package/dist/plugin.js.map +1 -0
- package/docs/ARCHITECTURE.md +92 -0
- package/docs/INSTALL.md +117 -0
- package/docs/README.md +44 -0
- package/docs/RELEASE.md +135 -0
- package/docs/SECURITY_AUDIT.md +38 -0
- package/hooks/opencode/verify-package.sh +46 -0
- package/package.json +26 -5
- package/prompts/dead_code.md +45 -0
- package/prompts/dependencies.md +49 -0
- package/prompts/discovery.md +47 -0
- package/prompts/dry.md +49 -0
- package/prompts/errors.md +52 -0
- package/prompts/final_verify.md +58 -0
- package/prompts/legacy.md +49 -0
- package/prompts/polish.md +48 -0
- package/prompts/types_consolidate.md +48 -0
- package/prompts/types_harden.md +51 -0
- package/wiki/Expedition-Workflow.md +32 -0
- package/wiki/Home.md +27 -0
- package/wiki/Installation.md +42 -0
- package/wiki/Release-Process.md +31 -0
- package/wiki/Security-and-Safety.md +21 -0
package/README.md
CHANGED
|
@@ -1,71 +1,168 @@
|
|
|
1
|
-
|
|
1
|
+
<h1 align="center">Code Archaeology</h1>
|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
<img src="assets/code-archaeology-banner.svg" alt="Code Archaeology OpenCode plugin banner" width="900">
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
8
|
+
<a href="https://github.com/Maleick/Code-Archaeology/stargazers"><img alt="GitHub stars" src="https://img.shields.io/github/stars/Maleick/Code-Archaeology?style=flat-square"></a>
|
|
9
|
+
<a href="https://github.com/Maleick/Code-Archaeology/commits/main"><img alt="Last commit" src="https://img.shields.io/github/last-commit/Maleick/Code-Archaeology?style=flat-square"></a>
|
|
10
|
+
<a href="https://github.com/Maleick/Code-Archaeology/releases"><img alt="GitHub release" src="https://img.shields.io/github/v/release/Maleick/Code-Archaeology?style=flat-square"></a>
|
|
11
|
+
<a href="https://www.npmjs.com/package/opencode-code-archaeology"><img alt="npm version" src="https://img.shields.io/npm/v/opencode-code-archaeology?style=flat-square"></a>
|
|
12
|
+
<a href="LICENSE"><img alt="License" src="https://img.shields.io/github/license/Maleick/Code-Archaeology?style=flat-square"></a>
|
|
13
|
+
<a href="docs/README.md"><img alt="Docs" src="https://img.shields.io/badge/docs-open-blue?style=flat-square"></a>
|
|
14
|
+
<a href="https://github.com/sponsors/Maleick"><img alt="Sponsor" src="https://img.shields.io/badge/sponsor-Maleick-fafbfc?style=flat-square&logo=github-sponsors"></a>
|
|
15
|
+
</p>
|
|
16
|
+
|
|
17
|
+
<p align="center">
|
|
18
|
+
<a href="#installation">Install</a> |
|
|
19
|
+
<a href="docs/README.md">Docs</a> |
|
|
20
|
+
<a href="https://github.com/Maleick/Code-Archaeology/wiki">Wiki</a> |
|
|
21
|
+
<a href="#commands">Commands</a> |
|
|
22
|
+
<a href="#safety-model">Safety</a> |
|
|
23
|
+
<a href="#release-docs">Release</a>
|
|
24
|
+
</p>
|
|
25
|
+
|
|
26
|
+
Code Archaeology is an OpenCode plugin that surveys, catalogs, and safely restores codebases by removing accumulated technical sediment in a fixed, test-gated expedition order.
|
|
27
|
+
|
|
28
|
+
```text
|
|
29
|
+
+---------------------------------------------------------------+
|
|
30
|
+
| CODE ARCHAEOLOGY CAPABILITY PANEL |
|
|
31
|
+
+-------------------+-------------------------------------------+
|
|
32
|
+
| Default mode | survey: reports only, zero source edits |
|
|
33
|
+
| Review mode | excavate: reports plus mock patches |
|
|
34
|
+
| Restore mode | applies approved changes with test gates |
|
|
35
|
+
| Local state | .archaeology/ runtime artifacts |
|
|
36
|
+
| Runtime | OpenCode plugin inside the target repo |
|
|
37
|
+
| Expedition order | fixed stratigraphy from survey to catalog |
|
|
38
|
+
+-------------------+-------------------------------------------+
|
|
39
|
+
```
|
|
2
40
|
|
|
3
|
-
|
|
41
|
+
## What It Does
|
|
4
42
|
|
|
5
|
-
|
|
43
|
+
Code Archaeology runs a systematic excavation of a repository before it changes code. It inventories the site, identifies technical debt strata, writes reviewable reports, and only applies approved changes in `restore` mode.
|
|
6
44
|
|
|
7
|
-
|
|
45
|
+
- Catalogs dead code, unused exports, unreachable functions, and stale artifacts.
|
|
46
|
+
- Removes legacy fallbacks, deprecated shims, and compatibility layers after review.
|
|
47
|
+
- Maps circular dependencies before extraction or type consolidation work.
|
|
48
|
+
- Consolidates duplicate type definitions only after dead code and legacy layers are removed.
|
|
49
|
+
- Hardens weak types without guessing uncertain replacements.
|
|
50
|
+
- Finds semantic duplication and error-handling slop while preserving I/O boundaries.
|
|
51
|
+
- Produces `.archaeology/` reports that stay local to the working repository.
|
|
8
52
|
|
|
9
|
-
##
|
|
53
|
+
## Installation
|
|
10
54
|
|
|
11
|
-
|
|
12
|
-
- Passing test suite (even if minimal)
|
|
13
|
-
- Type checker / linter installed
|
|
14
|
-
- `opencode` CLI available
|
|
55
|
+
For OpenCode, paste this handoff into your agent:
|
|
15
56
|
|
|
16
|
-
|
|
57
|
+
```text
|
|
58
|
+
Fetch and follow instructions from https://raw.githubusercontent.com/Maleick/Code-Archaeology/refs/heads/main/INSTALL.md
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Recommended plugin install in `opencode.json`:
|
|
62
|
+
|
|
63
|
+
```json
|
|
64
|
+
{
|
|
65
|
+
"plugin": [
|
|
66
|
+
"opencode-code-archaeology@git+https://github.com/Maleick/Code-Archaeology.git"
|
|
67
|
+
]
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Global npm install path:
|
|
17
72
|
|
|
18
73
|
```bash
|
|
19
|
-
# As an OpenCode plugin
|
|
20
74
|
npm install -g opencode-code-archaeology
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
cd Code-Archaeology
|
|
25
|
-
npm link
|
|
75
|
+
opencode-code-archaeology install
|
|
76
|
+
opencode-code-archaeology doctor
|
|
77
|
+
opencode-code-archaeology version
|
|
26
78
|
```
|
|
27
79
|
|
|
28
|
-
|
|
80
|
+
One-time package runner path, if your OpenCode setup supports package execution through Bun:
|
|
29
81
|
|
|
30
82
|
```bash
|
|
31
|
-
|
|
32
|
-
opencode
|
|
83
|
+
bunx opencode-code-archaeology install
|
|
84
|
+
bunx opencode-code-archaeology doctor
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
See [`INSTALL.md`](INSTALL.md) for prerequisites, verification, updating, and troubleshooting.
|
|
33
88
|
|
|
34
|
-
|
|
35
|
-
cat .archaeology/expedition1-report.md
|
|
36
|
-
# ... etc
|
|
89
|
+
## Quick Start
|
|
37
90
|
|
|
38
|
-
|
|
39
|
-
opencode run code-archaeology --mode restore --strict_mode false
|
|
91
|
+
Run the command family from inside the repository you want to inspect:
|
|
40
92
|
|
|
41
|
-
|
|
42
|
-
|
|
93
|
+
```text
|
|
94
|
+
/code-archaeology
|
|
43
95
|
```
|
|
44
96
|
|
|
45
|
-
|
|
97
|
+
Start non-destructively, review the reports, then choose whether to generate mock patches or apply approved changes:
|
|
46
98
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
99
|
+
```text
|
|
100
|
+
/code-archaeology-survey
|
|
101
|
+
/code-archaeology-excavate
|
|
102
|
+
/code-archaeology-restore
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## Expedition Flow
|
|
106
|
+
|
|
107
|
+
```mermaid
|
|
108
|
+
flowchart TD
|
|
109
|
+
A[Start /code-archaeology] --> B[Site Survey and Baseline]
|
|
110
|
+
B --> C[Dead Code Excavation]
|
|
111
|
+
C --> D[Legacy Stratum Removal]
|
|
112
|
+
D --> E[Circular Dependency Cartography]
|
|
113
|
+
E --> F[Type Catalog Consolidation]
|
|
114
|
+
F --> G[Type Restoration and Hardening]
|
|
115
|
+
G --> H[DRY Stratification]
|
|
116
|
+
H --> I[Error Handling Stratigraphy]
|
|
117
|
+
I --> J[Artifact Cleaning and Documentation]
|
|
118
|
+
J --> K[Site Preservation and Final Catalog]
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## Safety Model
|
|
122
|
+
|
|
123
|
+
```mermaid
|
|
124
|
+
flowchart LR
|
|
125
|
+
Survey[survey mode] --> Reports[write site reports]
|
|
126
|
+
Reports --> Review[human review]
|
|
127
|
+
Review --> Excavate[excavate mode: mock patches]
|
|
128
|
+
Review --> Restore[restore mode: approved changes]
|
|
129
|
+
Restore --> Verify[verify phase]
|
|
130
|
+
Verify -->|pass| Next[next expedition]
|
|
131
|
+
Verify -->|fail| Revert[revert phase and stop]
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
- `survey` is the default and writes reports only.
|
|
135
|
+
- `restore` modifies code and should run only after reports are reviewed.
|
|
136
|
+
- `.archaeology/` is local runtime state and should not be committed.
|
|
137
|
+
- Work is isolated to a configurable branch, `refactor/archaeology` by default.
|
|
138
|
+
- Tests and type checks gate each restore phase.
|
|
139
|
+
- Failed restore phases are reverted before the next expedition can proceed.
|
|
140
|
+
- Try/catch blocks around I/O and external input boundaries are never removed automatically.
|
|
56
141
|
|
|
57
|
-
##
|
|
142
|
+
## Commands
|
|
58
143
|
|
|
59
|
-
|
|
144
|
+
| Command | Purpose | File changes |
|
|
145
|
+
| --- | --- | --- |
|
|
146
|
+
| `/code-archaeology` | Start the full expedition in the configured mode. | Depends on mode; defaults to none. |
|
|
147
|
+
| `/code-archaeology-survey` | Generate site reports for review. | None outside `.archaeology/`. |
|
|
148
|
+
| `/code-archaeology-excavate` | Generate reports and mock patches. | None outside `.archaeology/patches/`. |
|
|
149
|
+
| `/code-archaeology-restore` | Apply approved high-confidence changes. | Yes, test-gated. |
|
|
60
150
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
151
|
+
## Parameters
|
|
152
|
+
|
|
153
|
+
| Parameter | Default | Description |
|
|
154
|
+
| --- | --- | --- |
|
|
155
|
+
| `repo_path` | `.` | Target repository to excavate. |
|
|
156
|
+
| `language` | `typescript` | Primary language for tooling selection. |
|
|
157
|
+
| `mode` | `survey` | `survey`, `excavate`, or `restore`. |
|
|
158
|
+
| `strict_mode` | `false` | When true, restore may also apply medium-confidence findings. |
|
|
159
|
+
| `test_command` | `npm test` | Test command run by verification hooks. |
|
|
160
|
+
| `typecheck_command` | `npx tsc --noEmit` | Type-check command run by verification hooks. |
|
|
161
|
+
| `branch_name` | `refactor/archaeology` | Branch used for isolated restore work. |
|
|
65
162
|
|
|
66
|
-
## Expedition Order
|
|
163
|
+
## Expedition Order
|
|
67
164
|
|
|
68
|
-
The
|
|
165
|
+
The expedition order is fixed because each layer depends on the previous excavation:
|
|
69
166
|
|
|
70
167
|
1. Site Survey & Baseline
|
|
71
168
|
2. Dead Code Excavation
|
|
@@ -78,51 +175,77 @@ The expeditions MUST run in this order due to stratigraphic dependencies:
|
|
|
78
175
|
9. Artifact Cleaning & Documentation
|
|
79
176
|
10. Site Preservation & Final Catalog
|
|
80
177
|
|
|
81
|
-
|
|
178
|
+
Do not consolidate types before dead code and legacy removal. Do not DRY code before dependency cycles are mapped.
|
|
82
179
|
|
|
83
|
-
## Language
|
|
180
|
+
## Language Tooling
|
|
84
181
|
|
|
85
182
|
| Language | Dead Code | Dependencies | Types | DRY |
|
|
86
|
-
|
|
87
|
-
| TypeScript | `knip
|
|
88
|
-
| JavaScript | `knip
|
|
183
|
+
| --- | --- | --- | --- | --- |
|
|
184
|
+
| TypeScript | `knip` | `madge` | `tsc` | `jscpd` |
|
|
185
|
+
| JavaScript | `knip` | `madge` | N/A | `jscpd` |
|
|
89
186
|
| Python | `vulture` | `pydeps` | `mypy` | `pylint` |
|
|
90
|
-
| Go | `deadcode
|
|
91
|
-
| Rust | `cargo-udeps
|
|
187
|
+
| Go | `deadcode` | `godepgraph` | `go vet` | `golangci-lint` |
|
|
188
|
+
| Rust | `cargo-udeps` | `cargo-deps` | `rustc` | `clippy` |
|
|
92
189
|
|
|
93
|
-
If
|
|
190
|
+
If a preferred tool is missing, Code Archaeology falls back to AST-based manual analysis and flags uncertain findings for human review.
|
|
94
191
|
|
|
95
192
|
## Architecture
|
|
96
193
|
|
|
97
|
-
```
|
|
194
|
+
```text
|
|
98
195
|
Code-Archaeology/
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
196
|
+
|-- assets/ # README and repository visual assets
|
|
197
|
+
|-- commands/ # OpenCode slash command definitions
|
|
198
|
+
|-- dist/ # Built package output for GitHub-based installs
|
|
199
|
+
|-- docs/ # Public docs and release notes
|
|
200
|
+
|-- hooks/opencode/ # Init, verification, revert, and status hooks
|
|
201
|
+
|-- plugins/ # OpenCode plugin entry point
|
|
202
|
+
|-- prompts/ # Expedition prompts by phase
|
|
203
|
+
|-- schema/ # JSON schemas for reports
|
|
204
|
+
|-- skills/ # Code Archaeology skill definition
|
|
205
|
+
|-- src/ # TypeScript source
|
|
206
|
+
|-- INSTALL.md # OpenCode install handoff
|
|
207
|
+
|-- README.md # Public project overview
|
|
208
|
+
`-- AGENTS.md # Agent runtime guide
|
|
108
209
|
```
|
|
109
210
|
|
|
110
|
-
##
|
|
211
|
+
## Runtime Artifacts
|
|
212
|
+
|
|
213
|
+
All expedition state is written to `.archaeology/` inside the target repository:
|
|
214
|
+
|
|
215
|
+
| Artifact | Purpose |
|
|
216
|
+
| --- | --- |
|
|
217
|
+
| `session.json` | Current expedition progress and configuration. |
|
|
218
|
+
| `site_survey.md` | Baseline inventory and stratum graph. |
|
|
219
|
+
| `expedition1-report.md` through `expedition8-report.md` | Per-expedition findings. |
|
|
220
|
+
| `FINAL_CATALOG.md` | Final excavation summary and recommendations. |
|
|
221
|
+
| `excavation_log.txt` | `git diff --stat` for applied restoration work. |
|
|
222
|
+
| `patches/` | Mock patches generated by `excavate` mode. |
|
|
223
|
+
|
|
224
|
+
## Local Testing
|
|
225
|
+
|
|
226
|
+
For plugin development:
|
|
111
227
|
|
|
112
228
|
```bash
|
|
113
|
-
# Install dependencies
|
|
114
229
|
npm install
|
|
115
|
-
|
|
116
|
-
# Build
|
|
117
230
|
npm run build
|
|
118
|
-
|
|
119
|
-
# Type check
|
|
120
231
|
npm run typecheck
|
|
232
|
+
npm pack --json --dry-run
|
|
233
|
+
bash -n hooks/opencode/*.sh
|
|
234
|
+
```
|
|
121
235
|
|
|
122
|
-
|
|
123
|
-
|
|
236
|
+
For a restore expedition, run the configured test and type-check commands between phases. The bundled verification hook is:
|
|
237
|
+
|
|
238
|
+
```bash
|
|
239
|
+
bash hooks/opencode/verify-phase.sh final_verify
|
|
124
240
|
```
|
|
125
241
|
|
|
242
|
+
## Release Docs
|
|
243
|
+
|
|
244
|
+
- [`docs/README.md`](docs/README.md) is the documentation landing page.
|
|
245
|
+
- [`docs/RELEASE.md`](docs/RELEASE.md) covers release preparation and publishing.
|
|
246
|
+
- [`INSTALL.md`](INSTALL.md) is the raw handoff for OpenCode installation.
|
|
247
|
+
- [GitHub Releases](https://github.com/Maleick/Code-Archaeology/releases) lists published versions.
|
|
248
|
+
|
|
126
249
|
## License
|
|
127
250
|
|
|
128
|
-
MIT
|
|
251
|
+
MIT. See [`LICENSE`](LICENSE).
|
package/SECURITY.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Security Policy
|
|
2
|
+
|
|
3
|
+
## Reporting A Vulnerability
|
|
4
|
+
|
|
5
|
+
Please report suspected vulnerabilities through a GitHub private security advisory for this repository. Do not open a public issue for vulnerabilities, secrets, private repository contents, or exploit details.
|
|
6
|
+
|
|
7
|
+
Include the affected version or commit, a concise reproduction, expected impact, and any relevant sanitized logs. A maintainer will review the advisory and coordinate a fix before public disclosure.
|
|
8
|
+
|
|
9
|
+
## Safety Model
|
|
10
|
+
|
|
11
|
+
Code Archaeology is designed to inspect and improve repositories without surprising users:
|
|
12
|
+
|
|
13
|
+
- `survey` is the default mode and produces reports without changing project files.
|
|
14
|
+
- `excavate` produces reports and mock patches without applying changes.
|
|
15
|
+
- `restore` can modify code only after review and should be run with tests or type checks available.
|
|
16
|
+
- Failed restore phases should be reverted before continuing.
|
|
17
|
+
- Runtime state is written to `.archaeology/` and should remain ignored and local.
|
|
18
|
+
- Documentation and examples must not include secrets, tokens, credentials, or private code.
|
|
19
|
+
|
|
20
|
+
The plugin must not remove try/catch blocks around I/O or external input boundaries automatically, and uncertain type replacements should be flagged for human review.
|
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.0.
|
|
1
|
+
2.0.2
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="900" height="300" viewBox="0 0 900 300" role="img" aria-labelledby="title desc">
|
|
2
|
+
<title id="title">Code Archaeology OpenCode Plugin</title>
|
|
3
|
+
<desc id="desc">Dark archaeology themed banner for the Code Archaeology OpenCode plugin.</desc>
|
|
4
|
+
<defs>
|
|
5
|
+
<linearGradient id="bg" x1="0" y1="0" x2="1" y2="1">
|
|
6
|
+
<stop offset="0" stop-color="#071018"/>
|
|
7
|
+
<stop offset="0.48" stop-color="#111827"/>
|
|
8
|
+
<stop offset="1" stop-color="#2a1809"/>
|
|
9
|
+
</linearGradient>
|
|
10
|
+
<linearGradient id="sand" x1="0" y1="0" x2="1" y2="0">
|
|
11
|
+
<stop offset="0" stop-color="#c0843f"/>
|
|
12
|
+
<stop offset="0.5" stop-color="#e0b15b"/>
|
|
13
|
+
<stop offset="1" stop-color="#8b5a2b"/>
|
|
14
|
+
</linearGradient>
|
|
15
|
+
<linearGradient id="tablet" x1="0" y1="0" x2="0" y2="1">
|
|
16
|
+
<stop offset="0" stop-color="#334155"/>
|
|
17
|
+
<stop offset="1" stop-color="#111827"/>
|
|
18
|
+
</linearGradient>
|
|
19
|
+
<filter id="glow" x="-30%" y="-30%" width="160%" height="160%">
|
|
20
|
+
<feGaussianBlur stdDeviation="4" result="blur"/>
|
|
21
|
+
<feMerge>
|
|
22
|
+
<feMergeNode in="blur"/>
|
|
23
|
+
<feMergeNode in="SourceGraphic"/>
|
|
24
|
+
</feMerge>
|
|
25
|
+
</filter>
|
|
26
|
+
</defs>
|
|
27
|
+
|
|
28
|
+
<rect width="900" height="300" fill="url(#bg)"/>
|
|
29
|
+
<path d="M0 222 C120 198 214 236 322 213 C452 186 549 216 672 194 C764 178 827 190 900 171 L900 300 L0 300 Z" fill="#20140b" opacity="0.92"/>
|
|
30
|
+
<path d="M0 244 C152 214 244 266 386 231 C505 202 626 242 744 210 C806 193 852 201 900 189 L900 300 L0 300 Z" fill="#2f1d0f"/>
|
|
31
|
+
<path d="M0 268 C138 246 267 281 405 258 C523 238 650 270 770 244 C827 232 865 232 900 222 L900 300 L0 300 Z" fill="url(#sand)" opacity="0.82"/>
|
|
32
|
+
|
|
33
|
+
<g opacity="0.35" stroke="#e0b15b" stroke-width="1" fill="none">
|
|
34
|
+
<path d="M41 96 H312"/>
|
|
35
|
+
<path d="M586 66 H852"/>
|
|
36
|
+
<path d="M640 103 H828"/>
|
|
37
|
+
<path d="M68 128 H242"/>
|
|
38
|
+
</g>
|
|
39
|
+
|
|
40
|
+
<g transform="translate(78 58)">
|
|
41
|
+
<path d="M74 8 L141 34 L116 146 L22 146 L0 35 Z" fill="url(#tablet)" stroke="#64748b" stroke-width="3"/>
|
|
42
|
+
<path d="M28 48 H103 M31 75 H111 M36 102 H91" stroke="#cbd5e1" stroke-width="6" stroke-linecap="round" opacity="0.72"/>
|
|
43
|
+
<path d="M95 138 L136 179" stroke="#d6a23f" stroke-width="12" stroke-linecap="round"/>
|
|
44
|
+
<path d="M126 169 L169 126" stroke="#d6a23f" stroke-width="12" stroke-linecap="round"/>
|
|
45
|
+
<path d="M138 120 C154 103 182 104 198 120 L169 149 Z" fill="#111827" stroke="#f6c453" stroke-width="6"/>
|
|
46
|
+
<circle cx="71" cy="31" r="9" fill="#f6c453" filter="url(#glow)"/>
|
|
47
|
+
</g>
|
|
48
|
+
|
|
49
|
+
<g transform="translate(300 70)">
|
|
50
|
+
<text x="0" y="43" font-family="Inter, Segoe UI, Arial, sans-serif" font-size="46" font-weight="800" fill="#f8fafc" letter-spacing="1">Code Archaeology</text>
|
|
51
|
+
<text x="2" y="83" font-family="Inter, Segoe UI, Arial, sans-serif" font-size="20" font-weight="600" fill="#f6c453">OpenCode plugin for systematic codebase excavation</text>
|
|
52
|
+
<text x="2" y="122" font-family="SFMono-Regular, Consolas, Liberation Mono, monospace" font-size="15" fill="#cbd5e1">survey - excavate - restore - verify</text>
|
|
53
|
+
<g transform="translate(0 145)" font-family="SFMono-Regular, Consolas, Liberation Mono, monospace" font-size="13" fill="#94a3b8">
|
|
54
|
+
<rect x="0" y="0" width="455" height="42" rx="10" fill="#020617" opacity="0.72" stroke="#334155"/>
|
|
55
|
+
<text x="18" y="26">dead code | legacy | cycles | types | DRY | errors</text>
|
|
56
|
+
</g>
|
|
57
|
+
</g>
|
|
58
|
+
|
|
59
|
+
<g opacity="0.55" fill="#f6c453">
|
|
60
|
+
<circle cx="807" cy="54" r="2"/>
|
|
61
|
+
<circle cx="846" cy="93" r="1.8"/>
|
|
62
|
+
<circle cx="758" cy="120" r="1.5"/>
|
|
63
|
+
<circle cx="63" cy="39" r="1.5"/>
|
|
64
|
+
<circle cx="219" cy="48" r="2"/>
|
|
65
|
+
</g>
|
|
66
|
+
</svg>
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { copyFile, mkdir, readFile, writeFile } from "node:fs/promises";
|
|
3
|
+
import { existsSync } from "node:fs";
|
|
4
|
+
import { dirname, join } from "node:path";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
import process from "node:process";
|
|
7
|
+
const PLUGIN = "opencode-code-archaeology@git+https://github.com/Maleick/Code-Archaeology.git";
|
|
8
|
+
const REQUIRED_FILES = [
|
|
9
|
+
"commands/code-archaeology.md",
|
|
10
|
+
"skills/code-archaeology/SKILL.md",
|
|
11
|
+
"hooks/opencode/init.sh",
|
|
12
|
+
"hooks/opencode/verify-phase.sh",
|
|
13
|
+
"AGENTS.md",
|
|
14
|
+
"README.md",
|
|
15
|
+
"INSTALL.md",
|
|
16
|
+
];
|
|
17
|
+
const cliFile = fileURLToPath(import.meta.url);
|
|
18
|
+
const root = dirname(dirname(cliFile));
|
|
19
|
+
function configPath() {
|
|
20
|
+
const configDir = process.env.OPENCODE_CONFIG_DIR || join(process.env.HOME || ".", ".config", "opencode");
|
|
21
|
+
return join(configDir, "opencode.json");
|
|
22
|
+
}
|
|
23
|
+
function backupPath(target) {
|
|
24
|
+
let candidate = `${target}.bak`;
|
|
25
|
+
let index = 1;
|
|
26
|
+
while (existsSync(candidate)) {
|
|
27
|
+
candidate = `${target}.bak.${index}`;
|
|
28
|
+
index += 1;
|
|
29
|
+
}
|
|
30
|
+
return candidate;
|
|
31
|
+
}
|
|
32
|
+
async function readPackageVersion() {
|
|
33
|
+
const packageJson = JSON.parse(await readFile(join(root, "package.json"), "utf8"));
|
|
34
|
+
return packageJson.version;
|
|
35
|
+
}
|
|
36
|
+
function printHelp() {
|
|
37
|
+
console.log(`Code Archaeology CLI
|
|
38
|
+
|
|
39
|
+
Usage:
|
|
40
|
+
opencode-code-archaeology help
|
|
41
|
+
opencode-code-archaeology install
|
|
42
|
+
opencode-code-archaeology doctor
|
|
43
|
+
opencode-code-archaeology version
|
|
44
|
+
|
|
45
|
+
Commands:
|
|
46
|
+
install Add Code Archaeology to opencode.json plugin array
|
|
47
|
+
doctor Verify core package files are present
|
|
48
|
+
version Print the package version
|
|
49
|
+
help Show this help`);
|
|
50
|
+
}
|
|
51
|
+
async function install() {
|
|
52
|
+
const target = configPath();
|
|
53
|
+
let config = {};
|
|
54
|
+
const exists = existsSync(target);
|
|
55
|
+
if (exists) {
|
|
56
|
+
config = JSON.parse(await readFile(target, "utf8"));
|
|
57
|
+
}
|
|
58
|
+
const plugins = Array.isArray(config.plugin) ? config.plugin : [];
|
|
59
|
+
if (!plugins.includes(PLUGIN)) {
|
|
60
|
+
config.plugin = [...plugins, PLUGIN];
|
|
61
|
+
}
|
|
62
|
+
await mkdir(dirname(target), { recursive: true });
|
|
63
|
+
let backup;
|
|
64
|
+
if (exists) {
|
|
65
|
+
backup = backupPath(target);
|
|
66
|
+
await copyFile(target, backup);
|
|
67
|
+
}
|
|
68
|
+
await writeFile(target, `${JSON.stringify(config, null, 2)}\n`);
|
|
69
|
+
console.log(`Updated ${target}`);
|
|
70
|
+
if (backup) {
|
|
71
|
+
console.log(`Backup written to ${backup}`);
|
|
72
|
+
}
|
|
73
|
+
console.log("Next steps:");
|
|
74
|
+
console.log("1. Restart OpenCode.");
|
|
75
|
+
console.log("2. Run /code-archaeology-survey in your target repository.");
|
|
76
|
+
}
|
|
77
|
+
function doctor() {
|
|
78
|
+
const missing = REQUIRED_FILES.filter((file) => !existsSync(join(root, file)));
|
|
79
|
+
if (missing.length > 0) {
|
|
80
|
+
console.error("Missing Code Archaeology package files:");
|
|
81
|
+
for (const file of missing) {
|
|
82
|
+
console.error(`- ${file}`);
|
|
83
|
+
}
|
|
84
|
+
process.exitCode = 1;
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
console.log("Code Archaeology package files present:");
|
|
88
|
+
for (const file of REQUIRED_FILES) {
|
|
89
|
+
console.log(`- ${file}`);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
const command = process.argv[2] || "help";
|
|
93
|
+
try {
|
|
94
|
+
if (command === "version") {
|
|
95
|
+
console.log(await readPackageVersion());
|
|
96
|
+
}
|
|
97
|
+
else if (command === "doctor") {
|
|
98
|
+
doctor();
|
|
99
|
+
}
|
|
100
|
+
else if (command === "install") {
|
|
101
|
+
await install();
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
printHelp();
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
catch (error) {
|
|
108
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
109
|
+
process.exitCode = 1;
|
|
110
|
+
}
|
|
111
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACxE,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,OAAO,MAAM,cAAc,CAAC;AAEnC,MAAM,MAAM,GAAG,+EAA+E,CAAC;AAC/F,MAAM,cAAc,GAAG;IACrB,8BAA8B;IAC9B,kCAAkC;IAClC,wBAAwB;IACxB,gCAAgC;IAChC,WAAW;IACX,WAAW;IACX,YAAY;CACb,CAAC;AAEF,MAAM,OAAO,GAAG,aAA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ACL,EAAE,EACF,QAAQ,EACR,OAAO,EACP,MAAM,GACP,MAAM,YAAY,CAAC;AAEpB,mBAAmB,YAAY,CAAC"}
|
package/dist/plugin.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,EAAE,EACF,QAAQ,EACR,OAAO,EACP,MAAM,GACP,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# Code Archaeology Architecture
|
|
2
|
+
|
|
3
|
+
Code Archaeology is an OpenCode plugin that operates entirely inside the target repository. It coordinates slash commands, a domain skill, shell hooks, prompts, schemas, and local `.archaeology/` artifacts to run a fixed excavation workflow.
|
|
4
|
+
|
|
5
|
+
## Repository Layout
|
|
6
|
+
|
|
7
|
+
```text
|
|
8
|
+
Code-Archaeology/
|
|
9
|
+
|-- assets/ # README and repository visual assets
|
|
10
|
+
|-- commands/ # OpenCode slash command definitions
|
|
11
|
+
|-- dist/ # Built package output for GitHub-based installs
|
|
12
|
+
|-- docs/ # Public documentation and release notes
|
|
13
|
+
|-- hooks/opencode/ # Init, verification, revert, and status hooks
|
|
14
|
+
|-- plugins/ # OpenCode plugin entry point
|
|
15
|
+
|-- prompts/ # Expedition prompts by phase
|
|
16
|
+
|-- schema/ # JSON schemas for reports
|
|
17
|
+
|-- skills/ # Code Archaeology skill definition
|
|
18
|
+
|-- src/ # TypeScript package and CLI source
|
|
19
|
+
|-- wiki/ # Source pages for GitHub Wiki publication
|
|
20
|
+
|-- INSTALL.md # Root install handoff
|
|
21
|
+
|-- README.md # Public project overview
|
|
22
|
+
`-- AGENTS.md # Agent runtime guide
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## OpenCode Plugin Surfaces
|
|
26
|
+
|
|
27
|
+
- `plugins/` exposes the plugin entry point consumed by OpenCode.
|
|
28
|
+
- `commands/` defines the slash command family: `/code-archaeology`, `/code-archaeology-survey`, `/code-archaeology-excavate`, and `/code-archaeology-restore`.
|
|
29
|
+
- `skills/` contains the domain workflow instructions agents follow during an expedition.
|
|
30
|
+
- `hooks/opencode/` provides shell gates for session setup, verification, rollback, and status updates.
|
|
31
|
+
- `prompts/` and `schema/` provide phase-specific guidance and artifact structure.
|
|
32
|
+
- `src/` builds the npm package and CLI used by `opencode-code-archaeology install`, `doctor`, and `version`.
|
|
33
|
+
|
|
34
|
+
## Commands, Skills, And Hooks
|
|
35
|
+
|
|
36
|
+
Commands are the user-facing entry points. A command selects the mode and starts the archaeology workflow in the target repository.
|
|
37
|
+
|
|
38
|
+
The Code Archaeology skill defines the expedition order, safety constraints, language-tool preferences, and reporting expectations. It is the agent-facing control layer that prevents phases from running out of order.
|
|
39
|
+
|
|
40
|
+
Hooks are the shell-level enforcement layer:
|
|
41
|
+
|
|
42
|
+
- `init.sh` initializes `.archaeology/` and session state.
|
|
43
|
+
- `verify-phase.sh <phase>` runs configured tests and type checks between phases.
|
|
44
|
+
- `revert-phase.sh <phase>` reverts changes when a restore phase fails verification.
|
|
45
|
+
- `update-expedition.sh <phase> <status> [findings]` updates session progress.
|
|
46
|
+
|
|
47
|
+
## Expedition Flow
|
|
48
|
+
|
|
49
|
+
The phase order is fixed because later cleanup depends on earlier evidence:
|
|
50
|
+
|
|
51
|
+
1. Site Survey & Baseline
|
|
52
|
+
2. Dead Code Excavation
|
|
53
|
+
3. Legacy Stratum Removal
|
|
54
|
+
4. Circular Dependency Cartography
|
|
55
|
+
5. Type Catalog Consolidation
|
|
56
|
+
6. Type Restoration & Hardening
|
|
57
|
+
7. DRY Stratification
|
|
58
|
+
8. Error Handling Stratigraphy
|
|
59
|
+
9. Artifact Cleaning & Documentation
|
|
60
|
+
10. Site Preservation & Final Catalog
|
|
61
|
+
|
|
62
|
+
`survey` mode writes reports only. `excavate` mode writes reports plus mock patches. `restore` mode applies approved changes and must pass verification between phases.
|
|
63
|
+
|
|
64
|
+
## Artifact Lifecycle
|
|
65
|
+
|
|
66
|
+
Runtime artifacts live in `.archaeology/` inside the target repository:
|
|
67
|
+
|
|
68
|
+
| Artifact | Purpose |
|
|
69
|
+
| --- | --- |
|
|
70
|
+
| `session.json` | Current expedition progress and configuration. |
|
|
71
|
+
| `site_survey.md` | Baseline inventory and site report. |
|
|
72
|
+
| `expedition1-report.md` through `expedition8-report.md` | Per-expedition findings. |
|
|
73
|
+
| `FINAL_CATALOG.md` | Final excavation summary and recommendations. |
|
|
74
|
+
| `excavation_log.txt` | `git diff --stat` for applied restoration work. |
|
|
75
|
+
| `patches/` | Mock patches generated by `excavate` mode. |
|
|
76
|
+
|
|
77
|
+
`.archaeology/` is ignored local state and should not be committed.
|
|
78
|
+
|
|
79
|
+
## Safety Gates
|
|
80
|
+
|
|
81
|
+
- Default to `survey` mode for reports only.
|
|
82
|
+
- Write a site report before removing or modifying code.
|
|
83
|
+
- Never consolidate types before dead code and legacy removal.
|
|
84
|
+
- Never remove try/catch blocks from I/O or external input boundaries automatically.
|
|
85
|
+
- Flag uncertain type replacements for human review instead of guessing.
|
|
86
|
+
- Run `verify-phase.sh` between restore phases.
|
|
87
|
+
- Run `revert-phase.sh` and stop if a phase introduces test failures.
|
|
88
|
+
- Keep restore work isolated to the configured branch, `refactor/archaeology` by default.
|
|
89
|
+
|
|
90
|
+
## Local State
|
|
91
|
+
|
|
92
|
+
The plugin keeps operational state in the target repository, not in a remote service. This makes expeditions reviewable and reproducible, but maintainers must keep `.archaeology/` out of commits and inspect generated reports before applying restore changes.
|