opencode-code-archaeology 2.0.0 → 2.2.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.
Files changed (76) hide show
  1. package/.github/ISSUE_TEMPLATE/bug_report.yml +63 -0
  2. package/.github/ISSUE_TEMPLATE/feature_request.yml +48 -0
  3. package/.github/pull_request_template.md +27 -0
  4. package/.github/workflows/ci.yml +45 -0
  5. package/.github/workflows/release.yml +46 -0
  6. package/AGENTS.md +42 -10
  7. package/CHANGELOG.md +79 -0
  8. package/CONTRIBUTING.md +50 -0
  9. package/INSTALL.md +211 -0
  10. package/README.md +255 -71
  11. package/SECURITY.md +20 -0
  12. package/VERSION +1 -1
  13. package/assets/code-archaeology-banner.svg +195 -0
  14. package/commands/code-archaeology.md +7 -5
  15. package/dist/cli.d.ts +3 -0
  16. package/dist/cli.d.ts.map +1 -0
  17. package/dist/cli.js +137 -0
  18. package/dist/cli.js.map +1 -0
  19. package/dist/index.d.ts +1 -5
  20. package/dist/index.d.ts.map +1 -1
  21. package/dist/index.js +1 -17
  22. package/dist/index.js.map +1 -1
  23. package/dist/platform.d.ts +4 -0
  24. package/dist/platform.d.ts.map +1 -0
  25. package/dist/platform.js +11 -0
  26. package/dist/platform.js.map +1 -0
  27. package/dist/plugin.d.ts +3 -0
  28. package/dist/plugin.d.ts.map +1 -0
  29. package/dist/plugin.js +3 -0
  30. package/dist/plugin.js.map +1 -0
  31. package/dist/runtime.d.ts +18 -0
  32. package/dist/runtime.d.ts.map +1 -0
  33. package/dist/runtime.js +49 -0
  34. package/dist/runtime.js.map +1 -0
  35. package/dist/types.d.ts +1 -6
  36. package/dist/types.d.ts.map +1 -1
  37. package/dist/types.js.map +1 -1
  38. package/docs/ARCHITECTURE.md +123 -0
  39. package/docs/INSTALL.md +156 -0
  40. package/docs/README.md +72 -0
  41. package/docs/RELEASE.md +139 -0
  42. package/docs/SECURITY_AUDIT.md +38 -0
  43. package/docs/index.html +740 -0
  44. package/hooks/hermes/runner.ps1 +247 -0
  45. package/hooks/hermes/runner.sh +262 -0
  46. package/hooks/hermes/setup.ps1 +41 -0
  47. package/hooks/hermes/setup.sh +41 -0
  48. package/hooks/opencode/init.ps1 +83 -0
  49. package/hooks/opencode/revert-phase.ps1 +12 -0
  50. package/hooks/opencode/revert-phase.sh +3 -8
  51. package/hooks/opencode/update-expedition.ps1 +51 -0
  52. package/hooks/opencode/verify-package.sh +47 -0
  53. package/hooks/opencode/verify-phase.ps1 +35 -0
  54. package/hooks/opencode/verify-phase.sh +7 -7
  55. package/hooks/shared/command-utils.ps1 +100 -0
  56. package/package.json +41 -6
  57. package/prompts/dead_code.md +45 -0
  58. package/prompts/dependencies.md +49 -0
  59. package/prompts/discovery.md +47 -0
  60. package/prompts/dry.md +49 -0
  61. package/prompts/errors.md +52 -0
  62. package/prompts/final_verify.md +58 -0
  63. package/prompts/legacy.md +49 -0
  64. package/prompts/polish.md +48 -0
  65. package/prompts/types_consolidate.md +48 -0
  66. package/prompts/types_harden.md +51 -0
  67. package/skills/code-archaeology/SKILL.md +2 -2
  68. package/skills/hermes/INTEGRATION.md +120 -0
  69. package/skills/hermes/README.md +167 -0
  70. package/skills/hermes/code-archaeology-prompt.md +203 -0
  71. package/wiki/Expedition-Workflow.md +34 -0
  72. package/wiki/Home.md +27 -0
  73. package/wiki/Installation.md +44 -0
  74. package/wiki/Release-Process.md +31 -0
  75. package/wiki/Security-and-Safety.md +21 -0
  76. package/plugins/code-archaeology.ts +0 -8
@@ -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
@@ -76,8 +76,8 @@ With `strict_mode: true`, restore also applies MEDIUM confidence findings.
76
76
  | `language` | `typescript` | Primary language |
77
77
  | `mode` | `survey` | `survey`, `excavate`, or `restore` |
78
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 |
79
+ | `test_command` | `npm test` | Recorded session default only; verification uses `CODE_ARCHAEOLOGY_TEST_COMMAND` for operator-approved overrides |
80
+ | `typecheck_command` | `npx tsc --noEmit` | Recorded session default only; verification uses `CODE_ARCHAEOLOGY_TYPECHECK_COMMAND` for operator-approved overrides |
81
81
  | `branch_name` | `refactor/archaeology` | Git branch to create |
82
82
 
83
83
  ## Language-Specific Tooling
@@ -0,0 +1,120 @@
1
+ # Code Archaeology Hermes Integration
2
+
3
+ ## Overview
4
+
5
+ Code Archaeology can run on Hermes Agent using cron-based phase execution. Each cron run executes exactly ONE expedition phase with test gates between phases.
6
+
7
+ ## Architecture
8
+
9
+ ```
10
+ Hermes Cron (every 15m)
11
+ → Read .archaeology/session.json
12
+ → Detect current phase (1 of 10)
13
+ → Execute ONE phase:
14
+ survey → excavate → restore (per phase)
15
+ → Run test/typecheck verification
16
+ → Keep or revert changes
17
+ → Advance to next phase
18
+ → STOP (next cron continues)
19
+ ```
20
+
21
+ ## Key Differences from OpenCode
22
+
23
+ | Feature | OpenCode | Hermes |
24
+ |---------|----------|--------|
25
+ | Entry | `/code-archaeology` slash command | `cronjob` |
26
+ | Phases | All in one session | One per cron run |
27
+ | Verification | Between expeditions | Between every phase |
28
+ | Revert | Manual or automatic | Automatic on failure |
29
+ | State | `.archaeology/session.json` | Same file |
30
+ | Background | Plugin stays active | Cron resumes automatically |
31
+
32
+ ## Setup
33
+
34
+ ```bash
35
+ # 1. Install Code Archaeology CLI
36
+ npm install -g opencode-code-archaeology
37
+
38
+ # 2. Setup Hermes runtime
39
+ cd ~/projects/Code-Archaeology
40
+ bash hooks/hermes/setup.sh
41
+
42
+ # 3. Create Hermes cronjob
43
+ hermes cronjob create \
44
+ --name "code-archaeology-expedition" \
45
+ --schedule "every 15m" \
46
+ --workdir ~/projects/Code-Archaeology \
47
+ --prompt "Run one Code Archaeology expedition phase. Read .archaeology/session.json, execute current phase with verification, advance to next phase."
48
+ ```
49
+
50
+ ## Hermes Prompt Template
51
+
52
+ See `skills/hermes/code-archaeology-prompt.md` for the full cron prompt.
53
+
54
+ ## Commands Mapping
55
+
56
+ | OpenCode | Hermes |
57
+ |----------|--------|
58
+ | `/code-archaeology` | `cronjob` runs expedition loop |
59
+ | `/code-archaeology-survey` | `mode = "survey"` in session.json |
60
+ | `/code-archaeology-excavate` | `mode = "excavate"` in session.json |
61
+ | `/code-archaeology-restore` | `mode = "restore"` in session.json |
62
+
63
+ ## Session File Format
64
+
65
+ Hermes uses the same `.archaeology/session.json` format as OpenCode:
66
+
67
+ ```json
68
+ {
69
+ "runtime": "hermes",
70
+ "status": "running",
71
+ "current_phase": "dead-code",
72
+ "completed_phases": ["site-survey"],
73
+ "mode": "survey",
74
+ "repo_path": ".",
75
+ "language": "typescript",
76
+ "test_command": "npm test",
77
+ "typecheck_command": "npx tsc --noEmit",
78
+ "branch_name": "refactor/archaeology",
79
+ "strict_mode": false,
80
+ "started_at": "2026-05-03T14:00:00Z"
81
+ }
82
+ ```
83
+
84
+ ## 10-Phase Expedition Order
85
+
86
+ | # | Phase | Hermes Action |
87
+ |---|-------|---------------|
88
+ | 1 | Site Survey & Baseline | Generate inventory report |
89
+ | 2 | Dead Code Excavation | Catalog unused code |
90
+ | 3 | Legacy Stratum Removal | Identify deprecated shims |
91
+ | 4 | Circular Dependency Cartography | Map dependency cycles |
92
+ | 5 | Type Catalog Consolidation | Find duplicate types |
93
+ | 6 | Type Restoration & Hardening | Flag weak types |
94
+ | 7 | DRY Stratification | Find semantic duplication |
95
+ | 8 | Error Handling Stratigraphy | Review error patterns |
96
+ | 9 | Artifact Cleaning & Documentation | Clean stale artifacts |
97
+ | 10 | Site Preservation & Final Catalog | Generate FINAL_CATALOG.md |
98
+
99
+ ## Safety Model
100
+
101
+ Same as OpenCode:
102
+ - `survey` is default — reports only, zero edits
103
+ - `restore` modifies code only after review
104
+ - Tests and type checks gate each phase
105
+ - Failed restores are automatically reverted
106
+ - Never remove try/catch from I/O boundaries
107
+
108
+ ## Limitations
109
+
110
+ - One phase per cron run (10 phases = ~2.5 hours minimum)
111
+ - No real-time slash command variants
112
+ - Phase order is fixed; cannot skip ahead
113
+ - Memory is session-based; use `memory` tool for persistence
114
+
115
+ ## Future Enhancements
116
+
117
+ - [ ] Auto-detect optimal phase interval based on repo size
118
+ - [ ] Parallel subagent analysis within a phase (Scout + Analyst)
119
+ - [ ] Cross-session memory for language-specific patterns
120
+ - [ ] Integration with Hermes checkpoint/rollback for safe resets
@@ -0,0 +1,167 @@
1
+ # Code Archaeology Hermes Skill
2
+
3
+ ## Installation
4
+
5
+ ```bash
6
+ # Clone Code Archaeology
7
+ git clone https://github.com/Maleick/Code-Archaeology.git
8
+ cd Code-Archaeology
9
+
10
+ # Install dependencies
11
+ npm install
12
+
13
+ # Verify
14
+ npm run typecheck
15
+ bash hooks/verify-package.sh
16
+ ```
17
+
18
+ ## Hermes Setup
19
+
20
+ ### 1. Setup Hermes Runtime
21
+
22
+ ```bash
23
+ cd ~/projects/Code-Archaeology
24
+ bash hooks/hermes/setup.sh
25
+ ```
26
+
27
+ ### 2. Create Session Config
28
+
29
+ ```bash
30
+ # Create session config
31
+ cat > .archaeology/session.json <<'EOF'
32
+ {
33
+ "runtime": "hermes",
34
+ "status": "running",
35
+ "current_phase": "site-survey",
36
+ "completed_phases": [],
37
+ "mode": "survey",
38
+ "repo_path": ".",
39
+ "language": "typescript",
40
+ "test_command": "npm test",
41
+ "typecheck_command": "npx tsc --noEmit",
42
+ "branch_name": "refactor/archaeology",
43
+ "strict_mode": false,
44
+ "started_at": "2026-05-03T14:00:00Z"
45
+ }
46
+ EOF
47
+ ```
48
+
49
+ ### 3. Create Cronjob
50
+
51
+ ```bash
52
+ hermes cronjob create \
53
+ --name "code-archaeology-expedition" \
54
+ --schedule "every 15m" \
55
+ --workdir ~/projects/Code-Archaeology \
56
+ --prompt "Run one Code Archaeology expedition phase. Read .archaeology/session.json, execute current phase with test/typecheck verification, advance to next phase. STOP after one phase."
57
+ ```
58
+
59
+ ## Usage
60
+
61
+ ### Start Expedition
62
+
63
+ ```bash
64
+ # Resume cron (first run auto-initializes)
65
+ hermes cronjob resume code-archaeology-expedition
66
+ ```
67
+
68
+ ### Check Status
69
+
70
+ ```bash
71
+ cat .archaeology/session.json | jq .
72
+ ls .archaeology/expedition*-report.md
73
+ ```
74
+
75
+ ### Change Mode
76
+
77
+ ```bash
78
+ # Switch from survey to excavate
79
+ jq '.mode = "excavate"' .archaeology/session.json > tmp.json && mv tmp.json .archaeology/session.json
80
+
81
+ # Switch from excavate to restore
82
+ jq '.mode = "restore"' .archaeology/session.json > tmp.json && mv tmp.json .archaeology/session.json
83
+ ```
84
+
85
+ ### Stop Expedition
86
+
87
+ ```bash
88
+ # Set stop flag
89
+ jq '.status = "stopped"' .archaeology/session.json > tmp.json && mv tmp.json .archaeology/session.json
90
+
91
+ # Or pause cron
92
+ hermes cronjob pause code-archaeology-expedition
93
+ ```
94
+
95
+ ## Phase Timeline
96
+
97
+ With 15-minute intervals:
98
+ - 10 phases × 15 min = **2.5 hours minimum**
99
+ - Survey mode: ~2.5 hours (reports only)
100
+ - Restore mode: ~2.5 hours + verification time
101
+
102
+ ## Reports Generated
103
+
104
+ | File | Content |
105
+ |------|---------|
106
+ | `.archaeology/site_survey.md` | Baseline inventory |
107
+ | `.archaeology/expedition1-report.md` | Site Survey |
108
+ | `.archaeology/expedition2-report.md` | Dead Code |
109
+ | `.archaeology/expedition3-report.md` | Legacy Removal |
110
+ | `.archaeology/expedition4-report.md` | Dependency Mapping |
111
+ | `.archaeology/expedition5-report.md` | Type Consolidation |
112
+ | `.archaeology/expedition6-report.md` | Type Hardening |
113
+ | `.archaeology/expedition7-report.md` | DRY Stratification |
114
+ | `.archaeology/expedition8-report.md` | Error Handling |
115
+ | `.archaeology/expedition9-report.md` | Artifact Cleaning |
116
+ | `.archaeology/FINAL_CATALOG.md` | Complete summary |
117
+ | `.archaeology/patches/*.patch` | Mock patches (excavate mode) |
118
+
119
+ ## Safety
120
+
121
+ Same as OpenCode:
122
+ - Survey mode: **zero file changes outside `.archaeology/`**
123
+ - Restore mode: **test-gated, auto-revert on failure**
124
+ - Never removes try/catch from I/O boundaries
125
+ - Never guesses types; flags for human review
126
+
127
+ ## Troubleshooting
128
+
129
+ ### Cron not running
130
+
131
+ ```bash
132
+ hermes cronjob list
133
+ hermes cronjob log code-archaeology-expedition
134
+ ```
135
+
136
+ ### Phase blocked
137
+
138
+ ```bash
139
+ # Check blocker
140
+ cat .archaeology/session.json | jq '.flags.blocked_reason'
141
+
142
+ # Reset and retry
143
+ jq '.status = "running" | del(.flags.blocked_reason)' .archaeology/session.json > tmp.json && mv tmp.json .archaeology/session.json
144
+ ```
145
+
146
+ ### Reports empty
147
+
148
+ - Ensure `mode` is set correctly in session.json
149
+ - Check that language tools are installed (`knip`, `madge`, etc.)
150
+ - Run `bash hooks/opencode/init.sh` to reinitialize
151
+
152
+ ## Comparison with OpenCode
153
+
154
+ | Feature | OpenCode | Hermes |
155
+ |---------|----------|--------|
156
+ | Entry | `/code-archaeology` | Cronjob |
157
+ | Phases | All in one session | One per 15-min cron |
158
+ | Real-time | Yes | Delayed |
159
+ | Slash variants | 3 commands | Mode flag in session |
160
+ | Background | Plugin active | Native cron |
161
+ | State | `.archaeology/session.json` | Same |
162
+
163
+ ## Links
164
+
165
+ - Code Archaeology repo: https://github.com/Maleick/Code-Archaeology
166
+ - Hermes docs: https://hermes-agent.nousresearch.com/docs
167
+ - OpenCode plugin: `opencode-code-archaeology`
@@ -0,0 +1,203 @@
1
+ ---
2
+ name: code-archaeology-hermes
3
+ description: Code Archaeology expedition runner for Hermes Agent — systematic codebase excavation with test-gated phases.
4
+ trigger: When running Code Archaeology on Hermes Agent via cronjob.
5
+ ---
6
+
7
+ # Code Archaeology Hermes Skill
8
+
9
+ ## One Phase Per Cron Run
10
+
11
+ Each cron run executes exactly ONE expedition phase. Do not combine phases.
12
+
13
+ ## Phase Detection (run FIRST)
14
+
15
+ ```bash
16
+ cd {{workdir}}
17
+ if [ -f .archaeology/session.json ]; then
18
+ phase=$(jq -r '.current_phase' .archaeology/session.json)
19
+ mode=$(jq -r '.mode' .archaeology/session.json)
20
+ status=$(jq -r '.status' .archaeology/session.json)
21
+ else
22
+ phase="site-survey"
23
+ mode="survey"
24
+ status="running"
25
+ fi
26
+ ```
27
+
28
+ **Decision tree:**
29
+ - `status` = "complete" → **STOP** (all phases done)
30
+ - `status` = "blocked" → **STOP** (report blocker)
31
+ - `phase` = "site-survey" → **Phase 1**
32
+ - `phase` = "dead-code" → **Phase 2**
33
+ - `phase` = "legacy-removal" → **Phase 3**
34
+ - `phase` = "dependency-mapping" → **Phase 4**
35
+ - `phase` = "type-consolidation" → **Phase 5**
36
+ - `phase` = "type-hardening" → **Phase 6**
37
+ - `phase` = "dry-stratification" → **Phase 7**
38
+ - `phase` = "error-handling" → **Phase 8**
39
+ - `phase` = "artifact-cleaning" → **Phase 9**
40
+ - `phase` = "final-catalog" → **Phase 10**
41
+
42
+ ## Expedition Phases
43
+
44
+ ### Phase 1: Site Survey & Baseline
45
+
46
+ 1. Create `.archaeology/` directory if missing
47
+ 2. Generate `site_survey.md` — baseline inventory of codebase
48
+ 3. Record: file count, language distribution, test coverage, dependencies
49
+ 4. **No code changes**
50
+
51
+ **STOP after survey.** Next run: Phase 2.
52
+
53
+ ### Phase 2: Dead Code Excavation
54
+
55
+ 1. Catalog dead code, unused exports, unreachable functions
56
+ 2. Generate `expedition2-report.md` with findings
57
+ 3. **Mode = survey**: reports only
58
+ 4. **Mode = restore**: remove dead code (test-gated)
59
+
60
+ **STOP after catalog.** Next run: Phase 3.
61
+
62
+ ### Phase 3: Legacy Stratum Removal
63
+
64
+ 1. Identify legacy fallbacks, deprecated shims, compatibility layers
65
+ 2. Generate `expedition3-report.md`
66
+ 3. **Never remove try/catch from I/O boundaries**
67
+ 4. **Mode = restore**: remove approved legacy code (test-gated)
68
+
69
+ **STOP after identification.** Next run: Phase 4.
70
+
71
+ ### Phase 4: Circular Dependency Cartography
72
+
73
+ 1. Map circular dependencies using language-specific tools
74
+ 2. Generate `expedition4-report.md` with dependency graph
75
+ 3. **No code changes** (mapping only)
76
+
77
+ **STOP after mapping.** Next run: Phase 5.
78
+
79
+ ### Phase 5: Type Catalog Consolidation
80
+
81
+ 1. Find duplicate type definitions
82
+ 2. Generate `expedition5-report.md`
83
+ 3. **Only run AFTER dead code and legacy removal**
84
+ 4. **Mode = restore**: consolidate types (test-gated)
85
+
86
+ **STOP after catalog.** Next run: Phase 6.
87
+
88
+ ### Phase 6: Type Restoration & Hardening
89
+
90
+ 1. Identify weak types without guessing replacements
91
+ 2. Generate `expedition6-report.md`
92
+ 3. Flag uncertain replacements for human review
93
+ 4. **Mode = restore**: harden approved types (test-gated)
94
+
95
+ **STOP after identification.** Next run: Phase 7.
96
+
97
+ ### Phase 7: DRY Stratification
98
+
99
+ 1. Find semantic duplication and error-handling slop
100
+ 2. Generate `expedition7-report.md`
101
+ 3. **Preserve I/O boundaries**
102
+ 4. **Mode = restore**: DRY approved code (test-gated)
103
+
104
+ **STOP after analysis.** Next run: Phase 8.
105
+
106
+ ### Phase 8: Error Handling Stratigraphy
107
+
108
+ 1. Review error-handling patterns
109
+ 2. Generate `expedition8-report.md`
110
+ 3. **Never remove try/catch from I/O or external input boundaries**
111
+ 4. **Mode = restore**: improve approved error handling (test-gated)
112
+
113
+ **STOP after review.** Next run: Phase 9.
114
+
115
+ ### Phase 9: Artifact Cleaning & Documentation
116
+
117
+ 1. Identify stale artifacts and documentation gaps
118
+ 2. Generate `expedition9-report.md`
119
+ 3. Clean approved artifacts (test-gated)
120
+
121
+ **STOP after cleaning.** Next run: Phase 10.
122
+
123
+ ### Phase 10: Site Preservation & Final Catalog
124
+
125
+ 1. Generate `FINAL_CATALOG.md` — complete excavation summary
126
+ 2. Run final verification (all tests + typecheck)
127
+ 3. Update session.json: `status = "complete"`
128
+
129
+ **STOP. Expedition complete.**
130
+
131
+ ## Verification (between phases)
132
+
133
+ ```bash
134
+ # Pre-phase: ensure clean state
135
+ {{test_command}}
136
+ {{typecheck_command}}
137
+
138
+ # Post-phase (restore mode only): verify changes
139
+ {{test_command}}
140
+ {{typecheck_command}}
141
+ ```
142
+
143
+ **If verification fails:**
144
+ 1. Revert changes: `git reset --hard HEAD`
145
+ 2. Update session: `status = "blocked"`, `blocked_reason = "..."`
146
+ 3. Report blocker and STOP
147
+
148
+ ## Mode Behavior
149
+
150
+ | Mode | Action | File Changes? |
151
+ |------|--------|---------------|
152
+ | **survey** | Generate reports only | None outside `.archaeology/` |
153
+ | **excavate** | Reports + mock patches | None outside `.archaeology/patches/` |
154
+ | **restore** | Apply approved changes | Yes, test-gated |
155
+
156
+ ## Rules
157
+
158
+ - **One phase per cron run** — never combine
159
+ - **Fixed order** — never skip phases
160
+ - **Survey first** — always generate reports before changes
161
+ - **Test gates** — run tests between every phase
162
+ - **Auto-revert** — revert on any verification failure
163
+ - **Preserve I/O** — never remove try/catch from boundaries
164
+ - **No guessing** — flag uncertain types for human review
165
+ - **Use [SILENT]** for no-op phases
166
+
167
+ ## Context Variables
168
+
169
+ | Variable | Source |
170
+ |----------|--------|
171
+ | `{{workdir}}` | Cronjob `workdir` setting |
172
+ | `{{mode}}` | session.json (survey/excavate/restore) |
173
+ | `{{test_command}}` | session.json |
174
+ | `{{typecheck_command}}` | session.json |
175
+ | `{{branch_name}}` | session.json (default: refactor/archaeology) |
176
+ | `{{language}}` | session.json (default: typescript) |
177
+
178
+ ## Language Tool Mapping
179
+
180
+ | Language | Dead Code | Dependencies | Types | DRY |
181
+ |----------|-----------|--------------|-------|-----|
182
+ | TypeScript | `knip` | `madge` | `tsc` | `jscpd` |
183
+ | JavaScript | `knip` | `madge` | N/A | `jscpd` |
184
+ | Python | `vulture` | `pydeps` | `mypy` | `pylint` |
185
+ | Go | `deadcode` | `godepgraph` | `go vet` | `golangci-lint` |
186
+ | Rust | `cargo-udeps` | `cargo-deps` | `rustc` | `clippy` |
187
+
188
+ ## STOP Conditions
189
+
190
+ - All 10 phases complete
191
+ - Verification fails (blocked)
192
+ - `stop_requested` flag set
193
+ - Human review required (strict mode findings)
194
+
195
+ ## Next Steps After Complete
196
+
197
+ 1. Review `.archaeology/FINAL_CATALOG.md`
198
+ 2. Review all `expedition*-report.md` files
199
+ 3. Apply mock patches from `.archaeology/patches/` if in excavate mode
200
+ 4. Merge `refactor/archaeology` branch if in restore mode
201
+ 5. Archive `.archaeology/` directory
202
+
203
+ **Start by detecting phase from session.json. Execute exactly ONE phase with verification. STOP.**