kb
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinesekb CLI and Knowledge Base Pattern
kb CLI and Knowledge Base Pattern
Build and maintain a self-compiling Obsidian markdown knowledge base using the CLI. The LLM reads raw sources, writes cross-linked wiki articles, files Q&A results back into the corpus, and runs lint-and-heal passes. The CLI also supports codebase ingestion with deep inspection commands for code quality, architecture health, and symbol relationships.
kbEach topic lives in its own top-level folder (e.g. ) with , , , subtrees plus a topic-level and . All topics share a single Obsidian vault at the repo root. Read for the full rationale and the four-phase pipeline (ingest → compile → query → lint).
ai-harness/raw/wiki/outputs/bases/log.mdCLAUDE.mdreferences/architecture.mdThe topic's (symlinked to ) is the schema document — it tells the LLM the scope, conventions, current articles, and research gaps for that topic. Co-evolve it as the topic matures.
CLAUDE.mdAGENTS.md使用 CLI构建并维护一个可自动编译的Obsidian Markdown知识库。LLM读取原始来源,编写带交叉链接的维基文章,将问答结果存入语料库,并运行检查与修复流程。该CLI还支持代码库导入,通过深度检查命令分析代码质量、架构健康状况和符号关系。
kb每个主题都位于独立的顶级文件夹中(例如),包含、、、子目录,以及主题级别的和。所有主题共享仓库根目录下的一个Obsidian库。阅读了解完整设计思路以及四阶段流水线(导入 → 编译 → 查询 → 检查)。
ai-harness/raw/wiki/outputs/bases/log.mdCLAUDE.mdreferences/architecture.md主题的**(符号链接至)是模式文档**——它告知LLM该主题的范围、约定、现有文章以及研究空白。随着主题发展,需同步更新该文档。
CLAUDE.mdAGENTS.mdPrerequisites
前置条件
- Verify the binary is available:
kbbashkb version - For search and index commands, verify QMD is installed:
bash
qmd --version # If missing: npm install -g @tobilu/qmd - Supported source languages for codebase analysis: TypeScript (), TSX (
.ts), JavaScript (.tsx), JSX (.js), Go (.jsx)..go
- 验证二进制文件可用:
kbbashkb version - 对于搜索和索引命令,验证QMD已安装:
bash
qmd --version # 若未安装:npm install -g @tobilu/qmd - 代码库分析支持的源语言:TypeScript()、TSX(
.ts)、JavaScript(.tsx)、JSX(.js)、Go(.jsx)。.go
Pattern Overview
模式概述
Based on Andrej Karpathy's LLM Wiki pattern, the KB treats the LLM as a compiler that reads raw source documents and produces a structured, cross-linked markdown wiki. The four-phase loop:
- Ingest — Scrape/curate sources via CLI →
kb(immutable staging)raw/ - Compile — LLM reads , writes
raw/articles (3000-4000 words, dense wikilinks)wiki/concepts/ - Query — Q&A against wiki → file answers to , promote strong answers to wiki
outputs/queries/ - Lint — Automated structural checks + LLM-driven semantic healing
Read for the full rationale, context-window vs RAG tradeoffs, and multi-topic vault design.
references/architecture.md基于Andrej Karpathy的LLM维基模式,该知识库将LLM视为编译器,读取原始源文档并生成结构化、带交叉链接的Markdown维基。四阶段循环:
- 导入 — 通过CLI抓取/整理来源 → 存入
kb(不可变暂存区)raw/ - 编译 — LLM读取内容,编写
raw/下的文章(3000-4000字,包含密集的维基链接)wiki/concepts/ - 查询 — 针对维基进行问答 → 将答案存入,将优质答案升级为维基文章
outputs/queries/ - 检查 — 自动化结构检查 + LLM驱动的语义修复
阅读了解完整设计思路、上下文窗口与RAG的权衡,以及多主题库设计。
references/architecture.mdRelated Skills
相关技能
This skill orchestrates several companion skills for the LLM-driven phases:
- obsidian-markdown — author wiki articles with valid Obsidian Flavored Markdown (wikilinks, callouts, embeds, properties).
- obsidian-bases — create files under
.basefor dashboard views, filters, and formulas.<topic>/bases/ - obsidian-cli — interact with the running Obsidian vault from the command line (open notes, search, refresh indexes).
此技能协调多个配套技能以实现LLM驱动的各阶段:
- obsidian-markdown — 使用符合规范的Obsidian Flavored Markdown(维基链接、提示框、嵌入、属性)编写维基文章。
- obsidian-bases — 在下创建
<topic>/bases/文件,用于仪表板视图、筛选器和公式。.base - obsidian-cli — 从命令行与运行中的Obsidian库交互(打开笔记、搜索、刷新索引)。
kb CLI Quick Reference
kb CLI快速参考
Topic management
主题管理
bash
kb topic new <slug> <title> <domain> # scaffold a new topic
kb topic list # list all topics in the vault
kb topic info <slug> # topic metadata (counts, last log entry)bash
kb topic new <slug> <title> <domain> # 搭建新主题
kb topic list # 列出库中所有主题
kb topic info <slug> # 主题元数据(统计数、最新日志条目)Ingestion (auto-generates frontmatter, auto-appends to log.md)
导入(自动生成前置元数据,自动追加至log.md)
bash
kb ingest url <url> --topic <slug> # scrape a web URL via Firecrawl
kb ingest file <path> --topic <slug> # convert local file (PDF, DOCX, EPUB, HTML, images w/OCR, etc.)
kb ingest youtube <url> --topic <slug> # extract YouTube transcript
kb ingest bookmarks <path> --topic <slug> # ingest a bookmark-cluster markdown file
kb ingest codebase <path> --topic <slug> # analyze a codebase into raw/codebase/bash
kb ingest url <url> --topic <slug> # 通过Firecrawl抓取网页URL
kb ingest file <path> --topic <slug> # 转换本地文件(PDF、DOCX、EPUB、HTML、带OCR的图片等)
kb ingest youtube <url> --topic <slug> # 提取YouTube字幕
kb ingest bookmarks <path> --topic <slug> # 导入书签集群Markdown文件
kb ingest codebase <path> --topic <slug> # 分析代码库并存入raw/codebase/Codebase inspection
代码库检查
bash
kb inspect smells [--type <smell-type>] --format json
kb inspect dead-code --format json
kb inspect complexity [--top N] --format json
kb inspect blast-radius [--min N] [--top N] --format json
kb inspect coupling [--unstable] --format json
kb inspect circular-deps --format json
kb inspect symbol <name> --format json
kb inspect file <path> --format json
kb inspect backlinks <name-or-path> --format json
kb inspect deps <name-or-path> --format jsonbash
kb inspect smells [--type <smell-type>] --format json
kb inspect dead-code --format json
kb inspect complexity [--top N] --format json
kb inspect blast-radius [--min N] [--top N] --format json
kb inspect coupling [--unstable] --format json
kb inspect circular-deps --format json
kb inspect symbol <name> --format json
kb inspect file <path> --format json
kb inspect backlinks <name-or-path> --format json
kb inspect deps <name-or-path> --format jsonStructural linting
结构检查
bash
kb lint [<slug>] [--save] # dead links, orphans, missing sources, format violations, stale contentbash
kb lint [<slug>] [--save] # 检查无效链接、孤立文章、缺失来源、格式违规、过时内容Indexing and search (requires QMD)
索引与搜索(需QMD)
bash
kb index --topic <slug> # create or update QMD collection
kb search "<query>" --topic <slug> # hybrid BM25 + vector search
kb search "<query>" --lex --topic <slug> # keyword-only search
kb search "<query>" --vec --topic <slug> # vector-only searchAfter running or , the CLI auto-appends entries to . Manual log entries are still needed for compile, query, promote, and split operations (Procedure 5).
kb ingestkb lint --save<topic>/log.mdbash
kb index --topic <slug> # 创建或更新QMD集合
kb search "<query>" --topic <slug> # 混合BM25 + 向量搜索
kb search "<query>" --lex --topic <slug> # 仅关键词搜索
kb search "<query>" --vec --topic <slug> # 仅向量搜索运行或后,CLI会自动将条目追加至。编译、查询、升级和拆分操作仍需手动添加日志条目(见流程5)。
kb ingestkb lint --save<topic>/log.mdCommand Dispatch
命令匹配
Map the user's intent to the correct command:
| Intent | Command |
|---|---|
| Scaffold a new topic | |
| List all topics | |
| Scrape a web URL | |
| Ingest a local file (PDF, DOCX, etc.) | |
| Extract a YouTube transcript | |
| Ingest bookmark clusters | |
| Analyze a codebase | |
| Find code smells | |
| Find dead exports and orphan files | |
| Rank functions by complexity | |
| Find high-impact symbols (blast radius) | |
| Find unstable files (coupling) | |
| Find circular imports | |
| Look up a specific symbol | |
| Look up a specific file | |
| Find what depends on X (incoming refs) | |
| Find what X depends on (outgoing deps) | |
| Run structural lint | |
| Index vault for search | |
| Search the knowledge base | |
将用户意图映射到正确命令:
| 意图 | 命令 |
|---|---|
| 搭建新主题 | |
| 列出所有主题 | |
| 抓取网页URL | |
| 导入本地文件(PDF、DOCX等) | |
| 提取YouTube字幕 | |
| 导入书签集群 | |
| 分析代码库 | |
| 查找代码异味 | |
| 查找死导出和孤立文件 | |
| 按复杂度排序函数 | |
| 查找高影响符号(影响范围) | |
| 查找不稳定文件(耦合度) | |
| 查找循环导入 | |
| 查找特定符号 | |
| 查找特定文件 | |
| 查找依赖X的内容(传入引用) | |
| 查找X依赖的内容(传出依赖) | |
| 运行结构检查 | |
| 为搜索创建库索引 | |
| 搜索知识库 | |
Codebase Analysis Workflow
代码库分析工作流
For codebase-specific analysis, the command must run before any inspect command.
kb ingest codebaseWorkflow A -- Code Analysis (no QMD required):
kb ingest codebase <path> --topic <slug> --> kb inspect <subcommand>Workflow B -- Full Pipeline (requires QMD):
kb ingest codebase <path> --topic <slug> --> kb index --> kb search <query>On first run, bootstraps the topic under by default. Later commands auto-discover this vault only when they run from inside that repository tree; otherwise pass .
kb ingest codebase<path>/.kb/vault/<topic-slug>/--vault <path>针对代码库的特定分析,必须先运行命令,才能执行任何inspect命令。
kb ingest codebase工作流A -- 代码分析(无需QMD):
kb ingest codebase <path> --topic <slug> --> kb inspect <subcommand>工作流B -- 完整流水线(需QMD):
kb ingest codebase <path> --topic <slug> --> kb index --> kb search <query>首次运行时,默认在下初始化主题。后续命令仅在该仓库目录内运行时自动识别此库;否则需传递参数。
kb ingest codebase<path>/.kb/vault/<topic-slug>/--vault <path>Ingest a Codebase
导入代码库
bash
kb ingest codebase <path> --topic <slug> --progress neverAlways use in agent contexts to prevent TTY progress bars from corrupting stdout.
Use and only when bootstrapping a missing topic.
--progress never--title--domainParse the JSON output from stdout to extract key values:
- -- the topic identifier for later commands
topicSlug - -- absolute path to the vault root
vaultPath - -- absolute path to the topic directory
topicPath - ,
filesScanned,filesParsed-- summary statisticssymbolsExtracted - -- check for warnings or errors
diagnostics
Stderr carries structured stage logs. Do not treat stderr content as failure evidence.
Key flags:
- -- override vault root location
--vault <dir> - -- deprecated alias for
--output <dir>--vault - -- target topic slug inside the vault
--topic <slug> - -- bootstrap-only topic title override
--title <value> - -- bootstrap-only topic domain override
--domain <value> - -- re-include paths that would otherwise be ignored (repeatable)
--include <pattern> - -- exclude additional paths from scanning (repeatable)
--exclude <pattern> - -- enable semantic analysis when adapters support it
--semantic
Read for the full flag table and output schema.
references/cli-ingest-codebase.mdbash
kb ingest codebase <path> --topic <slug> --progress never在Agent环境中始终使用,防止TTY进度条破坏标准输出。仅在初始化缺失主题时使用和参数。
--progress never--title--domain解析标准输出中的JSON以提取关键值:
- -- 后续命令使用的主题标识符
topicSlug - -- 库根目录的绝对路径
vaultPath - -- 主题目录的绝对路径
topicPath - ,
filesScanned,filesParsed-- 统计摘要symbolsExtracted - -- 检查警告或错误
diagnostics
标准错误输出包含结构化阶段日志,请勿将标准错误内容视为失败证据。
关键参数:
- -- 覆盖库根目录位置
--vault <dir> - --
--output <dir>的已弃用别名--vault - -- 库内的目标主题标识
--topic <slug> - -- 仅初始化时覆盖主题标题
--title <value> - -- 仅初始化时覆盖主题领域
--domain <value> - -- 重新包含原本会被忽略的路径(可重复使用)
--include <pattern> - -- 额外排除扫描路径(可重复使用)
--exclude <pattern> - -- 当适配器支持时启用语义分析
--semantic
阅读获取完整参数表和输出模式。
references/cli-ingest-codebase.mdInspect the Vault
检查库内容
Run inspect subcommands to analyze code quality and architecture.
Shared flags for all inspect subcommands:
- -- always use JSON for programmatic parsing
--format json - -- explicit vault root (omit to auto-discover from cwd)
--vault <path> - -- explicit topic slug (omit if only one topic exists)
--topic <slug>
运行inspect子命令分析代码质量和架构。
所有inspect子命令的共享参数:
- -- 用于程序解析时始终使用JSON格式
--format json - -- 显式指定库根目录(省略则从当前工作目录自动识别)
--vault <path> - -- 显式指定主题标识(若仅存在一个主题可省略)
--topic <slug>
Tabular Subcommands
表格类子命令
These return a list of rows sorted by the primary metric:
-
smells -- List symbols and files with detected code smells.
kb inspect smells --format json kb inspect smells --type high-complexity --format json -
dead-code -- List dead exports and orphan files.
kb inspect dead-code --format json -
complexity -- Rank functions/methods by cyclomatic complexity. Default top 20.
kb inspect complexity --format json kb inspect complexity --top 50 --format json -
blast-radius -- Rank symbols by transitive dependent count.
kb inspect blast-radius --format json kb inspect blast-radius --min 10 --top 20 --format json -
coupling -- Rank files by instability (Ce / (Ca + Ce)).
kb inspect coupling --format json kb inspect coupling --unstable --format json -
circular-deps -- List files participating in circular import chains.
kb inspect circular-deps --format json
这些命令返回按主指标排序的行列表:
-
smells -- 列出检测到代码异味的符号和文件。
kb inspect smells --format json kb inspect smells --type high-complexity --format json -
dead-code -- 列出死导出和孤立文件。
kb inspect dead-code --format json -
complexity -- 按圈复杂度对函数/方法排序。默认显示前20个。
kb inspect complexity --format json kb inspect complexity --top 50 --format json -
blast-radius -- 按传递依赖数量对符号排序。
kb inspect blast-radius --format json kb inspect blast-radius --min 10 --top 20 --format json -
coupling -- 按不稳定性(Ce / (Ca + Ce))对文件排序。
kb inspect coupling --format json kb inspect coupling --unstable --format json -
circular-deps -- 列出参与循环导入链的文件。
kb inspect circular-deps --format json
Detail Lookup Subcommands
详情查询子命令
These return field-value pairs for a single matched entity:
-
symbol <name> -- Case-insensitive substring match. Returns detail fields for a single match, or a summary table for multiple matches.
kb inspect symbol parseConfig --format json -
file <path> -- Exact source path lookup. Use the source-relative path as stored in vault frontmatter.
kb inspect file src/config.ts --format json
这些命令返回单个匹配实体的键值对:
-
symbol <name> -- 不区分大小写的子字符串匹配。返回单个匹配的详细字段,或多个匹配的摘要表。
kb inspect symbol parseConfig --format json -
file <path> -- 精确源路径查询。使用库前置元数据中存储的源相对路径。
kb inspect file src/config.ts --format json
Relation Subcommands
关系类子命令
These return relation edges (, , ):
target_pathtypeconfidence-
backlinks <name-or-path> -- Incoming references. Accepts a symbol name or file path.
kb inspect backlinks parseConfig --format json -
deps <name-or-path> -- Outgoing dependencies. Accepts a symbol name or file path.
kb inspect deps src/config.ts --format json
Read for all column schemas and flag details.
references/cli-inspect.md这些命令返回关系边(, , ):
target_pathtypeconfidence-
backlinks <name-or-path> -- 传入引用。接受符号名称或文件路径。
kb inspect backlinks parseConfig --format json -
deps <name-or-path> -- 传出依赖。接受符号名称或文件路径。
kb inspect deps src/config.ts --format json
阅读获取所有列模式和参数详情。
references/cli-inspect.mdIndex the Vault
为库创建索引
Index the vault content into QMD for search. This step requires QMD on PATH.
bash
kb index --topic <slug>The command is idempotent: it checks whether the collection already exists and chooses (create) or (refresh) automatically.
addupdateKey flags:
- (default true) -- run embedding after syncing files
--embed - -- force re-embedding all documents
--force-embed - -- attach human context to improve search relevance
--context <text> - -- override the derived collection name
--name <name>
Read for the full output schema.
references/cli-search-index.md将库内容索引到QMD以支持搜索。此步骤要求QMD在PATH中。
bash
kb index --topic <slug>该命令具有幂等性:它会检查集合是否已存在,自动选择创建(add)或更新(refresh)。
关键参数:
- (默认true)-- 同步文件后运行嵌入
--embed - -- 强制重新嵌入所有文档
--force-embed - -- 添加人工上下文以提高搜索相关性
--context <text> - -- 覆盖自动生成的集合名称
--name <name>
阅读获取完整输出模式。
references/cli-search-index.mdSearch the Vault
搜索库内容
Search indexed vault content with QMD. Requires a prior run.
kb indexbash
kb search "<query>" --topic <slug> --format jsonSearch modes:
- Hybrid (default) -- combines lexical and vector search
- Lexical () -- BM25 keyword search only
--lex - Vector () -- embedding-based semantic search
--vec
The and flags are mutually exclusive. Omit both for hybrid mode.
--lex--vecKey flags:
- (default 10) -- maximum results
--limit N - -- minimum relevance threshold
--min-score N - -- return full document content instead of snippets
--full - -- return all matches above the minimum score
--all
Read for full details.
references/cli-search-index.md使用QMD搜索已索引的库内容。需先运行命令。
kb indexbash
kb search "<query>" --topic <slug> --format json搜索模式:
- 混合模式(默认)-- 结合词法和向量搜索
- 词法模式()-- 仅BM25关键词搜索
--lex - 向量模式()-- 基于嵌入的语义搜索
--vec
--lex--vec关键参数:
- (默认10)-- 最大结果数
--limit N - -- 最低相关性阈值
--min-score N - -- 返回完整文档内容而非片段
--full - -- 返回所有高于最低分数的匹配结果
--all
阅读获取完整详情。
references/cli-search-index.mdKB Maintenance Procedures
知识库维护流程
Procedure 1: Compile a wiki article
流程1:编译维基文章
- Read to anchor on length, style, wikilink density, and sourcing rules.
references/compilation-guide.md - Identify candidate sources via or read
kb search "<topic phrase>" --topic <slug>.<topic>/wiki/index/Source Index.md - Load the candidate raw sources fully into context.
- Load for orientation on existing articles and wikilink targets (including in other topics).
<topic>/wiki/index/Concept Index.md - Surface takeaways BEFORE drafting. Present to the user: 3-5 key takeaways from the sources, the entities/concepts this article will introduce or update, and anything that contradicts existing wiki articles. Ask: "Anything specific to emphasize or de-emphasize?" Wait for the response. Skip this step only if the user has explicitly asked for autonomous compilation.
- Write the article to following the obsidian-markdown skill for wikilink, callout, and frontmatter syntax. Use the frontmatter schema from
<topic>/wiki/concepts/<Article Title>.md. Target 3000-4000 words with a Sources section, wikilinks to related articles, and code or diagram blocks where applicable.references/frontmatter-schemas.md - Backlink audit -- do not skip. Grep every existing article in for mentions of the new article's title, aliases, or core entities. For each match, add a
<topic>/wiki/concepts/wikilink at the first mention (and one later occurrence). This is the step most commonly skipped -- a compounding wiki depends on bidirectional links.[[New Article]]bashgrep -rln "<new article title or key term>" <topic>/wiki/concepts/ - Update the topic's indexes (Procedure 2).
- Update current-articles list.
<topic>/CLAUDE.md - Re-index the topic's collection: .
kb index --topic <slug> - Append an entry to (Procedure 5) -- e.g.,
<topic>/log.md.## [YYYY-MM-DD] compile | <Article Title> (<word_count> words, <N> sources)
When updating an existing article (rather than writing new), use the diff format and contradiction-sweep workflow described in .
Current / Proposed / Reason / Sourcereferences/compilation-guide.md- 阅读,明确文章长度、风格、维基链接密度和来源规则。
references/compilation-guide.md - 通过或阅读
kb search "<主题短语>" --topic <slug>确定候选来源。<topic>/wiki/index/Source Index.md - 将候选原始来源完全加载到上下文中。
- 加载,了解现有文章和维基链接目标(包括其他主题中的内容)。
<topic>/wiki/index/Concept Index.md - 在起草前先提炼要点。向用户展示:从来源中提取的3-5个关键要点、本文将介绍或更新的实体/概念,以及与现有维基文章矛盾的内容。询问:*“有什么需要特别强调或弱化的内容吗?”*等待用户回复。仅当用户明确要求自主编译时才可跳过此步骤。
- 按照obsidian-markdown技能的维基链接、提示框和前置元数据语法,将文章写入。使用
<topic>/wiki/concepts/<Article Title>.md中的前置元数据模式。目标字数为3000-4000字,包含来源部分、相关文章的维基链接,以及适用的代码或图表块。references/frontmatter-schemas.md - 反向链接审核——不可跳过。在下的所有现有文章中搜索新文章的标题、别名或核心实体。对于每个匹配项,在首次提及(以及后续一次提及)处添加
<topic>/wiki/concepts/维基链接。这是最常被跳过的步骤——一个相互关联的维基依赖于双向链接。[[New Article]]bashgrep -rln "<新文章标题或关键词>" <topic>/wiki/concepts/ - 更新主题索引(见流程2)。
- 更新中的现有文章列表。
<topic>/CLAUDE.md - 重新索引主题集合:。
kb index --topic <slug> - 向追加条目(见流程5)——例如
<topic>/log.md。## [YYYY-MM-DD] compile | <文章标题>(<字数>字,<N>个来源)
当更新现有文章(而非撰写新文章)时,使用中描述的差异格式和矛盾排查工作流。
references/compilation-guide.md当前内容 / 拟修改内容 / 修改原因 / 来源Procedure 2: Maintain topic indexes
流程2:维护主题索引
After adding, renaming, or removing any wiki article:
- -- update article count, total word count, featured sections, and any Obsidian Base embeds (use the obsidian-bases skill to author
<topic>/wiki/index/Dashboard.mdfiles and embed them)..base - -- insert/update the article row alphabetically with its one-line summary.
<topic>/wiki/index/Concept Index.md - -- for each new article, append rows for every source it cites, with a wikilink back to the article.
<topic>/wiki/index/Source Index.md - Optionally refresh the live view in Obsidian with the obsidian-cli skill (,
obsidian open <path>).obsidian search <query>
添加、重命名或删除任何维基文章后:
- -- 更新文章数量、总字数、特色版块,以及所有Obsidian Base嵌入内容(使用obsidian-bases技能编写
<topic>/wiki/index/Dashboard.md文件并嵌入)。.base - -- 按字母顺序插入/更新文章行,包含一行摘要。
<topic>/wiki/index/Concept Index.md - -- 对于每篇新文章,追加其引用的每个来源的行,并添加指向该文章的维基链接。
<topic>/wiki/index/Source Index.md - (可选)使用obsidian-cli技能刷新Obsidian中的实时视图(、
obsidian open <path>)。obsidian search <query>
Procedure 3: Query the wiki and file back the answer
流程3:查询维基并保存答案
A query has two phases: Phase A produces the answer by reading the wiki (never from general knowledge); Phase B files the answer back so the exploration compounds.
Precondition: Identify which topic(s) the question belongs to. If the question spans topics, load each topic's Concept Index.
查询分为两个阶段:阶段A通过读取维基生成答案(绝不使用通用知识);阶段B保存答案,使探索成果不断积累。
**前置条件:**确定问题所属的主题。若问题跨多个主题,加载每个主题的概念索引。
Phase A -- Answer from the wiki
阶段A -- 从维基获取答案
- Read the topic's Concept Index first (). Scan the full index to identify candidate articles. Do NOT answer from general knowledge -- the wiki is the source of truth, even when the answer seems obvious. A contradiction between the wiki and general knowledge is itself valuable signal.
<topic>/wiki/index/Concept Index.md - Locate relevant articles. At small scale (<30 articles), the index is enough. At larger scale, supplement with . Also grep the topic for keywords:
kb search "<phrase>" --topic <slug>.grep -rl "<keyword>" <topic>/wiki/concepts/ - Read the identified articles in full. Follow one level of when targets look relevant to the question. Stop at one hop -- deeper traversal wastes context.
[[wikilinks]] - (Optional) Pull in raw sources if an article's claim is ambiguous and its frontmatter points at a specific raw file worth verifying.
sources: - Synthesize the answer with these properties:
- Grounded in the wiki articles you just read -- every factual claim traces back to a citation.
[[Wiki Article]] - Notes agreements and disagreements between articles when they exist.
- Flags gaps explicitly: "The wiki has no article on X" or "[[Article Y]] does not yet cover Z".
- Suggests follow-up ingest targets or open questions.
- Grounded in the wiki articles you just read -- every factual claim traces back to a
- Match format to question type:
- Factual → prose with inline citations.
[[wikilink]] - Comparison → table with rows per alternative, citations in cells.
- How-it-works → numbered steps with citations.
- What-do-we-know-about-X → structured summary with "Known", "Open questions", "Gaps".
- Visual → ASCII/Mermaid diagram, Marp deck (see ), or matplotlib chart.
references/tooling-tips.md
- Factual → prose with inline
- 先阅读主题的概念索引()。扫描完整索引以确定候选文章。绝不从通用知识中获取答案——维基是唯一的事实来源,即使答案看似显而易见。维基与通用知识之间的矛盾本身就是有价值的信号。
<topic>/wiki/index/Concept Index.md - 定位相关文章。规模较小时(<30篇文章),索引已足够。规模较大时,可补充使用。也可在主题中搜索关键词:
kb search "<短语>" --topic <slug>。grep -rl "<关键词>" <topic>/wiki/concepts/ - 完整阅读找到的文章。当维基链接目标看起来与问题相关时,跟随一级。仅停留一级——更深层次的遍历会浪费上下文。
[[维基链接]] - (可选)提取原始来源——如果文章的某个声明模糊,且其前置元数据指向某个值得验证的特定原始文件。
sources: - 合成答案,需具备以下特性:
- 基于刚阅读的维基文章——每个事实声明都可追溯到引用。
[[维基文章]] - 记录文章之间的一致与分歧(若存在)。
- 明确指出空白:“维基中没有关于X的文章”或“[[文章Y]]尚未涵盖Z”。
- 建议后续导入目标或待解决问题。
- 基于刚阅读的维基文章——每个事实声明都可追溯到
- 根据问题类型匹配格式:
- 事实类 → 带内嵌引用的散文。
[[维基链接]] - 对比类 → 每行对应一个选项的表格,单元格中包含引用。
- 工作原理类 → 带引用的编号步骤。
- 关于X我们知道什么 → 包含“已知内容”、“待解决问题”、“空白”的结构化摘要。
- 可视化类 → ASCII/Mermaid图表、Marp幻灯片(见)或matplotlib图表。
references/tooling-tips.md
- 事实类 → 带内嵌
Phase B -- File back the answer
阶段B -- 保存答案
- Save the answer to with frontmatter:
<topic>/outputs/queries/<YYYY-MM-DD> <Question Slug>.md,type: output,stage: query. Seeinformed_by: ["[[Article 1]]", "[[Article 2]]"]for the full schema.references/frontmatter-schemas.md - In the body, list which wiki articles informed the answer under (as wikilinks) and call out new insights that should be absorbed back into those articles on the next compile pass.
informed_by: - When a filed-back insight contradicts or extends an article's claims, recompile the affected articles (Procedure 1).
- Promote to wiki when the synthesis is durable. If the answer is a first-class reference (a comparison table, a trade-off analysis, a new concept synthesized from multiple articles), copy it to following Procedure 1 standards and update the indexes (Procedure 2). Karpathy's pattern treats strong query answers as wiki citizens, not secondary artifacts.
<topic>/wiki/concepts/<Title>.md - Append to (Procedure 5) -- e.g.,
<topic>/log.mdplus a second line## [YYYY-MM-DD] query | <Question Slug>if promoted.## [YYYY-MM-DD] promote | <Title>
Anti-patterns to avoid:
- Answering from memory -- always read the wiki pages. The wiki may contradict what you think you know.
- No citations -- every factual claim must trace back to a .
[[wikilink]] - Skipping the save -- good query answers compound the wiki's value. Always file to ; promote when durable.
outputs/queries/ - Silent gaps -- surface missing coverage explicitly so the next ingest pass can fill it.
- 保存答案到,前置元数据为:
<topic>/outputs/queries/<YYYY-MM-DD> <问题标识>.md,type: output,stage: query。完整模式见informed_by: ["[[文章1]]", "[[文章2]]"]。references/frontmatter-schemas.md - 在正文中,列出为答案提供信息的维基文章(作为维基链接),并标注应在下次编译时吸收回这些文章的新见解。
- 当保存的见解与文章声明矛盾或扩展了文章内容时,重新编译受影响的文章(见流程1)。
- 当合成内容具有持久性时升级为维基文章。如果答案是一流参考内容(对比表格、权衡分析、从多篇文章合成的新概念),按照流程1的标准将其复制到,并更新索引(见流程2)。Karpathy模式将优质查询答案视为维基的一部分,而非次要产物。
<topic>/wiki/concepts/<标题>.md - 向追加条目(见流程5)——例如
<topic>/log.md,若升级为维基文章则添加第二行## [YYYY-MM-DD] query | <问题标识>。## [YYYY-MM-DD] promote | <标题>
需避免的反模式:
- 凭记忆回答 — 始终阅读维基页面。维基可能与你认为已知的内容矛盾。
- 无引用 — 每个事实声明都必须可追溯到。
[[维基链接]] - 跳过保存步骤 — 优质查询答案会提升维基的价值。始终保存到;具备持久性时升级为维基文章。
outputs/queries/ - 隐藏空白 — 明确指出缺失的内容,以便下次导入时补充。
Procedure 4: Lint and heal
流程4:检查与修复
Run structural lint via the CLI:
kbbash
kb lint <slug> --saveThis checks dead wikilinks, orphan articles, missing source references, format violations, and stale content, saving a dated report to . For each issue, propose the fix with a diff before applying -- do not batch-apply changes:
<topic>/outputs/reports/- Dead wikilink -- either create the missing article (Procedure 1) or rewrite the wikilink to point at an existing article.
- Orphan article -- add incoming wikilinks from at least one related article, or remove the article if it is outside the topic's scope.
- Missing source file -- an article's frontmatter references a file absent from
sources:. Either re-ingest (raw/) or correct the reference.kb ingest url/file - Stale content -- article's date is older than its source's
updated:date. Recompile with current sources.scraped: - Format violation -- fix missing frontmatter fields, H1 title, lead paragraph, or Sources section.
For deeper LLM-driven self-healing checks (inconsistencies across articles, missing coverage, wikilink audits, filed-back query absorption), read .
references/lint-procedure.mdAfter the heal pass, append to .
## [YYYY-MM-DD] lint | <N> issues found, <M> fixed<topic>/log.md通过 CLI运行结构检查:
kbbash
kb lint <slug> --save此命令检查无效维基链接、孤立文章、缺失来源引用、格式违规和过时内容,并将带日期的报告保存到。对于每个问题,在应用修复前先提出差异方案——不要批量应用更改:
<topic>/outputs/reports/- 无效维基链接 — 要么创建缺失的文章(见流程1),要么重写维基链接指向现有文章。
- 孤立文章 — 从至少一篇相关文章添加传入维基链接,若文章超出主题范围则删除。
- 缺失源文件 — 文章的前置元数据引用了
sources:中不存在的文件。要么重新导入(raw/),要么修正引用。kb ingest url/file - 过时内容 — 文章的日期早于其来源的
updated:日期。使用当前来源重新编译。scraped: - 格式违规 — 修复缺失的前置元数据字段、H1标题、导语段落或来源部分。
如需更深入的LLM驱动自修复检查(文章间不一致、缺失内容、维基链接审核、查询答案吸收),请阅读。
references/lint-procedure.md修复完成后,向追加。
<topic>/log.md## [YYYY-MM-DD] lint | 发现<N>个问题,修复<M>个Procedure 5: Append to log.md
流程5:追加至log.md
The CLI auto-appends log entries for and operations. Manual entries are needed for compile, query, promote, and split operations.
kbingestlint --saveFormat -- each entry is a single H2 heading with a consistent prefix so the log stays grep-able:
markdown
undefinedkbingestlint --save格式 — 每个条目都是一个H2标题,带有一致的前缀,以便日志可通过grep检索:
markdown
undefined[YYYY-MM-DD] <op> | <short description>
[YYYY-MM-DD] <操作> | <简短描述>
Where `<op>` is one of `compile`, `query`, `promote`, or `split` (ingest and lint are handled by `kb`).
**Examples:**
```markdown
其中`<操作>`为`compile`、`query`、`promote`或`split`之一(ingest和lint由`kb`自动处理)。
**示例:**
```markdown[2026-04-04] compile | Transformer Architecture (3847 words, 6 sources)
[2026-04-04] compile | Transformer Architecture (3847 words, 6 sources)
[2026-04-04] query | 2026-04-04 flash-attention-vs-paged-attention.md
[2026-04-04] query | 2026-04-04 flash-attention-vs-paged-attention.md
[2026-04-04] promote | FlashAttention vs PagedAttention (from query)
[2026-04-04] promote | FlashAttention vs PagedAttention (from query)
[2026-04-05] split | "Inference Optimization" → KV Cache, Speculative Decoding
[2026-04-05] split | "Inference Optimization" → KV Cache, Speculative Decoding
Optionally add a body paragraph under each entry with more context (key findings, source urls, decisions made). Keep entries terse -- the log is for skimming, not prose.
**Quick recent-activity check** -- the consistent prefix lets unix tools query the log:
```bash
grep "^## \[" <topic>/log.md | tail -10 # last 10 events
grep "^## \[.*compile" <topic>/log.md | wc -l # total compiles
grep "^## \[2026-04" <topic>/log.md # April 2026 eventsKeep at the topic root (not inside or ) so it sits alongside as a first-class topic artifact.
log.mdwiki/outputs/CLAUDE.md
可选择在每个条目下添加一段正文,提供更多上下文(关键发现、来源URL、做出的决策)。条目需简洁——日志用于快速浏览,而非长篇大论。
**快速查看近期活动** — 一致的前缀可通过Unix工具查询日志:
```bash
grep "^## \[" <topic>/log.md | tail -10 # 最近10个事件
grep "^## \[.*compile" <topic>/log.md | wc -l # 总编译次数
grep "^## \[2026-04" <topic>/log.md # 2026年4月的事件将放在主题根目录(而非或内),使其与一起作为主题的一级产物。
log.mdwiki/outputs/CLAUDE.mdOutput Format Selection
输出格式选择
All and commands support :
inspectsearch--format- json -- always use for programmatic parsing
- table -- human-readable aligned columns (default)
- tsv -- tab-separated for piping to Unix tools
The and commands always output JSON to stdout.
ingest codebaseindexRead for format examples and empty result handling.
references/output-formats.md所有和命令支持参数:
inspectsearch--format- json — 程序解析时始终使用此格式
- table — 人类可读的对齐列(默认)
- tsv — 制表符分隔格式,可传递给Unix工具
ingest codebaseindex阅读获取格式示例和空结果处理方式。
references/output-formats.mdError Handling
错误处理
CLI Errors
CLI错误
| Error | Recovery |
|---|---|
| Run |
| Run |
| Run |
| Re-run with |
| Remove those flags when re-ingesting an existing topic |
| Use |
| Use exact source-relative path from vault frontmatter (e.g. |
| 错误 | 恢复方法 |
|---|---|
| 先运行 |
| 运行 |
| 运行 |
| 重新运行并添加 |
| 重新导入现有主题时移除这些参数 |
| 使用 |
| 使用库前置元数据中的精确源相对路径(例如 |
KB Workflow Errors
知识库工作流错误
| Error | Recovery |
|---|---|
| Install the |
| Topic not found | Run |
| Article exceeds 4000 words | Extract a sub-topic into its own article and wikilink to it |
| Cross-topic wikilink ambiguity | Disambiguate with full path: |
| Create manually and backfill from git: |
Read for the full error catalog with causes and recovery steps.
references/error-handling.md| 错误 | 恢复方法 |
|---|---|
| 安装 |
| Topic not found | 运行 |
| Article exceeds 4000 words | 将子主题提取为独立文章并添加维基链接 |
| Cross-topic wikilink ambiguity | 使用完整路径消除歧义: |
| 手动创建并从git回填: |
阅读获取完整错误目录、原因和恢复步骤。
references/error-handling.mdConstraints
约束
MUST DO
必须执行
- Run before any inspect command on that topic
kb ingest codebase - Use when parsing output programmatically
--format json - Use when running
--progress neverin a non-interactive contextkb ingest codebase - Parse stdout only for command output; treat stderr as diagnostics
- Use the from ingest output for subsequent
topicSlugflags--topic - Read before writing wiki articles
references/compilation-guide.md - Run backlink audits after every article compile (Procedure 1, step 7)
- File query answers to (Procedure 3)
outputs/queries/ - Append manual log entries for compile, query, promote, and split operations
- 在对某个主题执行任何inspect命令前,先运行
kb ingest codebase - 程序解析输出时使用
--format json - 在非交互式环境中运行时使用
kb ingest codebase--progress never - 仅解析标准输出获取命令输出;将标准错误视为诊断信息
- 使用导入输出中的作为后续
topicSlug参数的值--topic - 编写维基文章前阅读
references/compilation-guide.md - 每次编译文章后运行反向链接审核(流程1,步骤7)
- 将查询答案保存到(流程3)
outputs/queries/ - 为编译、查询、升级和拆分操作追加手动日志条目
MUST NOT DO
禁止执行
- Pass both and
--lexto--vecsearch - Pass with
--force-embedto--embed=falseindex - Treat stderr content as failure evidence for
kb ingest codebase - Assume vault location without running ingest or checking for
.kb/vault/ - Use relative paths like for
./src/config.ts-- useinspect fileinsteadsrc/config.ts - Answer wiki queries from general knowledge -- the wiki is the source of truth
- Skip the backlink audit when compiling articles
- Batch-apply lint fixes without proposing diffs first
- 向命令同时传递
search和--lex参数--vec - 向命令同时传递
index和--force-embed参数--embed=false - 将的标准错误内容视为失败证据
kb ingest codebase - 未运行导入或检查就假设库位置
.kb/vault/ - 对使用相对路径如
inspect file——改用./src/config.tssrc/config.ts - 从通用知识中回答维基查询——维基是唯一事实来源
- 编译文章时跳过反向链接审核
- 未提出差异方案就批量应用检查修复