添加语言挂钩
- 作者仓库星标 0
- 作者仓库 skills-registry
- 领域
- 人工智能
- 作者声明的智能体
- 未找到明确声明;不据此推断已兼容或已测试
- 静态检查
- 88 / 100 · 启发式扫描,不代表运行安全
- 运行环境证据
- 未执行;当前没有隔离运行测试证据
- 作者 / 版本 / 许可证
- @tomevault-io · 未声明许可证
- 上下文用量评级
- 低消耗
- 接入复杂程度
- 即装即用
- 是否需要外部接口密钥
- 不需要
- 兼容的系统
- macOS · Linux · Windows
- 运行环境要求
- 未检出明确要求
- 检测到的文件与系统行为
-
- 只读
- 允许写入 / 修改
- 网络行为
- 仅限本地
- 安装命令数
- 无(仅作为资料)
需要注意: 未声明工具权限范围;实际权限由运行环境决定。
在 `chunker/hooks/` 中查找现有的 `<language>/` 目录。存在 - 您正在向现有语言添加新的钩子。阅读`<language>/index.ts`以查看当前的钩子链。不存在——你正在为一种新语言添加钩子。创建`<language>/`目录。
阅读`chunker/hooks/types.ts`。每个钩子实现: `HookContext` 提供: 只读: `containerNode`、 `validChildren`、 `code`、 `codeLines`、 `config` 可变: `excludedRows`、 `methodPrefixes`、 `methodStartLines`、 `bodyChunks`
创建`hooks/<language>/<hook-name>.ts`。遵循现有模式: `comment-capture.ts` — 提取文档注释,将行标记为已排除 `class-body-chunker.ts` — 将大型类主体拆分为方法级块 命名导出的钩子:`<language><Purpose>Hook`(例如,`rubyCommentCaptureHook`、`typescriptBodyChunkingHook`)。
`hooks/<language>/index.ts` 导出有序的钩子数组:
编辑`chunker/config.ts`。在`LANGUAGE_DEFINITIONS`中找到语言条目并添加`hooks`属性:如果`LANGUAGE_DEFINITIONS`中不存在该语言,请添加完整条目`loadModule`、`extractLanguage`、`chunkableTypes`和`hooks`。
测试在`tests/core/domains/ingest/pipeline/chunker/hooks/<language>/`中进行。遵循`typescript/`或`ruby/`目录中的现有测试模式。每个钩子应该有自己的测试文件,用真正的`HookContext`测试`process()`功能(使用`types.ts`中的`createHookContext()`)。
来源:artk0de/TeaRAGs-MCP — 由 TomeVault 分发。
# Add Language Hook
Add a chunking hook for a new or existing language in the ingest pipeline.
Hooks live in `src/core/domains/ingest/pipeline/chunker/hooks/<language>/`.
## Step 1: Check if the language directory exists
Look in `chunker/hooks/` for an existing `<language>/` directory.
- **Exists** — you're adding a new hook to an existing language. Read
`<language>/index.ts` to see the current hook chain.
- **Doesn't exist** — you're adding hooks for a new language. Create
`<language>/` directory.
## Step 2: Understand the hook interface
Read `chunker/hooks/types.ts`. Every hook implements:
```typescript
interface ChunkingHook {
name: string;
process: (ctx: HookContext) => void;
}
```
`HookContext` provides:
- **Read-only**: `containerNode`, `validChildren`, `code`, `codeLines`, `config`
- **Mutable**: `excludedRows`, `methodPrefixes`, `methodStartLines`,
`bodyChunks`
Hooks mutate the context in order. Earlier hooks populate state that later hooks
read (e.g., comment-capture populates `excludedRows`, body-chunker reads it).
## Step 3: Create the hook file
Create `hooks/<language>/<hook-name>.ts`. Follow existing patterns:
- `comment-capture.ts` — extracts doc comments, marks rows as excluded
- `class-body-chunker.ts` — splits large class bodies into method-level chunks
Name the exported hook: `<language><Purpose>Hook` (e.g.,
`rubyCommentCaptureHook`, `typescriptBodyChunkingHook`).
## Step 4: Create or update the barrel
`hooks/<language>/index.ts` exports the ordered hook array:
```typescript
import type { ChunkingHook } from "../types.js";
import { myCommentCaptureHook } from "./comment-capture.js";
import { myBodyChunkingHook } from "./class-body-chunker.js";
export const <language>Hooks: ChunkingHook[] = [
myCommentCaptureHook, // Order matters: comment-capture first
myBodyChunkingHook, // Body chunker reads excludedRows
];
```
## Step 5: Register in language config
Edit `chunker/config.ts`. Find the language entry in `LANGUAGE_DEFINITIONS` and
add the `hooks` property:
```typescript
import { <language>Hooks } from "./hooks/<language>/index.js";
// In LANGUAGE_DEFINITIONS:
<language>: {
// ... existing config ...
hooks: <language>Hooks,
},
```
If the language doesn't exist in `LANGUAGE_DEFINITIONS`, add the full entry with
`loadModule`, `extractLanguage`, `chunkableTypes`, and `hooks`.
## Step 6: Write tests
Tests go in `tests/core/domains/ingest/pipeline/chunker/hooks/<language>/`.
Follow existing test patterns in `typescript/` or `ruby/` directories.
Each hook should have its own test file testing the `process()` function with a
real `HookContext` (use `createHookContext()` from `types.ts`).
## Step 7: Verify
```bash
npx tsc --noEmit
npx vitest run tests/core/domains/ingest/pipeline/chunker/hooks/<language>/
```
---
> Source: [artk0de/TeaRAGs-MCP](https://github.com/artk0de/TeaRAGs-MCP) — distributed by [TomeVault](https://tomevault.io).
<!-- tomevault:4.0:skill_md:2026-05-22 -->
按说明文件中的顺序排列。
第1步:检查语言目录是否存在
第二步:了解hook接口
第三步:创建钩子文件
步骤 4:创建或更新桶
第5步:在语言配置中注册
文件/命令 -> src/core/domains/ingest/pipeline/chunker/hooks/<language>/ · chunker/hooks/ · <language>/ · <language>/index.ts · chunker/hooks/types.ts · HookContext · containerNode · validChildren
内容校验值 -> 040437fe71cd
当前原文的自动摘译,尚未人工审校。
第1步:检查语言目录是否存在
在
chunker/hooks/中查找现有的<language>/目录。存在 - 您正在向现有语言添加新的钩子。阅读<language>/index.ts可以看到当前的钩子链。不存在——你正在为一种新语言添加钩子。创建<language>/目录。第三步:创建钩子文件
创建
hooks/<language>/<hook-name>.ts。遵循现有模式:comment-capture.ts- 提取文档注释,将行标记为排除class-body-chunker.ts- 将大型类主体拆分为方法级块 命名导出的钩子:<language><Purpose>Hook(例如,rubyCommentCaptureHook、typescriptBodyChunkingHook)。