AI Agent 版本控制:Git 融合框架
开源项目为 Agent 引入 Git 概念,实现行为可追溯和可回溯。对 Agent 应用开发者有直接实用价值。
完整中文译文
追踪你的 agent 做了什么,哪个 prompt 写了每一行,以及检查任何步骤。
# 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>
就这样。你的 agent 活动现在可以审计了。
每个 agent 的回合都会自动捕获。不需要手动提交。
调试一个不好的重构 — 用 rgt log、rgt blame 和 rgt show 追踪真实的账单回退
查看你的 agent 实际做了什么
$ 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
责任追踪:哪个 prompt 写了这一行?
$ 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 agent 没有自己的版本控制
"五分钟前还能用"
"你为什么改了这个文件?"
"回到重构之前"
复制粘贴代码到新的聊天中
三个应该已经存在的原语:
rgt log — 这个会话做了什么?
rgt blame — 哪个 prompt 写了这一行?
rgt show — 检查任何步骤的完整上下文
我们给了 agent 对代码库的写入权限。但我们没有给自己相应的 git。re_gent 修复了这个问题。
re_gent 将 agent 活动存储在 .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"
}
Step 形成一个 DAG。每个会话有自己的分支。公共祖先进行去重。你获得了 git 级别的 agent 活动审计能力。
技术细节:查看 POC.md 了解完整规范。
安装
Homebrew(macOS/Linux)
brew tap regent-vcs/tap
brew install regent
这会安装 rgt 命令并自动为 bash、zsh 和 fish 设置 shell 补全。
Go
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 下载预编译的二进制文件
特性
Hooks 在 rgt init 时自动配置。不需要手动设置。
- 内容寻址存储 — BLAKE3 哈希、自动去重
- 快速查询 — SQLite 索引、sub-10ms 查询
- 按会话的 DAG — 并发会话作为单独的 ref 追踪
- 对话追踪 — 在 /compact 和 /clear 中幸存
- Hook 驱动 — 透明的 Claude Code、Codex 和 OpenCode 集成
- 零配置 — Hooks 在 rgt init 时自动配置
- 并发安全 — CAS ref、ACID 事务
- Gitignore 兼容 — 支持 .regentignore
VS Code 扩展
在编辑器中直接获取内联责任追踪注释:
# 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,不替代它。同时使用两者。
查看 ROADMAP.md 了解计划功能,包括:
- 非破坏性的回绕和分叉操作
- 额外的工具适配器(Cursor、Cline、Continue)
- 会话共享和合并支持
- 垃圾回收和完整性验证
欢迎贡献!有关指南,请参阅 CONTRIBUTING.md。
开发
QUICK_START.md — 5 分钟设置指南
测试通过:go test ./... 和 go test -race ./...
Linter 通过:golangci-lint run
代码格式化:go fmt ./...
依赖
cobra — CLI 框架
blake3 — BLAKE3 哈希
modernc.org/sqlite — 纯 Go SQLite
由贡献者构建
Discord • Discussions • Issues • Technical Spec