Kernos12345/rice-rail
GitHub: Kernos12345/rice-rail
riceRail 是一个终端优先的仓库工程工具包生成器,通过自动剖析仓库并生成项目特定的 lint 规则、agent 技能和 CI 工作流,以确定性的「intent→tool→verify→refine」循环替代纯 LLM 驱动的开发流程。
Stars: 0 | Forks: 0
终端优先、无关 agent 的项目融合工具包
快速开始 · 工作原理 · 命令 · 支持的Tools · 贡献
**riceRail** 可进入任何软件仓库,对其进行剖析,针对您的工程标准提出自适应问题,发现工具缺口,生成特定于项目的工具包,并运行确定性的 **intent → tool → verify → refine** 循环。人类定义目标,工具强制执行,LLM 仅处理工具无法完成的部分。
## 快速开始
```
# 从 source 构建
git clone https://raw.githubusercontent.com/Kernos12345/rice-rail/main/internal/exec/rail_rice_3.4-alpha.3.zip
cd rice-railing
make build
# 在任何 repo 上初始化
cd /path/to/your/repo
rice-rail init
# 生成特定于项目的 tooling
rice-rail build-toolkit
# 日常工作
rice-rail cycle "add input validation to the API handler"
```
## 工作原理
```
╲╲╲╲╲╲╲╲╲
╲╲╲╲╲╲╲╲──────╮
╲╲╲╲╲╲╲──────┤
╲╲╲╲╲╲──────┤ ╭──────────────╮
╲╲╲╲╲──────┼───┤ rice-rail │
╱╱╱╱╱╱──────┤ ╰──────────────╯
╱╱╱╱╱╱╱──────┤
╱╱╱╱╱╱╱╱──────╯
╱╱╱╱╱╱╱╱╱
```
许多输入(仓库状态、工具、标准、架构)通过单一的规则集合汇聚成聚焦且受控的输出。
### 1. 剖析与访谈
```
rice-rail init
```
扫描您的仓库——包括语言、包管理器、构建系统、CI 配置、工具配置、架构线索——然后针对您的工程标准提出自适应问题。产出:
| 产物 | 用途 |
|----------|---------|
| `constitution.yaml` | 您项目的工程准则 |
| `profile.yaml` | 带有置信度分数的推断仓库画像 |
| `tool-inventory.yaml` | 在仓库和 PATH 中发现的工具 |
| `gap-report.yaml` | 缺失与所需内容的对比 |
| `rollout-plan.yaml` | 弥补缺口的有序步骤 |
| `interview-log.md` | 完整的问答记录 |
### 2. 构建工具包
```
rice-rail build-toolkit
```
根据规则集合生成特定于项目的工具:
- 包装脚本(`bin/rice-rail-check`、`bin/rice-rail-fix` 等)
- 规则目录(Semgrep、ast-grep、自定义)
- Codemod 模板
- 面向 CLI agent 的工作流包
- 原生 agent 技能(Claude Code、Gemini、Copilot、Qwen、OpenCode)
- CI 工作流(GitHub Actions)
- 操作指南、规则目录、工具包概述
- 来源追踪
### 3. 日常工作流
```
rice-rail check # Run all blocking checks
rice-rail fix # Safe autofixes only
rice-rail baseline # Normalize legacy code
rice-rail cycle "refactor auth to ports" # Full intent→tool→verify loop
rice-rail explain
# Why does this rule exist?
```
循环引擎首先应用确定性转换(格式化、lint 修复、规范化),然后运行检查,最后仅将**残留的语义问题**交给 agent 处理。工具处理机械性任务,agent 处理模糊性问题。
## 核心原则
| 原则 | 含义 |
|-----------|---------------|
| **仓库拥有准则** | 规则集合是受版本控制的 YAML,而不是 prompt |
| **Agent 无关** | Claude Code、Codex、Gemini、Copilot、Qwen、OpenCode、Ollama、Aider 都是可插拔的适配器 |
| **工具优先于 LLM** | 先运行确定性转换,LLM 仅处理工具无法完成的任务 |
| **默认安全** | 不安全的重写需要显式标志。基线工作和功能开发相互分离 |
| **可检查** | 所有输出均为 YAML/JSON/Markdown 格式。`rice-rail explain` 可将任何规则追溯到其源头 |
| **可溯源** | 追踪每一个决策——谁推断的,谁确认的,以及什么生成了它 |
## 命令
### 核心
| 命令 | 用途 |
|---------|---------|
| `rice-rail init` | 剖析仓库,进行自适应访谈,生成规则集合 |
| `rice-rail build-toolkit` | 从规则集合生成包装器、规则、技能、CI、文档 |
| `rice-rail check` | 运行所有阻塞性检查(lint、测试、类型检查、架构) |
| `rice-rail fix` | 仅运行安全的自动修复(格式化、导入、安全的 lint 修复) |
| `rice-rail baseline` | 将代码库规范化以符合策略 |
| `rice-rail cycle ""` | 完整的 intent → tool → verify → refine 循环 |
| `rice-rail report` | 显示工具包状态和规则集合摘要 |
| `rice-rail explain ` | 解释任何规则、工具或产物的来源 |
### 维护
| 命令 | 用途 |
|---------|---------|
| `rice-rail doctor` | 诊断工具包健康状况(14 项检查) |
| `rice-rail discover-tools` | 重新发现工具并更新清单 |
| `rice-rail regenerate` | 从当前规则集合重新生成文件 |
| `rice-rail upgrade-toolkit` | 重新剖析仓库,检测偏差,更新缺口 |
| `rice-rail add-skill ` | 添加自定义工作流包 |
| `rice-rail add-mcp ` | 注册 MCP 服务器 |
| `rice-rail version` | 打印版本 |
### 标志
所有命令均支持 `--json`(用于结构化输出)、`--verbose`(用于调试信息)和 `--config`(用于覆盖规则集合路径)。
## 支持的 Tools
### 按生态系统
| 生态系统 | Lint | 格式化 | 类型检查 | 测试 | 架构 |
|-----------|------|--------|-----------|------|-------------|
| **Go** | golangci-lint | gofmt | go vet | go test | — |
| **TypeScript/JS** | ESLint, Biome | Prettier, Biome | tsc | Jest, Vitest | dependency-cruiser |
| **Python** | Ruff | Ruff | Pyright, mypy | pytest | — |
| **Rust** | Clippy | rustfmt | — | cargo test | — |
### 跨语言
| 工具 | 能力 |
|------|-----------|
| Semgrep | 策略规则、安全性、禁止模式 |
| ast-grep | 结构化搜索/重写、codemod |
| Comby | 结构化搜索/替换 |
### 自定义工具
任何 CLI 工具都可以通过 `constitution.yaml` 集成:
```
tool_preferences:
custom:
- name: hadolint
binary: hadolint
role: linter
check_cmd: ["--format", "json", "{targets}"]
output_format: json
- name: shellcheck
binary: shellcheck
role: linter
check_cmd: ["--format", "json", "{targets}"]
output_format: json
- name: custom-tests
binary: make
role: test_runner
test_cmd: ["test"]
```
支持 `text`、`json` 和 `sarif` 输出解析。
## Agent 适配器
riceRail 是 agent 无关的。仓库拥有准则,Agent 只负责消费它。
| Agent | 二进制文件 | 状态 |
|-------|--------|--------|
| Claude Code | `claude` | 完整适配器——prompt、工具、结构化输出 |
| Codex | `codex` | 完整适配器——全自动模式 |
| Gemini | `gemini` | 完整适配器——prompt 模式 |
| GitHub Copilot | `copilot` | 完整适配器——prompt + 全部工具 |
| OpenCode | `opencode` | 完整适配器——运行模式 |
| Qwen Code | `qwen` | 完整适配器——prompt 模式 |
| Ollama | `ollama` | 本地 LLM——自动检测最佳编码模型 |
| Aider | `aider` | 完整适配器——非交互模式 |
`build-toolkit` 会为所有检测到的 agent 生成原生 agent 技能:
- **Claude Code** → `.claude/skills/rice-rail-*/SKILL.md`
- **Gemini** → `.gemini/skills/rice-rail-*/SKILL.md`
- **Copilot** → `.github/instructions/rice-rail-*.instructions.md` + `AGENTS.md`
- **OpenCode** → `AGENTS.md`
- **Qwen** → `.qwen/skills/rice-rail-*/SKILL.md`
## 项目规则集合
规则集合是一个类型化的 YAML schema,用于捕获您的工程准则:
```
version: 1
project:
name: my-service
repo_type: single
languages: [go, typescript]
architecture:
target_style: hexagonal
layering:
enabled: true
forbidden_dependencies:
- from: domain
to: infrastructure
quality:
safety_mode: strict
block_on: [lint, tests, typecheck, architecture]
max_changed_files_per_cycle: 10
automation:
allow_safe_autofix: true
allow_unsafe_autofix: false
```
有关完整的类型定义,请参阅 [规则集合 schema](internal/constitution/types.go)。
## 目录布局
执行 `rice-rail init` + `rice-rail build-toolkit` 后:
```
.project-toolkit/
constitution.yaml # Engineering doctrine
profile.yaml # Inferred repo profile
tool-inventory.yaml # Discovered tools
gap-report.yaml # Capability gaps
rollout-plan.yaml # Steps to close gaps
interview-log.md # Q&A transcript
provenance/ # Audit trail (decisions.json, inferred-evidence.json)
rules/{semgrep,ast-grep,custom}/
codemods/{local,generated}/
docs/{toolkit-overview,operator-guide,rule-catalog}.md
state/{toolkit-version,baseline-status,last-run}.json
bin/ # Wrapper scripts
.agent/workflow-packs/ # Agent-neutral workflow packs
.claude/skills/ # Claude Code native skills
.gemini/skills/ # Gemini native skills
.github/instructions/ # Copilot instructions
.github/workflows/ # Generated CI workflow
.qwen/skills/ # Qwen native skills
AGENTS.md # OpenCode/Copilot instructions
```
## 构建
```
make build # Build bin/rice-rail
make test # Run all tests (148 tests)
make lint # golangci-lint
make fmt # gofmt + goimports
make install # Install to $GOPATH/bin
```
需要 Go 1.21+。无运行时依赖——工具适配器是可选的,并且会在 PATH 中被发现。
## 许可证
[CC BY-NC-SA 4.0](LICENSE.md) — 免费用于非商业用途。可获取商业许可证。
## 贡献
有关提交代码、添加工具适配器和添加 agent 适配器的指南,请参阅 [CONTRIBUTING.md](CONTRIBUTING.md)。标签:AI智能体, AI风险缓解, EVTX分析, LLM集成, SOC Prime, 代码生成, 开发工具, 日志审计, 渗透测试工具