teamai-cli 0.16.9 → 0.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,1019 +0,0 @@
1
- ---
2
- name: teamai-wiki
3
- description: "Persistent, incremental LLM Wiki — accumulate structured knowledge across multiple ingest/query sessions. Supports init, ingest (local files, URLs, sessions), query, lint, export, and status operations with [[wiki links]] cross-references."
4
- ---
5
-
6
- # /teamai-wiki
7
-
8
- 持续积累的多页面 Wiki 知识库。通过增量摄入(ingest)、查询(query)、健康检查(lint)不断积累知识,页面间用 `[[wiki links]]` 互相引用,可直接在 Obsidian 中浏览。
9
-
10
- **团队共享知识库**:wiki 存储在 team repo 的 `wiki/` 目录中,通过 `teamai pull/push` 与团队同步。不仅支持代码,也支持文档、会议纪要、设计决策、团队信息、流程规范等任何知识源。
11
-
12
- **替代 `/teamai-share-learnings`**:`/teamai-wiki ingest --from-session` 是 `/teamai-share-learnings` 的严格超集 — 结构化、增量、可查询。
13
-
14
- ## Usage
15
-
16
- ```
17
- /teamai-wiki init [dir] # 初始化 wiki 目录结构(dir 可选,可以是代码库、文档目录或空目录)
18
- /teamai-wiki ingest <source> # 摄入源文件/目录,更新 wiki 页面
19
- /teamai-wiki ingest <source> --batch # 批量摄入,少交互
20
- /teamai-wiki ingest <url> # 从 URL 摄入知识(网页、GitHub 仓库等)
21
- /teamai-wiki ingest --from-session # 从当前 Claude 会话中提取知识写入 wiki
22
- /teamai-wiki query "<question>" # 查询 wiki,综合回答
23
- /teamai-wiki query "<question>" --save # 查询并将回答存入 wiki
24
- /teamai-wiki lint # 健康检查:矛盾、孤立页、缺失引用
25
- /teamai-wiki status # 当前 wiki 统计(页面数、链接数、最近活动)
26
- /teamai-wiki export [--format md|html] # 导出 wiki 为单文件 Markdown 或 HTML
27
- ```
28
-
29
- ## What This Skill Does
30
-
31
- 实现 Karpathy LLM Wiki 模式的完整版本:
32
-
33
- 1. **持续积累** — wiki 是知识产物,每次 ingest 和 query 都在叠加知识
34
- 2. **增量摄入** — 通过 SHA256 哈希跟踪已处理文件,跳过未变更内容
35
- 3. **多源输入** — 支持本地文件/目录、URL、当前会话三种摄入来源
36
- 4. **结构化组织** — 八大分类:实体、概念、对比、人员、决策、流程、源摘要、查询结果
37
- 5. **双向引用** — `[[wiki links]]` 在页面间建立联系,自动维护 Backlinks
38
- 6. **可查询** — 基于已积累的 wiki 页面回答问题,带引用
39
- 7. **可导出** — 合并为单文件分享给不用 Obsidian 的同事
40
- 8. **可审计** — 操作日志(log.md)记录每次操作
41
-
42
- ## Wiki 目录结构
43
-
44
- ```
45
- wiki/ <- 存储在 team repo 中,通过 teamai pull/push 同步
46
- ├── _schema.md <- wiki 约定和配置(每次操作前读取)
47
- ├── index.md <- 所有页面目录索引(按分类组织,含一行摘要)
48
- ├── log.md <- 追加式操作日志
49
- ├── overview.md <- 全局综合概述页
50
- ├── _metadata.json <- 机器可读元数据(本地生成,不推送到 team repo)
51
-
52
- ├── entities/ <- 实体页(专有名词:具体的模块、服务、产品、项目)
53
- ├── concepts/ <- 概念页(通用名词:设计模式、架构原则、技术概念)
54
- ├── comparisons/ <- 对比页(两个或多个事物的对比分析)
55
- ├── people/ <- 人员页(团队成员、专长、职责)
56
- ├── decisions/ <- 决策页(架构决策记录 ADR、技术选型、变更原因)
57
- ├── processes/ <- 流程页(工作流、SOP、部署流程、on-call 流程)
58
- ├── sources/ <- 源文件摘要页(每个被摄入的源对应一个)
59
- └── queries/ <- 有价值的查询结果(--save 存入)
60
- ```
61
-
62
- ## 页面分类说明
63
-
64
- | 分类 | 目录 | 适用内容 | 示例 |
65
- |------|------|----------|------|
66
- | entity | entities/ | 专有名词:具体的模块、服务、产品、项目、工具 | hai-api-server, sglang-engine, pytorch |
67
- | concept | concepts/ | 通用名词:设计模式、架构原则、技术概念 | rollback-workflow, retry-backoff, pub-sub |
68
- | comparison | comparisons/ | 两个或多个事物的对比分析 | sglang-vs-vllm, redis-vs-memcached |
69
- | person | people/ | 团队成员、专长领域、负责模块 | jeff-xu, alice-chen |
70
- | decision | decisions/ | 架构决策、技术选型、变更记录 | use-redis-for-cache, migrate-to-k8s |
71
- | process | processes/ | 工作流、SOP、部署/on-call/发布流程 | deploy-to-prod, incident-response |
72
- | source | sources/ | 源文件的结构化摘要 | hai-api-server-py, design-doc-auth |
73
- | query | queries/ | 有价值的查询结果 | sync-vs-async-comparison |
74
-
75
- **分类选择由 LLM 智能判断**:ingest 时不需要手动指定分类。Agent 分析内容后自动决定应归入哪个目录。一份会议纪要可能同时产生 decisions/ 和 people/ 页面。
76
-
77
- ## 页面格式
78
-
79
- 每个 wiki 页面遵循统一格式:
80
-
81
- ```markdown
82
- ---
83
- title: Message Builder
84
- category: entity
85
- tags: [hai-flow, core, message-queue]
86
- sources: [hai_flow/hai_flow/core/message.py]
87
- created: 2026-04-08
88
- updated: 2026-04-08
89
- ---
90
-
91
- # Message Builder
92
-
93
- [正文内容...]
94
-
95
- ## Related
96
-
97
- - [[hai-flow-engine]] — 所属系统
98
- - [[rollback-workflow]] — 使用 MessageBuilder 实现回滚
99
-
100
- ## Backlinks
101
-
102
- _Pages that link here:_
103
- - [[overview]]
104
- - [[hai-flow-engine]]
105
- ```
106
-
107
- ### 各分类页面模板
108
-
109
- **comparisons/ 页面模板**:
110
-
111
- ```markdown
112
- ---
113
- title: SGLang vs vLLM
114
- category: comparison
115
- tags: [inference, serving, gpu]
116
- sources: []
117
- created: 2026-04-08
118
- updated: 2026-04-08
119
- ---
120
-
121
- # SGLang vs vLLM
122
-
123
- ## 对比维度
124
-
125
- | 维度 | SGLang | vLLM |
126
- |------|--------|------|
127
- | 吞吐 | ... | ... |
128
- | 延迟 | ... | ... |
129
- | 易用性 | ... | ... |
130
-
131
- ## 结论
132
- [什么场景选什么]
133
-
134
- ## Related
135
- - [[sglang-engine]]
136
- - [[vllm]]
137
-
138
- ## Backlinks
139
- ```
140
-
141
- **people/ 页面额外字段**:
142
-
143
- ```markdown
144
- ---
145
- title: Jeff Xu
146
- category: person
147
- tags: [backend, hai, gpu-infra]
148
- sources: []
149
- created: 2026-04-08
150
- updated: 2026-04-08
151
- ---
152
-
153
- # Jeff Xu
154
-
155
- ## 专长领域
156
- - GPU 推理服务架构
157
- - Kubernetes 集群管理
158
-
159
- ## 负责模块
160
- - [[hai-api-server]]
161
- - [[sglang-engine]]
162
-
163
- ## Related
164
- - [[alice-chen]] — 协作:前端开发
165
-
166
- ## Backlinks
167
- ```
168
-
169
- **decisions/ 页面额外字段**:
170
-
171
- ```markdown
172
- ---
173
- title: 选择 Redis 作为缓存层
174
- category: decision
175
- tags: [architecture, cache, redis]
176
- sources: [docs/adr/001-redis-cache.md]
177
- status: accepted
178
- date: 2026-03-15
179
- created: 2026-04-08
180
- updated: 2026-04-08
181
- ---
182
-
183
- # 选择 Redis 作为缓存层
184
-
185
- ## 背景
186
- [为什么需要这个决策]
187
-
188
- ## 决策
189
- [最终选择了什么]
190
-
191
- ## 原因
192
- [为什么选这个方案]
193
-
194
- ## 备选方案
195
- - 方案 A: ...
196
- - 方案 B: ...
197
-
198
- ## 影响
199
- [这个决策带来的影响]
200
-
201
- ## Related
202
- ## Backlinks
203
- ```
204
-
205
- **processes/ 页面额外字段**:
206
-
207
- ```markdown
208
- ---
209
- title: 生产环境部署流程
210
- category: process
211
- tags: [deploy, production, k8s]
212
- sources: [docs/runbooks/deploy.md]
213
- created: 2026-04-08
214
- updated: 2026-04-08
215
- ---
216
-
217
- # 生产环境部署流程
218
-
219
- ## 前置条件
220
- - [ ] 所有 CI 测试通过
221
- - [ ] Code review 已完成
222
-
223
- ## 步骤
224
- 1. ...
225
- 2. ...
226
-
227
- ## 回滚方案
228
- ...
229
-
230
- ## Related
231
- ## Backlinks
232
- ```
233
-
234
- ---
235
-
236
- ## Execution Steps
237
-
238
- When invoked, first determine the subcommand (init/ingest/query/lint/status/export), then follow the corresponding steps. **Do not skip steps.**
239
-
240
- ---
241
-
242
- ### Subcommand: `init [dir]`
243
-
244
- #### Step 1 — Parse arguments
245
-
246
- - `WIKI_DIR`: 根据当前项目的 teamai scope 决定:
247
- - 读取 `<projectRoot>/.teamai/config.yaml` 中的 `scope` 字段
248
- - **project scope** → `<projectRoot>/.teamai/wiki/`
249
- - **user scope**(或无项目配置时)→ `~/.teamai/wiki/`
250
- - `SOURCE_DIR`: 可选的 `dir` 参数
251
-
252
- 如果 `WIKI_DIR` 已经存在且包含 `_metadata.json`,提示用户已经初始化过,询问是否要重新初始化。
253
-
254
- #### Step 2 — 创建目录结构
255
-
256
- ```bash
257
- mkdir -p WIKI_DIR/{entities,concepts,comparisons,people,decisions,processes,sources,queries}
258
- ```
259
-
260
- #### Step 3 — 生成 _schema.md
261
-
262
- 写入 wiki 约定文档:
263
-
264
- ```markdown
265
- # Wiki Schema
266
-
267
- 本 wiki 由 `/teamai-wiki` skill 自动维护。
268
-
269
- ## 页面分类
270
-
271
- | 分类 | 目录 | 说明 | 示例 |
272
- |------|------|------|------|
273
- | entity | entities/ | 专有名词:具体的模块、服务、产品、项目 | hai-api-server, message-builder |
274
- | concept | concepts/ | 通用名词:设计模式、架构原则、技术概念 | rollback-workflow, deny-actions |
275
- | comparison | comparisons/ | 两个或多个事物的对比分析 | sglang-vs-vllm, redis-vs-memcached |
276
- | person | people/ | 团队成员、专长领域、负责模块 | jeff-xu, alice-chen |
277
- | decision | decisions/ | 架构决策记录、技术选型、变更原因 | use-redis-for-cache |
278
- | process | processes/ | 工作流、SOP、部署/发布/on-call 流程 | deploy-to-prod |
279
- | source | sources/ | 源文件/文档的结构化摘要 | hai-api-server-py |
280
- | query | queries/ | 有价值的查询结果 | sync-vs-async |
281
-
282
- ## 命名规则
283
-
284
- - 文件名使用 kebab-case:`message-builder.md`
285
- - 标题使用人类可读的格式:`Message Builder`
286
- - Wiki 链接使用文件名(不含 .md):`[[message-builder]]`
287
-
288
- ## 链接格式
289
-
290
- - 内部引用:`[[page-name]]` — 仅使用文件名,不含目录前缀
291
- - 带描述:`[[page-name]] — 简要说明`
292
- - 跨分类引用同样有效,链接是全局唯一的
293
-
294
- ## 页面模板
295
-
296
- 每个页面必须包含:
297
- 1. YAML frontmatter(title, category, tags, sources, created, updated)
298
- 2. 正文内容
299
- 3. Related 段落(出链)
300
- 4. Backlinks 段落(入链,由系统自动维护)
301
- ```
302
-
303
- #### Step 4 — 生成初始文件
304
-
305
- 写入空的 `index.md`:
306
-
307
- ```markdown
308
- # Wiki Index
309
-
310
- > Auto-maintained by /teamai-wiki. Last updated: YYYY-MM-DD
311
-
312
- ## Entities
313
-
314
- _No pages yet._
315
-
316
- ## Concepts
317
-
318
- _No pages yet._
319
-
320
- ## Comparisons
321
-
322
- _No pages yet._
323
-
324
- ## People
325
-
326
- _No pages yet._
327
-
328
- ## Decisions
329
-
330
- _No pages yet._
331
-
332
- ## Processes
333
-
334
- _No pages yet._
335
-
336
- ## Sources
337
-
338
- _No pages yet._
339
-
340
- ## Queries
341
-
342
- _No pages yet._
343
- ```
344
-
345
- 写入空的 `log.md`:
346
-
347
- ```markdown
348
- # Wiki Log
349
-
350
- | Time | Operation | Details |
351
- |------|-----------|---------|
352
- | YYYY-MM-DD HH:MM | init | Wiki initialized |
353
- ```
354
-
355
- 写入 `overview.md`:
356
-
357
- ```markdown
358
- ---
359
- title: Overview
360
- category: entity
361
- tags: [overview, index]
362
- sources: []
363
- created: YYYY-MM-DD
364
- updated: YYYY-MM-DD
365
- ---
366
-
367
- # Overview
368
-
369
- _This page will be populated after the first ingest._
370
-
371
- ## Related
372
-
373
- ## Backlinks
374
- ```
375
-
376
- 写入 `_metadata.json`:
377
-
378
- ```json
379
- {
380
- "version": 1,
381
- "wikiDir": "<absolute-path>",
382
- "sourceDir": null,
383
- "createdAt": "<ISO-timestamp>",
384
- "updatedAt": "<ISO-timestamp>",
385
- "sources": {},
386
- "pages": {
387
- "overview.md": {
388
- "title": "Overview",
389
- "category": "entity",
390
- "tags": ["overview", "index"],
391
- "outLinks": [],
392
- "inLinks": [],
393
- "updatedAt": "<ISO-timestamp>"
394
- }
395
- },
396
- "stats": {
397
- "totalPages": 1,
398
- "totalSources": 0,
399
- "totalLinks": 0,
400
- "lastIngest": null,
401
- "lastLint": null
402
- }
403
- }
404
- ```
405
-
406
- #### Step 5 — 智能检测源目录并首次 ingest
407
-
408
- 如果用户提供了 `dir` 参数:
409
-
410
- 1. **检测目录类型**:
411
- - 包含代码文件(`.py`, `.ts`, `.go`, `.rs`, `.java` 等)→ 代码项目
412
- - 包含 Markdown/文档文件但无代码 → 文档目录
413
- - 空目录或不存在 → 跳过 ingest
414
-
415
- 2. **代码项目**:自动触发 `ingest` 流程
416
- 3. **文档目录**:自动触发 `ingest` 流程(Agent 会智能提取 decisions、processes 等)
417
- 4. **空目录/不存在**:只完成 init,提示用户后续使用 `ingest` 添加内容
418
-
419
- 如果没有提供 `dir` 参数:只完成 init,不触发 ingest。
420
-
421
- 输出:
422
- ```
423
- Wiki initialized at WIKI_DIR
424
- Directories: entities/, concepts/, comparisons/, people/, decisions/, processes/, sources/, queries/
425
- Files: _schema.md, index.md, log.md, overview.md, _metadata.json
426
- ```
427
-
428
- 如果触发了 ingest:
429
- ```
430
- Auto-ingesting from: SOURCE_DIR (detected: code project / document directory)
431
- ```
432
-
433
- ---
434
-
435
- ### Subcommand: `ingest <source>`
436
-
437
- 这是核心操作。单次 ingest 可能创建或更新 10-15 个 wiki 页面。
438
-
439
- `<source>` 支持三种形式:
440
- - **本地路径**:文件或目录(`/path/to/dir` 或 `./file.md`)
441
- - **URL**:网页或 GitHub 仓库(`https://...`)
442
- - **`--from-session`**:从当前 Claude 会话上下文提取
443
-
444
- #### Step 1 — 读取 wiki 状态
445
-
446
- 读取以下文件(使用 Read 工具):
447
- - `_schema.md` — 了解 wiki 约定
448
- - `index.md` — 了解已有页面
449
- - `_metadata.json` — 已摄入文件的哈希
450
-
451
- 如果 `_metadata.json` 不存在,提示用户先运行 `/teamai-wiki init`。
452
-
453
- 如果 `_metadata.json` 解析失败(JSON 损坏),输出警告并尝试从 wiki 目录重建元数据。
454
-
455
- #### Step 2 — 识别源类型并扫描
456
-
457
- **如果 source 是本地路径**:
458
-
459
- 扫描文件,排除噪音和敏感文件:
460
-
461
- ```bash
462
- find SOURCE_PATH -type f \
463
- -not -path '*/node_modules/*' \
464
- -not -path '*/.git/*' \
465
- -not -path '*/dist/*' \
466
- -not -path '*/build/*' \
467
- -not -path '*/__pycache__/*' \
468
- -not -path '*/.next/*' \
469
- -not -path '*/vendor/*' \
470
- -not -path '*/.venv/*' \
471
- -not -path '*/venv/*' \
472
- -not -path '*/.tox/*' \
473
- -not -path '*/.mypy_cache/*' \
474
- -not -path '*/.pytest_cache/*' \
475
- -not -path '*/target/*' \
476
- -not -path '*/.cache/*' \
477
- -not -name '*.pyc' \
478
- -not -name '*.pyo' \
479
- -not -name '.DS_Store' \
480
- -not -name '*.lock' \
481
- -not -name 'package-lock.json' \
482
- -not -name '.env' \
483
- -not -name '.env.*' \
484
- -not -name '*.pem' \
485
- -not -name '*.key' \
486
- -not -name '*.p12' \
487
- -not -name 'credentials.json' \
488
- -not -name '*.secret' \
489
- -not -name 'id_rsa*' \
490
- -not -name '*.pfx' \
491
- | head -2000 \
492
- | sort
493
- ```
494
-
495
- 对每个文件计算 SHA256 哈希:
496
-
497
- ```bash
498
- sha256sum FILE_PATH
499
- ```
500
-
501
- 与 `_metadata.json` 中已记录的哈希比较:
502
- - **哈希相同** -> 跳过(文件未变更)
503
- - **哈希不同或新文件** -> 加入待处理列表
504
-
505
- 检测文件类型分布,判断是代码为主、文档为主还是混合:
506
- - 代码文件:`.py`, `.ts`, `.js`, `.go`, `.rs`, `.java`, `.kt`, `.c`, `.cpp`, `.h`, `.rb`, `.php`, `.swift`
507
- - 文档文件:`.md`, `.txt`, `.rst`, `.adoc`, `.doc`, `.docx`, `.pdf`
508
- - 配置文件:`.yaml`, `.yml`, `.json`, `.toml`, `.ini`, `.cfg`
509
-
510
- 如果总文件数为 0,输出 `No files found in SOURCE_PATH.` 并结束。
511
- 如果总文件数 > 500,提示用户指定子目录聚焦。
512
-
513
- **如果 source 是 URL**:
514
-
515
- 1. 判断 URL 类型:
516
- - GitHub 仓库 URL(`github.com/org/repo`)→ 使用 `gh` CLI 克隆到临时目录,然后按本地路径处理
517
- - 普通网页 → 使用 WebFetch 工具获取内容
518
- - 无法访问(需要认证等)→ 输出错误提示,建议用户手动下载后用本地路径 ingest
519
-
520
- 2. WebFetch 获取的内容作为单个文档处理,计算内容 SHA256 作为去重依据
521
-
522
- **如果使用 `--from-session`**:
523
-
524
- 1. 回顾当前会话上下文(不需要特殊工具,LLM 已有上下文)
525
- 2. 提取以下知识:
526
- - 解决了什么问题
527
- - 关键决策及原因
528
- - 发现的技术细节
529
- - 涉及的人员和职责
530
- - 可复用的模式或流程
531
- 3. 将提取的内容按分类组织,跳过 Step 2 的文件扫描,直接进入 Step 3
532
-
533
- 输出扫描摘要:
534
- ```
535
- Scanning: SOURCE_PATH (type: code/docs/mixed/url/session)
536
- Total files: N
537
- New files: X
538
- Changed files: Y
539
- Unchanged (skipped): Z
540
- ```
541
-
542
- 如果所有文件都未变更,输出 `All N files unchanged, nothing to ingest.` 并追加 log 条目后结束。
543
-
544
- #### Step 3 — 并行 Agent 分析
545
-
546
- **IMPORTANT: 使用 Agent 工具进行并行分析。在单条消息中启动多个 Agent。**
547
-
548
- 将待处理文件分组(每组 3-8 个文件),为每组启动一个 Agent,prompt 如下:
549
-
550
- ```
551
- 你是一个 Wiki 知识提取 Agent。分析以下源文件,提取 wiki 页面所需的信息。
552
-
553
- 当前 wiki 已有页面列表:[从 index.md 获取]
554
-
555
- 待分析文件:
556
- - file1.py
557
- - file2.md
558
- - ...
559
-
560
- 对每个文件,用 Read 工具读取内容,然后提取以下 8 类知识:
561
-
562
- 1. **实体(Entities)**:模块、类、服务、组件、工具 — 值得单独成页的东西
563
- - 名称(kebab-case 文件名)
564
- - 标题(人类可读)
565
- - 描述(2-4 句话)
566
- - 关键函数/方法列表(代码文件)或关键段落(文档文件)
567
- - 与其他实体的关系
568
-
569
- 2. **概念(Concepts)**:设计模式、架构原则、技术概念 — 通用的、可复用的思想
570
- - 名称
571
- - 描述
572
- - 涉及的实体
573
-
574
- 3. **对比(Comparisons)**:两个或多个事物的对比分析
575
- - 对比标题(A vs B 格式)
576
- - 对比维度
577
- - 结论/建议
578
-
579
- 4. **人员(People)**:文件中提到的团队成员、作者、负责人
580
- - 名称
581
- - 专长领域(从上下文推断)
582
- - 负责的模块/系统
583
-
584
- 4. **决策(Decisions)**:技术选型、架构决策、变更记录
585
- - 决策标题
586
- - 背景、选择、原因
587
- - 替代方案
588
-
589
- 5. **流程(Processes)**:工作流、SOP、部署/发布流程
590
- - 流程名称
591
- - 步骤描述
592
- - 前置条件
593
-
594
- 6. **关系(Links)**:各类页面之间的 [[wiki link]] 关系
595
-
596
- 7. **源摘要(Source Summary)**:每个文件的结构化摘要
597
- - 文件路径
598
- - 职责(一句话)
599
- - 关键内容
600
- - 依赖
601
-
602
- 注意:并非每种分类都会在每个文件中出现。只提取实际存在的内容,不要凭空创造。
603
-
604
- 输出格式为 Markdown,使用以下结构:
605
-
606
- ## New Pages
607
- ### [entity|concept|comparison|person|decision|process] page-name
608
- Title: ...
609
- Tags: ...
610
- Content: ...
611
- Related: [[link1]], [[link2]]
612
-
613
- ## Updated Pages
614
- ### page-name
615
- Additions: ...(需要追加到已有页面的内容)
616
-
617
- ## Source Summaries
618
- ### file-path
619
- Summary: ...
620
- ```
621
-
622
- **--batch 模式**:减少 Agent 交互,每个 Agent 处理更多文件(最多 15 个),输出更精简。
623
-
624
- **--from-session 模式**:不需要启动 Agent,主 LLM 直接从会话上下文提取知识,按上述 7 类组织输出。
625
-
626
- #### Step 4 — 写入/更新 wiki 页面
627
-
628
- 收集所有 Agent 结果后:
629
-
630
- **新页面**(使用 Write 工具):
631
- - 实体 -> `entities/<name>.md`
632
- - 概念 -> `concepts/<name>.md`
633
- - 对比 -> `comparisons/<name>.md`
634
- - 人员 -> `people/<name>.md`
635
- - 决策 -> `decisions/<name>.md`
636
- - 流程 -> `processes/<name>.md`
637
- - 源摘要 -> `sources/<name>.md`
638
-
639
- 每个页面使用标准格式(见"页面格式"小节),包含:
640
- - YAML frontmatter(使用对应分类的模板字段)
641
- - 正文
642
- - Related 段落(出链)
643
- - 空的 Backlinks 段落(下一步填充)
644
-
645
- **更新已有页面**(使用 Edit 工具):
646
- - 追加新信息到正文
647
- - 更新 Related 段落
648
- - 更新 frontmatter 中的 `updated` 日期和 `sources` 列表
649
-
650
- **命名规则**:
651
- - 文件名 kebab-case:`message-builder.md`
652
- - 避免过长文件名,最多 5 个单词
653
- - 源摘要文件名由源路径生成:`hai_api/server.py` -> `hai-api-server-py.md`
654
- - 人员页面用姓名拼音或英文名:`jeff-xu.md`
655
- - 对比页面用 A-vs-B 格式:`sglang-vs-vllm.md`
656
- - 决策页面用动词短语:`use-redis-for-cache.md`
657
- - 流程页面用名词短语:`deploy-to-prod.md`
658
-
659
- **避免重复页面**:创建前检查 index.md 和 _metadata.json,如果已有同名或近似页面,更新而非新建。
660
-
661
- #### Step 5 — 更新 backlinks
662
-
663
- 扫描所有 wiki 页面,收集 `[[link]]` 引用关系。
664
-
665
- 对每个页面,更新其 `## Backlinks` 段落:
666
-
667
- ```markdown
668
- ## Backlinks
669
-
670
- _Pages that link here:_
671
- - [[overview]]
672
- - [[hai-flow-engine]]
673
- ```
674
-
675
- 使用 Grep 工具搜索 `[[page-name]]` 的引用:
676
-
677
- ```
678
- grep -r '\[\[page-name\]\]' WIKI_DIR/ --include='*.md'
679
- ```
680
-
681
- **只更新新增/变更页面的 backlinks 以及引用了这些页面的已有页面的 backlinks。**
682
-
683
- #### Step 6 — 更新 index.md
684
-
685
- 重新生成 `index.md`,按分类组织所有页面:
686
-
687
- ```markdown
688
- # Wiki Index
689
-
690
- > Auto-maintained by /teamai-wiki. Last updated: YYYY-MM-DD
691
- > Pages: N | Links: M | Sources: K
692
-
693
- ## Entities
694
-
695
- - [[message-builder]] — 消息构造器,hai-flow 核心组件
696
- - [[hai-api-server]] — HAI API 主服务
697
-
698
- ## Concepts
699
-
700
- - [[rollback-workflow]] — 回滚工作流设计模式
701
-
702
- ## Comparisons
703
-
704
- - [[sglang-vs-vllm]] — 推理框架对比:吞吐、延迟、易用性
705
-
706
- ## People
707
-
708
- - [[jeff-xu]] — GPU 推理服务架构、K8s 集群管理
709
-
710
- ## Decisions
711
-
712
- - [[use-redis-for-cache]] — 选择 Redis 作为缓存层(2026-03)
713
-
714
- ## Processes
715
-
716
- - [[deploy-to-prod]] — 生产环境部署流程
717
-
718
- ## Sources
719
-
720
- - [[hai-api-server-py]] — hai_api/server.py
721
-
722
- ## Queries
723
-
724
- _No queries yet._
725
- ```
726
-
727
- #### Step 7 — 更新 overview.md
728
-
729
- 如果本次 ingest 带来了重大新信息(新页面 > 3 或首次 ingest),更新 `overview.md`:
730
- - 综合描述项目/团队的整体架构和知识概览
731
- - 列出核心模块及其关系
732
- - 引用相关页面 `[[links]]`
733
-
734
- #### Step 8 — 追加 log.md
735
-
736
- 追加一行操作日志:
737
-
738
- ```markdown
739
- | YYYY-MM-DD HH:MM | ingest | Source: <path/url/session>, Type: <code/docs/mixed/url/session>, New pages: X, Updated: Y, Skipped: Z |
740
- ```
741
-
742
- #### Step 9 — 更新 _metadata.json
743
-
744
- 更新以下字段:
745
- - `sources`: 添加/更新已摄入文件的哈希和关联页面
746
- - `pages`: 添加/更新页面的元数据(title, category, tags, outLinks, inLinks)
747
- - `stats`: 更新统计数据
748
- - `updatedAt`: 当前时间戳
749
- - `sourceDir`: 如果未设置,记录源目录路径
750
-
751
- 输出 ingest 摘要:
752
- ```
753
- Ingest complete
754
- Source: <path> (type: code/docs/mixed/url/session)
755
- New pages: X (entities: A, concepts: B, comparisons: C, people: D, decisions: E, processes: F, sources: G)
756
- Updated pages: Y
757
- Skipped: Z unchanged files
758
- Total wiki links: N
759
- ```
760
-
761
- ---
762
-
763
- ### Subcommand: `query "<question>"`
764
-
765
- #### Step 1 — 读取 wiki 索引
766
-
767
- 读取 `index.md` 和 `_metadata.json`,了解 wiki 中有哪些页面。
768
-
769
- 如果 wiki 为空(无页面),提示用户先运行 `/teamai-wiki ingest`。
770
-
771
- #### Step 2 — 定位相关页面
772
-
773
- 根据问题关键词,从 index.md 中识别 3-8 个最相关的页面。也可使用 Grep 搜索 wiki 页面内容:
774
-
775
- ```
776
- grep -r -l 'keyword' WIKI_DIR/ --include='*.md'
777
- ```
778
-
779
- #### Step 3 — 读取相关页面
780
-
781
- 使用 Read 工具读取定位到的 wiki 页面。沿着 `[[links]]` 扩展阅读范围(最多读取 12 个页面)。
782
-
783
- #### Step 4 — 综合回答
784
-
785
- 基于 wiki 页面内容,回答用户问题:
786
- - 引用来源页面:`(参见 [[page-name]])`
787
- - 如果 wiki 中没有足够信息,明确说明并建议 ingest 更多源文件
788
- - 回答语言跟随用户问题的语言
789
-
790
- #### Step 5 — 保存查询结果(如果 --save)
791
-
792
- 如果用户使用了 `--save` 参数:
793
- - 生成文件名(根据问题关键词,kebab-case)
794
- - 写入 `queries/<name>.md`,使用标准页面格式
795
- - 更新 index.md 的 Queries 分类
796
- - 更新 _metadata.json
797
-
798
- #### Step 6 — 追加 log.md
799
-
800
- ```markdown
801
- | YYYY-MM-DD HH:MM | query | Q: "<question>", Pages read: N, Saved: yes/no |
802
- ```
803
-
804
- ---
805
-
806
- ### Subcommand: `lint`
807
-
808
- #### Step 1 — 读取所有 wiki 页面
809
-
810
- 读取 `_metadata.json` 获取页面列表,然后读取所有 wiki 页面内容。
811
-
812
- 如果页面较多(>30),使用 Agent 工具并行读取和分析。
813
-
814
- #### Step 2 — 执行检查
815
-
816
- 检查以下问题:
817
-
818
- **Broken Links**:
819
- - 页面中的 `[[link]]` 指向不存在的页面
820
-
821
- **Orphan Pages**:
822
- - 没有任何其他页面链接到它(backlinks 为空,且不是 overview/index)
823
-
824
- **Contradictions**:
825
- - 不同页面对同一实体或概念的不同描述(需要 AI 判断)
826
-
827
- **Missing Pages**:
828
- - 被多个页面通过 `[[link]]` 引用但不存在的页面
829
-
830
- **Stale Content**:
831
- - 如果 `_metadata.json` 中记录的源文件哈希与当前文件不同,标记对应的 wiki 页面为 potentially stale
832
-
833
- **Backlink Mismatches**:
834
- - 实际引用关系与 Backlinks 段落不一致
835
-
836
- **Empty Categories**:
837
- - 目录存在但没有任何页面的分类(提示用户可以 ingest 相关内容)
838
-
839
- #### Step 3 — 输出报告
840
-
841
- ```markdown
842
- ## Wiki Lint Report
843
-
844
- ### Broken Links (N)
845
- - [[missing-page]] referenced in entities/message-builder.md:15
846
-
847
- ### Orphan Pages (N)
848
- - entities/old-module.md — no incoming links
849
-
850
- ### Missing Pages (N)
851
- - [[rabbitmq-integration]] — referenced by 3 pages, suggest creating it
852
-
853
- ### Stale Content (N)
854
- - sources/server-py.md — source file changed since last ingest
855
-
856
- ### Backlink Mismatches (N)
857
- - entities/foo.md — missing backlink from concepts/bar.md
858
-
859
- ### Empty Categories (N)
860
- - people/ — no pages yet (consider: /teamai-wiki ingest team-roster or meeting notes)
861
- - processes/ — no pages yet (consider: /teamai-wiki ingest runbooks or SOPs)
862
-
863
- ### Summary
864
- Pages: N | Links: M | Issues: K
865
- ```
866
-
867
- #### Step 4 — 追加 log.md
868
-
869
- ```markdown
870
- | YYYY-MM-DD HH:MM | lint | Issues found: N (broken: A, orphan: B, missing: C, stale: D) |
871
- ```
872
-
873
- ---
874
-
875
- ### Subcommand: `status`
876
-
877
- #### Step 1 — 读取 _metadata.json
878
-
879
- 读取 wiki 的 `_metadata.json`。如果不存在,提示先运行 `/teamai-wiki init`。
880
-
881
- #### Step 2 — 输出统计
882
-
883
- ```
884
- Wiki Status
885
- Wiki: WIKI_DIR
886
- Pages: N (entities: A, concepts: B, comparisons: C, people: D, decisions: E, processes: F, sources: G, queries: H)
887
- Links: M (avg N.N per page)
888
- Sources ingested: K files
889
- Last ingest: YYYY-MM-DD HH:MM
890
- Last lint: YYYY-MM-DD HH:MM (or "never")
891
- Recent log entries:
892
- - [time] ingest: ...
893
- - [time] query: ...
894
- ```
895
-
896
- Also read the last 5 lines of `log.md` for recent activity.
897
-
898
- ---
899
-
900
- ### Subcommand: `export [--format md|html]`
901
-
902
- 将 wiki 导出为单个文件,方便分享给不用 Obsidian 的同事。
903
-
904
- #### Step 1 — 读取 wiki 状态
905
-
906
- 读取 `_metadata.json` 和 `index.md`。如果 wiki 为空,提示先 ingest 内容。
907
-
908
- #### Step 2 — 确定导出格式
909
-
910
- - `--format md`(默认):合并为单个 Markdown 文件
911
- - `--format html`:生成带目录导航的 HTML 页面
912
-
913
- #### Step 3 — 合并内容
914
-
915
- **Markdown 格式**:
916
-
917
- 按 index.md 的顺序,将所有页面合并为一个文件:
918
-
919
- ```markdown
920
- # Wiki Export: <wiki-name>
921
-
922
- > Exported on YYYY-MM-DD | Pages: N | Links: M
923
-
924
- ---
925
-
926
- ## Table of Contents
927
-
928
- [自动生成目录]
929
-
930
- ---
931
-
932
- ## Entities
933
-
934
- ### Message Builder
935
-
936
- [页面正文,[[links]] 转换为 Markdown 内部锚点 [text](#anchor)]
937
-
938
- ---
939
-
940
- ### HAI API Server
941
-
942
- [...]
943
-
944
- ---
945
-
946
- ## Concepts
947
-
948
- [...]
949
-
950
- ## Comparisons
951
-
952
- [...]
953
-
954
- ## People
955
-
956
- [...]
957
-
958
- ## Decisions
959
-
960
- [...]
961
-
962
- ## Processes
963
-
964
- [...]
965
- ```
966
-
967
- **HTML 格式**:
968
-
969
- 生成一个自包含的 HTML 文件:
970
- - 左侧:目录导航(按分类折叠)
971
- - 右侧:页面内容
972
- - `[[links]]` 转换为页面内锚点跳转
973
- - 基本样式(可读、打印友好)
974
-
975
- #### Step 4 — 写入输出文件
976
-
977
- - Markdown: `wiki/export/wiki-export-YYYY-MM-DD.md`
978
- - HTML: `wiki/export/wiki-export-YYYY-MM-DD.html`
979
-
980
- ```bash
981
- mkdir -p WIKI_DIR/export
982
- ```
983
-
984
- 输出:
985
- ```
986
- Wiki exported to: <path>
987
- Format: md/html
988
- Pages included: N
989
- File size: X KB
990
- ```
991
-
992
- #### Step 5 — 追加 log.md
993
-
994
- ```markdown
995
- | YYYY-MM-DD HH:MM | export | Format: md/html, Pages: N, Output: <path> |
996
- ```
997
-
998
- ---
999
-
1000
- ## Behavioral Rules
1001
-
1002
- 1. **每次操作前必须读取 `_schema.md`** — 确保遵循 wiki 约定。
1003
- 2. **增量优先** — ingest 只处理新增和变更的文件,通过 SHA256 哈希判断。
1004
- 3. **使用 Agent 工具并行分析** — 源文件分析必须并行,在单条消息中启动多个 Agent。
1005
- 4. **保持页面精简** — 每个页面聚焦一个实体或概念,避免巨型页面。单页不超过 200 行。
1006
- 5. **双向链接** — 每次创建/更新页面后,维护 Backlinks。
1007
- 6. **Backlinks 段落由系统维护** — 不要手动编辑 Backlinks,它由 ingest 和 lint 自动更新。
1008
- 7. **追加式 log** — log.md 只追加,不修改或删除历史记录。
1009
- 8. **_metadata.json 是真相来源** — 页面列表、文件哈希、链接图都以此为准。
1010
- 9. **命名一致性** — 文件名 kebab-case,标题 Title Case 或人类可读中文。
1011
- 10. **幂等性** — 重复 ingest 同一源目录应产生相同结果(不会重复创建页面)。
1012
- 11. **wiki 路径** — 读取 `<projectRoot>/.teamai/config.yaml` 的 `scope` 字段:project scope 用 `<projectRoot>/.teamai/wiki/`,user scope 用 `~/.teamai/wiki/`。与 teamai push/pull 的 `WikiHandler.getSharedWikiDir()` 逻辑对齐。
1013
- 12. **Obsidian 兼容** — 所有 `[[links]]` 使用 Obsidian 格式,方便用户在 Obsidian 中直接浏览。
1014
- 13. **语言** — Wiki 页面内容默认使用中文撰写,技术术语保持英文原文。
1015
- 14. **智能分类** — LLM 根据内容自动判断页面归属哪个分类目录,无需用户指定。
1016
- 15. **敏感文件排除** — ingest 时自动跳过 `.env`、`*.pem`、`*.key`、`credentials.json` 等可能含密钥的文件。
1017
- 16. **容错处理** — `_metadata.json` 损坏时尝试从 wiki 目录重建;URL 无法访问时给出清晰错误提示。
1018
- 17. **源类型自适应** — 代码目录和文档目录使用不同的分析策略,混合目录自动分组处理。
1019
- 18. **团队同步** — wiki 页面通过 `teamai push/pull` 与团队共享。`_metadata.json` 不推送,每次 pull 后由本地重建。修改 wiki 后提醒用户运行 `teamai push` 同步到团队。