Initial commit: company-kb framework
- 完整的知识库框架(P0-P5 路线图) - 12篇治理文档 - 工具脚本(kb-init.sh, kb-lint-fm.py, feishu-sync.py, kb-bot) - 7个 Claude 命令 - 示例项目和测试项目(wanniu-l1) - 契约文件(meta/kb-contract.yaml) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
0
.claude/commands/.gitkeep
Executable file
0
.claude/commands/.gitkeep
Executable file
15
.claude/commands/kb-ask.md
Executable file
15
.claude/commands/kb-ask.md
Executable file
@@ -0,0 +1,15 @@
|
||||
---
|
||||
description: 查询循环——基于知识库回答,强制溯源,无据报 Gap
|
||||
argument-hint: <问题>
|
||||
---
|
||||
|
||||
查询循环。问题:`$ARGUMENTS`。基于本知识库 markdown 回答,**每条结论必须挂原始出处**。
|
||||
|
||||
执行:
|
||||
1. 先扫 `projects/` 及相关目录,用语义检索定位相关页(可先看各 `_index.md` 和文件名,再读命中页)。
|
||||
2. 综合回答,**每个关键结论后标出处**:引用页的 `source_link`,或页面路径 `[[slug]]`。
|
||||
3. **无据即报 Gap**:知识库没有覆盖的部分,明确说"知识库暂无此信息",**绝不用训练数据编造**,可建议用 `/kb-ingest` 补充。
|
||||
4. 若命中页 `status: seed`(未成熟),提示该结论可信度较低。
|
||||
5. 回答末尾附"依据页"清单(路径 + source_link)。
|
||||
|
||||
若这个问答有长期价值,提示用户可用 `/kb-save` 回写成 `questions/` 页沉淀。
|
||||
18
.claude/commands/kb-check.md
Executable file
18
.claude/commands/kb-check.md
Executable file
@@ -0,0 +1,18 @@
|
||||
---
|
||||
description: frontmatter 校验 + lint 体检
|
||||
argument-hint: [可选:路径,默认全库]
|
||||
---
|
||||
|
||||
跑知识库健康体检。
|
||||
|
||||
1. 执行:`python3 tools/kb-lint-fm.py $ARGUMENTS`(无参数则扫全库)。
|
||||
2. 解读退出码:
|
||||
- `0`:全绿,简报"检查 N 页,0 错误"。
|
||||
- `1`:有 frontmatter 错误(缺硬必填 / 未激活 type / enum 非法 / 派生必填缺失)。
|
||||
- `2`:环境问题(缺 PyYAML → 提示 `pip install pyyaml`;缺契约文件)。
|
||||
3. 对每条错误:
|
||||
- **安全项**(补 title、补可推导字段、加 wikilink)→ 你直接自动修,修完重跑确认。
|
||||
- **有损项**(删页、合并、改 type、解决矛盾)→ 列出来交用户拍板,**不擅自改**。
|
||||
4. 简报修了什么、还剩什么需人处理。
|
||||
|
||||
校验规则一律以 `meta/kb-contract.yaml` 为准。
|
||||
24
.claude/commands/kb-ingest.md
Executable file
24
.claude/commands/kb-ingest.md
Executable file
@@ -0,0 +1,24 @@
|
||||
---
|
||||
description: 录入循环——把原始资料编译成 OKF 合规知识页
|
||||
argument-hint: <项目代号> <源:文件路径/URL/粘贴的聊天>
|
||||
---
|
||||
|
||||
录入循环。参数:`$ARGUMENTS`(第一个词是项目代号,其余是源)。人只负责丢资料 + 一句说明 + 对要点点头;其余你自动完成。
|
||||
|
||||
执行步骤:
|
||||
1. **读契约**:先读 `meta/kb-contract.yaml` 拿 type 集、字段必填矩阵、enum。所有 frontmatter 严格据此,禁止硬编码。
|
||||
2. **取内容**:源是文件→Read;是 URL→WebFetch;是粘贴文本→直接用。
|
||||
3. **去重**:与 `meta/ingest-manifest.json` 比对内容 hash,命中则跳过并告知。
|
||||
4. **落原文**:原始内容存到 `projects/<代号>/` 对应子目录(doc→docs/,聊天→conversations/)。
|
||||
5. **抽要点**:展示 3-5 个关键发现(决策/需求/风险/客户信息),请用户点头或修正。
|
||||
6. **编译成页**:按要点写成 OKF 合规页(参考 `projects/_example/` 的结构与 frontmatter):
|
||||
- 自动补齐可推导字段:`title`(←H1/文件名)、`created`(←源日期或今天)、`ingested`(=今天)、`source`/`source_link`(←采集来源)、`status: seed`。
|
||||
- 只有判断类字段(如 `author`、信息有效期 `timestamp`)需要时才问人。
|
||||
- 决策→`decisions/`(type: decision),聊天沉淀→`conversations/`(type: conversation)。
|
||||
- 加 `related: [[...]]` wikilink 连到项目 _index 和相关页。
|
||||
7. **矛盾挂起**:若新信息与已有页冲突,用 `> [!contradiction]` callout 标注,**不静默覆盖**,交人裁决。
|
||||
8. **更新 manifest**:把 hash + 时间 + 影响页写回 `meta/ingest-manifest.json`。
|
||||
9. **校验**:跑 `python3 tools/kb-lint-fm.py projects/<代号>`,必须 exit 0。
|
||||
10. 简报写了哪些页。
|
||||
|
||||
铁律:AI 永不擅自有损操作(删/覆盖)、永不编造、溯源字段必挂。
|
||||
27
.claude/commands/kb-link.md
Executable file
27
.claude/commands/kb-link.md
Executable file
@@ -0,0 +1,27 @@
|
||||
---
|
||||
description: 编译链接——把工作目录/NAS/URL 的物料"链接"进知识库(提炼精华+留指针,不搬原件)
|
||||
argument-hint: <文件路径 / NAS路径 / URL / 或直接口述哪个文件> [项目代号]
|
||||
---
|
||||
|
||||
「编译过的链接」录入。人只需**点名一个物料**(`$ARGUMENTS`:文件路径 / NAS 路径 / URL,或口述"我工作目录的 XX 文件"),其余你自动完成。核心:**不搬原件,提炼精华 + 留 source_link 指针**——原文件原地不动,库保持精简。
|
||||
|
||||
执行步骤:
|
||||
1. **读契约**:先读 `meta/kb-contract.yaml` 拿 type 集 / 字段必填矩阵 / enum。frontmatter 严格据此,禁止硬编码。
|
||||
2. **定位原物料**:
|
||||
- 口述文件 → 在用户工作目录/NAS 下定位,不确定就让用户确认绝对路径。
|
||||
- 文件路径/NAS 路径 → Read 直接读。
|
||||
- URL → WebFetch。
|
||||
- 记下原始位置作为 `source_link`(NAS/本地绝对路径,或 URL)。
|
||||
3. **判 source**:工作目录/本机文件→`本地`;NAS 投递区或共享目录→`NAS`;飞书→`飞书文档`;网页→按来源。
|
||||
4. **读一遍,提炼**:抽 3-8 个关键要点(决策/需求/客户信息/数据/风险),展示给用户点头或修正。**不复制原文全文进库**。
|
||||
5. **写一页"编译链接"知识页**到对应项目目录(默认 `doc`;若本质是决策→`decision`):
|
||||
- frontmatter:`type`、`title`(←文件名/H1)、`created`(←文件时间或今天)、`ingested`=今天、`source`、`source_link`=原文件指针、`status: seed`、`related: [[...]]`。
|
||||
- 正文结构:`## 摘要`(AI 提炼的精华,可检索)+ `## 原件` (source_link 指针 + 一句"全文见原件")。
|
||||
- 精华进库 = 抗原件移动/删除;指针留原件 = 库不膨胀。
|
||||
6. **去重**:对提炼内容或原文 hash 比对 `meta/ingest-manifest.json`,命中则提示已链接过。
|
||||
7. **快照后门(可选)**:若判断该原件**关键且易变/可能被删**,主动提议"是否复制原件进 `assets/` 兜底?"——**用户点头才复制**,默认只留链接。
|
||||
8. **挂 wikilink**:连到项目 `_index` 和相关页。
|
||||
9. **更新 manifest** + 跑 `python3 tools/kb-lint-fm.py <项目目录>`(exit 0)。
|
||||
10. 简报:写了哪页、source_link 指向哪、是否快照。
|
||||
|
||||
铁律:默认不搬原件(库精简);AI 永不擅自复制/删改原文件;永不编造,提炼只基于真实读到的内容。
|
||||
14
.claude/commands/kb-new.md
Executable file
14
.claude/commands/kb-new.md
Executable file
@@ -0,0 +1,14 @@
|
||||
---
|
||||
description: 建新项目骨架(OKF 合规目录 + _index.md)
|
||||
argument-hint: <项目代号>
|
||||
---
|
||||
|
||||
为项目代号 `$ARGUMENTS` 建骨架。
|
||||
|
||||
1. 若给了代号,运行:`bash tools/kb-init.sh $ARGUMENTS`
|
||||
- 未给代号则先问用户要一个英文短代号(如 `power-bid`、`clientA`)。
|
||||
2. 脚本会建出 `projects/<代号>/{_index.md,docs/,decisions/,conversations/,assets/}`,`_index.md` 带 `type: project` + `status: seed` 的 OKF frontmatter。
|
||||
3. 跑 `python3 tools/kb-lint-fm.py projects/$ARGUMENTS` 确认新骨架合规(exit 0)。
|
||||
4. 简报:建了哪些文件,提示用户下一步用 `/kb-ingest $ARGUMENTS <源>` 录入资料。
|
||||
|
||||
字段规范一律以 `meta/kb-contract.yaml` 为准,不要硬编码 type 或字段。
|
||||
17
.claude/commands/kb-save.md
Executable file
17
.claude/commands/kb-save.md
Executable file
@@ -0,0 +1,17 @@
|
||||
---
|
||||
description: 把当前对话的洞察回写为 questions/ 知识页
|
||||
argument-hint: [可选:一句话点题]
|
||||
---
|
||||
|
||||
把当前对话中有价值的问答/洞察沉淀成一页知识。`$ARGUMENTS` 是可选点题。
|
||||
|
||||
前置:`question` 是预留 type(`meta/kb-contract.yaml` 中 `active: false`)。若尚未激活:
|
||||
1. 提示用户"首次回写需激活 question type",征得同意后把契约里 `question` 改成 `active: true` 并 `mkdir -p questions/`。
|
||||
|
||||
执行:
|
||||
1. 读 `meta/kb-contract.yaml` 确认 question 字段要求。
|
||||
2. 提炼本轮对话的问题 + 结论,写到 `questions/<slug>.md`:
|
||||
- frontmatter:`type: question`、`title`、`status`(草稿→seed)、`created`/`ingested`=今天、`related: [[...]]` 连到依据页。
|
||||
- 正文:问题 / 结论 / 依据(挂 source_link)。
|
||||
3. 跑 `python3 tools/kb-lint-fm.py questions/` 确认 exit 0。
|
||||
4. 简报路径。绝不把无据推测写成知识——只沉淀有出处的结论。
|
||||
16
.claude/commands/kb-status.md
Executable file
16
.claude/commands/kb-status.md
Executable file
@@ -0,0 +1,16 @@
|
||||
---
|
||||
description: 知识库健康仪表盘——源计数 / type 分布 / 红线观察
|
||||
---
|
||||
|
||||
生成知识库现状概览。
|
||||
|
||||
1. **源计数**(P5 向量库红线观察点,红线≈100 源/几百页):
|
||||
- 统计 `projects/` 下知识页总数:`find projects -name '*.md' -not -name '_index.md' | wc -l`
|
||||
- 项目数:`ls -d projects/*/ | grep -v _example | wc -l`
|
||||
2. **type 分布**:按 frontmatter `type` 分组计数(grep 各页 type 字段)。
|
||||
3. **健康**:跑 `python3 tools/kb-lint-fm.py` 取错误/警告数。
|
||||
4. **status 分布**:seed / developing / mature 各多少。
|
||||
5. 读 `meta/stats.md` 附上人工记录的观察。
|
||||
6. 输出一张简表;若知识页数逼近 ~几百页,提示"接近规模红线,考虑启用 P5 向量库导航层(见 docs/05-路线图.md)"。
|
||||
|
||||
只读操作,不改任何文件。
|
||||
Reference in New Issue
Block a user