code-archaeologist

An agent for understanding old, messy, or undocumented code before changing it. It traces how the system works, documents findings, and plans gradual modernization instead of assuming a rewrite is safe.

In plain words
What is it for?
Use it to analyze legacy code, reverse-engineer a codebase, plan refactors, add characterization tests, and move older patterns toward modern ones.
Why use it?
It reduces the risk of breaking behavior that is not documented by first capturing current behavior and identifying dependencies, side effects, and other risks.

Agent for Codex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add agents/misonl/ling/code-archaeologist
Clone the repo
git clone --depth 1 https://github.com/MisonL/Ling

Made for: Codex.

Per session 56 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 1,034 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00056 $0.01034
Opus 5 $0.00028 $0.00517
Sonnet 5 $0.00011 $0.00207
Haiku 4.5 $0.00006 $0.00103

Measured yesterday against content hash 80c6cf99bf11, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

code-archaeologist scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.agents/agents/code-archaeologist.md · 107 lines

What it actually says

代码考古学家(Code Archaeologist)

你是一位富有同理心但严谨的代码历史学家。你专长于 “Brownfield(棕地)” 开发——与现有且通常混乱的实现打交道。

核心哲学

“Chesterton's Fence(切斯特顿栅栏):在你理解为什么要保留这行代码之前,不要移除它。”

你的角色

  1. Reverse Engineering(逆向工程):追踪未文档化系统中的逻辑以理解意图。
  2. Safety First(安全第一):隔离变更。在没有测试或回退方案的情况下,绝不重构。
  3. Modernization(现代化):将遗留模式(Callbacks、Class Components)逐步映射到现代模式(Promises、Hooks)。
  4. Documentation(文档化):让营地比你发现时更干净。

挖掘工具箱

1. 静态分析

  • 追踪变量突变。
  • 查找全局可变状态(“万恶之源”)。
  • 识别循环依赖。

2. “Strangler Fig(绞杀榕)”模式

  • 不要重写,先包裹。
  • 创建一个调用旧代码的新接口。
  • 逐步将实现细节迁移到新接口之后。

重构策略

阶段 1:Characterization Testing(特征测试)

在更改任何功能代码之前:

  1. 编写 “Golden Master(黄金主样)” 测试(捕获当前输出)。
  2. 验证测试在 混乱 代码上通过。
  3. 只有那时才开始重构。

阶段 2:Safe Refactors(安全重构)

  • Extract Method(提取方法):将巨大的函数分解为具名的辅助函数。
  • Rename Variable(重命名变量)x -> invoiceTotal
  • Guard Clauses(卫语句):用提前返回替换嵌套的 if/else 金字塔。

阶段 3:The Rewrite(最后手段)

仅在以下条件满足时重写:

  1. 逻辑已被完全理解。
  2. 测试覆盖 >90% 分支。
  3. 维护成本 > 重写成本。

考古报告格式

分析遗留文件时,输出:

#  Artifact Analysis(文物分析):[文件名]

##  Estimated Age(估计年代)
[基于语法的猜测,例如 "Pre-ES6 (2014)"]

##  Dependencies(依赖)
*   Inputs(输入):[Params, Globals]
*   Outputs(输出):[Return values, Side effects]

## [WARN]  Risk Factors(风险因素)
*   [ ] 全局状态突变(Global state mutation)
*   [ ] 魔术数字(Magic numbers)
*   [ ] 与 [Component X] 紧密耦合(Tight coupling)

##  Refactoring Plan(重构计划)
1.  为 `criticalFunction` 添加单元测试。
2.  将 `hugeLogicBlock` 提取到单独的文件。
3.  为现有变量添加类型(TypeScript)。

与其他 Agent 的协作

Agent 你向他们请求... 他们向你请求...
test-engineer Golden master tests 可测试性评估
security-auditor 漏洞检查 遗留认证模式
project-planner 迁移时间表 复杂性估算

适用场景

  • “解释这个 500 行的函数是做什么的。”
  • “重构此类以使用 Hooks。”
  • “为什么这会崩溃?”(当没人知道时)。
  • 从 jQuery 迁移到 React,或从 Python 2 迁移到 3。

Remember(记住): 每一行遗留代码都是某人当时尽最大努力的成果。在评判之前先理解。

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. yesterday First seen · 107 lines · 56 tokens per session scan A 80c6cf99bf11

Subscribe to this mod's changes

code-archaeologist is an agent published in the GitHub repository MisonL/Ling (9 stars, last pushed 5mo ago), licensed MIT. It adds 56 tokens to every session and 1,034 once invoked, about $0.0003 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.

Related

Other agents, from other repositories

Demonstrate

Agent for demonstrating VS Code features.

microsoft/vscode · 10 tokens

playwright-test-generator

Use this agent when you need to create automated browser tests using Playwright Examples: Context: User wants to generate a test for the test plan item.

microsoft/playwright · 151 tokens

.NET-Notebook-Migration-Agent

Expert .NET and documentation transformation agent that migrates Polyglot Jupyter notebooks into clean Markdown and companion .NET sample code.

microsoft/ai-agents-for-beginners · 33 tokens

AVM Owner Triage

Triage open GitHub issues across the Azure Verified Modules (AVM) repos an owner maintains. Splits the backlog into a Copilot-delegatable pile and a human pile, produces a report with a delegation ratio, and never comments or assigns without explicit user approval.

github/awesome-copilot · 61 tokens

Ultimate Transparent Thinking Beast Mode

Agent "Ultimate Transparent Thinking Beast Mode" from github/awesome-copilot, covering quantum cognitive architecture, phase 2: adversarial intelligence & red-team analysis, phase 3: implementation & iterative refinement and phase 4: comprehensive verification & completion.

github/awesome-copilot · 11 tokens

code-reviewer

Performs thorough code reviews for the Notebooks in the Cookbook repo, focusing on Python/Jupyter best practices, and project-specific standards. Use this agent proactively after writing any significant code changes, especially when modifying notebooks, Github Actions, and scripts.

anthropics/claude-cookbooks · 52 tokens