coden-tree-sitter
v0.1.0
Published
CodeN tool plugin: parse source files with Tree-sitter and return a compact JSON AST
Readme
coden-tree-sitter
CodeN 工具插件:读取工作区源码文件,用 Tree-sitter 解析并返回紧凑 JSON 抽象语法树(AST),供 Agent 做代码理解与进一步处理。
安装
coden plugin install npm:coden-tree-sitter
coden plugin list发布到 npm registry 后可用。项目内安装需先获得工作区信任。
工具:parse_ast
输入:
| 参数 | 类型 | 必填 | 说明 |
| --- | --- | --- | --- |
| filePath | string | 是 | 文件路径,相对工作区或绝对路径 |
| language | string | 否 | 覆盖扩展名推断(如 cpp、typescript) |
| maxSizeBytes | number | 否 | 文件大小上限,默认 2000000,范围 [1024, 20000000] |
返回:content 为紧凑 JSON AST(节点含 type、startRow、startColumn、startIndex、endRow、endColumn、endIndex、children);metadata 含 language、filePath、sizeBytes、lineCount、hasError、errorCount、parseMs。
支持语言
javascript、typescript、tsx、python、java、c、cpp、go、rust、json、bash、html、css、c_sharp、ruby、swift、kotlin、scala、haskell
(typescript 在 tree-sitter 0.25 core 下若 TS 默认导出不可用会自动回退到同包 tsx grammar。)
开发
npm install --legacy-peer-deps
bun run typecheck
bun run test
bun run build原生依赖 tree-sitter 需要能编译/加载 N-API addon;grammar 包 peer 范围与 [email protected] 有部分冲突,安装时使用 --legacy-peer-deps。
已知限制
- 不读取工作区之外的文件(路径越界返回错误)。
- 大文件(默认 >2MB)拒绝解析,
maxSizeBytes可在[1024, 20M]内调整。 - 不包含
yaml、php、sql、r(对应 grammar 与tree-sitter 0.25core 不兼容或不可用)。
