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

Tree-sitter CLI

$ tree-sitter 基金会 低风险
Tree-sitter (OSS) · 文件检索与编辑 · MIT · macos / linux / windows

tree-sitter 可将源码解析为具体语法树、执行 .scm 查询、通过 tree-sitter tags 提取符号定义并构建语法解析器。解析与查询子命令均为只读操作,generate 则用于生成本地 C 解析器代码。

FCRS-1.0 综合评分
85 /100
良好 (Good)
中置信度 (源码/文档)
零摩擦安装命令
brew install tree-sitter
CLI vs MCP 选型建议 优先选 CLI

在工作区直接运行 tree-sitter parse 或 tree-sitter tags 比通过 MCP 包装更快、更直接。

Agent 友好度体检单

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

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

FCRS-1.0 六维评分拆解

Agent 友好度 20 / 25

支持 --quiet 与 --xml 等非交互选项,但 parse 默认输出为 S 表达式而非 --json。

  • Deterministic stdout for parse, query, and tags subcommands
安全与权限边界 23 / 25

parse/query/tags 均为只读;仅显式调用 generate 时才会向磁盘写入解析器文件。

  • Separates read-only inspection commands from generate
安装与运行摩擦 12 / 15

提供 brew、npm、cargo 及预编译包,但编译新语法需要本地 C 工具链。

  • Distributed via brew, npm, and cargo; needs C compiler for grammar builds
能力覆盖与边际价值 13 / 15

非常适合语法验证、.scm 查询调试与语法仓库开发。

  • First-party parser and query evaluation tool
维护与来源背书 9 / 10

生态级基础项目,支撑 Neovim、GitHub 代码导航与 ast-grep。

  • Widely adopted foundation project under MIT
文档与可验证性 8 / 10

官方文档站详细覆盖了各子命令及配置文件格式。

  • Maintained documentation at tree-sitter.github.io

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

鉴权方式
无需鉴权
凭证存储位置

无需任何凭证;仅使用本地语法配置与源代码文件。

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

100% 免费、离线且开源(MIT)。

可复制到 CLAUDE.md / AGENTS.md 的安全护栏
# tree-sitter Agent Rules
- Use `parse`, `query`, and `tags` for read-only inspection; only run `generate` inside grammar repos.
- Ensure target language parsers are configured in `~/.config/tree-sitter/config.json` before invoking `parse`.

Agent 高频安全命令配方

只读查询(安全推荐)

将源文件解析为 S 表达式语法树
tree-sitter parse --quiet src/parser.rs

校验语法并按参数输出解析错误或 CST 节点。

从源文件中提取符号标签
tree-sitter tags src/main.ts

利用语法的 tags 查询输出函数、类与方法定义。

受控写入与预演

根据 grammar.js 重新生成 C 解析器文件
tree-sitter generate

在 Tree-sitter 语法仓库内生成更新后的 src/parser.c 产物。

核心优势

  • + 官方权威解析器 CLI,适合验证语法树并调试 .scm 查询规则。
  • + 全面覆盖 brew、npm 与 cargo 安装渠道。

注意事项与踩坑点

  • ! 在非语法仓库中调用 parse 需预先配置本地语言语法;日常代码搜索用 ast-grep 更省心。

已验证兼容的 Agent 宿主

Claude Code Codex CLI Gemini CLI