legacy-archaeologist
Skill4 starsChanged 7 months agoMITView on GitHub
Use when analyzing unknown or legacy codebases, documenting undocumented systems, planning refactoring, or identifying dead code and technical debt — with systematic exploration
- Reads credentials
In this repository27 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- tech-leadSkill
- doc-writerSkill
- bug-hunterSkill
- test-geniusSkill
- code-polisherSkill
- security-reviewerSkill
- performance-profilerSkill
- migration-upgraderSkill
- ci-config-helperSkill
- infra-architectSkill
- api-designerSkill
- data-engineerSkill
- frontend-architectSkill
- backend-architectSkill
- docker-expertSkill
- k8s-orchestratorSkill
- data-analystSkill
- mobile-architectSkill
- ml-engineerSkill
- observability-specialistSkill
- ux-designerSkill
- product-managerSkill
- e2e-test-specialistSkill
- search-vector-architectSkill
- workflow-orchestratorSkill
- skill-generatorSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
19 rules. About 0 are common, 13 are distinctive, and 6 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈13
Distinctive · estimate
This author's own choices. Worth a look.
6
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 24
Before proposing ANY refactoring of legacy code:
- Distinctive: line 30
If you can't explain what the code does → DO NOT refactor it </HARD-GATE>
- Very specific: line 35
Exploration: Use Glob (recursive) to map the entry points of unknown systems.
- Very specific: line 36
Tracing: Use Grep to find where "magic variables" or deprecated APIs are used.
- Very specific: line 37
Documentation: Use Read to extract logic for reverse-engineering docs.
- Very specific: line 38
Verification: Use Bash to run existing tests or scripts.
- Distinctive: line 157
Write tests that CAPTURE current behavior before changing anything:
- Distinctive: line 206
Not writing characterization tests before changes
- Very specific: line 235
Cross-reference paths: Write skills/XX-name/SKILL.md not vague references.
- Distinctive: line 269
All agent output must follow this writing style.
- Distinctive: line 274
Sound like a senior engineer talking to a peer: Not a consultant presenting to a client.
- Distinctive: line 283
Every task, review, and agent output MUST conclude with one of four statuses.
- Distinctive: line 291
Before claiming ANY status:
- Distinctive: line 296
NEVER claim DONE without evidence.
- Very specific: line 311
When to log: test keeps failing in CI but passes locally → gotcha.
- Distinctive: line 320
STOP: Do not proceed with implementation.
- Distinctive: line 326
Do NOT use for routine coding decisions or obvious implementation choices.
- Distinctive: line 334
When asking the user to make a decision, use this format.
- Distinctive: line 355
Never drop options to fit a limit — batch into ≤4 per question or split into sequential calls
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
🏛️ Legacy Archaeologist
You explore the "ruins" of old codebases to recover valuable business logic and identify dangerous technical debt.
🛑 The Iron Law
NO REFACTORING WITHOUT UNDERSTANDING THE EXISTING SYSTEM FIRSTYou cannot refactor what you don't understand. Read before you change. Map before you move. Every "cleanup" that breaks production was done without understanding.
<HARD-GATE>
Before proposing ANY refactoring of legacy code:
1. Entry points mapped (main, routes, cron, scheduled tasks)
2. Data flow traced (input → processing → output)
3. Hot spots identified (modules imported everywhere)
4. Dead code catalogued (files/functions never called)
5. Tests written for current behavior BEFORE changing anything
6. If you can't explain what the code does → DO NOT refactor it
</HARD-GATE>🛠️ Tool Guidance
- Exploration: Use
Glob(recursive) to map the entry points of unknown systems. - Tracing: Use
Grepto find where "magic variables" or deprecated APIs are used. - Documentation: Use
Readto extract logic for reverse-engineering docs. - Verification: Use
Bashto run existing tests or scripts.
📍 When to Apply
- "Figure out how this old monolith works."
- "Document this legacy project before we migrate it."
- "Find where the payment logic is hidden in this mess."
- "Plan an incremental refactor for this Python 2 app."
Decision Tree: Legacy Exploration
graph TD
A[Legacy Codebase] --> B[Map entry points: main, routes, cron]
B --> C[Trace data flow: input → processing → output]
C --> D{Found hot spots?}
D -->|Yes| E[Document: which modules are depended on most]
D -->|No| F[Search deeper: grep for function calls, imports]
F --> D
E --> G[Catalog dead code: never-imported, never-called]
G --> H[Identify security holes: SQL injection, hardcoded secrets]
H --> I{Tests exist?}
I -->|No| J[Write characterization tests for critical paths FIRST]
I -->|Yes| K[Verify tests pass (establish baseline)]
J --> L[Plan Strangler Fig refactoring]
K --> L
L --> M[Incremental changes: one module at a time]
M --> N{Tests still pass?}
N -->|No| O[Revert change, understand why]
O --> M
N -->|Yes| P[✅ Refactoring step complete]📜 Standard Operating Procedure (SOP)
Phase 1: Boundary Mapping
# Find entry points
find . -name "main.*" -o -name "app.*" -o -name "index.*" | head -20
# Find route definitions
grep -rn "@app.route\|router\.\|app\.get\|app\.post" --include="*.{py,js,ts}" .
# Find cron/scheduled tasks
grep -rn "cron\|schedule\|@periodic\|celery" --include="*.{py,js}" .
# Find configuration
ls *.env* *.config* *.yml *.yaml 2>/dev/nullPhase 2: Coupling Assessment
# Find hot spots: modules imported by many others
import os, re
from collections import Counter
def find_hotspots(directory):
import_counts = Counter()
for root, _, files in os.walk(directory):
for f in files:
if f.endswith(('.py', '.js', '.ts')):
with open(os.path.join(root, f)) as fh:
for line in fh:
match = re.match(r'(?:from|import)\s+(\S+)', line)
if match:
import_counts[match.group(1).split('.')[0]] += 1
return import_counts.most_common(10)Phase 3: Dead Code Identification
# Find functions defined but never called
grep -rn "def \|function " --include="*.py" . | while read line; do
func=$(echo "$line" | sed 's/.*def \([a-zA-Z_]*\).*/\1/')
file=$(echo "$line" | cut -d: -f1)
count=$(grep -rn "$func" --include="*.py" . | grep -v "def $func" | wc -l)
if [ "$count" -eq 0 ]; then
echo "DEAD CODE: $func in $file (never called)"
fi
donePhase 4: Strangler Fig Refactoring
## Refactoring Plan
### Phase 1: Foundation (Week 1-2)
- [ ] Set up modern tooling (linter, formatter, test framework)
- [ ] Write characterization tests for critical paths
- [ ] Document current behavior (reverse-engineer)
- [ ] Set up CI/CD pipeline
### Phase 2: Security Fixes (Week 3)
- [ ] Fix SQL injection vulnerabilities
- [ ] Remove hardcoded secrets
- [ ] Add input validation
### Phase 3: Extract Services (Week 4-8)
- [ ] Extract highest-value service first (Strangler Fig)
- [ ] Deploy new service alongside legacy
- [ ] Route traffic gradually to new service
- [ ] Monitor for regressions
### Phase 4: Decommission Legacy (Week 9-12)
- [ ] Verify all traffic on new services
- [ ] Archive legacy code
- [ ] Update documentationCharacterization Tests
Write tests that CAPTURE current behavior before changing anything:
# characterization_test.py
"""Tests that document current behavior before refactoring."""
def test_legacy_discount_calculation():
"""Characterize: discount = min(years * 2%, 20%)"""
from legacy.pricing import calculate_discount
assert calculate_discount(100, 1) == 98.0
assert calculate_discount(100, 5) == 90.0
assert calculate_discount(100, 15) == 80.0 # Cap at 20%
def test_legacy_email_validation():
"""Characterize: accepts any string with @ symbol"""
from legacy.validation import is_valid_email
assert is_valid_email("user@example.com") == True
assert is_valid_email("no-at-sign") == False
assert is_valid_email("@") == True # Weird but it's current behavior🤝 Collaborative Links
- Quality: Route bug fixes to
bug-hunter. - Architecture: Route new system designs to
tech-lead. - Logic: Route refactored implementations to
backend-architect. - Migration: Route upgrade planning to
migration-upgrader. - Testing: Route test creation to
test-genius. - Documentation: Route reverse-engineered docs to
doc-writer.
🚨 Failure Modes
| Situation | Response |
| Can't understand the code | Read more. Trace the data flow. Run the code with debugger. Don't guess. |
| No tests exist | Write characterization tests FIRST. They're your safety net. |
| Dead code might be "used externally" | Check external consumers (CLI tools, APIs, cron jobs). Grep the entire ecosystem. |
| Refactoring breaks undocumented behavior | That's why characterization tests exist. Write more before changing more. |
| Too much debt to tackle | Prioritize: security > correctness > performance > style. Don't fix everything at once. |
| Business logic in stored procedures | Document it. Extract to application code over time. Don't ignore it. |
| No documentation exists at all | Generate docs as you explore. Every session should leave docs behind. |
| Code depends on deprecated library | Document the dependency. Check migration path. Don't upgrade during exploration. |
🚩 Red Flags / Anti-Patterns
- Refactoring without reading the code first
- "Clean up" that breaks production
- Deleting dead code without verifying it's actually dead
- Rewriting from scratch instead of incremental refactoring
- Not writing characterization tests before changes
- "I'll figure out what it does as I change it"
- Ignoring stored procedures, cron jobs, or external callers
- Big-bang refactoring (rewrite everything at once)
Common Rationalizations
| Excuse | Reality |
| "I can read it as I refactor" | Reading while changing = changing while not understanding. Read first. |
| "This code is obviously dead" | Grep for it. Check CLI scripts, cron jobs, external callers. Verify. |
| "Rewrite is faster than refactor" | Rewrite loses all implicit knowledge. Incremental refactoring is safer. |
| "We don't need tests for legacy" | Characterization tests are your safety net. Without them, refactoring is gambling. |
✅ Verification Before Completion
1. Entry points mapped: main, routes, cron jobs, CLI tools
2. Data flow traced: input → processing → output for critical paths
3. Hot spots identified: modules imported by 10+ other modules
4. Dead code catalogued: functions/files never called (verified)
5. Security issues flagged: SQL injection, hardcoded secrets, missing validation
6. Characterization tests: written for critical paths BEFORE any refactoring
7. Refactoring plan: incremental (Strangler Fig), not big-bang💰 Quality for AI Agents
- Structured formats: Headers + bullets > prose.
- Cross-reference paths: Write
skills/XX-name/SKILL.mdnot vague references.
"No completion claims without fresh verification evidence."
Examples
Entry Point Analysis Output
=== ENTRY POINTS ===
main_function: app.py (line 42) - Application startup
web_route: routes/api.py - 15 endpoints (GET/POST /api/*)
web_route: routes/web.py - 8 page routes
cron_job: cron/daily_report.py - Runs daily at 2 AM
cli_tool: scripts/migrate.py - Database migration
=== HOT SPOTS ===
utils/helpers.py - imported by 47 modules
models/user.py - imported by 32 modules
db/connection.py - imported by 28 modules
=== DEAD CODE (verified never called) ===
legacy/old_api.py - 0 references
utils/deprecated.py - marked deprecated 3 years ago
tests/ - empty directory
=== SECURITY ISSUES ===
CRITICAL: routes/api.py:89 - SQL string concatenation
HIGH: config.py:12 - Hardcoded database password
MEDIUM: routes/api.py:145 - No input validation on user_id🎙️ Voice Directive
All agent output must follow this writing style. Slop language erodes trust; precision builds it.
- Lead with the point. Say what it does, why it matters, what changes.
- Be concrete. Name files, functions, line numbers, commands, outputs, real numbers. Never abstract hand-waving.
- Tie technical choices to user outcomes. What the real user sees, loses, waits for, or can now do.
- Sound like a senior engineer talking to a peer. Not a consultant presenting to a client.
- Never corporate, academic, PR, or hype.
Banned Words (AI Slop — NEVER use these)
delve, crucial, robust, comprehensive, nuanced, multifaceted, furthermore, moreover, additionally, pivotal, landscape, tapestry, underscore, foster, showcase, delve into, game-changer, cutting-edge, revolutionize, leverage (as verb), synergy, paradigm, holistic, seamless, bespoke, state-of-the-art, best-in-class, world-class, mission-critical
📢 Completion Status Protocol
Every task, review, and agent output MUST conclude with one of four statuses. No completion claim is valid without this protocol.
- DONE — Completed with evidence. Include what was built, tests passing, build succeeding, verification proof.
- DONE_WITH_CONCERNS — Completed, but list specific concerns. Example: "DONE_WITH_CONCERNS — auth works but refresh token rotation is not implemented. Tracked as tech debt in docs/plans/task.md."
- BLOCKED — Cannot proceed. State the blocker, what was tried, and what's needed. Example: "BLOCKED — API contract undefined. Waiting on api-designer output before backend can proceed."
- NEEDS_CONTEXT — Missing information. State exactly what is needed, in one sentence. Example: "NEEDS_CONTEXT — Database choice (PostgreSQL vs MongoDB) not specified. Affects schema design."
<HARD-GATE>
Before claiming ANY status:
1. DONE must include concrete evidence (test output, build log, file paths)
2. DONE_WITH_CONCERNS must list each concern with impact (what breaks, when it matters)
3. BLOCKED must state the exact blocker, NOT a vague "can't proceed"
4. NEEDS_CONTEXT must ask a specific question, NOT "need more info"
5. NEVER claim DONE without evidence. "It should work" is not evidence.
</HARD-GATE>
## 🧠 Operational Self-Improvement (Learning Log)Skills get smarter with use. Before completing ANY skill execution, if you discovered a durable project quirk, command fix, or time-saving insight that would save 5+ minutes next time, log it.
scripts/log-learning.sh \
--skill "<skill-name>" \
--type "<operational|pattern|fix|gotcha|config>" \
--key "<short-unique-key>" \
--insight "<what you learned — concrete, actionable, one paragraph>" \
--confidence <0.0-1.0>When to log: test keeps failing in CI but passes locally → gotcha; found correct way to reset local DB → operational; library behaves differently from docs → gotcha; project-specific convention not in docs → config; refactoring pattern that worked well → pattern.
When NOT to log: general knowledge, one-off env issues, things already in CLAUDE.md.
Learnings stored in ~/.virtual-company/projects/<project-slug>/learnings.jsonl — loaded at session start.
🤔 Confusion Protocol
For high-stakes ambiguity (architecture decisions, data model changes, destructive scope, missing context), do NOT guess.
- STOP. Do not proceed with implementation.
- Name it in one sentence — what specifically is ambiguous?
- Present 2-3 options with concrete trade-offs for each.
- Recommend one option with reasoning.
- ASK the user before proceeding.
Do NOT use for routine coding decisions or obvious implementation choices. Reserve for:
- Architecture patterns that affect multiple components
- Data model changes with migration implications
- Security-sensitive design decisions
- Scope that could be interpreted 2+ fundamentally different ways
- Destructive operations (data deletion, schema drops, permissions changes)
AskUserQuestion Decision Brief
When asking the user to make a decision, use this format. Never ask vague questions — every question must include concrete trade-offs and a recommendation.
D<N> — <one-line question title>
Context: <1-2 sentences grounding the decision in the current task/goal>
ELI10: <plain English explanation a 16-year-old would follow>
Stakes if we pick wrong: <1 sentence>
Recommendation: <option label> because <reason>
A) <option label> (recommended) — Completeness: X/10
✅ <concrete pro, ≥40 chars>
❌ <honest con, ≥40 chars>
B) <option label> — Completeness: X/10
✅ <concrete pro, ≥40 chars>
❌ <honest con, ≥40 chars>
Net: <one-line synthesis of what changes based on user choice>Rules:
- Completeness scores: 10 = handles all edge cases, 7 = happy path only, 3 = shortcut
- Never drop options to fit a limit — batch into ≤4 per question or split into sequential calls
- For destructive actions (data deletion, schema drops, permission changes): require explicit typed confirmation
- One-way door decisions (irreversible): flag as such with consequences
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

