/agentsop-repo-map
Symbol-level code context for LLM coder-agents: tree-sitter extracts symbols, PageRank ranks them over the cross-file reference graph, and the top class/function signatures are fed to the LLM as a token-budgeted read-only map (not RAG, no vector index, human-auditable). Use when
$ npx -y skills add agentsope/SkillAlchemy --skill agentsop-repo-map --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
- Fires itselfAuto-invocation. Claude auto-loads it when your prompt matches the work.Auto-invocation is when the right skill fires by itself at the right moment, driven by a FLOW.md router and a hook, instead of you invoking it by name. It is the difference between a skill being installed and a skill actually getting used.Read the full definition →
- You can call itInvoke it directly when you want it.
- Slash command
/agentsop-repo-map
Context preview
The summary Claude sees to decide when to auto-load this skill.
Symbol-level code context for LLM coder-agents: tree-sitter extracts symbols, PageRank ranks them over the cross-file reference graph, and the top class/function signatures are fed to the LLM as a token-budgeted read-only map (not RAG, no vector index, human-auditable). Use when
SKILL.md
agentsop-repo-map.SKILL.mdname: agentsop-repo-map
version: 0.1.0
description: >-
Symbol-level code context for LLM coder-agents: tree-sitter extracts symbols, PageRank ranks them over the cross-file reference graph, and the top class/function signatures are fed to the LLM as a token-budgeted read-only map (not RAG, no vector index, human-auditable). Use when an agent must locate the right files in a large/multi-file repo, when builds/refreshes/scopes a repo-map, or when "model edits the wrong file" needs fixing.
domain: symbol-level code context for LLM coder-agents
source: aider.chat repo-map docs + Paul Gauthier blog + SWE-Bench Lite evidence + cross-tool comparison
audience: coder-agents (Aider/Cline/Cursor/Continue/OpenHands/custom) editing multi-file repositories via LLMs
status: specialized but high-leverage; hits on every multi-file edit
Repo-Map — 让 LLM 在大仓库里找到正确文件
> 一句话:**`tree-sitter` 抽取符号 → 在跨文件引用图上跑 PageRank → 按 token 预算把最重要的 class/function 签名作为只读地图塞进上下文**。它不是 RAG、不维护向量索引、可被人审。Aider 用同样的机制在 SWE-Bench Lite 上把"正确文件命中率"打到 **70.3%** [aider.chat/2024/05/22/swe-bench-lite.html]。
这是一个**工具技能**(tool skill),不绑定 Aider;任何 coder-agent harness 只要能给 LLM 喂上下文,都可以接入或自建 repo-map。
1. 何时激活本技能
下列任一条件成立时,将"构建/刷新/使用 repo-map"作为该会话的标准动作:
- 任务涉及 **多文件编辑** 或 **跨文件影响分析**(rename、抽函数、改 API 签名、加 hook 点)。
- 仓库 ≥ ~20 个源文件,或 LLM 无法靠记忆/猜测找到正确目标。
- 你不想(或不能)维护 embedding 索引:环境无 GPU、不允许出仓数据、PR 评审需可追溯证据。
- 你想给 LLM **可审计的导航地图**(vs. 黑盒向量检索)。`/map` 一样的 dump 必须能给人看。
- 多文件编辑后 LLM 反复改错文件、编造路径、SEARCH/REPLACE 找不到目标——典型的"没地图就乱走"信号。
- 你在写**自定义 coder agent**,需要一个"廉价、确定性、即时刷新"的代码 context 原语。
**不应激活的反面信号**:单文件改动且文件已知;任务是从零起项目;二进制资产仓库;非源代码(CSV/data lake)—— 详见 §6。
2. 核心心智模型
2.1 三个原语 + 两个不变量
+----------------------+ +-----------------------+ +-----------------------+
| 1. tree-sitter | | 2. cross-file graph | | 3. token budget |
| symbol extraction |-->| + PageRank-style |-->| (dynamic, shrink |
| | | importance rank | | when files added) |
| - parse, no execute | | - nodes = files | | - default ~1k tokens |
| - class / fn / sig | | - edges = symbol refs | | - cap configurable |
| - works offline, | | - PageRank picks | | - 0 = disabled |
| no LLM call | | "most referenced" | | |
+----------------------+ +-----------------------+ +-----------------------+
|
v
+-----------------------------------+
| Output: skeleton text in prompt |
| (NOT a tool-call, NOT a vector) |
| |
| path/to/file.py: |
| class Auth: |
| def login(user, pwd) -> T |
| def logout() -> None |
| def hash_password(pwd) -> str |
+-----------------------------------+**不变量 A — Skeleton over snippets**:地图只放 **签名/类名/函数名**,不放函数体。LLM 真要看实现,就**让它点名要文件**——这是 read-only navigation aid,不是 retriever。
> "If it needs to see more code, the LLM can use the map to figure out which files it needs to look at." [aider.chat/docs/repomap.html]
**不变量 B — Dynamic budget**:当对话还没加载任何文件时,地图**展开**到上限(给 LLM 最多导航信息);一旦真的把文件加进可读写上下文,地图**自动收缩**(省下的 token 让给真代码)。
> "Aider adjusts the size of the repo map dynamically based on the state of the chat." [aider.chat/docs/repomap.html]
2.2 为什么不用 embeddings/RAG(设计决策)
| 维度 | Repo-map (tree-sitter + PageRank) | Embedding RAG | |---|---|---| | LLM 可读性 | 真签名,LLM 能直接推理 | 向量,LLM 看不懂;只能信检索器选出的片段 | | 索引维护 | 无;每次会话按需重建 | 需要 chunker + embedder + 向量库 + 失效策略 | | 确定性 | 同代码同输入 → 同地图 | embedding 模型/参数变化 → 检索结果漂移 | | 可审计 | 一段纯文本,能 `cat`、能 diff、能给 reviewer 看 | 黑盒:哪些 chunk 被选不直观 | | 出仓风险 | 全本地静态分析 | 通常调用外部 embedding API | | 失败模式 | tree-sitter 不支持该语言 → 优雅降级 | 语义距离 ≠ 调用关系,错召回 |
**核心判据**:编辑代码的瓶颈是"**找到要改的文件**",不是"找到语义相近的段落"。LLM 在签名级别上做"我该改哪里"的推理远比让向量替它推理强。
> Aider's repo-map "successfully identified the correct file to edit in **70.3%** of the benchmark tasks." 这一数字**不依赖 embeddings、不依赖代码执行、不依赖网络** [aider.chat/2024/05/22/swe-bench-lite.html]。
2.3 LLM 看到的上下文分三层(优先级递减)
| 层 | 内容 | 写权限 | |---|---|---| | 系统/编辑格式 | harness 固化 | harness | | **Repo-map**(本技能) + read-only files + CONVENTIONS | **只读上下文** | 人/agent 配置 | | Read-write files | LLM 唯一允许编辑的 | 人/agent 显式加入 |
**铁律**:repo-map 是**地图**,不是**写集合**。LLM 看见某个文件在地图里 ≠ 它能编辑它。**写集合永远只由人/agent 显式声明**(在 Aider 里是 `/add`;在自建 harness 里是"可编辑文件白名单")。这条边界是 repo-map 安全使用的前提。
2.4 25k token 的稀释阈
> "Above about 25k tokens of context, most models start to become distracted." [aider.chat/docs/troubleshooting/edit-errors.html]
repo-map **本身就在 token 预算里**。如果地图占太大,反而稀释了真正的源码上下文。所以预算需要"够找路 + 不挤压代码"。经验起点:1k–4k tokens;monorepo 上限 8k;超过就要靠**子目录/ignore 文件**先缩小搜索范围(§3 Phase 4)。
2.5 Skeleton-over-snippets 的工程含义
| 选 skeleton | 选 snippets | |---|---| | 全仓导航、定位修改点 | 已锁定 ≤5 个文件、想看实现细节 | | Token 预算紧 | 真的需要函数体语义 | | 多语言混合 | 单语言、深度分析 |
skeleton 给"哪儿",snippets 给"怎么"。**永远先 skeleton,再 snippets**——倒过来会把预算烧光、还没找到对的文件。
3. SOP 工作流
Phase 1 — Bootstrap:建图(每会话一次)
1. 确认仓库类型:源码 + git 历史。否则不要用 repo-map(见 §6)。
2. 应用 ignore 列表:
- .gitignore(必)
- 自定义 ignore(如 Aider 的 .aiderignore;自建 agent 可直接复用)
- 默认排除:vendor/, node_modules/, dist/, build/, *.min.js, generated/
3. 选定 tree-sitter 语言集:
- 主流(Python/JS/TS/Go/Rust/Java/C/C++/Ruby/PHP/...) 默认开
- 小众语言:要么接 grammars,要么留作 fallback(只列文件路径)
4. 设定 token 预算:
- 小仓库(<200 文件): 1k–2k
- 中等(200–2000 文件): 2k–4k
- Monorepo(>2000 文件): 4k–8k + 限定子目录
5. 首次运行:构建符号表 + 引用图 + PageRank。后续增量更新。输出物:一段纯文本骨架(path + 类/函数签名),符合 token 预算。
Phase 2 — Use:让 LLM 用地图回答"改哪里"
**反模式**:人类拍脑袋决定加哪些文件 → 漏文件、加多文件。
**正确模式**:把"定位"问题外包给 LLM + repo-map。
[harness 提供给 LLM 的上下文]
- system prompt
- repo-map skeleton (read-on
Read more
name: agentsop-repo-map version: 0.1.0 description: >- Symbol-level code context for LLM coder-agents: tree-sitter extracts symbols, PageRank ranks them over the cross-file reference graph, and the top class/function signatures are fed to the LLM as a token-budgeted read-only map (not RAG, no vector index, human-auditable). Use when an agent must locate the right files in a large/multi-file repo, when builds/refreshes/scopes a repo-map, or when "model edits the wrong file" needs fixing. domain: symbol-level code context for LLM coder-agents source: aider.chat repo-map docs + Paul Gauthier blog + SWE-Bench Lite evidence + cross-tool comparison audience: coder-agents (Aider/Cline/Cursor/Continue/OpenHands/custom) editing multi-file repositories via LLMs status: specialized but high-leverage; hits on every multi-file edit
Repo-Map — 让 LLM 在大仓库里找到正确文件
> 一句话:**`tree-sitter` 抽取符号 → 在跨文件引用图上跑 PageRank → 按 token 预算把最重要的 class/function 签名作为只读地图塞进上下文**。它不是 RAG、不维护向量索引、可被人审。Aider 用同样的机制在 SWE-Bench Lite 上把"正确文件命中率"打到 **70.3%** [aider.chat/2024/05/22/swe-bench-lite.html]。
这是一个**工具技能**(tool skill),不绑定 Aider;任何 coder-agent harness 只要能给 LLM 喂上下文,都可以接入或自建 repo-map。
1. 何时激活本技能
下列任一条件成立时,将"构建/刷新/使用 repo-map"作为该会话的标准动作:
- 任务涉及 **多文件编辑** 或 **跨文件影响分析**(rename、抽函数、改 API 签名、加 hook 点)。
- 仓库 ≥ ~20 个源文件,或 LLM 无法靠记忆/猜测找到正确目标。
- 你不想(或不能)维护 embedding 索引:环境无 GPU、不允许出仓数据、PR 评审需可追溯证据。
- 你想给 LLM **可审计的导航地图**(vs. 黑盒向量检索)。`/map` 一样的 dump 必须能给人看。
- 多文件编辑后 LLM 反复改错文件、编造路径、SEARCH/REPLACE 找不到目标——典型的"没地图就乱走"信号。
- 你在写**自定义 coder agent**,需要一个"廉价、确定性、即时刷新"的代码 context 原语。
**不应激活的反面信号**:单文件改动且文件已知;任务是从零起项目;二进制资产仓库;非源代码(CSV/data lake)—— 详见 §6。
2. 核心心智模型
2.1 三个原语 + 两个不变量
+----------------------+ +-----------------------+ +-----------------------+
| 1. tree-sitter | | 2. cross-file graph | | 3. token budget |
| symbol extraction |-->| + PageRank-style |-->| (dynamic, shrink |
| | | importance rank | | when files added) |
| - parse, no execute | | - nodes = files | | - default ~1k tokens |
| - class / fn / sig | | - edges = symbol refs | | - cap configurable |
| - works offline, | | - PageRank picks | | - 0 = disabled |
| no LLM call | | "most referenced" | | |
+----------------------+ +-----------------------+ +-----------------------+
|
v
+-----------------------------------+
| Output: skeleton text in prompt |
| (NOT a tool-call, NOT a vector) |
| |
| path/to/file.py: |
| class Auth: |
| def login(user, pwd) -> T |
| def logout() -> None |
| def hash_password(pwd) -> str |
+-----------------------------------+**不变量 A — Skeleton over snippets**:地图只放 **签名/类名/函数名**,不放函数体。LLM 真要看实现,就**让它点名要文件**——这是 read-only navigation aid,不是 retriever。
> "If it needs to see more code, the LLM can use the map to figure out which files it needs to look at." [aider.chat/docs/repomap.html]
**不变量 B — Dynamic budget**:当对话还没加载任何文件时,地图**展开**到上限(给 LLM 最多导航信息);一旦真的把文件加进可读写上下文,地图**自动收缩**(省下的 token 让给真代码)。
> "Aider adjusts the size of the repo map dynamically based on the state of the chat." [aider.chat/docs/repomap.html]
2.2 为什么不用 embeddings/RAG(设计决策)
| 维度 | Repo-map (tree-sitter + PageRank) | Embedding RAG | |---|---|---| | LLM 可读性 | 真签名,LLM 能直接推理 | 向量,LLM 看不懂;只能信检索器选出的片段 | | 索引维护 | 无;每次会话按需重建 | 需要 chunker + embedder + 向量库 + 失效策略 | | 确定性 | 同代码同输入 → 同地图 | embedding 模型/参数变化 → 检索结果漂移 | | 可审计 | 一段纯文本,能 `cat`、能 diff、能给 reviewer 看 | 黑盒:哪些 chunk 被选不直观 | | 出仓风险 | 全本地静态分析 | 通常调用外部 embedding API | | 失败模式 | tree-sitter 不支持该语言 → 优雅降级 | 语义距离 ≠ 调用关系,错召回 |
**核心判据**:编辑代码的瓶颈是"**找到要改的文件**",不是"找到语义相近的段落"。LLM 在签名级别上做"我该改哪里"的推理远比让向量替它推理强。
> Aider's repo-map "successfully identified the correct file to edit in **70.3%** of the benchmark tasks." 这一数字**不依赖 embeddings、不依赖代码执行、不依赖网络** [aider.chat/2024/05/22/swe-bench-lite.html]。
2.3 LLM 看到的上下文分三层(优先级递减)
| 层 | 内容 | 写权限 | |---|---|---| | 系统/编辑格式 | harness 固化 | harness | | **Repo-map**(本技能) + read-only files + CONVENTIONS | **只读上下文** | 人/agent 配置 | | Read-write files | LLM 唯一允许编辑的 | 人/agent 显式加入 |
**铁律**:repo-map 是**地图**,不是**写集合**。LLM 看见某个文件在地图里 ≠ 它能编辑它。**写集合永远只由人/agent 显式声明**(在 Aider 里是 `/add`;在自建 harness 里是"可编辑文件白名单")。这条边界是 repo-map 安全使用的前提。
2.4 25k token 的稀释阈
> "Above about 25k tokens of context, most models start to become distracted." [aider.chat/docs/troubleshooting/edit-errors.html]
repo-map **本身就在 token 预算里**。如果地图占太大,反而稀释了真正的源码上下文。所以预算需要"够找路 + 不挤压代码"。经验起点:1k–4k tokens;monorepo 上限 8k;超过就要靠**子目录/ignore 文件**先缩小搜索范围(§3 Phase 4)。
2.5 Skeleton-over-snippets 的工程含义
| 选 skeleton | 选 snippets | |---|---| | 全仓导航、定位修改点 | 已锁定 ≤5 个文件、想看实现细节 | | Token 预算紧 | 真的需要函数体语义 | | 多语言混合 | 单语言、深度分析 |
skeleton 给"哪儿",snippets 给"怎么"。**永远先 skeleton,再 snippets**——倒过来会把预算烧光、还没找到对的文件。
3. SOP 工作流
Phase 1 — Bootstrap:建图(每会话一次)
1. 确认仓库类型:源码 + git 历史。否则不要用 repo-map(见 §6)。
2. 应用 ignore 列表:
- .gitignore(必)
- 自定义 ignore(如 Aider 的 .aiderignore;自建 agent 可直接复用)
- 默认排除:vendor/, node_modules/, dist/, build/, *.min.js, generated/
3. 选定 tree-sitter 语言集:
- 主流(Python/JS/TS/Go/Rust/Java/C/C++/Ruby/PHP/...) 默认开
- 小众语言:要么接 grammars,要么留作 fallback(只列文件路径)
4. 设定 token 预算:
- 小仓库(<200 文件): 1k–2k
- 中等(200–2000 文件): 2k–4k
- Monorepo(>2000 文件): 4k–8k + 限定子目录
5. 首次运行:构建符号表 + 引用图 + PageRank。后续增量更新。输出物:一段纯文本骨架(path + 类/函数签名),符合 token 预算。
Phase 2 — Use:让 LLM 用地图回答"改哪里"
**反模式**:人类拍脑袋决定加哪些文件 → 漏文件、加多文件。
**正确模式**:把"定位"问题外包给 LLM + repo-map。
[harness 提供给 LLM 的上下文] - system prompt - repo-map skeleton (read-on
Other skills on skillalchemy.
- /LEAP
LEAP — 落地执行引擎。内含两条管线:A 分支蒸馏(从 raw data 提取 skill)、 B 分支融合(多 skill 编织为一个)。被 SkillAlchemy 编排器调用。 Use when 编排器判断需要蒸馏或融合时。
Open skill - /Lens
Lens — 给你的问题加一层认知镜片。输入任意任务描述,输出增强版 description, 发现「你不知道自己不知道」的隐性维度、前置条件和认知路线。 Use when 用户说「帮我想想」「分析一下」「生成 skill」「蒸馏」「融合」 或输入看起来太简单需要展开。
Open skill - /agentsop-agent-topology-selection
Cross-framework enhancement overlay for choosing a multi-agent topology BEFORE writing any agent. A binary-question rubric — is single-agent + tools enough? do agents need to know about each other? does the output need one voice? — maps the answer to single-agent / supervisor /
Open skill - /agentsop-aider
SOP for terminal-based, git-native AI pair programming with Aider (git work-tree + tree-sitter repo-map + edit-format + human-in-loop REPL). Use when editing code in an existing git repo via an LLM, when you need to converge a change to 2-5 files, pick an edit format that fits
Open skill - /agentsop-bio-fraud-forensics
Screens biomedical / life-science papers for signs of data fabrication, image manipulation, and statistical anomalies, using the detection techniques distilled from the field's canonical exposure platforms (PubPeer, Data Colada, Science Integrity Digest, For Better Science) and
Open skill - /agentsop-bounded-loop
Universal discipline for any LM-driven loop — agent retries, plan-act-observe, multi-agent handoffs, optimiser passes, test-fix cycles. Encodes the one rule every framework documents quietly and every team relearns expensively: the LM in the loop is NEVER a reliable terminator.
Open skill

