跳到正文
cccskills
免费在 GitHub 公开

tree-sitter-language-pack-chunking-for-llms

Use when the user wants to split source code into chunks for an LLM context window without breaking syntax mid-construct. Covers `ts-pack process --chunk-size`, why syntax-aware splits beat fixed-byte splits, picking a size, and the chunk JSON shape.

中文简介正在准备中。当前显示原文说明。

xberg-io/tree-sitter-language-pack星标 478(GitHub 478 + cccskills 0)

实测评分 未实测

查看安装方法

包含的文件(2)

  • SKILL.md3.0 KB
  • index.md566 B

SKILL.md(原文)

安装前可以查看交给 AI 代理的指令内容。

<!-- AI-RULEZ :: GENERATED FILE — DO NOT EDIT Content-Hash: blake3:f73428c23ccd047c1e8d74065c6be1dcc21b97f1f3e235ebc2a6779317208188 Source-Hash: blake3:f6af1693d7e3d301871730c180582f140a9c6aeee0d040ba3edbfb33b5d38409 Schema-Version: v1 -->

Syntax-aware chunking for LLMs

Splitting code on a fixed byte or line count cuts functions in half and strips context. ts-pack process <file> --chunk-size <bytes> splits on syntactic boundaries (whole functions, classes, blocks) so each chunk is a coherent unit, and emits them in the JSON chunks array.

Quick recipe

# ~2 KB chunks aligned to syntax boundaries
ts-pack process src/app.ts --chunk-size 2000

--chunk-size is a maximum size in bytes. The splitter packs whole syntactic units up to that bound; an oversized single construct becomes its own chunk rather than being cut. Chunks are added to the normal process JSON output under chunks.

Picking a size

  • Match the downstream model's token budget. A rough rule: bytes ÷ 4 ≈ tokens for code, so --chunk-size 4000 is on the order of ~1k tokens.
  • Larger chunks preserve more local context but fit fewer per request.
  • Leave headroom for the prompt, the surrounding messages, and the response — do not size chunks to the full context window.

Combining with extraction

Chunking composes with the other process features, so you can attach structure metadata to each request:

ts-pack process src/service.py --structure --chunk-size 3000 \
  | jq '{chunks: (.chunks | length), functions: (.structure | length)}'

Chunk output

chunks is a list of code-chunk objects in the process JSON. Each chunk carries its source text plus span information (line/byte offsets), so you can cite or re-locate a chunk back in the original file. Iterate the array to feed an LLM one coherent unit at a time:

ts-pack process big_module.py --chunk-size 2500 \
  | jq -c '.chunks[]'

SDK equivalent

The SDK exposes chunking through the process config: set the chunk_max_size field (in bytes) on ProcessConfig — the same value the CLI's --chunk-size flag sets. ProcessConfig is a frozen dataclass, so pass it to the constructor:

from tree_sitter_language_pack import process, ProcessConfig

config = ProcessConfig("python", chunk_max_size=2500)
result = process(source_code, config)
for chunk in result.chunks:          # ProcessResult is an object, not a dict
    send_to_llm(chunk.content)

When not to chunk

For a single small file that already fits the context window, skip chunking and pass the file whole. Reach for chunking when a file is large, when you are batching many files into a RAG index, or when you need stable, syntactically coherent units to cite.

评价

还没有评价。欢迎分享你的使用感受。

评论

无需登录即可发表。欢迎分享使用感受、提问,或说明在哪些环境下无法运行。

还没有评论。来写第一条吧。

提交后会立即公开。请勿填写邮箱、电话等个人信息。URL 最多 2 个。

0 / 1000 字

此表单受 reCAPTCHA 保护,适用 Google 的隐私权政策和服务条款。

同一仓库的技能

api

免费

Use tree-sitter-language-pack api reference documentation.

中文简介正在准备中。当前显示原文说明。

xberg-io/tree-sitter-language-pack4782026年10月26日 更新

cli

免费

Use tree-sitter-language-pack cli reference documentation.

中文简介正在准备中。当前显示原文说明。

xberg-io/tree-sitter-language-pack4782026年10月26日 更新

mcp

免费

Use tree-sitter-language-pack mcp reference documentation.

中文简介正在准备中。当前显示原文说明。

xberg-io/tree-sitter-language-pack4782026年10月26日 更新

Parse and extract code intelligence from 372 programming languages using tree-sitter grammars. Use when writing code that parses source, extracts structure/imports/exports/symbols/docstrings/comments, detects a language, runs syntax diagnostics, or produces syntax-aware chunks for LLMs — in Rust, Python, Node.js/TypeScript, or the ts-pack CLI. Covers installation, the CLI surface, the SDK surface, and parser-cache management.

中文简介正在准备中。当前显示原文说明。

xberg-io/tree-sitter-language-pack4782026年10月26日 更新

Use when the user wants to know which programming language a file or snippet is. Covers implicit detection in `ts-pack parse`/`process`, confirming support with `ts-pack list`/`info`, and the SDK detection functions for path, extension, and raw content.

中文简介正在准备中。当前显示原文说明。

xberg-io/tree-sitter-language-pack4782026年10月26日 更新

Use when the user wants structured code metadata from a source file — functions, classes, imports, exports, symbols, docstrings, comments, or syntax diagnostics. Covers `ts-pack process` feature flags, the JSON result shape, and the default feature set.

中文简介正在准备中。当前显示原文说明。

xberg-io/tree-sitter-language-pack4782026年10月26日 更新

查看 xberg-io 的全部技能

报告此技能的问题