← 研究筆記
將儲存庫交給 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,並用它處理自己的原始碼。

repomix 會掃描儲存庫,將檔案清單、目錄結構和檔案內容合併成一個檔案,過程中也會執行內建的機密掃描。這個專案以 MIT 授權條款發布原始碼 (*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 生態系中常見的預設規則組。我在 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