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,117 @@
1
+ # Install Code Archaeology
2
+
3
+ This guide mirrors the root [`INSTALL.md`](../INSTALL.md) and covers the recommended OpenCode plugin configuration plus the npm CLI install path.
4
+
5
+ ## Prerequisites
6
+
7
+ - OpenCode installed and available in your shell.
8
+ - Node.js 18 or newer with npm.
9
+ - Git installed and available in your shell.
10
+ - A target repository with tests or type checks before running `restore` mode.
11
+
12
+ ## Recommended OpenCode Plugin Install
13
+
14
+ Add Code Archaeology to the top-level `plugin` array in `opencode.json`:
15
+
16
+ ```json
17
+ {
18
+ "plugin": [
19
+ "opencode-code-archaeology@git+https://github.com/Maleick/Code-Archaeology.git"
20
+ ]
21
+ }
22
+ ```
23
+
24
+ Restart OpenCode after editing the configuration. The command family should then be available inside a Git repository:
25
+
26
+ ```text
27
+ /code-archaeology
28
+ /code-archaeology-survey
29
+ /code-archaeology-excavate
30
+ /code-archaeology-restore
31
+ ```
32
+
33
+ ## npm Global Install
34
+
35
+ Use the npm package when you want the CLI installer and diagnostics:
36
+
37
+ ```bash
38
+ npm install -g opencode-code-archaeology
39
+ opencode-code-archaeology install
40
+ opencode-code-archaeology doctor
41
+ opencode-code-archaeology version
42
+ ```
43
+
44
+ Then restart OpenCode and run:
45
+
46
+ ```text
47
+ /code-archaeology-survey
48
+ ```
49
+
50
+ ## Verification
51
+
52
+ Confirm the published package and local CLI are visible:
53
+
54
+ ```bash
55
+ npm view opencode-code-archaeology version
56
+ npm view opencode-code-archaeology dist-tags
57
+ opencode-code-archaeology doctor
58
+ opencode-code-archaeology version
59
+ ```
60
+
61
+ For a local clone, run focused package checks:
62
+
63
+ ```bash
64
+ npm install
65
+ npm run build
66
+ npm run typecheck
67
+ bash -n hooks/opencode/*.sh
68
+ ```
69
+
70
+ To verify plugin behavior, restart OpenCode in a Git repository and run:
71
+
72
+ ```text
73
+ /code-archaeology-survey
74
+ ```
75
+
76
+ The survey should create `.archaeology/` reports without modifying source files.
77
+
78
+ ## Updating
79
+
80
+ For plugin-array installs, update through your OpenCode package manager flow, then restart OpenCode. If your setup caches Git plugins, clear the cached `opencode-code-archaeology` package and let OpenCode reinstall it.
81
+
82
+ For npm global installs:
83
+
84
+ ```bash
85
+ npm install -g opencode-code-archaeology@latest
86
+ npm list -g opencode-code-archaeology --depth=0
87
+ opencode-code-archaeology doctor
88
+ ```
89
+
90
+ ## Troubleshooting
91
+
92
+ ### Plugin Not Loading
93
+
94
+ - Confirm `opencode.json` is valid JSON.
95
+ - Confirm the package entry is in the top-level `plugin` array, not `plugins`.
96
+ - Restart OpenCode after changing configuration.
97
+ - Confirm Git can reach `https://github.com/Maleick/Code-Archaeology.git`.
98
+
99
+ ### Commands Not Found
100
+
101
+ - Restart OpenCode so it reloads plugin commands.
102
+ - Confirm the npm package installed with `npm list -g opencode-code-archaeology --depth=0` if using the global path.
103
+ - Run `/code-archaeology-survey` from inside a Git repository.
104
+
105
+ ### Stale Cache
106
+
107
+ - Remove the cached OpenCode package for `opencode-code-archaeology` if your runtime keeps one.
108
+ - Reinstall or rerun OpenCode plugin resolution.
109
+ - Restart OpenCode before testing again.
110
+
111
+ ### Restore Safety
112
+
113
+ - Start with `/code-archaeology-survey`; it writes reports only.
114
+ - Review `.archaeology/site_survey.md` and expedition reports before restore.
115
+ - Use `/code-archaeology-excavate` for mock patches if you want another review gate.
116
+ - Run `/code-archaeology-restore` only when the target repository has tests or type checks available.
117
+ - Do not commit `.archaeology/`; it is local runtime state.
package/docs/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # Code Archaeology Documentation
2
+
3
+ Code Archaeology is an OpenCode plugin for systematic codebase excavation, cataloging, and restoration. It runs inside the target repository, writes local `.archaeology/` reports, and only modifies source files in `restore` mode after review and verification.
4
+
5
+ These Markdown files are ready to serve from GitHub Pages, but this repository does not assume Pages is already enabled.
6
+
7
+ ## Quick Links
8
+
9
+ - [Install Guide](INSTALL.md)
10
+ - [Architecture](ARCHITECTURE.md)
11
+ - [Release Process](RELEASE.md)
12
+ - [Security Audit](SECURITY_AUDIT.md)
13
+ - [Repository README](../README.md)
14
+ - [Root Install Handoff](../INSTALL.md)
15
+
16
+ ## Quick Start
17
+
18
+ Install the package globally, register the plugin, then verify the CLI:
19
+
20
+ ```bash
21
+ npm install -g opencode-code-archaeology
22
+ opencode-code-archaeology install
23
+ opencode-code-archaeology doctor
24
+ opencode-code-archaeology version
25
+ ```
26
+
27
+ Restart OpenCode in the repository you want to inspect and start with the non-destructive survey command:
28
+
29
+ ```text
30
+ /code-archaeology-survey
31
+ ```
32
+
33
+ Review `.archaeology/site_survey.md` and expedition reports before using:
34
+
35
+ ```text
36
+ /code-archaeology-excavate
37
+ /code-archaeology-restore
38
+ ```
39
+
40
+ ## Safety Warning
41
+
42
+ `survey` mode writes reports only. `excavate` mode writes reports and mock patches. `restore` mode can edit source files and should only run after report review, on an isolated branch, with tests or type checks available.
43
+
44
+ Do not commit `.archaeology/`; it is local runtime state.
@@ -0,0 +1,135 @@
1
+ # Release Process
2
+
3
+ This checklist is for future `opencode-code-archaeology` releases. `v2.0.2` is the current release example; replace it with the next version when preparing a new release.
4
+
5
+ ## 1. Preflight
6
+
7
+ - Work from the release readiness branch or a dedicated release worktree.
8
+ - Confirm the worktree has no unrelated changes you intend to publish accidentally.
9
+ - Confirm no secrets or local runtime state are staged.
10
+ - Review `README.md`, `INSTALL.md`, `docs/`, `wiki/`, `CHANGELOG.md`, and package metadata for version-specific claims.
11
+ - Confirm `.archaeology/`, `.superpowers/`, `node_modules/`, and logs are ignored.
12
+
13
+ ## 2. Version Bump
14
+
15
+ For a future release, replace `2.0.2` with the target version:
16
+
17
+ ```bash
18
+ npm version 2.0.2 --no-git-tag-version
19
+ ```
20
+
21
+ Update `VERSION` to the same value:
22
+
23
+ ```text
24
+ 2.0.2
25
+ ```
26
+
27
+ Confirm `package.json`, `package-lock.json`, and `VERSION` agree.
28
+
29
+ ## 3. Changelog
30
+
31
+ - Add a `v2.0.2` entry, or the future target version, to `CHANGELOG.md`.
32
+ - Include user-visible changes, safety notes, and any migration instructions.
33
+ - Keep the release notes factual and avoid claiming publication steps that have not happened yet.
34
+
35
+ ## 4. Verification
36
+
37
+ Run focused release checks before committing:
38
+
39
+ ```bash
40
+ npm install
41
+ npm run build
42
+ npm run typecheck
43
+ npm audit --audit-level=moderate
44
+ npm outdated --json
45
+ bash -n hooks/opencode/*.sh
46
+ npm pack --json --dry-run
47
+ ```
48
+
49
+ Expected outcomes:
50
+
51
+ - Build and typecheck pass.
52
+ - npm audit reports no moderate-or-higher vulnerabilities.
53
+ - npm outdated reports `{}` or no actionable outdated dependencies.
54
+ - Shell hooks pass syntax checks.
55
+ - The package dry run includes required files.
56
+
57
+ ## 5. npm Pack Required Files
58
+
59
+ Inspect `npm pack --json --dry-run` output for the package contents. Required files should include:
60
+
61
+ - `dist/`
62
+ - `assets/`
63
+ - `hooks/`
64
+ - `commands/`
65
+ - `skills/`
66
+ - `plugins/`
67
+ - `schema/`
68
+ - `prompts/`
69
+ - `docs/`
70
+ - `wiki/`
71
+ - `AGENTS.md`
72
+ - `VERSION`
73
+ - `INSTALL.md`
74
+ - `README.md`
75
+ - `CHANGELOG.md`
76
+ - `CONTRIBUTING.md`
77
+ - `SECURITY.md`
78
+ - `LICENSE`
79
+
80
+ If any required file is missing, update the `files` array in `package.json`, rerun `npm install` if the lockfile needs to change, and repeat the package dry run.
81
+
82
+ ## 6. Commit, Tag, And Push
83
+
84
+ Only perform these steps after verification passes and after confirming the branch is safe to publish:
85
+
86
+ ```bash
87
+ git status --short
88
+ git add README.md INSTALL.md docs wiki assets .github SECURITY.md CONTRIBUTING.md CHANGELOG.md package.json package-lock.json VERSION .gitignore
89
+ git commit -m "chore: prepare v2.0.2 release"
90
+ git tag v2.0.2
91
+ git push origin HEAD
92
+ git push origin v2.0.2
93
+ ```
94
+
95
+ For a future release, use the future version in the commit message and tag.
96
+
97
+ ## 7. GitHub Release
98
+
99
+ Create the GitHub release from the matching tag:
100
+
101
+ ```bash
102
+ gh release create v2.0.2 --title "v2.0.2" --notes-file CHANGELOG.md
103
+ ```
104
+
105
+ Before publishing, trim the notes to the specific version section if `CHANGELOG.md` contains multiple releases.
106
+
107
+ ## 8. npm Publish
108
+
109
+ Publish only after the GitHub tag and release are correct:
110
+
111
+ ```bash
112
+ npm publish --access public
113
+ ```
114
+
115
+ If publishing fails, do not create a replacement tag unless the failure requires a new package version. Fix the issue, rerun verification, and follow npm versioning rules.
116
+
117
+ ## 9. Final Checks
118
+
119
+ Confirm the public release surfaces report the expected version:
120
+
121
+ ```bash
122
+ npm view opencode-code-archaeology version
123
+ npm view opencode-code-archaeology dist-tags
124
+ gh release view v2.0.2
125
+ ```
126
+
127
+ Optionally verify a fresh install path:
128
+
129
+ ```bash
130
+ npm install -g opencode-code-archaeology@latest
131
+ opencode-code-archaeology doctor
132
+ opencode-code-archaeology version
133
+ ```
134
+
135
+ Do not claim GitHub Pages is enabled unless repository settings confirm it.
@@ -0,0 +1,38 @@
1
+ # Security Audit Notes
2
+
3
+ These notes capture the current release-readiness security posture for Code Archaeology. They are intended to accompany the release checklist and should be refreshed before each publication.
4
+
5
+ ## Current Findings
6
+
7
+ - `npm audit --audit-level=moderate` is expected to be clean for the current dependency set.
8
+ - `npm outdated --json` is expected to be clean for the current dependency set.
9
+ - No hardcoded secrets are expected in source, docs, hooks, commands, prompts, schemas, or package metadata.
10
+ - `.archaeology/` is local runtime state and is ignored by Git.
11
+ - `.superpowers/` is local planning state and is ignored by Git.
12
+ - Shell hooks in `hooks/opencode/` are syntax-checkable with `bash -n hooks/opencode/*.sh`.
13
+
14
+ ## Local State
15
+
16
+ Code Archaeology writes operational state into `.archaeology/` in the target repository. This directory can contain project structure, findings, generated reports, mock patches, and restoration logs. It should stay local unless a maintainer intentionally extracts a report for review.
17
+
18
+ ## Restore-Mode Safety Caveat
19
+
20
+ `restore` mode can modify source files. It should only run after `survey` reports are reviewed, preferably after `excavate` mock patches are reviewed, and only when the target repository has tests or type checks available. Failed restore phases should be reverted with the bundled revert hook before continuing.
21
+
22
+ The tool must not remove try/catch blocks around I/O or external input boundaries automatically, and uncertain type replacements should be flagged for human review instead of guessed.
23
+
24
+ ## Release Checklist
25
+
26
+ Before publishing a release:
27
+
28
+ ```bash
29
+ npm install
30
+ npm run build
31
+ npm run typecheck
32
+ npm audit --audit-level=moderate
33
+ npm outdated --json
34
+ bash -n hooks/opencode/*.sh
35
+ npm pack --json --dry-run
36
+ ```
37
+
38
+ Inspect the package dry run for required files and for accidental inclusion of local state. Do not publish if `.archaeology/`, `.superpowers/`, credentials, logs, or editor state appear in the package contents.
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+
4
+ pack_json=$(npm pack --json --dry-run)
5
+
6
+ PACK_JSON="$pack_json" node <<'NODE'
7
+ const pack = JSON.parse(process.env.PACK_JSON ?? '[]');
8
+ const files = new Set((pack[0]?.files ?? []).map((file) => file.path));
9
+
10
+ const requiredFiles = [
11
+ 'dist/cli.js',
12
+ 'dist/index.js',
13
+ 'commands/code-archaeology.md',
14
+ 'skills/code-archaeology/SKILL.md',
15
+ 'hooks/opencode/init.sh',
16
+ 'hooks/opencode/verify-phase.sh',
17
+ 'hooks/opencode/revert-phase.sh',
18
+ 'hooks/opencode/update-expedition.sh',
19
+ 'hooks/opencode/verify-package.sh',
20
+ 'prompts/discovery.md',
21
+ 'schema/expedition-report.json',
22
+ 'docs/README.md',
23
+ 'wiki/Home.md',
24
+ 'assets/code-archaeology-banner.svg',
25
+ 'AGENTS.md',
26
+ 'VERSION',
27
+ 'README.md',
28
+ 'INSTALL.md',
29
+ 'SECURITY.md',
30
+ 'CONTRIBUTING.md',
31
+ 'CHANGELOG.md',
32
+ 'LICENSE',
33
+ ];
34
+
35
+ const missingFiles = requiredFiles.filter((file) => !files.has(file));
36
+
37
+ if (missingFiles.length > 0) {
38
+ console.error('Package is missing required files:');
39
+ for (const file of missingFiles) {
40
+ console.error(`- ${file}`);
41
+ }
42
+ process.exit(1);
43
+ }
44
+
45
+ console.log(`Package dry-run includes ${files.size} files and all required release assets.`);
46
+ NODE
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-code-archaeology",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
4
4
  "description": "Excavate, catalog, and restore a codebase by removing accumulated sediment—dead code, legacy fallbacks, circular dependencies, weak types, and defensive programming slop.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -12,6 +12,10 @@
12
12
  ".": {
13
13
  "types": "./dist/index.d.ts",
14
14
  "default": "./dist/index.js"
15
+ },
16
+ "./plugin": {
17
+ "types": "./dist/plugin.d.ts",
18
+ "default": "./dist/plugin.js"
15
19
  }
16
20
  },
17
21
  "files": [
@@ -20,15 +24,28 @@
20
24
  "commands",
21
25
  "skills",
22
26
  "plugins",
23
- "policies",
27
+ "prompts",
24
28
  "schema",
29
+ "docs/README.md",
30
+ "docs/INSTALL.md",
31
+ "docs/ARCHITECTURE.md",
32
+ "docs/RELEASE.md",
33
+ "docs/SECURITY_AUDIT.md",
34
+ "wiki",
35
+ "assets",
36
+ ".github",
25
37
  "AGENTS.md",
26
38
  "VERSION",
27
39
  "README.md",
40
+ "INSTALL.md",
41
+ "SECURITY.md",
42
+ "CONTRIBUTING.md",
43
+ "CHANGELOG.md",
28
44
  "LICENSE"
29
45
  ],
30
46
  "scripts": {
31
47
  "build": "tsc",
48
+ "test": "npm run build && node --test tests/*.test.mjs",
32
49
  "typecheck": "tsc --noEmit",
33
50
  "verify:pack": "bash hooks/opencode/verify-package.sh",
34
51
  "prepack": "tsc"
@@ -46,14 +63,18 @@
46
63
  "type": "git",
47
64
  "url": "git+https://github.com/Maleick/Code-Archaeology.git"
48
65
  },
49
- "homepage": "https://github.com/Maleick/Code-Archaeology",
66
+ "author": {
67
+ "name": "Maleick",
68
+ "url": "https://github.com/Maleick"
69
+ },
70
+ "homepage": "https://github.com/Maleick/Code-Archaeology#readme",
50
71
  "bugs": {
51
72
  "url": "https://github.com/Maleick/Code-Archaeology/issues"
52
73
  },
53
74
  "license": "MIT",
54
75
  "devDependencies": {
55
- "@types/node": "^20.0.0",
56
- "typescript": "^5.0.0"
76
+ "@types/node": "^25.6.0",
77
+ "typescript": "^6.0.3"
57
78
  },
58
79
  "engines": {
59
80
  "node": ">=18"
@@ -0,0 +1,45 @@
1
+ # Expedition 1: Dead Code Excavation
2
+
3
+ ## Objective
4
+ Identify and catalog all dead code—unused exports, unreachable functions, unreferenced variables, and orphaned files.
5
+
6
+ ## Instructions
7
+
8
+ 1. **Tool-Based Discovery**
9
+ - Run `knip` (TypeScript/JavaScript) or `vulture` (Python)
10
+ - Run `jscpd` to find duplicate code that may indicate dead copies
11
+ - If tools unavailable, perform AST-based manual analysis
12
+
13
+ 2. **Classification**
14
+ For each finding, classify confidence:
15
+ - **HIGH**: Tool-confirmed unused export with zero references
16
+ - **MEDIUM**: Likely unused but has dynamic access or test references
17
+ - **LOW**: Possibly used via reflection or build-time injection
18
+
19
+ 3. **Impact Assessment**
20
+ - Note if removal affects public API
21
+ - Check for test files that import but don't meaningfully test
22
+ - Verify no build scripts or CI depend on the code
23
+
24
+ ## Output
25
+
26
+ Write to `.archaeology/expedition1-report.md`:
27
+ - Table of all findings with file paths, line numbers, confidence levels
28
+ - Categorized by type (unused export, unreachable code, orphaned file, duplicate)
29
+ - Recommended action per finding (remove, flag for review, keep)
30
+ - Estimated lines of code affected
31
+
32
+ ## Execution Rules
33
+ - If `mode == survey`: catalog only, zero changes
34
+ - If `mode == excavate`: generate mock patch files for review
35
+ - If `mode == restore`:
36
+ - Remove HIGH confidence artifacts always
37
+ - Remove MEDIUM confidence artifacts only if `strict_mode == true`
38
+ - NEVER remove LOW confidence artifacts
39
+ - Run tests after each removal batch
40
+ - Revert immediately if tests fail
41
+
42
+ ## Constraints
43
+ - NEVER remove code that is dynamically accessed (eval, require(variable), etc.)
44
+ - NEVER remove exports that are part of a public API unless explicitly deprecated
45
+ - ALWAYS verify with grep that no references exist before removing
@@ -0,0 +1,49 @@
1
+ # Expedition 3: Circular Dependency Cartography
2
+
3
+ ## Objective
4
+ Map all circular dependencies in the module graph and provide remediation strategies.
5
+
6
+ ## Instructions
7
+
8
+ 1. **Tool-Based Analysis**
9
+ - Run `madge --circular` (TypeScript/JavaScript)
10
+ - Run `pydeps` (Python) or equivalent
11
+ - If tools unavailable, build import graph manually
12
+
13
+ 2. **Dependency Mapping**
14
+ For each cycle found:
15
+ - List all files in the cycle
16
+ - Identify the specific imports creating the cycle
17
+ - Determine if the cycle is direct (A→B→A) or indirect (A→B→C→A)
18
+ - Calculate cycle complexity (number of nodes, edges)
19
+
20
+ 3. **Remediation Strategy**
21
+ For each cycle, determine the best fix:
22
+ - Extract shared code to a new module (preferred)
23
+ - Use dependency inversion / interfaces
24
+ - Move code to break the cycle
25
+ - Convert to dynamic imports (if appropriate)
26
+ - Flag as architectural issue requiring human design review
27
+
28
+ ## Output
29
+
30
+ Write to `.archaeology/expedition3-report.md`:
31
+ - Complete cycle inventory with file paths and import chains
32
+ - Visualization data (can be rendered with graphviz)
33
+ - Remediation recommendation per cycle
34
+ - Estimated effort to resolve each cycle
35
+
36
+ ## Execution Rules
37
+ - If `mode == survey`: catalog only
38
+ - If `mode == excavate`: generate detailed migration plans
39
+ - If `mode == restore`:
40
+ - Fix simple cycles (2-node, clear extraction path) automatically
41
+ - Flag complex cycles for human review
42
+ - NEVER create new abstractions that obscure the cycle—break it properly
43
+ - Run tests after each fix
44
+
45
+ ## Constraints
46
+ - NEVER introduce dynamic imports just to hide a cycle—fix the architecture
47
+ - NEVER extract code into poorly-named "utils" files—use domain-appropriate names
48
+ - ALWAYS ensure the fixed graph has no new cycles introduced
49
+ - ALWAYS verify the cycle is real (not a type-only import that tree-shakes away)
@@ -0,0 +1,47 @@
1
+ # Phase 0: Site Survey & Baseline
2
+
3
+ ## Objective
4
+ Establish a complete inventory of the codebase before any modifications. Document the baseline state so all subsequent expeditions have a reference point.
5
+
6
+ ## Instructions
7
+
8
+ 1. **Verify Preconditions**
9
+ - Confirm working tree is clean
10
+ - Confirm tests pass at baseline
11
+ - Create branch `{{ branch_name }}`
12
+ - Create `.archaeology/` directory
13
+
14
+ 2. **File Inventory**
15
+ - Catalog all source files by directory
16
+ - Note file counts, line counts, and language distribution
17
+ - Identify configuration files (package.json, tsconfig, etc.)
18
+
19
+ 3. **Dependency Mapping**
20
+ - Document all external dependencies
21
+ - Note devDependencies vs production dependencies
22
+ - Flag any deprecated or outdated packages
23
+
24
+ 4. **Baseline Metrics**
25
+ - Record test count and coverage (if available)
26
+ - Record type error count
27
+ - Record lint error count
28
+ - Save current git HEAD to `.archaeology/baseline.txt`
29
+
30
+ ## Output
31
+
32
+ Write to `.archaeology/site_survey.md`:
33
+ - Executive summary of codebase size and structure
34
+ - Dependency health assessment
35
+ - Baseline metrics table
36
+ - Risk factors identified
37
+
38
+ Write to `.archaeology/artifact_inventory.json`:
39
+ - Machine-readable file inventory
40
+
41
+ Write to `.archaeology/stratum_graph.json`:
42
+ - Dependency graph data for visualization
43
+
44
+ ## Constraints
45
+ - ZERO file modifications in this phase
46
+ - If tests fail at baseline, abort immediately
47
+ - Do not proceed to Expedition 1 until this report is complete
package/prompts/dry.md ADDED
@@ -0,0 +1,49 @@
1
+ # Expedition 6: DRY Stratification
2
+
3
+ ## Objective
4
+ Identify semantic duplication across the codebase and extract shared abstractions. Only extract true semantic duplicates, not coincidental similarity.
5
+
6
+ ## Instructions
7
+
8
+ 1. **Duplicate Detection**
9
+ - Run `jscpd` with `min_duplicate_lines: 5`
10
+ - Search for repeated patterns manually (error messages, validation logic, API calls)
11
+ - Look for copy-pasted code blocks with minor variations
12
+
13
+ 2. **Semantic Analysis**
14
+ For each duplicate found:
15
+ - Determine if the duplication is coincidental (same structure, different semantics)
16
+ - Check if the duplicated code represents a real domain concept
17
+ - Assess if extraction would create a meaningful abstraction
18
+ - Verify the duplicated code isn't better left inline (trivial one-liners)
19
+
20
+ 3. **Extraction Planning**
21
+ - Identify the canonical location for the extracted code
22
+ - Determine the appropriate abstraction level (function, class, constant, etc.)
23
+ - Plan parameterization for minor variations
24
+ - Check for existing utility libraries that could host the code
25
+
26
+ ## Output
27
+
28
+ Write to `.archaeology/expedition6-report.md`:
29
+ - Catalog of all duplications with locations and similarity scores
30
+ - Classification: semantic vs. coincidental
31
+ - Extraction recommendation for each semantic duplicate
32
+ - Proposed abstraction name and location
33
+ - Files affected by extraction
34
+
35
+ ## Execution Rules
36
+ - If `mode == survey`: catalog only
37
+ - If `mode == excavate`: generate extraction plans with before/after code
38
+ - If `mode == restore`:
39
+ - Extract HIGH confidence semantic duplications
40
+ - Extract MEDIUM confidence only if `strict_mode == true`
41
+ - NEVER extract coincidental similarities—leave them inline
42
+ - Run tests after each extraction
43
+
44
+ ## Constraints
45
+ - NEVER extract code into a "utils" grab bag—use domain-appropriate names
46
+ - NEVER create abstractions over cyclic dependencies (fix cycles in Expedition 3 first)
47
+ - ALWAYS ensure the extracted code is actually used in 3+ places or is likely to be
48
+ - NEVER change behavior during extraction—pure refactor only
49
+ - ALWAYS prefer composition over premature abstraction