AI 智能体版本控制
追踪你的智能体做了什么、每一行代码是由哪条提示词编写的,并检查任意步骤。
快速开始
# Install via Homebrew (macOS/Linux) brew tap regent-vcs/tap brew install regent # Or via Go go install github.com/regent-vcs/regent/cmd/rgt@latest # Initialize in your project cd your-project rgt init # Work with Claude Code, Codex, or OpenCode normally — activity is tracked automatically # See what happened rgt log rgt blame src/file.go:42 rgt show <step-hash>
就这样。你的智能体活动现在可审计了。
演示
demo.mp4
智能体的每一次交互回合都会被自动捕获。无需手动提交。
示例
- 调试糟糕的重构——使用 `rgt log`、`rgt blame` 和 `rgt show` 追踪一次真实的计费回归问题。
你能获得什么
查看你的智能体实际做了什么
$ rgt log Step a1b2c3d | 2 min ago | Tool: Edit │ File: src/handler.go │ Added error handling to request handler │ + 5 lines, - 2 lines Step d4e5f6g | 5 min ago | Tool: Write │ File: tests/handler_test.go │ Created unit tests for handler │ + 23 lines Step f8g9h0i | 8 min ago | Tool: Bash │ Command: go mod tidy │ Cleaned up dependencies
溯源:这一行是由哪条提示词编写的?
$ rgt blame src/handler.go:42 Line 42: func handleRequest(w http.ResponseWriter, r *http.Request) { Step: a1b2c3d4e5f6 Session: claude-20260502-143021 Tool: Edit Prompt: "Add error handling to the request handler"
追踪多个并发会话
$ rgt sessions Active Sessions: claude_code:claude-20260502-143021 | 3 steps | Last: 2 min ago codex_cli:codex-20260502-091534 | 7 steps | Last: 2 hours ago $ rgt log --session claude_code:claude-20260502-143021 # Filter history by session
查看任何变更的完整上下文
$ rgt show a1b2c3d Step a1b2c3d4e5f6 Parent: d4e5f6g7h8i9 Session: claude-20260502-143021 Time: 2026-05-02 14:30:21 Tool: Edit File: src/handler.go Changes: + func handleRequest(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + http.Error(w, "Method not allowed", 405) + return + } - func handleRequest(w http.ResponseWriter, r *http.Request) { Conversation: User: "Add error handling to reject non-GET requests" Assistant: "I'll add method validation to the handler..."
为什么存在这个工具
AI 智能体没有自己的版本控制。
你懂这种痛苦:
- “五分钟前还能用的”
- “你为什么要改那个文件?”
- “回退到重构之前的状态”
- `/compact` 然后祈祷
- 把代码复制粘贴到一个新的聊天窗口
三个本应已经存在的基本命令:
- `rgt log`——这个会话做了什么?
- `rgt blame`——这一行是由哪条提示词编写的?
- `rgt show`——检查任意步骤的完整上下文
我们给了智能体对代码库的写入权限。但我们没有给自己一个针对它的 git。`re_gent` 解决了这个问题。
工作原理
`re_gent` 将智能体活动存储在 `.regent/` 目录中(类似于 `.git/`):
.regent/
├── objects/ # Content-addressed blobs (BLAKE3)
├── refs/ # Session pointers (one per agent)
├── index.db # SQLite query index
└── config.toml
每次使用工具的交互回合都会创建一个 Step(步骤)——一个内容寻址的快照,记录了发生了什么变化、为什么变化以及是谁要求的:
Step { parent: <previous-step-hash> tree: <workspace-snapshot> causes: [{ tool_name: "Edit", args: <input>, result: <output> }] session_id: "claude_code:claude-20260502-143021" timestamp: "2026-05-02T14:30:21Z" }
步骤形成一个有向无环图(DAG)。每个会话都有自己的分支。共同的祖先会被去重。你就能获得针对智能体活动的 git 级别的可审计性。
技术细节:请参阅 POC.md 获取完整规范。
安装
通过 Homebrew(macOS/Linux)
brew tap regent-vcs/tap brew install regent
这会安装 `rgt` 命令,并自动为 bash、zsh 和 fish 设置 shell 补全。
通过 Go Install
go install github.com/regent-vcs/regent/cmd/rgt@latest
Shell 补全(手动设置):
# Bash rgt completion bash > /usr/local/etc/bash_completion.d/rgt # Zsh rgt completion zsh > "${fpath[1]}/_rgt" # Fish rgt completion fish > ~/.config/fish/completions/rgt.fish
从源码安装
git clone https://github.com/regent-vcs/regent
cd regent
go build -o rgt ./cmd/rgt
sudo mv rgt /usr/local/bin/ 二进制发布版
从 GitHub Releases 下载预构建的二进制文件
支持的工具
| 工具 | 状态 |
|---|---|
| Claude Code | 完全支持 |
| OpenAI Codex CLI | 完全支持 |
| OpenCode | 完全支持 |
| Cursor、Cline、Continue | 计划中 |
钩子会在 `rgt init` 时自动配置。无需手动设置。
命令
| 命令 | 描述 |
|---|---|
| `rgt init` | 在当前目录初始化 `.regent/` |
| `rgt log` | 显示步骤历史(支持 `--session`、`-n`、`--json`、`--graph`) |
| `rgt sessions` | 列出所有活跃会话 |
| `rgt status` | 显示当前仓库状态 |
| `rgt show <step>` | 显示一个步骤的完整上下文(工具调用 + 对话) |
| `rgt blame <path>[:<line>]` | 显示文件中每一行的来源 |
| `rgt cat <hash>` | 通过哈希值检查任意对象 |
| rgt 版本 | 打印版本信息 |
| rgt 补全 | 生成 Shell 补全脚本 |
功能特性
- 内容寻址存储 — BLAKE3 哈希,自动去重
- 快速查询 — SQLite 索引,亚 10 毫秒级查找
- 按会话划分的 DAG — 并发会话作为独立引用进行追踪
- 对话追踪 — 在 /compact 和 /clear 操作后依然保留
- 钩子驱动 — 透明集成 Claude Code、Codex 和 OpenCode
- 零配置 — 在 rgt init 时自动配置钩子
- 并发安全 — CAS 引用,ACID 事务
- 兼容 Gitignore — 支持 .regentignore
编辑器集成
VSCode 扩展
直接在编辑器中获取内联追溯注释:
# From VSIX (Recommended) # Download the latest .vsix from: # https://github.com/regent-vcs/vscode-regent/releases # Then in VS Code: Extensions > ... > Install from VSIX... # From source (Development) git clone https://github.com/regent-vcs/vscode-regent cd vscode-regent npm install && npm run compile # Press F5 in VS Code to launch Extension Development Host
功能特性:
- 内联追溯注释,显示哪一步修改了每一行
- 悬停工具提示,显示完整的步骤上下文(时间戳、工具名称、参数)
- 侧边栏中的会话时间线视图
- 一键访问对话历史
要求:必须在项目中安装 rgt CLI 并运行 rgt init。
re_gent 与 Git 对比
| Git | re_gent | |
|---|---|---|
| 追踪代码 | ✅ | ✅ |
| 追踪智能体活动 | ❌ | ✅ |
| 带提示词的追溯 | ❌ | ✅ |
| 对话历史 | ❌ | ✅ |
| 并发会话 | ⚠️ 共享工作区冲突 | ✅ 独立的捕获会话引用 |
| 用途 | 开发者版本控制系统 | 智能体审计追踪 |
re_gent 是对 git 的补充,而非替代。两者可同时使用。
路线图
请参阅 ROADMAP.md 了解计划中的功能,包括:
- 非破坏性回退与分支操作
- 更多工具适配器(Cursor、Cline、Continue)
- 会话共享与合并支持
- 垃圾回收与完整性验证
贡献指南
欢迎贡献!请参阅 CONTRIBUTING.md 了解指南。
快速入门:
- QUICK_START.md — 5 分钟设置指南
- 适合新手的入门问题
在提交 PR 之前:
- 测试通过:go test ./... 和 go test -race ./...
- 代码检查通过:golangci-lint run
- 代码格式化:go fmt ./...
构建工具
- cobra — CLI 框架
- blake3 — BLAKE3 哈希
- go-diff — Myers 差异算法
- modernc.org/sqlite — 纯 Go 实现的 SQLite
许可证
由贡献者构建
关于
AI 编码智能体的版本控制。
re-gent.dev
发布版本 5
re_gent v1.1.0
软件包
贡献者
编程语言
- Go 98.6%
- Shell 1.1%
- Makefile 0.3%