add 语言 hook
- 作者仓库星标 0
- 作者仓库 skills-registry
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.tsto 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:
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 excludedclass-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:
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:
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
npx tsc --noEmit
npx vitest run tests/core/domains/ingest/pipeline/chunker/hooks/<language>/
<!-- tomevault:4.0:skill_md:2026-05-22 -->Source: artk0de/TeaRAGs-MCP — distributed by TomeVault.
- 流狐分类
- AI 智能
- 作者声明 Agent
- 未找到明确声明;不据此推断已兼容或已测试
- 静态检查
- 88 / 100 · 启发式扫描,不代表运行安全
- 作者 / 版本 / 许可
- @tomevault-io · 未声明 license
- 流狐 Token 估算
- 低消耗
- 流狐接入估算
- 即装即用
- 是否需要外部 API Key
- 未发现要求
- 检测到的系统要求
- macOS · Linux · Windows
- 底层运行要求
- 未声明
- 检测到的文件与系统行为
-
- 只读
- 允许写入 / 修改
- 检测到的网络行为
- 仅限本地
- 安装命令数
- 无(仅作为资料)
档案由构建时根据 SKILL.md 与安装命令自动衍生,可能与作者实际意图存在差异。
需要注意: 未限定 allowed-tools,默认拥有全部工具权限。
作者没有在当前 SKILL.md 中定义固定输出样例。 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.
Read chunker/hooks/types.ts. Every hook implements: HookContext provides: Read-only: containerNode, validChildren, code, codeLines, config
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
hooks/<language>/index.ts exports the ordered hook array:
Edit chunker/config.ts. Find the language entry in LANGUAGEDEFINITIONS and add the hooks property: If the language doesn't exist in LANGUAGEDEFINITIONS, add the full entry with
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
# 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[] = [
… 作者原文负责流程事实;流狐只索引当前章节、要点、文件与命令。
章节 -> Step 1: Check if the language directory exists → Step 2: Understand the hook interface → Step 3: Create the hook file → Step 4: Create or update the barrel → Step 5: Register in language config → Step 6: Write tests
要点 -> Exists · Doesn't exist · Read-only · Mutable
文件/命令 -> src/core/domains/ingest/pipeline/chunker/hooks/<language>/ · chunker/hooks/ · <language>/ · <language>/index.ts · chunker/hooks/types.ts · HookContext · containerNode · validChildren
内容 SHA-256 -> 040437fe71cd
方法与流程
适用与边界
原文中的明确线索
src/core/domains/ingest/pipeline/chunker/hooks/<language>/、chunker/hooks/、<language>/、<language>/index.ts、chunker/hooks/types.ts、HookContext、containerNode、validChildren