rasros/lx

GitHub: rasros/lx

这是一个基于 Go 语言的 CLI 工具,可将代码库智能打包并格式化为文本,方便直接导入 Claude 或 ChatGPT 进行分析。

Stars: 47 | Forks: 3

# lx 安装 [![Go Reference](https://pkg.go.dev/badge/github.com/rasros/lx.svg)](https://pkg.go.dev/github.com/rasros/lx) [![Go Report Card](https://goreportcard.com/badge/github.com/rasros/lx)](https://goreportcard.com/report/github.com/rasros/lx) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE) `lx` 是一个 CLI 工具,可将您的代码库打包成单个上下文字符串,供 LLM 使用。 它会遍历目录,遵守您的 gitignore 规则,跳过二进制文件,并将 Markdown、XML 或 HTML 直接输出到剪贴板,同时附带估算的 token 计数。 与盲目地将文件拼接在一起不同,`lx` 将参数作为流进行处理。这意味着您可以在单个命令中即时对不同文件应用不同规则(如行数限制或过滤器)。 [安装说明](#installation) • [用法](#usage) • [流处理](#stream-processing-model) • [配置](#configuration) ## 功能特性 * 针对单个文件和最终输出的 token 估算。 * 尊重 `.gitignore`、`.ignore` 和 `.lxignore` 的智能遍历。 * 支持流处理以在命令中途应用修饰符(如 `--tail 50`)。 * 输出标准 Markdown、XML(适合 Claude)或 HTML。 * 在 Linux、macOS 和 Windows 上直接复制到系统剪贴板。 * 与 Unix 管道(`find`、`fd`、`git` 等)配合良好。 ## 安装说明 ### Go 安装 ``` go install github.com/rasros/lx/cmd/lx@latest ``` ### Curl 脚本(预构建二进制文件) ``` curl -fsSL https://raw.github.com/rasros/lx/main/install.sh | bash ``` ### 依赖项 剪贴板支持(`-c`)在 X11 Linux 上需要 `xclip`,在 Wayland 上需要 `wl-clipboard`。macOS 和 Windows 开箱即用。 ## 用法 ### 基础打包 获取当前目录中的所有内容(忽略隐藏文件)并复制到剪贴板: ``` lx -c ``` ### 按类型过滤 获取所有 Python 文件,但跳过测试文件: ``` lx -i "*.py" -e "*test*" src/ ``` ### XML 输出 将目录作为结构化 XML 转储(Claude 更偏好此格式): ``` lx --xml . ``` ### Prompt 注入 在代码上下文之前添加自定义指令: ``` lx -p "Refactor the following code to use contexts:" main.go ``` ### 自定义部分 添加自定义标题以对特定文件进行分组(也会调整 XML 输出): ``` lx -s "Code under test" src/database/users -s "Test fixtures" src/tests/fixtures ``` ### 使用 fzf 进行交互式选择 使用 `fd` 查找文件,用 `lx` 预览它们,并打包最终选择的内容: ``` fd -t f | fzf -m --preview 'lx -n 20 {}' | lx -c ``` ### 通过管道传输到 LLM CLI 将上下文直接发送到 [llm](https://github.com/simonw/llm) 工具: ``` lx -p "Explain this project structure" src/ | llm ``` ### 与 git 协作 仅打包当前分支中更改的文件: ``` git diff --name-only main | lx -c ``` ## 流处理模型 `lx` 从左到右依次读取参数。标志不是全局的,它们作为修饰符作用于后续的任何文件,直到您重置它们。 1. 修饰符:(`-n`, `--tail`, `-i`) 应用于后续文件。 2. 操作:(`file`, `dir/`) 捕获当前状态。 3. 重置:(`-N`, `-E`) 清除活动的修饰符。 示例:获取日志文件的最后 50 行,然后一次性获取 `main.go` 的全部内容。 ``` lx --tail 50 app.log -N src/main.go ``` | Argument | Type | Effect | |---------------|----------|-----------------------------------------------| | `--tail 50` | Modifier | 将读取策略设置为最后 50 行 | | `app.log` | Action | 使用 tail 策略进行处理 | | `-N` | Reset | 清除 tail 策略,恢复为完整内容 | | `src/main.go` | Action | 完整处理 | ## 输出格式 | Flag | Format | Best For | |-----------|----------|------------------------------------------------| | (default) | Markdown | ChatGPT, GitHub Copilot, DeepSeek | | `--xml` | XML | Claude (使用 `` 和 `` 标签) | | `--html` | HTML | 存档或可视化调试 | ## 配置 您可以在 `~/.config/lx/config.yaml` 中设置默认值: ``` output_mode: "stdout" # stdout, copy output_format: "xml" # markdown, xml, html show_hidden: false follow_symlinks: false ignore: true # respects .gitignore ``` ## 对比 | Feature | lx | repopack | files-to-prompt | |-------------------|----|----------|-----------------| | Language | Go | Node.js | Python | | Stream Processing | ✅ | ❌ | ❌ | | Clipboard Copy | ✅ | ❌ | ❌ | | XML Support | ✅ | ✅ | ✅ | | Token Estimation | ✅ | ✅ | ❌ | | Binary Detection | ✅ | ✅ | ✅ |
标签:ChatGPT, Claude, CVE检测, DLL 劫持, EVTX分析, Git忽略, Go语言, LLM, Markdown, Promptflow, SOC Prime, Token估算, Unix管道, Unmanaged PE, XML输出, 代码上下文, 代码打包, 剪贴板, 大语言模型, 开发工具, 文件过滤, 文档结构分析, 日志审计, 流式处理, 生产力工具, 程序破解