Coding Guidelines

📅 发布时间:2026/9/13 2:14:30
Coding Guidelines
Coding Guidelines【免费下载链接】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.项目地址: https://gitcode.com/GitHub_Trending/rep/repomixFollow the Airbnb JavaScript Style GuideSuggest splitting files into smaller, focused units when appropriateAdd comments for non-obvious logic. Keep all text in EnglishAll new features should have corresponding unit testsGenerate Comprehensive OutputInclude all content without abbreviation, unless specified otherwiseOptimize for handling large codebases while maintaining output quality然后在配置中加入 json5 { output: { instructionFilePath: repomix-instruction.md, // other options... } }指令内容会追加在输出文件末尾的专属区段。长上下文资料置于提示词顶部、查询与指令置于底部能显著提升模型响应质量。8.6 注释移除output.removeComments设为true时会尝试移除支持类型文件的注释减小输出并聚焦核心代码。支持语言HTML、CSS、JavaScript、TypeScript、Vue、Svelte、Python、PHP、Ruby、C、C#、Java、Go、Rust、Swift、Kotlin、Dart、Shell、YAML。注意注释移除采用保守策略以避免误删代码复杂情况下部分注释可能被保留。8.7 文件处理器input.processorsinput.processors在打包之前用外部命令转换文件内容匹配文件的原始内容被命令的 stdout 替换——适用于降 Token 或格式转换JSON→TOON、SVG 压缩、notebook→脚本{ input: { processors: [ { pattern: **/*.json, command: npx toon-format/cli {file} } ] } }{file}占位符必填会被替换为保存文件内容的临时文件路径命令 stdout 成为新内容。模式按序求值、首个匹配生效每文件一个处理器。每项还接受timeout毫秒默认60000与onErrorfail中止打包为默认skip警告并保留原始内容。Schema 约束见 configSchema.ts。常用示例模式command作用**/*.jsonjq -c . {file}去除空白压缩 JSON**/*.jsonnpx toon-format/cli {file}转换为紧凑的 TOON 格式**/*.svgnpx svgo -i {file} -o -压缩 SVG**/*.ipynbjupyter nbconvert --to script --stdout {file}将 Jupyter notebook 转为纯 Python 脚本警告文件处理器会执行配置文件中的任意命令因此默认拒绝执行仅本地 CLI 运行启用——与 npm 脚本或 Makefile 同级的信任边界。若你在他人提供的仓库中运行repomix而未先审查其repomix.config.json处理器命令将在你的机器上执行务必先审查不受信任仓库的配置。对库 APIpack()/runCli()、MCP 服务器与托管网站禁用cliRun.ts 仅在真实 CLI 入口注入enableFileProcessors: true。远程仓库--remote只有在显式传入--remote-trust-config时才信任克隆的配置及处理器否则远程配置根本不会被加载。凭证请通过环境变量如$TOKEN引用而非内联日志打印的是未展开的变量名超时时 Repomix 会杀掉命令的 shell但命令自拉起的常驻后台进程可能残留。九、安全检测Repomix 内置基于 Secretlint 的安全检查检测文件中潜在的敏感信息帮助你在分享打包仓库前识别风险。检测结果在打包完成后显示于 CLI 输出 Security Check: ────────────────── 2 suspicious file(s) detected: 1. src/utils/test.txt 2. tests/utils/secretLintUtils.test.ts Please review these files for potentially sensitive information.默认启用。可关闭{ security: { enableSecurityCheck: false } }或使用 CLI 选项repomix --no-security-check关闭安全检查可能泄露敏感信息仅在测试文件或含示例凭据的文档等必要场景使用。实现上securityCheck.ts 会把文件内容以及启用时的 git diff、git log 内容分批每批 50 项交给最多 2 个 worker 线程的线程池执行 secretlint 检测返回可疑文件结果后packager.ts 会从最终输出中剔除这些文件。检测规则本身位于 workers/securityCheckWorker.ts。远程仓库配置信任repomix.config.*是代码而非纯数据.ts/.js配置加载时会被执行input.processors会运行外部命令路径选项可读取仓库外文件。加载陌生仓库的配置约等于运行它的 Makefile。因此克隆仓库的配置默认绝不加载你的全局配置与 CLI 选项仍然生效。用--remote-trust-config或REPOMIX_REMOTE_TRUST_CONFIGtrue选择信任时交互式终端会先展示即将运行的配置再询问Yes, once—— 仅信任本次运行。Yes, and dont ask again for this repository—— 决策基于内容固定content-pinned记录所批准配置的哈希若该仓库之后变更配置会再次询问direnv allow 模式。No默认选中—— 中止且不加载配置。展示的配置会转义控制字符、ANSI 与双向字符输出有上限、每行加前缀指向克隆目录外的符号链接配置会被拒绝——你审查的就是将运行的。该提示在--force、非交互 shell如 CI以及已选择始终信任时跳过。重要内容固定仅覆盖入口配置文件。.ts/.js配置可以import其他文件input.processors可以调用外部脚本这些都不会被哈希。请将不再询问理解为对该仓库的信任而不只是对读到的那个文件的信任。远程信任决策的持久化实现位于 remoteConfigTrustStore.ts提示 UI 见 remoteConfigTrustPrompt.ts。十、MCP 服务器集成Repomix 支持 Model Context ProtocolMCP让 AI 助手直接与你的代码库交互。以 MCP 服务器运行时Repomix 提供工具让 AI 无需手动准备文件即可打包本地或远程仓库repomix --mcpMCP 服务器入口见 mcpServer.ts工具注册与运行见 mcpToolRuntime.ts。10.1 沙箱模式默认 MCP 服务器可读取宿主用户可读的任何路径——对可信本地助手方便但对不可信客户端或 Agent 过于宽泛。--sandbox将文件工具限制在单一工作区内# 限制在当前工作目录 repomix --mcp --sandbox # 限制在指定目录 repomix --mcp --sandbox path/to/project沙箱开启时所有路径都相对于工作区根绝对路径、~、..、Windows 盘符/UNC 路径以及通过符号链接解析到根之外的路径均被拒绝且只注册只读、根受限的工具远程打包、Skill 生成、附加外部输出均被禁用。原始文件工具file_system_read_file、file_system_read_directory仅在沙箱模式下可用。这是工具面的应用层限制而非操作系统级沙箱。路径约束实现见 pathScope.ts。10.2 配置 MCP 服务器VS Code两种方式任选其一使用安装徽章一键安装npx -y repomix --mcp。命令行code --add-mcp {name:repomix,command:npx,args:[-y,repomix,--mcp]} code-insiders --add-mcp {name:repomix,command:npx,args:[-y,repomix,--mcp]}ClineVS Code 扩展编辑cline_mcp_settings.json{ mcpServers: { repomix: { command: npx, args: [-y, repomix, --mcp] } } }Cursor在Cursor SettingsMCP Add new global MCP server中添加类似配置。Claude Desktop编辑claude_desktop_config.json配置与 Cline 类似。Claude Codeclaude mcp add repomix -- npx -y repomix --mcp使用 Docker 而非 npx{ mcpServers: { repomix-docker: { command: docker, args: [run, -i, --rm, ghcr.io/yamadashy/repomix, --mcp] } } }配置完成后AI 助手可直接调用 Repomix 能力分析代码库无需手动准备文件。10.3 可用 MCP 工具pack_codebase将本地代码目录打包为 AI 分析用 XML。directory要打包目录的绝对路径compress可选默认 false启用 Tree-sitter 压缩可减少约 70% Token 且保留语义通常无需因为 grep 工具支持增量获取includePatterns/ignorePatterns可选fast-glob 模式逗号分隔outputPatterns可选按文件包含级别数组{ pattern, compress?, directoryStructureOnly? }首个匹配生效topFilesLength可选默认 10摘要中显示的最大文件数attach_packed_output附加已存在的打包输出文件供 AI 分析。path含 repomix-output.xml 的目录或直接指向打包 XML 文件topFilesLength可选默认 10免去重新处理直接访问既有打包仓库pack_remote_repository获取、克隆并打包 GitHub 仓库。remoteGitHub URL 或 user/repo 格式其余参数与 pack_codebase 相同read_repomix_output读取 Repomix 输出文件支持按行范围分段读取大文件。outputId输出文件 IDstartLine/endLine可选起始/结束行号1 起闭区间grep_repomix_output用 grep 式功能JavaScript RegExp 语法在输出文件中搜索。pattern搜索模式contextLines可选默认 0前后上下文行数beforeLines/afterLines可选分别控制前后上下文优先级高于 contextLinesignoreCase可选默认 false忽略大小写file_system_read_file仅沙箱模式读取沙箱工作区内文件path相对工作区根如src/index.ts。匹配已知密钥格式的内容会被拒绝额外启发式防护。file_system_read_directory仅沙箱模式列出沙箱工作区内目录带[FILE]/[DIR]指示符。十一、Claude Code 插件与 Agent Skills11.1 Claude Code 插件安装/plugin marketplace add yamadashy/repomix # 安装 MCP 服务器插件推荐基础 /plugin install repomix-mcprepomix # 安装命令插件扩展功能 /plugin install repomix-commandsrepomix # 安装仓库探索插件AI 分析 /plugin install repomix-explorerrepomix或使用交互式安装器/plugin。插件一览repomix-mcpMCP 服务器插件打包本地与远程仓库、读取和搜索打包输出、自动 Tree-sitter 压缩约 70% Token 削减。repomix-commands斜杠命令插件/repomix-commands:pack-local—— 以各种选项打包本地代码库/repomix-commands:pack-remote—— 打包并分析远程 GitHub 仓库示例/repomix-commands:pack-local后接Pack this project as markdown with compression/repomix-commands:pack-remote yamadashy/repomix后接Pack only TypeScript files...repomix-explorerAI 分析 Agent 插件自然语言探索与分析自动先运行npx repomixlatest打包再用 Grep/Read 工具增量搜索输出。示例/repomix-explorer:explore-local ./src后接Find all authentication-related code。本仓库内已附带一份可直接使用的 Repomix Explorer Skill 定义见 skills/repomix-explorer/SKILL.md。11.2 Agent Skills 生成Repomix 可以生成 Claude Agent Skills 格式输出创建可复用的代码库参考目录# 从本地目录生成 repomix --skill-generate # 自定义 Skill 名称 repomix --skill-generate my-project-reference # 自定义项目名 repomix --skill-generate --skill-project-name My Project # 从远程仓库生成 repomix --remote https://github.com/user/repo --skill-generate运行时会询问保存位置个人 Skills~/.claude/skills/全项目可用或项目 Skills.claude/skills/随 git 共享。非交互用法CI 与自动化repomix --skill-generate --skill-output ./my-skills repomix --skill-generate --skill-output ./my-skills --force repomix --remote user/repo --skill-generate my-skill --skill-output ./output --force生成结构.claude/skills/skill-name/ ├── SKILL.md # 主 Skills 元数据与文档 └── references/ ├── summary.md # 用途、格式与统计 ├── project-structure.md # 带行数的目录树 ├── files.md # 全部文件内容grep 友好 └── tech-stacks.md # 语言、框架、依赖自动生成名称未提供名称时自动生成——repomix src/ --skill-generate生成repomix-reference-src--remote user/repo生成repomix-reference-repoCustomName规范化为 kebab-case。Skills 生成实现见 skill/ 目录如 packSkill.ts、skillTechStack.ts。与其他特性组合repomix --skill-generate --include src/**/*.ts --ignore **/*.test.ts repomix --skill-generate --compress repomix --remote yamadashy/repomix --skill-generate十二、GitHub Actions 集成在 CI 工作流中自动化打包- name: Pack repository with Repomix uses: yamadashy/repomix/.github/actions/repomixmain with: output: repomix-output.xml style: xml不同格式与目录、压缩组合- name: Pack repository with Repomix uses: yamadashy/repomix/.github/actions/repomixmain with: output: repomix-output.md style: markdown- name: Pack repository with Repomix uses: yamadashy/repomix/.github/actions/repomixmain with: directories: src tests include: **/*.ts,**/*.md ignore: **/*.test.ts output: repomix-output.txt compress: true上传产物- name: Pack repository with Repomix uses: yamadashy/repomix/.github/actions/repomixmain with: directories: src output: repomix-output.txt compress: true - name: Upload Repomix output uses: actions/upload-artifactv7 with: name: repomix-output path: repomix-output.txt完整工作流示例name: Pack repository with Repomix on: workflow_dispatch: push: branches: [ main ] pull_request: branches: [ main ] jobs: pack-repo: runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkoutv7 - name: Pack repository with Repomix uses: yamadashy/repomix/.github/actions/repomixmain with: output: repomix-output.xml - name: Upload Repomix output uses: actions/upload-artifactv7 with: name: repomix-output.xml path: repomix-output.xml retention-days: 30Action 输入名称说明默认directories空格分隔的目录列表如src tests docs.include逗号分隔的 include glob如**/*.ts,**/*.mdignore逗号分隔的 ignore glob如**/*.test.ts,**/node_modules/**output打包文件相对路径扩展名决定格式.txt、.md、.xmlrepomix-output.xmlcompress启用智能压缩truestyle输出风格xml、markdown、json、plainxmladditional-args额外裸参数如--no-file-summary --no-security-checkrepomix-versionnpm 包版本支持 semver 范围、标签或具体版本latestAction 输出output_file—— 生成文件的路径可在后续步骤中用于产物上传、LLM 处理等。十三、以库的形式使用 Repomix除了 CLIRepomix 也可作为 Node.js 库嵌入应用。所有公共导出见 src/index.ts。13.1 安装与基础用法npm install repomiximport { runCli, type CliOptions } from repomix; // 用自定义选项处理当前目录 async function packProject() { const options { output: output.xml, style: xml, compress: true, quiet: true } as CliOptions; const result await runCli([.], process.cwd(), options); return result.packResult; }13.2 处理远程仓库import { runCli, type CliOptions } from repomix; // 克隆并处理 GitHub 仓库 async function processRemoteRepo(repoUrl) { const options { remote: repoUrl, output: output.xml, compress: true } as CliOptions; return await runCli([.], process.cwd(), options); }13.3 使用核心组件需要更细粒度控制时使用底层 APIimport { searchFiles, collectFiles, processFiles, TokenCounter } from repomix; async function analyzeFiles(directory) { // 查找并收集文件 const { filePaths } await searchFiles(directory, { /* config */ }); const rawFiles await collectFiles(filePaths, directory); const processedFiles await processFiles(rawFiles, { /* config */ }); // 统计 Token const tokenCounter new TokenCounter(o200k_base); // 返回分析结果 return processedFiles.map(file ({ path: file.path, tokens: tokenCounter.countTokens(file.content) })); }打包全流程编排见 packager.ts搜索文件 → 排序 → 收集内容与 git diff/log 子进程并行→ 安全检查与文件处理并发 → 过滤可疑文件 → 生成并写出输出与指标计算并发其中还包含 Token 缓存预加载、git 变更频率预取、worker 线程池预热等性能优化。13.4 打包注意事项使用 Rolldown 或 esbuild 等工具打包 repomix 时部分依赖需保持外部、WASM 文件需复制必须外部的依赖tinypool通过文件路径生成 worker 线程。需复制的 WASM 文件web-tree-sitter.wasm→ 与打包 JS 同目录代码压缩功能需要Tree-sitter 语言文件 →REPOMIX_WASM_DIR环境变量指定目录。十四、常见问题与提示词模板生成打包文件后可搭配以下提示词使用代码审查与重构This file contains my entire codebase. Please review the overall structure and suggest any improvements or refactoring opportunities, focusing on maintainability and scalability.文档生成Based on the codebase in this file, please generate a detailed README.md that includes an overview of the project, its main features, setup instructions, and usage examples.测试用例生成Analyze the code in this file and suggest a comprehensive set of unit tests for the main functions and classes. Include edge cases and potential error scenarios.代码质量评估Review the codebase for adherence to coding best practices and industry standards. Identify areas where the code could be improved in terms of readability, maintainability, and efficiency. Suggest specific changes to align the code with best practices.库概览This file contains the entire codebase of library. Please provide a comprehensive overview of the library, including its main purpose, key features, and overall architecture.【免费下载链接】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.项目地址: https://gitcode.com/GitHub_Trending/rep/repomix创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考