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.
@@ -0,0 +1,52 @@
1
+ # Expedition 7: Error Handling Stratigraphy
2
+
3
+ ## Objective
4
+ Identify and catalog problematic error handling patterns: suppressed errors, empty catch blocks, overly broad try/catch, and error swallowing.
5
+
6
+ ## Instructions
7
+
8
+ 1. **Pattern Search**
9
+ Search for these anti-patterns:
10
+ - Empty or console-only catch blocks
11
+ - `catch (e) { return null; }` or similar suppression
12
+ - `try/catch` around non-throwing code (defensive overprogramming)
13
+ - Broad exception types when specific ones are available
14
+ - `suppress`, `silence`, `safe`, `onError` in function names (often indicate error hiding)
15
+ - Ignored Promise rejections (`.catch(() => {})`)
16
+
17
+ 2. **Context Analysis**
18
+ For each finding:
19
+ - Determine if the suppression is intentional (expected failure case)
20
+ - Identify what error information is being lost
21
+ - Assess if the error should propagate to a higher handler
22
+ - Check if logging/monitoring is adequate
23
+
24
+ 3. **Boundary Classification**
25
+ - I/O boundary: File system, network, external API calls (legitimate try/catch)
26
+ - Internal boundary: Business logic, pure functions (suspicious suppression)
27
+ - User input boundary: Form validation, CLI arguments (may need specific handling)
28
+
29
+ ## Output
30
+
31
+ Write to `.archaeology/expedition7-report.md`:
32
+ - Inventory of all error handling issues with locations
33
+ - Classification by anti-pattern type
34
+ - Risk assessment (data loss, silent failures, debugging difficulty)
35
+ - Recommended fix for each issue
36
+ - Boundary classification for each finding
37
+
38
+ ## Execution Rules
39
+ - If `mode == survey`: catalog only
40
+ - If `mode == excavate`: generate fix proposals
41
+ - If `mode == restore`:
42
+ - Remove error hiding from internal boundaries
43
+ - Add proper logging or propagation
44
+ - NEVER remove try/catch from I/O or external input boundaries
45
+ - Run tests after each change
46
+
47
+ ## Constraints
48
+ - NEVER remove try/catch from I/O operations (file read, network request, DB query)
49
+ - NEVER remove try/catch from external API boundaries
50
+ - ALWAYS preserve error information—replace suppression with logging or re-throwing
51
+ - NEVER let errors propagate unhandled—replace with explicit error handling
52
+ - ALWAYS consider if the catch block is testing an expected condition (if so, refactor to validation)
@@ -0,0 +1,58 @@
1
+ # Phase 9: Site Preservation & Final Catalog
2
+
3
+ ## Objective
4
+ Verify all previous expeditions produced a healthy codebase. Generate final metrics and preserve the excavation record.
5
+
6
+ ## Instructions
7
+
8
+ 1. **Test Verification**
9
+ - Run `{{ test_command }}` — must exit 0
10
+ - Run `{{ typecheck_command }}` — must exit 0
11
+ - If either fails, STOP and revert to baseline
12
+
13
+ 2. **Regression Checks**
14
+ - Re-run dependency analysis—verify no NEW cycles introduced
15
+ - Re-run dead code analysis—verify no NEW dead code created
16
+ - Check that no types were weakened during previous expeditions
17
+ - Verify no new duplications were introduced
18
+
19
+ 3. **Metrics Collection**
20
+ - Calculate lines changed (added/removed)
21
+ - Calculate test coverage delta (if available)
22
+ - Count type errors resolved
23
+ - Count cycles broken
24
+ - Count dead code removed
25
+
26
+ 4. **Diff Preservation**
27
+ - Run `git diff --stat > .archaeology/excavation_log.txt`
28
+ - Capture the complete change summary
29
+
30
+ ## Output
31
+
32
+ Write to `.archaeology/FINAL_CATALOG.md`:
33
+ - Executive summary of all expeditions
34
+ - Before/after metrics comparison table
35
+ - List of all artifacts removed
36
+ - List of all types consolidated
37
+ - List of all cycles broken
38
+ - Recommendations for future maintenance
39
+ - Human review sign-off checklist (if mode != survey)
40
+
41
+ Write to `.archaeology/excavation_log.txt`:
42
+ - Complete `git diff --stat` output
43
+
44
+ ## Final Checks
45
+ - [ ] All tests passing
46
+ - [ ] Type checker zero errors
47
+ - [ ] No new circular dependencies
48
+ - [ ] No new dead code
49
+ - [ ] Linting passes (if applicable)
50
+ - [ ] Documentation updated
51
+ - [ ] Human review completed (if mode != survey)
52
+
53
+ ## Constraints
54
+ - NEVER claim success if any test fails
55
+ - NEVER ignore new type errors introduced during expeditions
56
+ - ALWAYS revert all changes if this phase fails—do not leave repo in broken state
57
+ - ALWAYS preserve `.archaeology/` directory for historical record
58
+ - NEVER delete `.archaeology/` reports even after successful completion
@@ -0,0 +1,49 @@
1
+ # Expedition 2: Legacy Stratum Removal
2
+
3
+ ## Objective
4
+ Identify and catalog legacy code patterns: deprecated APIs, polyfills, compatibility shims, and fallback code for outdated environments.
5
+
6
+ ## Instructions
7
+
8
+ 1. **Pattern Search**
9
+ Search for these patterns across the codebase:
10
+ - `@deprecated` annotations or JSDoc tags
11
+ - `TODO(legacy)` or similar markers
12
+ - `polyfill`, `shim`, `compat`, `fallback` in filenames or code
13
+ - Feature detection for obsolete browsers/environments
14
+ - Version checks for long-EOL dependencies
15
+
16
+ 2. **Context Analysis**
17
+ For each legacy artifact found:
18
+ - Determine when it was added (git blame if possible)
19
+ - Identify what modern replacement exists
20
+ - Assess if any active code still depends on it
21
+ - Check if tests specifically cover the legacy path
22
+
23
+ 3. **Risk Assessment**
24
+ - HIGH confidence: Marked deprecated, no internal references, modern replacement available
25
+ - MEDIUM confidence: Legacy pattern but may have edge-case consumers
26
+ - LOW confidence: Unclear if removal would break downstream consumers
27
+
28
+ ## Output
29
+
30
+ Write to `.archaeology/expedition2-report.md`:
31
+ - Inventory of all legacy artifacts with location and context
32
+ - Classification by confidence level
33
+ - Recommended replacement for each artifact
34
+ - Migration path for consumers (if applicable)
35
+
36
+ ## Execution Rules
37
+ - If `mode == survey`: catalog only
38
+ - If `mode == excavate`: generate migration guide + mock patches
39
+ - If `mode == restore`:
40
+ - Remove HIGH confidence legacy code
41
+ - Remove MEDIUM confidence only if `strict_mode == true`
42
+ - Update documentation to reflect removals
43
+ - Run tests after each batch
44
+
45
+ ## Constraints
46
+ - NEVER remove polyfills for features still needed by supported environments
47
+ - NEVER remove fallback code for external APIs that are still unstable
48
+ - ALWAYS verify no active imports before removing deprecated exports
49
+ - NEVER break public API without explicit deprecation period documentation
@@ -0,0 +1,48 @@
1
+ # Expedition 8: Artifact Cleaning & Documentation
2
+
3
+ ## Objective
4
+ Final cleanup pass: remove unnecessary comments, fix formatting, update documentation, and remove any remaining slop accumulated during previous expeditions.
5
+
6
+ ## Instructions
7
+
8
+ 1. **Documentation Audit**
9
+ - Remove outdated JSDoc comments (references to removed parameters, old behavior)
10
+ - Update README files to reflect removed features or changed APIs
11
+ - Remove boilerplate comments that state the obvious
12
+ - Ensure all public APIs have accurate documentation
13
+
14
+ 2. **Code Cleanup**
15
+ - Remove debug console.log statements
16
+ - Remove commented-out code blocks (if not already removed in Expedition 1)
17
+ - Fix inconsistent formatting (trailing whitespace, mixed indentation)
18
+ - Remove unused imports (if not caught by Expedition 1)
19
+
20
+ 3. **Slop Detection**
21
+ - Look for defensive programming that is no longer needed
22
+ - Remove type assertions that are now properly typed (from Expedition 5)
23
+ - Clean up temporary variables used during previous expeditions
24
+ - Verify no TODO comments were left unresolved
25
+
26
+ ## Output
27
+
28
+ Write to `.archaeology/expedition8-report.md`:
29
+ - Summary of all cleanup actions taken
30
+ - Documentation updates made
31
+ - Files modified in this expedition
32
+ - Remaining slop flagged for human review (if any)
33
+
34
+ ## Execution Rules
35
+ - If `mode == survey`: catalog only
36
+ - If `mode == excavate`: generate cleanup patch
37
+ - If `mode == restore`:
38
+ - Perform all safe cleanup actions
39
+ - NEVER remove meaningful comments explaining complex logic
40
+ - NEVER change code semantics during cleanup
41
+ - Run tests after cleanup
42
+
43
+ ## Constraints
44
+ - NEVER remove comments explaining WHY (only remove WHAT comments that state the obvious)
45
+ - NEVER change formatting in files that weren't otherwise modified (noise in diff)
46
+ - ALWAYS preserve license headers and legal comments
47
+ - NEVER remove TODO comments that are still valid—move them to issue tracker instead
48
+ - ALWAYS run linter/formatter after cleanup if available
@@ -0,0 +1,48 @@
1
+ # Expedition 4: Type Catalog Consolidation
2
+
3
+ ## Objective
4
+ Consolidate duplicate or redundant type definitions. Remove type definitions for code that was removed in previous expeditions.
5
+
6
+ ## Instructions
7
+
8
+ 1. **Type Discovery**
9
+ - Scan for duplicate interface/type definitions
10
+ - Find types defined in multiple files with same or similar shapes
11
+ - Identify types that shadow or extend each other unnecessarily
12
+ - Catalog type definitions for dead code removed in Expedition 1
13
+
14
+ 2. **Deduplication Analysis**
15
+ For each duplicate cluster:
16
+ - Compare structural similarity (are they actually the same?)
17
+ - Check usage patterns (which variant is more widely used?)
18
+ - Assess if they diverge intentionally (business logic differences)
19
+ - Determine canonical location (shared types directory, domain module, etc.)
20
+
21
+ 3. **Migration Planning**
22
+ - Plan imports to redirect to canonical type
23
+ - Identify if any type refinements are needed during consolidation
24
+ - Flag types that should merge vs. types that should remain separate
25
+
26
+ ## Output
27
+
28
+ Write to `.archaeology/expedition4-report.md`:
29
+ - Catalog of duplicate type clusters
30
+ - Consolidation plan for each cluster
31
+ - File paths affected by migration
32
+ - Types flagged for human review (uncertain merges)
33
+
34
+ ## Execution Rules
35
+ - If `mode == survey`: catalog only
36
+ - If `mode == excavate`: generate type migration maps
37
+ - If `mode == restore`:
38
+ - Consolidate HIGH confidence duplicates
39
+ - Update all imports to point to canonical definitions
40
+ - Remove orphaned type definitions
41
+ - Run type checker after each consolidation batch
42
+
43
+ ## Constraints
44
+ - NEVER merge types that have semantic differences (even if structurally similar)
45
+ - NEVER guess at the correct merged type—flag for review if uncertain
46
+ - ALWAYS run the type checker after changes—zero errors before proceeding
47
+ - ALWAYS preserve JSDoc comments on types during migration
48
+ - NEVER consolidate before dead code removal is complete (prevents cataloging discarded code)
@@ -0,0 +1,51 @@
1
+ # Expedition 5: Type Restoration & Hardening
2
+
3
+ ## Objective
4
+ Replace weak types (`any`, `unknown`, `Object`, `Function`) with precise types. Strengthen interfaces and add missing type constraints.
5
+
6
+ ## Instructions
7
+
8
+ 1. **Weak Type Scan**
9
+ Search for these patterns:
10
+ - Explicit `any` annotations
11
+ - `unknown` used where a specific type is inferable
12
+ - `Object` or `{}` as parameter/return types
13
+ - `Function` type (use specific call signatures instead)
14
+ - Missing return type annotations on exported functions
15
+ - `map[string]interface{}` (Go) or equivalent weak structures
16
+
17
+ 2. **Type Inference**
18
+ For each weak type found:
19
+ - Examine usage patterns to infer the correct type
20
+ - Check test files for type expectations
21
+ - Look at how the value is destructured or accessed
22
+ - Consider if a branded type or discriminated union is appropriate
23
+
24
+ 3. **Confidence Assessment**
25
+ - HIGH: Usage clearly indicates specific type, tests confirm
26
+ - MEDIUM: Type is inferable but has some dynamic access
27
+ - LOW: Too many possible shapes, requires domain knowledge
28
+
29
+ ## Output
30
+
31
+ Write to `.archaeology/expedition5-report.md`:
32
+ - Inventory of all weak types with locations
33
+ - Proposed replacement type for each
34
+ - Confidence level per replacement
35
+ - Files that would be affected by changes
36
+
37
+ ## Execution Rules
38
+ - If `mode == survey`: catalog only
39
+ - If `mode == excavate`: generate type patch proposals
40
+ - If `mode == restore`:
41
+ - Replace HIGH confidence weak types
42
+ - Replace MEDIUM confidence only if `strict_mode == true`
43
+ - NEVER replace LOW confidence types—flag for human review
44
+ - Run type checker after each file—stop on errors
45
+
46
+ ## Constraints
47
+ - NEVER use `any` to "fix" a complex type—use proper typing
48
+ - NEVER remove necessary `unknown` types (e.g., from external APIs)
49
+ - NEVER change runtime behavior when adding types—types only
50
+ - ALWAYS verify type checker passes with zero errors before proceeding
51
+ - NEVER guess types for external library internals—use their type definitions
@@ -0,0 +1,32 @@
1
+ # Expedition Workflow
2
+
3
+ [Home](Home) | [Installation](Installation) | [Security](Security-and-Safety) | [Release](Release-Process)
4
+
5
+ Code Archaeology runs phases in a fixed order so later changes are based on earlier evidence.
6
+
7
+ 1. Site Survey & Baseline
8
+ 2. Dead Code Excavation
9
+ 3. Legacy Stratum Removal
10
+ 4. Circular Dependency Cartography
11
+ 5. Type Catalog Consolidation
12
+ 6. Type Restoration & Hardening
13
+ 7. DRY Stratification
14
+ 8. Error Handling Stratigraphy
15
+ 9. Artifact Cleaning & Documentation
16
+ 10. Site Preservation & Final Catalog
17
+
18
+ ## Modes
19
+
20
+ | Mode | Behavior |
21
+ | --- | --- |
22
+ | `survey` | Reports only; no source edits. |
23
+ | `excavate` | Reports plus mock patches in `.archaeology/patches/`. |
24
+ | `restore` | Applies approved changes with verification gates. |
25
+
26
+ ## Local Artifacts
27
+
28
+ `.archaeology/` contains `session.json`, `site_survey.md`, expedition reports, `FINAL_CATALOG.md`, `excavation_log.txt`, and optional mock patches. It is local runtime state and should not be committed.
29
+
30
+ ## Gates
31
+
32
+ `hooks/opencode/init.sh` initializes the session. `verify-phase.sh` runs tests and type checks between restore phases. `revert-phase.sh` reverts a failed restore phase. `update-expedition.sh` records progress.
package/wiki/Home.md ADDED
@@ -0,0 +1,27 @@
1
+ # Code Archaeology Wiki
2
+
3
+ Code Archaeology is an OpenCode plugin for systematic codebase excavation, cataloging, and restoration. It runs a fixed, report-first workflow and keeps runtime artifacts local in `.archaeology/`.
4
+
5
+ ## Navigation
6
+
7
+ - [Installation](Installation)
8
+ - [Expedition Workflow](Expedition-Workflow)
9
+ - [Security and Safety](Security-and-Safety)
10
+ - [Release Process](Release-Process)
11
+
12
+ ## Quick Start
13
+
14
+ ```bash
15
+ npm install -g opencode-code-archaeology
16
+ opencode-code-archaeology install
17
+ opencode-code-archaeology doctor
18
+ opencode-code-archaeology version
19
+ ```
20
+
21
+ Restart OpenCode inside a Git repository and run:
22
+
23
+ ```text
24
+ /code-archaeology-survey
25
+ ```
26
+
27
+ Start with `survey`, review reports, then choose `excavate` for mock patches or `restore` for approved, test-gated changes.
@@ -0,0 +1,42 @@
1
+ # Installation
2
+
3
+ [Home](Home) | [Workflow](Expedition-Workflow) | [Security](Security-and-Safety) | [Release](Release-Process)
4
+
5
+ ## OpenCode Plugin Install
6
+
7
+ Add the package to the top-level `plugin` array in `opencode.json`:
8
+
9
+ ```json
10
+ {
11
+ "plugin": [
12
+ "opencode-code-archaeology@git+https://github.com/Maleick/Code-Archaeology.git"
13
+ ]
14
+ }
15
+ ```
16
+
17
+ Restart OpenCode. Commands should be available inside a Git repository:
18
+
19
+ ```text
20
+ /code-archaeology
21
+ /code-archaeology-survey
22
+ /code-archaeology-excavate
23
+ /code-archaeology-restore
24
+ ```
25
+
26
+ ## npm CLI Path
27
+
28
+ ```bash
29
+ npm install -g opencode-code-archaeology
30
+ opencode-code-archaeology install
31
+ opencode-code-archaeology doctor
32
+ opencode-code-archaeology version
33
+ ```
34
+
35
+ For updates:
36
+
37
+ ```bash
38
+ npm install -g opencode-code-archaeology@latest
39
+ npm list -g opencode-code-archaeology --depth=0
40
+ ```
41
+
42
+ If commands do not appear, restart OpenCode, verify `opencode.json` uses `plugin` singular, and clear any stale OpenCode plugin cache.
@@ -0,0 +1,31 @@
1
+ # Release Process
2
+
3
+ [Home](Home) | [Installation](Installation) | [Workflow](Expedition-Workflow) | [Security](Security-and-Safety)
4
+
5
+ Use this checklist for future `opencode-code-archaeology` releases. `v2.0.2` is the current example version; replace it with the target version.
6
+
7
+ ## Checklist
8
+
9
+ 1. Review the worktree for unrelated changes and local state.
10
+ 2. Bump package files with `npm version 2.0.2 --no-git-tag-version`.
11
+ 3. Update `VERSION` to `2.0.2`.
12
+ 4. Update `CHANGELOG.md` with release notes.
13
+ 5. Run verification:
14
+
15
+ ```bash
16
+ npm install
17
+ npm run build
18
+ npm run typecheck
19
+ npm audit --audit-level=moderate
20
+ npm outdated --json
21
+ bash -n hooks/opencode/*.sh
22
+ npm pack --json --dry-run
23
+ ```
24
+
25
+ 6. Confirm the package dry run includes `dist`, `assets`, `hooks`, `commands`, `skills`, `plugins`, `schema`, `prompts`, `docs`, `wiki`, `README.md`, `INSTALL.md`, `CHANGELOG.md`, `SECURITY.md`, `CONTRIBUTING.md`, `VERSION`, `AGENTS.md`, and `LICENSE`.
26
+ 7. Commit release files, tag `v2.0.2`, push the branch, and push the tag.
27
+ 8. Create the GitHub release from the tag.
28
+ 9. Publish npm with `npm publish --access public`.
29
+ 10. Confirm `npm view opencode-code-archaeology version` and `gh release view v2.0.2` show the expected release.
30
+
31
+ Do not claim GitHub Pages is enabled unless repository settings confirm it.
@@ -0,0 +1,21 @@
1
+ # Security And Safety
2
+
3
+ [Home](Home) | [Installation](Installation) | [Workflow](Expedition-Workflow) | [Release](Release-Process)
4
+
5
+ ## Current Audit Notes
6
+
7
+ - `npm audit --audit-level=moderate` is expected to be clean.
8
+ - `npm outdated --json` is expected to be clean.
9
+ - No hardcoded secrets are expected in source, docs, hooks, commands, prompts, schemas, or metadata.
10
+ - `.archaeology/` and `.superpowers/` are ignored local state.
11
+ - Shell hooks can be syntax checked with `bash -n hooks/opencode/*.sh`.
12
+
13
+ ## Restore Caveat
14
+
15
+ `restore` mode can edit source files. Run it only after reviewing `survey` reports, preferably after reviewing `excavate` mock patches, and only when tests or type checks are available.
16
+
17
+ Failed restore phases should be reverted before continuing. The workflow must not remove try/catch blocks around I/O or external input boundaries automatically, and uncertain type replacements should be flagged for review.
18
+
19
+ ## Before Publishing
20
+
21
+ Run build, typecheck, npm audit, npm outdated, shell syntax checks, and `npm pack --json --dry-run`. Inspect the package contents for accidental local state or secrets before publishing.