解决向 LLM 输入大量代码的痛点工具,支持整库或部分代码序列化。205 点赞说明社区需求强烈,对 AI 编程工作流直接提效。
一个基于 Rust 的快速工具,可以将仓库或目录中的文本文件序列化以供 LLM 消费。
特性:
Yek یک 在波斯语/法语中意为"一"。
考虑有一个这样的简单仓库:
.
├── README.md
├── src
│ ├── main.rs
│ └── utils.rs
└── tests
└── test.rs
在此目录中运行 yek 将生成单个文件并将其写入临时目录,内容如下:
>>>> README.md
... content ...
>>>> tests/test.rs
... content ...
>>>> src/utils.rs
... content ...
>>>> src/main.rs
... content ...
yek 会优先将更重要的文件放在输出的末尾。这对于 LLM 消费很有用,因为 LLM 倾向于更多地关注上下文中后期出现的内容。
为你的平台选择安装方法:
curl -fsSL https://azimi.me/yek.sh | bash
irm https://azimi.me/yek.ps1 | iex
git clone https://github.com/mohsen1/yek
cd yek
cargo install --path .
yek 有合理的默认值,你可以直接在目录中运行 yek 来序列化整个仓库。它将序列化仓库中的所有文件并将其写入临时文件。文件的路径将打印到控制台。
yek
yek src/ | pbcopy
yek --tokens 128k
yek 将移除任何超过上限上下文大小的文件。它会尝试适配更重要的文件
yek --max-size 100KB --output-dir /tmp/yek src/
yek src/ tests/
yek file1.txt file2.txt file3.txt
yek "src/**/*.ts"
yek "src/main.rs" "tests/*.rs" "docs/README.md"
使用通配符模式时,确保引用它们以防止 shell 展开。
yek --help
Usage: yek [OPTIONS] [input-paths]...
Arguments:
[input-paths]... Input files and/or directories to process
Options:
--no-config Do not use a config file
--config-file <CONFIG_FILE> Path to the config file
-V, --version Print version of yek
--max-size <MAX_SIZE> Max size per chunk. e.g. "10MB" or "128K" or when using token counting mode, "100" or "128K" [default: 10MB]
--tokens <TOKENS> Use token mode instead of byte mode
--json Enable JSON output
--debug Enable debug output
--line-numbers Include line numbers in output
--output-dir [<OUTPUT_DIR>] Output directory. If none is provided & stdout is a TTY, we pick a temp dir
--output-name [<OUTPUT_NAME>] Output filename. If provided, write output to this file in current directory
--output-template [<OUTPUT_TEMPLATE>] Output template. Defaults to ">>>> FILE_PATH\nFILE_CONTENT"
--ignore-patterns <IGNORE_PATTERNS>... Ignore patterns
--unignore-patterns <UNIGNORE_PATTERNS>... Unignore patterns. Yek has some built-in ignore patterns, but you can override them here.
-t, --tree-header Include directory tree header in output (incompatible with JSON output)
--tree-only Show only the directory tree (no file contents, incompatible with JSON output)
-h, --help Print help
[input-paths]... - 要处理的文件或目录。支持通配符模式(引用它们以防止 shell 展开)
--no-config - 跳过加载任何配置文件
--config-file <CONFIG_FILE> - 使用特定的配置文件路径,而不是搜索默认配置文件
-V, --version - 打印版本信息并退出
--max-size <MAX_SIZE> - 每个输出的最大大小限制(例如 "10MB"、"128K")。在字节模式中使用
--tokens <TOKENS> - 使用基于 token 的计数而不是字节(例如 "128k"、"100")。启用 token 模式
--json - 以 JSON 格式而不是文本输出结果
--debug - 启用调试日志以进行故障排除
--line-numbers - 在输出中为每个文件包含行号
--output-dir [<OUTPUT_DIR>] - 输出文件的目录。如果未指定且未流式传输,使用临时目录
--output-name [<OUTPUT_NAME>] - 输出的特定文件名。如果指定,以此名称写入当前目录
--output-template [<OUTPUT_TEMPLATE>] - 格式化输出的模板。使用 FILE_PATH 和 FILE_CONTENT 占位符
--ignore-patterns <IGNORE_PATTERNS>... - 要忽略的其他模式(扩展 .gitignore 和默认值)
--unignore-patterns <UNIGNORE_PATTERNS>... - 覆盖内置忽略规则的模式
-t, --tree-header - 在输出开头包含目录树(与 JSON 不兼容)
--tree-only - 仅显示目录树结构,不显示文件内容(与 JSON 不兼容)
你可以在项目根目录放置一个名为 yek.yaml 的文件,或者通过 --config-file 传递自定义路径。配置文件允许你:
大多数 CLI 选项都可以在配置文件中设置。以下选项可以配置:
max_size - 大小限制(与 --max-size 相同)
tokens - Token 计数限制(与 --tokens 相同)
ignore_patterns - 其他忽略模式(与 --ignore-patterns 相同)
unignore_patterns - 覆盖内置忽略(与 --unignore-patterns 相同)
输出配置:
json - 启用 JSON 输出(与 --json 相同)
debug - 启用调试模式(与 --debug 相同)
line_numbers - 包含行号(与 --line-numbers 相同)
output_dir - 输出目录(与 --output-dir 相同)
output_name - 输出文件名(与 --output-name 相同)
output_template - 输出模板(与 --output-template 相同)
tree_header - 包含目录树标题(与 --tree-header 相同)
tree_only - 仅显示目录树(与 --tree-only 相同)
priority_rules - 文件优先级规则(仅配置文件)
binary_extensions - 其他二进制文件扩展名(仅配置文件)
git_boost_max - 基于 Git 的最大优先级提升(仅配置文件)
某些 CLI 选项如 --no-config、--config-file 和 --version 是仅限 CLI 的,不能在配置文件中设置。
你也可以使用 yek.toml 或 yek.json 代替 yek.yaml。
这是可选的,你可以在项目根目录配置 yek.yaml 文件。
# 添加要忽略的模式(除了 .gitignore)
ignore_patterns:
- "ai-prompts/**"
- "__generated__/**"
# 配置基于 Git 的优先级提升(可选)
git_boost_max: 50 # 基于 Git 历史的最大分数提升(默认:100)
# 定义处理顺序的优先级规则
# 更高的分数会优先处理
priority_rules:
- score: 100
pattern: "^src/lib/"
- score: 90
pattern: "^src/"
- score: 80
pattern: "^docs/"
# 添加要忽略的其他二进制文件扩展名
# 这些扩展内置列表(.jpg、.png、.exe 等)
binary_extensions:
- ".blend" # Blender 文件
- ".fbx" # 3D 模型文件
- ".max" # 3ds Max 文件
- ".psd" # Photoshop 文件
# 输出配置
max_size: "128K" # 大小限制(也可以使用 tokens: "100k")
json: false # 启用 JSON 输出
debug: false # 启用调试日志
line_numbers: false # 在输出中包含行号
tree_header: false # 在开头包含目录树
# 定义输出目录
output_dir: /tmp/yek
# 定义输出文件名(以此名称写入当前目录)
output_name: yek-output.txt
# 定义输出模板。
# FILE_PATH 和 FILE_CONTENT 应该在模板中出现。
output_template: "FILE_PATH\n\nFILE_CONTENT"
yek 很快。它用 Rust 编写,并并行执行许多操作以加快处理速度。
以下是将其与 Repomix 对 Next.js 项目进行序列化的基准比较:
time yek
Executed in 5.19 secs fish external
usr time 2.85 secs 54.00 micros 2.85 secs
sys time 6.31 secs 629.00 micros 6.31 secs
time repomix
Executed in 22.24 mins fish external
usr time 21.99 mins 0.18 millis 21.99 mins
sys time 0.23 mins 1.72 millis 0.23 mins
yek 的速度比 repomix 快 230 倍。
查看提议的功能。我很乐意接受新功能请求。请撰写详细提案来讨论新功能。
Repomix - 一个以类似于 yek 的方式将仓库序列化为单个文件的工具。
Aider - 一个使用 AI 进行编码的完整类 IDE 体验
yek 不是"炫目"快速。它只是快速,与你的计算机一样快。↩
yek 不是"炫目"快速。它只是快速,与你的计算机一样快。↩