← 研究笔记
把代码仓库交给 LLM 前先检查:运行 repomix

把代码仓库交给 LLM 前先检查:运行 repomix

记录在无网络访问的情况下运行 repomix 的过程。这个 CLI 会把整个代码仓库打包成一个文件,供 LLM 使用;我检查了它的 token 构成和内置的密钥扫描功能。

本文涉及的仓库

yamadashy/repomix

📦 Repomix is a powerful tool that packs your entire repository into a single, AI-friendly file. Perfect for when you need to feed your codebase to Large Language Models (LLMs) or other AI tools like Claude, ChatGPT, DeepSeek, Perplexity, Gemini, Gemma, Llama, Grok, and more.

27.2k TypeScript MIT License

把整个代码仓库交给 LLM 之前,需要先检查两件事:token 数量,以及是否可能不小心把密钥或凭据一起交出去。手动检查很耗时,最后可能还没检查就把仓库交了出去。repomix 在把仓库打包成一个文件的同时,能够处理这两项工作。我构建了它,并用它处理了自己的源代码。

repomix 会扫描代码仓库,把文件列表、目录结构和文件内容合并到一个文件中。在这个过程中,它还会运行内置的密钥扫描。该项目以 MIT License(*1)发布源代码。

1. 安装

repomix 使用 Node.js,依赖项很少。容器镜像很快就构建完成了。

FROM docker.io/library/node:24.18.0-slim
RUN npm install -g repomix@1.16.1
WORKDIR /work
podman build -t repomix-sandbox .

2. 打包它自己的源代码

我把 repomix 自己的 src 目录作为目标,并在无网络访问的情况下运行了命令。

podman run --rm --network none --memory 2g --cpus 2 --pids-limit 512 --userns=keep-id \
  -v "$(pwd)":/work -w /work repomix-sandbox \
  repomix src --style markdown --output /work/output.md

-v 会让指定目录在容器内可供读取和写入。请使用一个专门为本次实验准备的空目录,不要在其中放置私钥或凭据。

命令生成了以下输出:

📈 Top 5 Files by Token Count:
──────────────────────────────
1.  core/skill/skillTechStack.ts (4,837 tokens, 19,462 chars, 3.4%)
2.  core/file/fileSearch.ts (4,408 tokens, 19,575 chars, 3.1%)
3.  cli/cliRun.ts (3,929 tokens, 16,962 chars, 2.8%)
4.  core/output/outputGenerate.ts (3,750 tokens, 16,895 chars, 2.6%)
5.  core/metrics/tokenCountCache.ts (3,599 tokens, 14,905 chars, 2.5%)

🔎 Security Check:
──────────────────
✔ No suspicious files detected.

📊 Pack Summary:
────────────────
  Total Files: 137 files
 Total Tokens: 142,511 tokens
  Total Chars: 604,068 chars
       Output: output.md
     Security: ✔ No suspicious files detected

把仓库交出去之前,可以利用每个文件的 token 数量,找出占总量比例最大的文件。repomix 原样使用了 @secretlint/secretlint-rule-preset-recommend,这是 JS/TS 生态中常见的 preset。我确认它在 src/core/security/ 下被使用。目标中没有可疑文件,因此扫描以“no suspicious files”结束。这次扫描没有发现目标中需要标记的问题。本次运行并没有测试扫描功能的检测准确性。如果要交出的仓库中包含密钥或凭据,请务必自行检查结果,并把它当作一项检查来使用。

生成的 output.md 开头会说明文件格式和目录结构,并介绍如何加载代码仓库提供的“Repository Instruction”。由于用户可以在下一步把打包结果交给 LLM,repomix 还为它的 LLM 读者附带了一份使用指南。

交接前检查 token 规模和风险

把代码库交给 LLM 时,有两项常规检查:估算 token 规模,以及评估风险。repomix 把两项检查合并到一个命令中,因此可以在打包仓库的同时完成检查。工具默认就会执行这些检查,不需要在每次交接前重新决定要检查什么。

来源

*1 repomix(GitHub),https://github.com/yamadashy/repomix,MIT License