CLI 目录 横向对比 FCRS-1.0 标准 /llms.txt
← 返回 CLI 目录

Buf

$ buf 官方出品 低风险
Buf · 代码托管与研发协同 · Apache-2.0 · macos / linux / windows

Buf 官方命令行工具,以确定性的 Protobuf 规范检查、向后兼容性破坏检测、格式化与托管代码生成替代繁琐易错的 protoc 调用。原生 --error-format=json 与 buf format --diff --exit-code 极大提升了 Agent 处理 Protobuf 的可靠性。

FCRS-1.0 综合评分
95 /100
极佳 (Excellent)
中置信度 (源码/文档)
零摩擦安装命令
brew install buf
CLI vs MCP 选型建议 优先选 CLI

直接在工作区本地运行 Protobuf 检查、兼容性比对与代码生成,优先使用 buf CLI。

Agent 友好度体检单

✓ 原生 JSON 输出
— 字段裁剪
✓ 无头非交互
✓ 支持 Dry-Run
✓ 只读模式开关
— 支持 NO_COLOR
✓ 自省/Schema 发现
— 官方 SKILL.md

当前为静态评估(本机尚未安装或尚未运行探针)。可在本地运行 npm run data:probe 并提交 data/probes/ 升级为实测证据。

FCRS-1.0 六维评分拆解

Agent 友好度 24 / 25

在 lint、breaking 与 build 中全面支持 --error-format=json,并提供 buf format --diff --exit-code 与 buf config ls-lint-rules --format json。

  • --error-format=json supported across lint, breaking, and build
  • buf format --diff --exit-code provides clean dry-run verification
安全与权限边界 23 / 25

本地 lint、breaking 与 format --diff 严格只读;远程 buf push 及本地写入 format -w/generate 均由独立子命令或标志隔离。

  • Clear separation between read-only checks and -w / generate / push
安装与运行摩擦 15 / 15

静态 Go 单二进制,可通过 Homebrew、npm、go install、Docker 与 GitHub Releases 安装,无需外部 protoc。

  • Zero external protoc dependency required for linting and breaking checks
能力覆盖与边际价值 14 / 15

以可复现的 buf.yaml / buf.gen.yaml 工作流替代脆弱的 protoc 长参数链。

  • Fast Protobuf parsing, breaking-change detection, and remote/local codegen
维护与来源背书 10 / 10

Buf 官方开源项目(bufbuild/buf),采用 Apache-2.0 协议高频维护。

  • Official bufbuild/buf repository
文档与可验证性 9 / 10

buf.build/docs 拥有极佳的 CLI 参考手册与规则文档。

  • Official CLI reference at buf.build/docs/reference/cli/buf/

安全边界、鉴权与放权指南

鉴权方式
无需鉴权 环境变量密钥 本地配置文件
凭证存储位置

本地 lint/format/generate 无需凭证;若访问 Buf Schema Registry (BSR),凭证保存在 ~/.netrc 或 BUF_TOKEN 环境变量中。

潜在副作用
只读查询 本地写入 远端写入
费用与配额提示

Apache-2.0 开源 CLI,本地使用完全免费(BSR 私有仓库套餐为可选项)。

可复制到 CLAUDE.md / AGENTS.md 的安全护栏
# Buf (buf) Agent Rules
- Always pass `--error-format=json` to `buf lint` and `buf breaking`.
- Run `buf format --diff --exit-code` before `buf format -w`, and never push to BSR (`buf push`) without explicit user consent.

Agent 高频安全命令配方

只读查询(安全推荐)

以 JSON 格式检查 Protobuf 规范
buf lint --error-format=json

依据 buf.yaml 规则校验 .proto 文件,并逐行输出 JSON 诊断。

对比 main 分支检测破坏性变更
buf breaking --against '.git#branch=main' --error-format=json

以 JSON 检测相对 main 分支的 .proto 协议或源码破坏性变更,不修改文件。

受控写入与预演

先预览差异再格式化 .proto 文件
buf format --diff --exit-code && buf format -w

先通过 --diff --exit-code 预检格式差异,再按需执行 -w 原地格式化。

核心优势

  • + lint、breaking 与 build 统一支持 --error-format=json,且内置独立 Protobuf 编译器。
  • + 原生支持 Git 感知的 buf breaking --against '.git#branch=main',精准拦截协议兼容回退。

注意事项与踩坑点

  • ! buf.gen.yaml 中若引用 BSR 远程依赖或远程插件,需要联网权限(私有模块需 BUF_TOKEN)。
  • ! 不同代际的仓库可能混用 buf.yaml v1 与 v2 配置格式。

已验证兼容的 Agent 宿主

Claude Code Codex CLI Gemini CLI