| name | kb-init |
| description | 初始化一个 LLM 驱动的知识库。当用户说"初始化知识库"、"创建知识库"、"新建知识库"、"kb init"时触发。
基于 Karpathy 的 LLM Knowledge Base 模式:raw/ 存原始资料,LLM 编译成 wiki/,索引替代 RAG。
|
| user-invocable | true |
| argument-hint | ["可选:目标目录路径,默认当前目录"] |
/kb-init
Initialize an LLM-driven knowledge base directory structure.
Steps
1. Determine target directory
Use $ARGUMENTS as the target directory path if provided; otherwise use the current working directory. Store this as {target}.
2. Check for existing knowledge base
Use the Read tool to check if {target}/index/MASTER-INDEX.md exists. If it does, warn the user:
⚠️ 目标目录已包含知识库(发现 index/MASTER-INDEX.md)。继续操作可能覆盖现有配置。是否继续?
Wait for user confirmation before proceeding. If user declines, abort.
3. Create directory structure
Use the Bash tool to create the following directories under {target}:
mkdir -p {target}/raw
mkdir -p {target}/wiki/concepts
mkdir -p {target}/wiki/sources
mkdir -p {target}/wiki/comparisons
mkdir -p {target}/output/analysis
mkdir -p {target}/output/slides
mkdir -p {target}/index
mkdir -p {target}/scripts/extractors
Directory purposes:
raw/ — 原始资料(只读,LLM 不改动)
wiki/concepts/ — 核心概念文章
wiki/sources/ — 来源摘要
wiki/comparisons/ — 对比分析
output/analysis/ — 查询输出的分析报告
output/slides/ — Marp 幻灯片输出
index/ — 索引文件
scripts/extractors/ — 预处理脚本
4. Locate kb-skills repository root
Determine the kb-skills installation directory by finding where this SKILL.md lives and going up 2 levels to the repo root. Store this as {kb-skills-repo}.
KB_SKILLS_REPO="$(cd "$(dirname "$0")/../.." && pwd)"
In practice, use the Bash tool to resolve the path relative to this skill file's known location under skills/kb-init/SKILL.md.
5. Copy template files
Copy template files from {kb-skills-repo}/templates/general/ to {target}/index/:
cp {kb-skills-repo}/templates/general/ONTOLOGY.md {target}/index/
cp {kb-skills-repo}/templates/general/MASTER-INDEX.md {target}/index/
cp {kb-skills-repo}/templates/general/TOPIC-MAP.md {target}/index/
cp {kb-skills-repo}/templates/general/RAW-REGISTRY.md {target}/index/
Do NOT overwrite existing index files without user confirmation. If any target file already exists, ask before overwriting.
6. Copy preprocessing scripts
Copy preprocessing scripts from {kb-skills-repo}/scripts/ to {target}/scripts/:
cp {kb-skills-repo}/scripts/*.py {target}/scripts/
cp {kb-skills-repo}/scripts/requirements.txt {target}/scripts/
7. Check Python dependencies
Run the following to check which dependencies are installed:
pip show pymupdf openpyxl pandas pytesseract python-docx Pillow 2>&1
Parse the output and report which packages are missing. If any are missing, ask the user:
以下 Python 依赖缺失:{missing_list}。是否运行 pip install -r scripts/requirements.txt 安装?
If user agrees, run pip install -r {target}/scripts/requirements.txt.
8. Configure SessionStart hook (optional)
Ask the user:
是否配置 SessionStart 钩子?该钩子会在每次会话启动时自动检测 raw/ 目录中的新文件。
If user agrees:
- Read the path of
{kb-skills-repo}/hooks/check_raw.py
- Read
~/.claude/settings.json using the Read tool
- Add a SessionStart hook entry that runs
python {kb-skills-repo}/hooks/check_raw.py {target}/raw to the hooks.SessionStart array in ~/.claude/settings.json
- Write the updated settings back using the Edit tool
9. Print initialization summary
Print a summary like:
✅ 知识库初始化完成!
📁 目录结构:
{target}/raw/ — 原始资料
{target}/wiki/concepts/ — 核心概念
{target}/wiki/sources/ — 来源摘要
{target}/wiki/comparisons/ — 对比分析
{target}/output/analysis/ — 分析报告
{target}/output/slides/ — 幻灯片
{target}/index/ — 索引文件
{target}/scripts/ — 预处理脚本
📄 模板文件:已复制 ONTOLOGY.md, MASTER-INDEX.md, TOPIC-MAP.md, RAW-REGISTRY.md
🐍 Python 依赖:{status}
🔗 SessionStart 钩子:{hook_status}
10. Suggest next step
Print:
📌 下一步:把资料文件放入 raw/ 目录,然后运行 /kb-ingest