my-skill
Use this skill when you need to verify valid enum field values.
- License 许可
- MIT
- 最近更新
- 2026-11-09
- Stars
- ★ 7
- Forks
- 0
01 前言 Front Matter
- type
- Playbook
- title
- Tree Sitter Language Pack Detecting Languages
- x-ai-rulez
- { "id": "tree-sitter-language-pack-detecting-languages", "kind": "skill", "metadata": { "name": "tree-sitter-language-pack-detecting-languages" } }
- description
- 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.
02 资源文件 5
- 资产文件assets/.gitkeep—
- 参考文档eval_queries.json18 B
- 参考文档index.md328 B
- 参考文档references/.gitkeep—
- 脚本scripts/.gitkeep—
03 SKILL.md 正文
Detecting languages
tree-sitter-language-pack maps a file to one of 372 supported languages. Detection works from a file path, a bare extension, or — via the SDK — the file content itself.
On the CLI: detection is implicit
There is no standalone ts-pack detect command. parse and process
auto-detect the language from the file extension and act on it:
ts-pack parse src/app.ts # detects "typescript", parses
ts-pack process app.py # detects "python", extracts
When detection fails (no extension, ambiguous, or stdin), pass --language:
cat snippet | ts-pack parse - --language go
To check whether a language name is supported and cached without parsing
anything, use list and info:
ts-pack list --filter type # languages whose name contains "type"
ts-pack list --manifest # every language in the remote manifest
ts-pack info typescript # is it known? is it downloaded? cache path?
In the SDK: explicit detection
The core exposes three detection functions, including content-based detection that the CLI does not surface:
| Function | Detects from |
|---|---|
detect_language_from_path(path) |
Full path (uses the extension). |
detect_language_from_extension(ext) |
A bare extension like "rs". |
detect_language_from_content(content) |
Raw source text — no path needed. |
Each returns the language name or null/None when no grammar matches.
Python
from tree_sitter_language_pack import (
detect_language_from_path,
detect_language_from_extension,
detect_language_from_content,
)
detect_language_from_path("src/app.py") # "python"
detect_language_from_extension("rs") # "rust"
detect_language_from_content(open("x").read()) # from the shebang line, if present
Node.js / TypeScript
import { detectLanguageFromPath, detectLanguageFromContent } from "@xberg-io/tree-sitter-language-pack";
const lang = detectLanguageFromPath("src/app.ts") ?? detectLanguageFromContent(source);
Choosing CLI vs SDK
- Path or extension is enough, one-shot → just run
ts-pack parse/processand let it auto-detect. - Only raw content (a pasted snippet, a stream, a file with no extension) →
use the SDK's
detect_language_from_content, then pass the result as--languageto the CLI if needed.
When to reach for the other skills
Once the language is known, hand off to tree-sitter-language-pack-parsing-source (syntax tree) or
tree-sitter-language-pack-extracting-code-structure (metadata). To see or prefetch the parser for a
detected language, see tree-sitter-language-pack-managing-parsers.
04 同仓库更多 Skills
fixable-skill
Exercise grouped Action fix findings.
skilllint
Use the skilllint CLI to validate, explain, and fix agent plugins, skills, agents, commands, and platform files. Use when asked to lint agent artifacts, investigate a skilllint rule ID, or verify a plugin before commit.
my-skill
Use this skill when you need to verify valid name pattern compliance.
my-skill
Use this skill when you need to verify quoted descriptions with colons: example.
my-skill
Use this skill when you need to verify CSV string format for tools.
my-skill
Use this skill when you need to verify field types are all correct.