opencode-code-archaeology 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,258 @@
1
+ /**
2
+ * Core type definitions for Code Archaeology — OpenCode plugin for systematic
3
+ * codebase excavation, cataloging, and restoration.
4
+ *
5
+ * @module code-archaeology-types
6
+ */
7
+ /** Valid operational modes. */
8
+ export type ArchaeologyMode = "survey" | "excavate" | "restore";
9
+ /** Supported programming languages. */
10
+ export type TargetLanguage = "typescript" | "javascript" | "python" | "go" | "rust";
11
+ /** Expedition phases in fixed order. */
12
+ export type ExpeditionPhase = "survey" | "dead_code" | "legacy" | "dependencies" | "types_consolidate" | "types_harden" | "dry" | "errors" | "polish" | "final_verify";
13
+ /** Confidence levels for findings. */
14
+ export type ConfidenceLevel = "HIGH" | "MEDIUM" | "LOW";
15
+ /** Status values for expedition progress. */
16
+ export type ExpeditionStatus = "pending" | "running" | "complete" | "failed" | "skipped";
17
+ /** Tool types used for analysis. */
18
+ export type AnalysisTool = "knip" | "vulture" | "madge" | "pydeps" | "jscpd" | "tsc" | "mypy" | "ast_grep" | "manual";
19
+ /** Event types emitted by the plugin. */
20
+ export type EventType = "phase_complete" | "phase_failed" | "finding_detected" | "report_generated";
21
+ /** Runtime parameters for an archaeology session. */
22
+ export interface ArchaeologyConfig {
23
+ /** Absolute or relative path to repository root. */
24
+ repo_path: string;
25
+ /** Primary language for tooling and AST selection. */
26
+ language: TargetLanguage;
27
+ /** Operational mode. */
28
+ mode: ArchaeologyMode;
29
+ /** Whether to auto-restore medium-confidence findings. */
30
+ strict_mode: boolean;
31
+ /** Command to verify correctness (must exit 0 on success). */
32
+ test_command: string;
33
+ /** Command for static type verification. */
34
+ typecheck_command: string;
35
+ /** Git branch to create and work on. */
36
+ branch_name: string;
37
+ }
38
+ /** Default configuration values. */
39
+ export declare const DEFAULT_CONFIG: ArchaeologyConfig;
40
+ /** A single detected artifact (dead code, legacy pattern, etc.). */
41
+ export interface Finding {
42
+ /** Unique identifier for this finding. */
43
+ id: string;
44
+ /** Expedition phase that detected this. */
45
+ phase: ExpeditionPhase;
46
+ /** File path relative to repo root. */
47
+ file: string;
48
+ /** Line number (1-indexed). */
49
+ line: number;
50
+ /** Column number (1-indexed). */
51
+ column?: number;
52
+ /** Type of artifact found. */
53
+ type: string;
54
+ /** Human-readable description. */
55
+ description: string;
56
+ /** Confidence in this finding. */
57
+ confidence: ConfidenceLevel;
58
+ /** Whether this would be auto-removed in restore mode. */
59
+ auto_removable: boolean;
60
+ /** Recommended action. */
61
+ recommendation: string;
62
+ /** Tool that detected this (or "manual"). */
63
+ detected_by: AnalysisTool;
64
+ }
65
+ /** A cluster of related findings (e.g., duplicate types). */
66
+ export interface FindingCluster {
67
+ /** Cluster identifier. */
68
+ id: string;
69
+ /** Phase that produced this cluster. */
70
+ phase: ExpeditionPhase;
71
+ /** Human-readable name. */
72
+ name: string;
73
+ /** Findings in this cluster. */
74
+ findings: Finding[];
75
+ /** Consolidation/remediation plan. */
76
+ plan: string;
77
+ /** Whether this cluster is safe to auto-fix. */
78
+ auto_fixable: boolean;
79
+ }
80
+ /** State of an individual expedition phase. */
81
+ export interface Expedition {
82
+ /** Phase identifier. */
83
+ phase: ExpeditionPhase;
84
+ /** Human-readable name. */
85
+ name: string;
86
+ /** Current status. */
87
+ status: ExpeditionStatus;
88
+ /** Number of findings detected. */
89
+ findings_count: number;
90
+ /** Path to the generated report. */
91
+ report_path?: string;
92
+ /** ISO-8601 timestamp when phase started. */
93
+ started_at?: string;
94
+ /** ISO-8601 timestamp when phase completed. */
95
+ completed_at?: string;
96
+ /** Error message if phase failed. */
97
+ error?: string;
98
+ }
99
+ /** Top-level structure of `.archaeology/session.json`. */
100
+ export interface Session {
101
+ /** Schema version. */
102
+ version: number;
103
+ /** Plugin version. */
104
+ plugin_version: string;
105
+ /** Session identifier. */
106
+ session_id: string;
107
+ /** Configuration used for this session. */
108
+ config: ArchaeologyConfig;
109
+ /** ISO-8601 timestamp when session started. */
110
+ started_at: string;
111
+ /** ISO-8601 timestamp of last update. */
112
+ updated_at: string;
113
+ /** All expeditions and their status. */
114
+ expeditions: Expedition[];
115
+ /** Total findings across all expeditions. */
116
+ total_findings: number;
117
+ /** Number of auto-fixable findings. */
118
+ auto_fixable_count: number;
119
+ /** Baseline git commit SHA. */
120
+ baseline_commit?: string;
121
+ /** Whether the session completed successfully. */
122
+ completed: boolean;
123
+ }
124
+ /** File inventory entry from the site survey. */
125
+ export interface FileEntry {
126
+ /** Relative path. */
127
+ path: string;
128
+ /** File size in bytes. */
129
+ size: number;
130
+ /** Line count. */
131
+ lines: number;
132
+ /** Language detected. */
133
+ language?: string;
134
+ /** Whether this is a test file. */
135
+ is_test: boolean;
136
+ }
137
+ /** Dependency entry from the site survey. */
138
+ export interface DependencyEntry {
139
+ /** Package name. */
140
+ name: string;
141
+ /** Installed version. */
142
+ version: string;
143
+ /** Whether it's a dev dependency. */
144
+ is_dev: boolean;
145
+ /** Whether the package is deprecated. */
146
+ is_deprecated?: boolean;
147
+ }
148
+ /** Baseline metrics captured at survey time. */
149
+ export interface BaselineMetrics {
150
+ /** Total files. */
151
+ total_files: number;
152
+ /** Total lines of code. */
153
+ total_lines: number;
154
+ /** Test file count. */
155
+ test_files: number;
156
+ /** External dependency count. */
157
+ dependencies: number;
158
+ /** Type error count. */
159
+ type_errors: number;
160
+ /** Lint error count. */
161
+ lint_errors: number;
162
+ /** Test pass/fail status. */
163
+ tests_passing: boolean;
164
+ }
165
+ /** Top-level structure of `.archaeology/site_survey.json`. */
166
+ export interface SiteSurvey {
167
+ /** Schema version. */
168
+ version: number;
169
+ /** Baseline git commit. */
170
+ baseline_commit: string;
171
+ /** File inventory. */
172
+ files: FileEntry[];
173
+ /** Dependency inventory. */
174
+ dependencies: DependencyEntry[];
175
+ /** Baseline metrics. */
176
+ metrics: BaselineMetrics;
177
+ }
178
+ /** A single edge in the dependency graph. */
179
+ export interface DependencyEdge {
180
+ /** Source module. */
181
+ from: string;
182
+ /** Target module. */
183
+ to: string;
184
+ /** Import statement or reference. */
185
+ import_statement?: string;
186
+ }
187
+ /** A circular dependency cycle. */
188
+ export interface DependencyCycle {
189
+ /** Cycle identifier. */
190
+ id: string;
191
+ /** Files involved in the cycle. */
192
+ files: string[];
193
+ /** Edges forming the cycle. */
194
+ edges: DependencyEdge[];
195
+ /** Whether this is a direct cycle (A→B→A). */
196
+ is_direct: boolean;
197
+ /** Recommended fix strategy. */
198
+ fix_strategy: string;
199
+ }
200
+ /** Summary statistics for a single expedition report. */
201
+ export interface ExpeditionReportSummary {
202
+ /** Phase identifier. */
203
+ phase: ExpeditionPhase;
204
+ /** Number of findings. */
205
+ findings: number;
206
+ /** Number of HIGH confidence findings. */
207
+ high_confidence: number;
208
+ /** Number of MEDIUM confidence findings. */
209
+ medium_confidence: number;
210
+ /** Number of LOW confidence findings. */
211
+ low_confidence: number;
212
+ /** Estimated lines of code affected. */
213
+ estimated_loc_impact: number;
214
+ }
215
+ /** Top-level structure of `FINAL_CATALOG.md` data. */
216
+ export interface FinalCatalog {
217
+ /** Schema version. */
218
+ version: number;
219
+ /** Session summary. */
220
+ session: Session;
221
+ /** Per-expedition summaries. */
222
+ expeditions: ExpeditionReportSummary[];
223
+ /** Total lines added. */
224
+ lines_added: number;
225
+ /** Total lines removed. */
226
+ lines_removed: number;
227
+ /** Number of cycles broken. */
228
+ cycles_broken: number;
229
+ /** Number of types consolidated. */
230
+ types_consolidated: number;
231
+ /** Recommendations for future maintenance. */
232
+ recommendations: string[];
233
+ }
234
+ /** Minimal OpenCode plugin server shape. */
235
+ export interface PluginServer {
236
+ /** Event handler (currently a no-op stub). */
237
+ event(): undefined;
238
+ }
239
+ /** CLI argument shape for `opencode-code-archaeology`. */
240
+ export interface CliArgs {
241
+ /** Target repository path. */
242
+ repo?: string;
243
+ /** Target language. */
244
+ language?: TargetLanguage;
245
+ /** Operational mode. */
246
+ mode?: ArchaeologyMode;
247
+ /** Strict mode flag. */
248
+ strict?: boolean;
249
+ /** Specific phase to run (optional). */
250
+ phase?: ExpeditionPhase;
251
+ /** Test command override. */
252
+ testCommand?: string;
253
+ /** Typecheck command override. */
254
+ typecheckCommand?: string;
255
+ /** Branch name override. */
256
+ branch?: string;
257
+ }
258
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,+BAA+B;AAC/B,MAAM,MAAM,eAAe,GAAG,QAAQ,GAAG,UAAU,GAAG,SAAS,CAAC;AAEhE,uCAAuC;AACvC,MAAM,MAAM,cAAc,GAAG,YAAY,GAAG,YAAY,GAAG,QAAQ,GAAG,IAAI,GAAG,MAAM,CAAC;AAEpF,wCAAwC;AACxC,MAAM,MAAM,eAAe,GACvB,QAAQ,GACR,WAAW,GACX,QAAQ,GACR,cAAc,GACd,mBAAmB,GACnB,cAAc,GACd,KAAK,GACL,QAAQ,GACR,QAAQ,GACR,cAAc,CAAC;AAEnB,sCAAsC;AACtC,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,QAAQ,GAAG,KAAK,CAAC;AAExD,6CAA6C;AAC7C,MAAM,MAAM,gBAAgB,GAAG,SAAS,GAAG,SAAS,GAAG,UAAU,GAAG,QAAQ,GAAG,SAAS,CAAC;AAEzF,oCAAoC;AACpC,MAAM,MAAM,YAAY,GACpB,MAAM,GACN,SAAS,GACT,OAAO,GACP,QAAQ,GACR,OAAO,GACP,KAAK,GACL,MAAM,GACN,UAAU,GACV,QAAQ,CAAC;AAEb,yCAAyC;AACzC,MAAM,MAAM,SAAS,GAAG,gBAAgB,GAAG,cAAc,GAAG,kBAAkB,GAAG,kBAAkB,CAAC;AAMpG,qDAAqD;AACrD,MAAM,WAAW,iBAAiB;IAChC,oDAAoD;IACpD,SAAS,EAAE,MAAM,CAAC;IAClB,sDAAsD;IACtD,QAAQ,EAAE,cAAc,CAAC;IACzB,wBA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AAM,CAAC;IACrB,kCAAkC;IAClC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,4BAA4B;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB"}
package/dist/types.js ADDED
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Core type definitions for Code Archaeology — OpenCode plugin for systematic
3
+ * codebase excavation, cataloging, and restoration.
4
+ *
5
+ * @module code-archaeology-types
6
+ */
7
+ /** Default configuration values. */
8
+ export const DEFAULT_CONFIG = {
9
+ repo_path: ".",
10
+ language: "typescript",
11
+ mode: "survey",
12
+ strict_mode: false,
13
+ test_command: "npm test",
14
+ typecheck_command: "npx tsc --noEmit",
15
+ branch_name: "refactor/archaeology",
16
+ };
17
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAoEH,oCAAoC;AACpC,MAAM,CAAC,MAAM,cAAc,GAAsB;IAC/C,SAAS,EAAE,GAAG;IACd,QAAQ,EAAE,YAAY;IACtB,IAAI,EAAE,QAAQ;IACd,WAAW,EAAE,KAAK;IAClB,YAAY,EAAE,UAAU;IACxB,iBAAiB,EAAE,kBAAkB;IACrC,WAAW,EAAE,sBAAsB;CACpC,CAAC"}
@@ -0,0 +1,84 @@
1
+ # Initialize .archaeology/ directory for Code Archaeology.
2
+
3
+ set -euo pipefail
4
+
5
+ ARCHAEOLOGY_DIR=".archaeology"
6
+ SESSION_FILE="$ARCHAEOLOGY_DIR/session.json"
7
+
8
+ SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
9
+ RELEASE_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
10
+ if [[ -f "$RELEASE_ROOT/VERSION" ]]; then
11
+ PLUGIN_VERSION="$(tr -d '[:space:]' < "$RELEASE_ROOT/VERSION")"
12
+ else
13
+ PLUGIN_VERSION="dev"
14
+ fi
15
+
16
+ REPO_ROOT=$(git rev-parse --show-toplevel 2>/dev/null) || {
17
+ echo "Error: not inside a git repository" >&2
18
+ exit 1
19
+ }
20
+ cd "$REPO_ROOT"
21
+
22
+ echo "Code Archaeology v${PLUGIN_VERSION} initializing..."
23
+
24
+ if ! command -v jq >/dev/null 2>&1; then
25
+ echo "Warning: jq not found. Install with: brew install jq" >&2
26
+ fi
27
+
28
+ mkdir -p "$ARCHAEOLOGY_DIR"
29
+ mkdir -p "$ARCHAEOLOGY_DIR/patches"
30
+
31
+ # Initialize session.json
32
+ if [[ ! -f "$SESSION_FILE" ]]; then
33
+ NOW=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
34
+ SESSION_ID="archaeology-$(date -u +%s)-$$"
35
+ BASELINE_COMMIT=$(git rev-parse HEAD 2>/dev/null || echo "unknown")
36
+
37
+ jq -n \
38
+ --arg sid "$SESSION_ID" \
39
+ --arg now "$NOW" \
40
+ --arg ver "$PLUGIN_VERSION" \
41
+ --arg baseline "$BASELINE_COMMIT" \
42
+ '{
43
+ version: 1,
44
+ plugin_version: $ver,
45
+ session_id: $sid,
46
+ config: {
47
+ repo_path: ".",
48
+ language: "typescript",
49
+ mode: "survey",
50
+ strict_mode: false,
51
+ test_command: "npm test",
52
+ typecheck_command: "npx tsc --noEmit",
53
+ branch_name: "refactor/archaeology"
54
+ },
55
+ started_at: $now,
56
+ updated_at: $now,
57
+ expeditions: [
58
+ {phase: "survey", name: "Site Survey \u0026 Baseline", status: "pending", findings_count: 0},
59
+ {phase: "dead_code", name: "Dead Code Excavation", status: "pending", findings_count: 0},
60
+ {phase: "legacy", name: "Legacy Stratum Removal", status: "pending", findings_count: 0},
61
+ {phase: "dependencies", name: "Circular Dependency Cartography", status: "pending", findings_count: 0},
62
+ {phase: "types_consolidate", name: "Type Catalog Consolidation", status: "pending", findings_count: 0},
63
+ {phase: "types_harden", name: "Type Restoration \u0026 Hardening", status: "pending", findings_count: 0},
64
+ {phase: "dry", name: "DRY Stratification", status: "pending", findings_count: 0},
65
+ {phase: "errors", name: "Error Handling Stratigraphy", status: "pending", findings_count: 0},
66
+ {phase: "polish", name: "Artifact Cleaning \u0026 Documentation", status: "pending", findings_count: 0},
67
+ {phase: "final_verify", name: "Site Preservation \u0026 Final Catalog", status: "pending", findings_count: 0}
68
+ ],
69
+ total_findings: 0,
70
+ auto_fixable_count: 0,
71
+ baseline_commit: $baseline,
72
+ completed: false
73
+ }' > "$SESSION_FILE"
74
+ echo "Initialized $SESSION_FILE"
75
+ else
76
+ NOW=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
77
+ jq --arg now "$NOW" \
78
+ --arg ver "$PLUGIN_VERSION" \
79
+ '.updated_at = $now | .plugin_version = $ver' \
80
+ "$SESSION_FILE" > "$SESSION_FILE.tmp" && mv "$SESSION_FILE.tmp" "$SESSION_FILE"
81
+ echo "Refreshed $SESSION_FILE"
82
+ fi
83
+
84
+ echo "Code Archaeology workspace ready at $ARCHAEOLOGY_DIR"
@@ -0,0 +1,17 @@
1
+ # Revert changes in the current working tree back to the last commit.
2
+ # Usage: revert-phase.sh [phase-name]
3
+
4
+ set -euo pipefail
5
+
6
+ PHASE="${1:-unknown}"
7
+
8
+ echo "[$PHASE] ⚠️ Reverting changes due to failure..."
9
+
10
+ # Stash any changes and drop them
11
+ git stash push -m "code-archaeology-revert-$PHASE" --include-untracked 2>/dev/null || true
12
+ git stash drop 2>/dev/null || true
13
+
14
+ # Reset to HEAD
15
+ git reset --hard HEAD
16
+
17
+ echo "[$PHASE] ✅ Reverted to last commit"
@@ -0,0 +1,46 @@
1
+ # Update expedition status in session.json
2
+ # Usage: update-expedition.sh <phase> <status> [findings_count] [error_message]
3
+
4
+ set -euo pipefail
5
+
6
+ PHASE="$1"
7
+ STATUS="$2"
8
+ FINDINGS="${3:-0}"
9
+ ERROR="${4:-}"
10
+
11
+ ARCHAEOLOGY_DIR=".archaeology"
12
+ SESSION_FILE="$ARCHAEOLOGY_DIR/session.json"
13
+
14
+ if [[ ! -f "$SESSION_FILE" ]]; then
15
+ echo "Error: session.json not found. Run init.sh first." >&2
16
+ exit 1
17
+ fi
18
+
19
+ NOW=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
20
+
21
+ if command -v jq >/dev/null 2>&1; then
22
+ if [[ -n "$ERROR" ]]; then
23
+ jq --arg phase "$PHASE" \
24
+ --arg status "$STATUS" \
25
+ --argjson findings "$FINDINGS" \
26
+ --arg error "$ERROR" \
27
+ --arg now "$NOW" \
28
+ '(.expeditions[] | select(.phase == $phase)) |= (.status = $status | .findings_count = $findings | .error = $error | .completed_at = $now) | .updated_at = $now' \
29
+ "$SESSION_FILE" > "$SESSION_FILE.tmp" && mv "$SESSION_FILE.tmp" "$SESSION_FILE"
30
+ else
31
+ jq --arg phase "$PHASE" \
32
+ --arg status "$STATUS" \
33
+ --argjson findings "$FINDINGS" \
34
+ --arg now "$NOW" \
35
+ '(.expeditions[] | select(.phase == $phase)) |= (.status = $status | .findings_count = $findings | .completed_at = $now) | .updated_at = $now' \
36
+ "$SESSION_FILE" > "$SESSION_FILE.tmp" && mv "$SESSION_FILE.tmp" "$SESSION_FILE"
37
+ fi
38
+
39
+ # Update total findings
40
+ jq '(.total_findings = ([.expeditions[].findings_count] | add // 0))' \
41
+ "$SESSION_FILE" > "$SESSION_FILE.tmp" && mv "$SESSION_FILE.tmp" "$SESSION_FILE"
42
+
43
+ echo "[$PHASE] Updated status: $STATUS (findings: $FINDINGS)"
44
+ else
45
+ echo "[$PHASE] Status: $STATUS (findings: $FINDINGS) [jq not available, session not updated]"
46
+ fi
@@ -0,0 +1,31 @@
1
+ # Verify that tests pass and typecheck succeeds.
2
+ # Usage: verify-phase.sh [phase-name]
3
+
4
+ set -euo pipefail
5
+
6
+ PHASE="${1:-unknown}"
7
+ ARCHAEOLOGY_DIR=".archaeology"
8
+ SESSION_FILE="$ARCHAEOLOGY_DIR/session.json"
9
+
10
+ SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
11
+
12
+ # Source config from session file if jq is available
13
+ TEST_CMD="npm test"
14
+ TYPECHECK_CMD="npx tsc --noEmit"
15
+ if command -v jq >/dev/null 2>&1 && [[ -f "$SESSION_FILE" ]]; then
16
+ TEST_CMD=$(jq -r '.config.test_command // "npm test"' "$SESSION_FILE")
17
+ TYPECHECK_CMD=$(jq -r '.config.typecheck_command // "npx tsc --noEmit"' "$SESSION_FILE")
18
+ fi
19
+
20
+ echo "[$PHASE] Running test command: $TEST_CMD"
21
+ if ! bash -c "$TEST_CMD"; then
22
+ echo "[$PHASE] ❌ Tests FAILED" >&2
23
+ exit 1
24
+ fi
25
+
26
+ echo "[$PHASE] Running typecheck: $TYPECHECK_CMD"
27
+ if ! bash -c "$TYPECHECK_CMD" 2>/dev/null; then
28
+ echo "[$PHASE] ⚠️ Typecheck reported errors (non-blocking for some languages)" >&2
29
+ fi
30
+
31
+ echo "[$PHASE] ✅ Verification passed"
package/package.json ADDED
@@ -0,0 +1,61 @@
1
+ {
2
+ "name": "opencode-code-archaeology",
3
+ "version": "2.0.0",
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
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "bin": {
9
+ "opencode-code-archaeology": "dist/cli.js"
10
+ },
11
+ "exports": {
12
+ ".": {
13
+ "types": "./dist/index.d.ts",
14
+ "default": "./dist/index.js"
15
+ }
16
+ },
17
+ "files": [
18
+ "dist",
19
+ "hooks",
20
+ "commands",
21
+ "skills",
22
+ "plugins",
23
+ "policies",
24
+ "schema",
25
+ "AGENTS.md",
26
+ "VERSION",
27
+ "README.md",
28
+ "LICENSE"
29
+ ],
30
+ "scripts": {
31
+ "build": "tsc",
32
+ "typecheck": "tsc --noEmit",
33
+ "verify:pack": "bash hooks/opencode/verify-package.sh",
34
+ "prepack": "tsc"
35
+ },
36
+ "keywords": [
37
+ "opencode",
38
+ "plugin",
39
+ "refactor",
40
+ "cleanup",
41
+ "static-analysis",
42
+ "code-quality",
43
+ "archaeology"
44
+ ],
45
+ "repository": {
46
+ "type": "git",
47
+ "url": "git+https://github.com/Maleick/Code-Archaeology.git"
48
+ },
49
+ "homepage": "https://github.com/Maleick/Code-Archaeology",
50
+ "bugs": {
51
+ "url": "https://github.com/Maleick/Code-Archaeology/issues"
52
+ },
53
+ "license": "MIT",
54
+ "devDependencies": {
55
+ "@types/node": "^20.0.0",
56
+ "typescript": "^5.0.0"
57
+ },
58
+ "engines": {
59
+ "node": ">=18"
60
+ }
61
+ }
@@ -0,0 +1,8 @@
1
+ export {
2
+ id,
3
+ repoRoot,
4
+ version,
5
+ server,
6
+ } from "../src/index.ts";
7
+
8
+ export type * from "../src/types";
@@ -0,0 +1,99 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "$id": "code-archaeology/expedition-report",
4
+ "title": "Expedition Report",
5
+ "description": "Schema for individual expedition reports generated by Code Archaeology",
6
+ "type": "object",
7
+ "required": ["phase", "name", "findings", "generated_at"],
8
+ "properties": {
9
+ "phase": {
10
+ "type": "string",
11
+ "enum": [
12
+ "survey",
13
+ "dead_code",
14
+ "legacy",
15
+ "dependencies",
16
+ "types_consolidate",
17
+ "types_harden",
18
+ "dry",
19
+ "errors",
20
+ "polish",
21
+ "final_verify"
22
+ ],
23
+ "description": "Expedition phase identifier"
24
+ },
25
+ "name": {
26
+ "type": "string",
27
+ "description": "Human-readable phase name"
28
+ },
29
+ "findings": {
30
+ "type": "array",
31
+ "description": "Artifacts detected in this expedition",
32
+ "items": {
33
+ "type": "object",
34
+ "required": ["id", "file", "line", "type", "description", "confidence"],
35
+ "properties": {
36
+ "id": {
37
+ "type": "string",
38
+ "description": "Unique finding identifier"
39
+ },
40
+ "file": {
41
+ "type": "string",
42
+ "description": "File path relative to repo root"
43
+ },
44
+ "line": {
45
+ "type": "integer",
46
+ "description": "Line number (1-indexed)"
47
+ },
48
+ "column": {
49
+ "type": "integer",
50
+ "description": "Column number (1-indexed)"
51
+ },
52
+ "type": {
53
+ "type": "string",
54
+ "description": "Type of artifact found"
55
+ },
56
+ "description": {
57
+ "type": "string",
58
+ "description": "Human-readable description"
59
+ },
60
+ "confidence": {
61
+ "type": "string",
62
+ "enum": ["HIGH", "MEDIUM", "LOW"],
63
+ "description": "Confidence level"
64
+ },
65
+ "recommendation": {
66
+ "type": "string",
67
+ "description": "Recommended action"
68
+ }
69
+ }
70
+ }
71
+ },
72
+ "summary": {
73
+ "type": "object",
74
+ "properties": {
75
+ "total_findings": {
76
+ "type": "integer"
77
+ },
78
+ "high_confidence": {
79
+ "type": "integer"
80
+ },
81
+ "medium_confidence": {
82
+ "type": "integer"
83
+ },
84
+ "low_confidence": {
85
+ "type": "integer"
86
+ },
87
+ "estimated_loc_impact": {
88
+ "type": "integer",
89
+ "description": "Estimated lines of code affected"
90
+ }
91
+ }
92
+ },
93
+ "generated_at": {
94
+ "type": "string",
95
+ "format": "date-time",
96
+ "description": "ISO-8601 timestamp"
97
+ }
98
+ }
99
+ }