179 lines
5.6 KiB
Markdown
179 lines
5.6 KiB
Markdown
<!-- WEHUB_ZH_README -->
|
||
> [!NOTE]
|
||
> 本文档由 WeHub 基于上游 README 翻译整理,属于社区翻译,非官方中文文档。
|
||
> [English](./README.en.md) · [原始项目](https://github.com/rtk-ai/rtk) · [上游 README](https://github.com/rtk-ai/rtk/blob/HEAD/README.md)
|
||
> 原作者、版权与许可证归属以原始项目及本仓库 LICENSE 文件为准。
|
||
|
||
<p align="center">
|
||
<img src="https://avatars.githubusercontent.com/u/258253854?v=4" alt="RTK - Rust Token Killer" width="500">
|
||
</p>
|
||
|
||
<p align="center">
|
||
<strong>高性能 CLI 代理,将 LLM token 消耗降低 60-90%</strong>
|
||
</p>
|
||
|
||
<p align="center">
|
||
<a href="https://github.com/rtk-ai/rtk/actions"><img src="https://github.com/rtk-ai/rtk/workflows/Security%20Check/badge.svg" alt="CI"></a>
|
||
<a href="https://github.com/rtk-ai/rtk/releases"><img src="https://img.shields.io/github/v/release/rtk-ai/rtk" alt="Release"></a>
|
||
<a href="https://opensource.org/licenses/Apache-2.0"><img src="https://img.shields.io/badge/License-Apache_2.0-blue.svg" alt="License: Apache 2.0"></a>
|
||
<a href="https://discord.gg/RySmvNF5kF"><img src="https://img.shields.io/discord/1478373640461488159?label=Discord&logo=discord" alt="Discord"></a>
|
||
<a href="https://formulae.brew.sh/formula/rtk"><img src="https://img.shields.io/homebrew/v/rtk" alt="Homebrew"></a>
|
||
</p>
|
||
|
||
<p align="center">
|
||
<a href="https://www.rtk-ai.app">官网</a> •
|
||
<a href="#安装">安装</a> •
|
||
<a href="docs/TROUBLESHOOTING.md">故障排除</a> •
|
||
<a href="docs/contributing/ARCHITECTURE.md">架构</a> •
|
||
<a href="https://discord.gg/RySmvNF5kF">Discord</a>
|
||
</p>
|
||
|
||
<p align="center">
|
||
<a href="README.md">English</a> •
|
||
<a href="README_fr.md">Francais</a> •
|
||
<a href="README_zh.md">中文</a> •
|
||
<a href="README_ja.md">日本語</a> •
|
||
<a href="README_ko.md">한국어</a> •
|
||
<a href="README_es.md">Espanol</a>
|
||
</p>
|
||
|
||
---
|
||
|
||
rtk 在命令输出到达 LLM 上下文之前进行过滤和压缩。单一 Rust 二进制文件,零依赖,<10ms 开销。
|
||
|
||
## Token 节省(30 分钟 Claude Code 会话)
|
||
|
||
| 操作 | 频率 | 标准 | rtk | 节省 |
|
||
|------|------|------|-----|------|
|
||
| `ls` / `tree` | 10x | 2,000 | 400 | -80% |
|
||
| `cat` / `read` | 20x | 40,000 | 12,000 | -70% |
|
||
| `grep` / `rg` | 8x | 16,000 | 3,200 | -80% |
|
||
| `git status` | 10x | 3,000 | 600 | -80% |
|
||
| `git diff` | 5x | 10,000 | 2,500 | -75% |
|
||
| `cargo test` / `npm test` | 5x | 25,000 | 2,500 | -90% |
|
||
| **总计** | | **~118,000** | **~23,900** | **-80%** |
|
||
|
||
## 安装
|
||
|
||
### Homebrew(推荐)
|
||
|
||
```bash
|
||
brew install rtk
|
||
```
|
||
|
||
### 快速安装(Linux/macOS)
|
||
|
||
```bash
|
||
curl -fsSL https://raw.githubusercontent.com/rtk-ai/rtk/refs/heads/master/install.sh | sh
|
||
```
|
||
|
||
### Cargo
|
||
|
||
```bash
|
||
cargo install --git https://github.com/rtk-ai/rtk
|
||
```
|
||
|
||
### 验证
|
||
|
||
```bash
|
||
rtk --version # 应显示 "rtk 0.27.x"
|
||
rtk gain # 应显示 token 节省统计
|
||
```
|
||
|
||
## 快速开始
|
||
|
||
```bash
|
||
# 1. 为 Claude Code 安装 hook(推荐)
|
||
rtk init --global
|
||
|
||
# 2. 重启 Claude Code,然后测试
|
||
git status # 自动重写为 rtk git status
|
||
```
|
||
|
||
## 工作原理
|
||
|
||
```
|
||
没有 rtk: 使用 rtk:
|
||
|
||
Claude --git status--> shell --> git Claude --git status--> RTK --> git
|
||
^ | ^ | |
|
||
| ~2,000 tokens(原始) | | ~200 tokens | 过滤 |
|
||
+-----------------------------------+ +------- (已过滤)-----+----------+
|
||
```
|
||
|
||
四种策略:
|
||
|
||
1. **智能过滤** - 去除噪音(注释、空白、样板代码)
|
||
2. **分组** - 聚合相似项(按目录分文件,按类型分错误)
|
||
3. **截断** - 保留相关上下文,删除冗余
|
||
4. **去重** - 合并重复日志行并计数
|
||
|
||
## 命令
|
||
|
||
### 文件
|
||
```bash
|
||
rtk ls . # 优化的目录树
|
||
rtk read file.rs # 智能文件读取
|
||
rtk find "*.rs" . # 紧凑的查找结果
|
||
rtk grep "pattern" . # 按文件分组的搜索结果
|
||
```
|
||
|
||
### Git
|
||
```bash
|
||
rtk git status # 紧凑状态
|
||
rtk git log -n 10 # 单行提交
|
||
rtk git diff # 精简 diff
|
||
rtk git push # -> "ok main"
|
||
```
|
||
|
||
### 测试
|
||
```bash
|
||
rtk jest # Jest 紧凑输出
|
||
rtk vitest # Vitest 紧凑输出
|
||
rtk pytest # Python 测试(-90%)
|
||
rtk go test # Go 测试(-90%)
|
||
rtk test <cmd> # 仅显示失败(-90%)
|
||
```
|
||
|
||
### 构建 & 检查
|
||
```bash
|
||
rtk lint # ESLint 按规则分组
|
||
rtk tsc # TypeScript 错误分组
|
||
rtk cargo build # Cargo 构建(-80%)
|
||
rtk ruff check # Python lint(-80%)
|
||
```
|
||
|
||
### 容器
|
||
```bash
|
||
rtk docker ps # 紧凑容器列表
|
||
rtk docker logs <container> # 去重日志
|
||
rtk kubectl pods # 紧凑 Pod 列表
|
||
```
|
||
|
||
### 分析
|
||
```bash
|
||
rtk gain # 节省统计
|
||
rtk gain --graph # ASCII 图表(30 天)
|
||
rtk discover # 发现遗漏的节省机会
|
||
```
|
||
|
||
## 文档
|
||
|
||
- **[TROUBLESHOOTING.md](docs/TROUBLESHOOTING.md)** - 解决常见问题
|
||
- **[INSTALL.md](INSTALL.md)** - 详细安装指南
|
||
- **[ARCHITECTURE.md](docs/contributing/ARCHITECTURE.md)** - 技术架构
|
||
|
||
## 贡献
|
||
|
||
欢迎贡献!请在 [GitHub](https://github.com/rtk-ai/rtk) 上提交 issue 或 PR。
|
||
|
||
加入 [Discord](https://discord.gg/RySmvNF5kF) 社区。
|
||
|
||
## 许可证
|
||
|
||
Apache 2.0 许可证 - 详见 [LICENSE](LICENSE)。
|
||
|
||
## 免责声明
|
||
|
||
详见 [DISCLAIMER.md](DISCLAIMER.md)。
|