source-kb 0.2.2__py3-none-any.whl
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.
- cli/__init__.py +50 -0
- cli/__main__.py +5 -0
- cli/commands/__init__.py +1 -0
- cli/commands/anchor_fix.py +47 -0
- cli/commands/diff_doc.py +52 -0
- cli/commands/dispatch.py +77 -0
- cli/commands/extract.py +72 -0
- cli/commands/file_list.py +74 -0
- cli/commands/index.py +84 -0
- cli/commands/lock.py +89 -0
- cli/commands/merge.py +60 -0
- cli/commands/merge_delta.py +19 -0
- cli/commands/metadata.py +24 -0
- cli/commands/pipeline.py +45 -0
- cli/commands/post_merge.py +43 -0
- cli/commands/query.py +52 -0
- cli/commands/render.py +101 -0
- cli/commands/scan_repos.py +46 -0
- cli/commands/setup.py +94 -0
- cli/commands/split.py +196 -0
- cli/commands/stale_files.py +98 -0
- cli/commands/validate.py +191 -0
- core/__init__.py +32 -0
- core/config.py +261 -0
- core/docs/__init__.py +7 -0
- core/docs/section_updater.py +286 -0
- core/docs/shared.py +149 -0
- core/git.py +294 -0
- core/interfaces.py +249 -0
- core/monitor/__init__.py +5 -0
- core/monitor/progress.py +83 -0
- core/monitor/prompt_store.py +49 -0
- core/paths.py +141 -0
- core/preset.py +237 -0
- core/preset_accessors.py +202 -0
- core/preset_classify.py +132 -0
- core/preset_hooks.py +129 -0
- core/preset_profile.py +89 -0
- core/prompt/__init__.py +7 -0
- core/prompt/__main__.py +147 -0
- core/prompt/content.py +320 -0
- core/prompt/context_manager.py +164 -0
- core/prompt/renderer.py +236 -0
- core/prompt/response_parser.py +274 -0
- core/prompt/templates.py +357 -0
- core/prompt/validate_parity.py +162 -0
- core/prompt/variables.py +339 -0
- core/rag/__init__.py +22 -0
- core/rag/__main__.py +136 -0
- core/rag/bm25_index.py +268 -0
- core/rag/chunker.py +273 -0
- core/rag/embedder.py +151 -0
- core/rag/indexer.py +292 -0
- core/rag/loader.py +89 -0
- core/rag/retriever.py +82 -0
- core/skeleton/__init__.py +11 -0
- core/skeleton/__main__.py +934 -0
- core/skeleton/anchor_fix.py +250 -0
- core/skeleton/classify.py +331 -0
- core/skeleton/cmd_anchor_fix.py +43 -0
- core/skeleton/cmd_diff_doc.py +44 -0
- core/skeleton/cmd_lock.py +87 -0
- core/skeleton/cmd_merge_delta.py +41 -0
- core/skeleton/community.py +233 -0
- core/skeleton/dependency_graph.py +306 -0
- core/skeleton/diff_doc.py +248 -0
- core/skeleton/dispatch.py +273 -0
- core/skeleton/dispatch_render.py +319 -0
- core/skeleton/dispatch_source.py +111 -0
- core/skeleton/extract.py +218 -0
- core/skeleton/extract_methods.py +298 -0
- core/skeleton/file_list.py +239 -0
- core/skeleton/impact.py +278 -0
- core/skeleton/jar_download.py +177 -0
- core/skeleton/jar_resolver.py +186 -0
- core/skeleton/loader.py +162 -0
- core/skeleton/merge.py +278 -0
- core/skeleton/merge_delta.py +229 -0
- core/skeleton/metadata.py +96 -0
- core/skeleton/metadata_builders.py +264 -0
- core/skeleton/module_dag.py +330 -0
- core/skeleton/parsers/__init__.py +71 -0
- core/skeleton/parsers/jqassistant.py +300 -0
- core/skeleton/parsers/jqassistant_cypher.py +225 -0
- core/skeleton/parsers/regex.py +171 -0
- core/skeleton/parsers/treesitter.py +324 -0
- core/skeleton/parsers/treesitter_java.py +284 -0
- core/skeleton/parsers/treesitter_multi.py +289 -0
- core/skeleton/pom_parser.py +299 -0
- core/skeleton/post_merge.py +295 -0
- core/skeleton/post_merge_llm.py +82 -0
- core/skeleton/query.py +195 -0
- core/skeleton/shard_context.py +177 -0
- core/skeleton/split.py +180 -0
- core/skeleton/split_cache.py +107 -0
- core/skeleton/split_feedback.py +174 -0
- core/skeleton/split_plan.py +219 -0
- core/skeleton/split_plan_helpers.py +305 -0
- core/skeleton/split_plan_llm.py +274 -0
- core/utils.py +135 -0
- core/validators/__init__.py +65 -0
- core/validators/__main__.py +215 -0
- core/validators/consistency.py +203 -0
- core/validators/coverage.py +171 -0
- core/validators/duplicates.py +76 -0
- core/validators/engine.py +224 -0
- core/validators/links.py +76 -0
- core/validators/sampling.py +169 -0
- core/validators/structure.py +144 -0
- engine/__init__.py +7 -0
- engine/assembler.py +231 -0
- engine/confirm.py +65 -0
- engine/dedup.py +106 -0
- engine/main.py +211 -0
- engine/pipeline/__init__.py +163 -0
- engine/pipeline/recovery.py +250 -0
- engine/pipeline/steps/__init__.py +23 -0
- engine/pipeline/steps/audit.py +220 -0
- engine/pipeline/steps/audit_apply.py +195 -0
- engine/pipeline/steps/audit_helpers.py +155 -0
- engine/pipeline/steps/classify_llm.py +236 -0
- engine/pipeline/steps/classify_prompt.py +223 -0
- engine/pipeline/steps/finalize.py +160 -0
- engine/pipeline/steps/generate.py +169 -0
- engine/pipeline/steps/generate_batch.py +197 -0
- engine/pipeline/steps/generate_recovery.py +170 -0
- engine/pipeline/steps/llm_plan_split.py +253 -0
- engine/pipeline/steps/lock.py +64 -0
- engine/pipeline/steps/preflight.py +237 -0
- engine/pipeline/steps/preflight_adjust.py +147 -0
- engine/pipeline/steps/pregenerate.py +130 -0
- engine/pipeline/steps/quality.py +81 -0
- engine/pipeline/steps/skeleton.py +149 -0
- engine/pipeline/steps/source.py +163 -0
- engine/pipeline/steps/sync.py +117 -0
- engine/pipeline/steps/sync_finalize.py +237 -0
- engine/pipeline/steps/sync_update.py +341 -0
- engine/pipelines.py +91 -0
- engine/runner.py +335 -0
- engine/strategies/__init__.py +86 -0
- engine/strategies/api.py +128 -0
- engine/strategies/delegated.py +50 -0
- engine/strategies/dryrun.py +25 -0
- engine/two_phase.py +143 -0
- mcp_server/__init__.py +73 -0
- mcp_server/__main__.py +5 -0
- mcp_server/tools/__init__.py +1 -0
- mcp_server/tools/config.py +63 -0
- mcp_server/tools/discovery.py +276 -0
- mcp_server/tools/generation.py +184 -0
- mcp_server/tools/planning.py +144 -0
- mcp_server/tools/source.py +175 -0
- mcp_server/tools/validation.py +140 -0
- mcp_server/tools/workflow.py +166 -0
- mcp_server/workflow_loader.py +204 -0
- presets/generic/audit_dimensions.md +132 -0
- presets/generic/doc_types.yaml +152 -0
- presets/generic/preset.yaml +115 -0
- presets/java-spring/audit_dimensions.md +228 -0
- presets/java-spring/audit_dimensions.yaml +203 -0
- presets/java-spring/doc_types.yaml +269 -0
- presets/java-spring/hooks.py +122 -0
- presets/java-spring/preset.yaml +341 -0
- presets/java-spring/templates/README.md +34 -0
- presets/java-spring/templates/audit-system.md +15 -0
- presets/java-spring/templates/subagent-aop.md +105 -0
- presets/java-spring/templates/subagent-api.md +63 -0
- presets/java-spring/templates/subagent-architecture.md +111 -0
- presets/java-spring/templates/subagent-async-events.md +107 -0
- presets/java-spring/templates/subagent-audit-api-contracts.md +40 -0
- presets/java-spring/templates/subagent-audit-architecture.md +38 -0
- presets/java-spring/templates/subagent-audit-business.md +40 -0
- presets/java-spring/templates/subagent-audit-data-models.md +40 -0
- presets/java-spring/templates/subagent-business.md +129 -0
- presets/java-spring/templates/subagent-caching.md +75 -0
- presets/java-spring/templates/subagent-database-access.md +114 -0
- presets/java-spring/templates/subagent-enum.md +75 -0
- presets/java-spring/templates/subagent-error-handling.md +91 -0
- presets/java-spring/templates/subagent-external-integrations.md +80 -0
- presets/java-spring/templates/subagent-index.md +122 -0
- presets/java-spring/templates/subagent-messaging.md +97 -0
- presets/java-spring/templates/subagent-model.md +88 -0
- presets/java-spring/templates/subagent-observability.md +91 -0
- presets/java-spring/templates/subagent-scheduled.md +81 -0
- presets/java-spring/templates/subagent-security.md +102 -0
- presets/java-spring/templates/subagent-structure.md +101 -0
- presets/java-spring/templates/subagent-sync-section.md +34 -0
- presets/java-spring/templates/subagent-utils.md +73 -0
- presets/java-spring/templates/sync-system.md +8 -0
- presets/java-spring/workflow-extensions.md +112 -0
- skills/__init__.py +1 -0
- skills/_shared/README.md +30 -0
- skills/_shared/doc-coverage-shared.md +134 -0
- skills/_shared/doc-quality-standard.md +1058 -0
- skills/_shared/doc-subagent-rules.md +762 -0
- skills/_shared/windows-compat.md +89 -0
- skills/kb-audit/SKILL.md +52 -0
- skills/kb-audit/rules.md +88 -0
- skills/kb-audit/steps/step-01-prepare.md +75 -0
- skills/kb-audit/steps/step-02-audit.md +96 -0
- skills/kb-audit/steps/step-03-verify.md +65 -0
- skills/kb-audit/steps/step-04-report.md +64 -0
- skills/kb-init/SKILL.md +146 -0
- skills/kb-init/rules.md +187 -0
- skills/kb-init/steps/step-01-scope.md +62 -0
- skills/kb-init/steps/step-02-source.md +410 -0
- skills/kb-init/steps/step-03-generate.md +307 -0
- skills/kb-init/steps/step-04-quality.md +92 -0
- skills/kb-init/steps/step-05-finalize.md +132 -0
- skills/kb-init/templates/core/execution-modes.md +29 -0
- skills/kb-init/templates/core/output-only.md +4 -0
- skills/kb-init/templates/core/readwrite.md +33 -0
- skills/kb-search/SKILL.md +138 -0
- skills/kb-search/rules.md +64 -0
- skills/kb-sync/SKILL.md +43 -0
- skills/kb-sync/rules.md +70 -0
- skills/kb-sync/scripts/rebuild_module.py +91 -0
- skills/kb-sync/scripts/scan_repos.py +687 -0
- skills/kb-sync/steps/step-01-detect.md +72 -0
- skills/kb-sync/steps/step-02-update.md +71 -0
- skills/kb-sync/steps/step-03-verify.md +47 -0
- skills/kb-sync/steps/step-04-finalize.md +52 -0
- source_kb-0.2.2.dist-info/METADATA +194 -0
- source_kb-0.2.2.dist-info/RECORD +228 -0
- source_kb-0.2.2.dist-info/WHEEL +5 -0
- source_kb-0.2.2.dist-info/entry_points.txt +3 -0
- source_kb-0.2.2.dist-info/licenses/LICENSE +21 -0
- source_kb-0.2.2.dist-info/top_level.txt +6 -0
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# Step 1: 检测
|
|
2
|
+
|
|
3
|
+
## 1.1 获取知识库锁
|
|
4
|
+
|
|
5
|
+
按 `rules.md` §3 锁协议获取 `{knowledge_dir}/.kb-lock`,超时 30 分钟。
|
|
6
|
+
|
|
7
|
+
```shell
|
|
8
|
+
# 检查锁文件
|
|
9
|
+
cat "{knowledge_dir}/.kb-lock" 2>/dev/null
|
|
10
|
+
# 不存在或已超时 → 创建
|
|
11
|
+
echo '{"pid": '$$', "timestamp": "'$(date -u +%Y-%m-%dT%H:%M:%SZ)'", "operation": "kb-sync"}' > "{knowledge_dir}/.kb-lock"
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## 1.2 更新源码缓存
|
|
15
|
+
|
|
16
|
+
如果模块有 `.source-cache`,先更新:
|
|
17
|
+
|
|
18
|
+
```shell
|
|
19
|
+
git -C .source-cache/{module} pull
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
没有缓存则按以下方式创建:
|
|
23
|
+
|
|
24
|
+
```shell
|
|
25
|
+
git clone --depth 1 --branch {branch} {repo_url} .source-cache/{module}
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## 1.3 检测变动
|
|
29
|
+
|
|
30
|
+
```shell
|
|
31
|
+
source-kb scan-repos --config kb-project.yaml
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
可选参数:`--kb {kb}`、`--module {module}`、`--force`
|
|
35
|
+
|
|
36
|
+
无变动 → 释放锁(跳到 step-04 §4.3),正常结束。
|
|
37
|
+
|
|
38
|
+
## 1.4 变动分类
|
|
39
|
+
|
|
40
|
+
按 preset 的 `file_classification` 分类变动文件 → 确定需更新的文档列表。
|
|
41
|
+
|
|
42
|
+
分类结果示例:
|
|
43
|
+
- `model` 类文件变动 → data-models.md
|
|
44
|
+
- `controller` / `api` 类文件变动 → api-contracts.md
|
|
45
|
+
- `service` 类文件变动 → business-logic.md
|
|
46
|
+
- `config` / `aspect` 类文件变动 → architecture.md
|
|
47
|
+
|
|
48
|
+
## 1.5 降级检查
|
|
49
|
+
|
|
50
|
+
变动文件 > 20 个 → **降级为 kb-audit 完整流程**:
|
|
51
|
+
1. 释放锁(删除 `.kb-lock`)
|
|
52
|
+
2. 提示用户执行 `/kb-audit --module {module}`
|
|
53
|
+
3. kb-sync 流程终止,不继续后续步骤
|
|
54
|
+
|
|
55
|
+
## 1.6 可选文档触发检查
|
|
56
|
+
|
|
57
|
+
如果变动文件中新增了中间件使用(如新引入 `@KafkaListener`、`@RabbitListener`),按 `audit_dimensions.md` 的触发条件检测:
|
|
58
|
+
|
|
59
|
+
- 命中且对应可选文档不存在 → 标记为待新建(在 Step 2 中创建)
|
|
60
|
+
- 命中且文档已存在 → 加入更新列表
|
|
61
|
+
- 未命中 → 跳过
|
|
62
|
+
|
|
63
|
+
## Gate 1 检查清单
|
|
64
|
+
|
|
65
|
+
- [ ] `.kb-lock` 已创建
|
|
66
|
+
- [ ] 源码缓存已更新
|
|
67
|
+
- [ ] `scan_repos.py` 已执行,变动文件已列出
|
|
68
|
+
- [ ] 变动文件已按 preset 分类
|
|
69
|
+
- [ ] 变动文件 ≤ 20 个(否则已降级终止)
|
|
70
|
+
- [ ] 可选文档触发条件已检查
|
|
71
|
+
|
|
72
|
+
全部通过 → 加载 `step-02-update.md`
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# Step 2: 更新
|
|
2
|
+
|
|
3
|
+
## 2.1 骨架增量提取
|
|
4
|
+
|
|
5
|
+
无论变动文件数量多少,都更新骨架以保持最新。
|
|
6
|
+
|
|
7
|
+
### 增量模式(变动文件 ≤ 10 个)
|
|
8
|
+
|
|
9
|
+
```shell
|
|
10
|
+
# 提取变动文件的骨架到 delta
|
|
11
|
+
source-kb extract \
|
|
12
|
+
--repo "{repo}" --preset {preset} --files {changed_files...} --compact \
|
|
13
|
+
--output "{module_dir}/.skeleton-delta.json"
|
|
14
|
+
|
|
15
|
+
# 合并 delta 到已有骨架
|
|
16
|
+
source-kb merge-delta \
|
|
17
|
+
--delta "{module_dir}/.skeleton-delta.json" --target "{module_dir}"
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
脚本自动检测目标格式(`.skeleton.json` 单文件或 `.skeleton/` 分片目录),按文件路径替换同名条目、追加新条目,完成后删除 delta 文件。可先用 `--dry-run` 预览合并计划。
|
|
21
|
+
|
|
22
|
+
### 全量模式(变动文件 > 10 个)
|
|
23
|
+
|
|
24
|
+
跳过 delta 合并,直接全量重新提取:
|
|
25
|
+
|
|
26
|
+
```shell
|
|
27
|
+
source-kb extract \
|
|
28
|
+
--repo "{repo}" --preset {preset} --full --compact --output "{module_dir}"
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## 2.2 文档更新
|
|
32
|
+
|
|
33
|
+
按 `rules.md` §4 依赖链顺序更新文档(从 `doc_types.yaml` 的 `depends_on` 字段拓扑排序)。
|
|
34
|
+
|
|
35
|
+
只更新 Step 1 分类中确定需要更新的文档,跳过无关文档。
|
|
36
|
+
|
|
37
|
+
### 更新方式
|
|
38
|
+
|
|
39
|
+
- 定位文档中对应章节,**只重写匹配章节**,不改动其他部分
|
|
40
|
+
- 新增内容追加到对应章节末尾
|
|
41
|
+
- 删除的源码对应内容标记为 `~~已移除~~` 或直接删除
|
|
42
|
+
|
|
43
|
+
### 源码读取规则
|
|
44
|
+
|
|
45
|
+
- 优先读 `.source-cache/{module}` 下的文件(缓存模式)
|
|
46
|
+
- 缓存不存在时 fallback 到 `git show {commit}:{path}`
|
|
47
|
+
|
|
48
|
+
### 写入纪律
|
|
49
|
+
|
|
50
|
+
- 格式遵循 preset 的文档格式规范(表格对齐、代码块标注语言、锚点命名)
|
|
51
|
+
- 内容深度遵循业务视角组织原则(不是代码翻译,是业务逻辑说明)
|
|
52
|
+
- Write-as-you-go:每处理完一个文档立即写盘,不攒到最后
|
|
53
|
+
|
|
54
|
+
## 2.3 引用级联检查
|
|
55
|
+
|
|
56
|
+
当中立文档(data-models / api-contracts / caching / messaging / architecture)发生**章节结构变更**(`##`/`###` 标题增删或重编号)时:
|
|
57
|
+
|
|
58
|
+
1. 提取被修改文档的所有 `##`/`###` 标题(修改前 vs 修改后)
|
|
59
|
+
2. 如果标题发生变更 → 在 business-logic.md 中搜索指向该文档的锚点链接
|
|
60
|
+
3. 失效的锚点 → 自动修复(更新为新锚点)或降级为文件级链接(去掉 `#锚点` 部分)
|
|
61
|
+
|
|
62
|
+
注意:纯内容修改(字段表增删行、配置值变更)不影响锚点,无需级联。只有章节标题变更才需要级联检查。
|
|
63
|
+
|
|
64
|
+
## Gate 2 检查清单
|
|
65
|
+
|
|
66
|
+
- [ ] 骨架已更新(delta 合并或全量重提取)
|
|
67
|
+
- [ ] 所有目标文档已按依赖顺序更新
|
|
68
|
+
- [ ] 引用级联检查已完成(如有章节标题变更)
|
|
69
|
+
- [ ] 每个文档更新后已立即写盘
|
|
70
|
+
|
|
71
|
+
全部通过 → 加载 `step-03-verify.md`
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# Step 3: 校验
|
|
2
|
+
|
|
3
|
+
## 3.1 覆盖率校验
|
|
4
|
+
|
|
5
|
+
文档更新后,执行覆盖率校验确认质量:
|
|
6
|
+
|
|
7
|
+
```shell
|
|
8
|
+
source-kb validate coverage check \
|
|
9
|
+
--skeleton "{module_dir}/.skeleton.json" --docs-dir "{module_dir}" --type {module_type}
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
### 阈值
|
|
13
|
+
|
|
14
|
+
- 覆盖率 ≥ 80% → 通过
|
|
15
|
+
- 覆盖率 < 80% → 补充缺失方法,重新校验直到达标
|
|
16
|
+
|
|
17
|
+
### 补充策略
|
|
18
|
+
|
|
19
|
+
1. 从校验输出中提取未覆盖的方法列表
|
|
20
|
+
2. 按优先级排序:`high` complexity > `medium` > `low`
|
|
21
|
+
3. 定位对应文档章节,补充缺失方法的说明
|
|
22
|
+
4. 重新执行覆盖率校验
|
|
23
|
+
|
|
24
|
+
## 3.2 共享文档更新检测
|
|
25
|
+
|
|
26
|
+
如果变动涉及模块间调用关系、错误码、数据模型等,检查 `{knowledge_dir}/_shared/` 下的共享文档是否需要同步更新。
|
|
27
|
+
|
|
28
|
+
### 检测规则
|
|
29
|
+
|
|
30
|
+
| 共享文档 | 检测方式 | 触发条件 |
|
|
31
|
+
|---------|---------|---------|
|
|
32
|
+
| `cross-module-calls.md` | grep architecture.md | 新增/修改 Feign 或 Dubbo 接口声明 |
|
|
33
|
+
| `error-codes.md` | grep api-contracts.md | 新增/修改错误码表 |
|
|
34
|
+
| `database-ddl.md` | grep data-models.md | 新增/修改 `@TableName` 注解对应的表 |
|
|
35
|
+
|
|
36
|
+
### 更新方式
|
|
37
|
+
|
|
38
|
+
- 命中 → 定位共享文档中对应章节,增量更新
|
|
39
|
+
- 未命中 → 跳过
|
|
40
|
+
|
|
41
|
+
## Gate 3 检查清单
|
|
42
|
+
|
|
43
|
+
- [ ] 覆盖率 ≥ 80%
|
|
44
|
+
- [ ] 共享文档检测已执行(cross-module-calls / error-codes / database-ddl)
|
|
45
|
+
- [ ] 需要更新的共享文档已更新
|
|
46
|
+
|
|
47
|
+
全部通过 → 加载 `step-04-finalize.md`
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# Step 4: 收尾
|
|
2
|
+
|
|
3
|
+
## 4.1 Embedding 服务预检
|
|
4
|
+
|
|
5
|
+
索引重建前先确认 Embedding 服务可用:
|
|
6
|
+
|
|
7
|
+
```shell
|
|
8
|
+
source-kb validate links --config kb-project.yaml
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
预检失败 → ⚠️ 暂停,提示用户检查 Embedding 服务配置,不执行索引重建。文档更新仍然保留,下次 sync 可补建索引。
|
|
12
|
+
|
|
13
|
+
## 4.2 索引重建
|
|
14
|
+
|
|
15
|
+
文件级增量重建(只重建有修改的文档):
|
|
16
|
+
|
|
17
|
+
```shell
|
|
18
|
+
source-kb rebuild \
|
|
19
|
+
--config kb-project.yaml --kb {kb} --module {module} --files {modified.md...}
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## 4.3 基线更新
|
|
23
|
+
|
|
24
|
+
**前置条件**(R7):只有文档更新(Step 2)和覆盖率校验(Step 3)都成功后,才更新基线 commit。
|
|
25
|
+
|
|
26
|
+
如果 Step 2 文档更新失败或 Step 3 覆盖率不达标 → 不更新基线。下次 sync 会重新处理这批变动。
|
|
27
|
+
|
|
28
|
+
```shell
|
|
29
|
+
# 仅在上述步骤全部成功后执行
|
|
30
|
+
source-kb scan-repos --config kb-project.yaml --update-state --kb {kb} --module {module} {commit}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## 4.4 释放锁
|
|
34
|
+
|
|
35
|
+
**必须执行**(R2),无论前面步骤成功或失败:
|
|
36
|
+
|
|
37
|
+
```shell
|
|
38
|
+
rm -f "{knowledge_dir}/.kb-lock"
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## 完成报告
|
|
42
|
+
|
|
43
|
+
流程结束后输出摘要:
|
|
44
|
+
|
|
45
|
+
| 项目 | 状态 |
|
|
46
|
+
|------|------|
|
|
47
|
+
| 变动文件数 | {n} 个 |
|
|
48
|
+
| 更新文档 | {doc_list} |
|
|
49
|
+
| 覆盖率 | {coverage}% |
|
|
50
|
+
| 共享文档更新 | {shared_docs} |
|
|
51
|
+
| 索引重建 | ✅ / ⚠️ 跳过 |
|
|
52
|
+
| 基线更新 | ✅ / ⚠️ 跳过(原因) |
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: source-kb
|
|
3
|
+
Version: 0.2.2
|
|
4
|
+
Summary: Auto-generate structured knowledge base documents from source code. Supports AI agent mode (skill-based) and MCP server interface.
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
Keywords: knowledge-base,documentation,code-analysis,llm,mcp
|
|
7
|
+
Classifier: Development Status :: 4 - Beta
|
|
8
|
+
Classifier: Intended Audience :: Developers
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
+
Classifier: Topic :: Software Development :: Documentation
|
|
14
|
+
Requires-Python: >=3.10
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
License-File: LICENSE
|
|
17
|
+
Requires-Dist: requests>=2.28.0
|
|
18
|
+
Requires-Dist: pyyaml>=6.0
|
|
19
|
+
Requires-Dist: filelock>=3.12.0
|
|
20
|
+
Provides-Extra: mcp
|
|
21
|
+
Requires-Dist: mcp>=1.0.0; extra == "mcp"
|
|
22
|
+
Provides-Extra: skeleton
|
|
23
|
+
Requires-Dist: tree-sitter<0.22.0,>=0.21.0; extra == "skeleton"
|
|
24
|
+
Requires-Dist: tree-sitter-languages>=1.10.0; extra == "skeleton"
|
|
25
|
+
Provides-Extra: rag
|
|
26
|
+
Requires-Dist: chromadb>=0.4.0; extra == "rag"
|
|
27
|
+
Provides-Extra: full
|
|
28
|
+
Requires-Dist: mcp>=1.0.0; extra == "full"
|
|
29
|
+
Requires-Dist: chromadb>=0.4.0; extra == "full"
|
|
30
|
+
Requires-Dist: tree-sitter<0.22.0,>=0.21.0; extra == "full"
|
|
31
|
+
Requires-Dist: tree-sitter-languages>=1.10.0; extra == "full"
|
|
32
|
+
Provides-Extra: dev
|
|
33
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
34
|
+
Requires-Dist: ruff>=0.4.0; extra == "dev"
|
|
35
|
+
Dynamic: license-file
|
|
36
|
+
|
|
37
|
+
# source-kb
|
|
38
|
+
|
|
39
|
+
English | [中文](README.md)
|
|
40
|
+
|
|
41
|
+
Auto-generate structured knowledge base documents from source code, build vector indexes, and support RAG retrieval.
|
|
42
|
+
|
|
43
|
+
## Features
|
|
44
|
+
|
|
45
|
+
- **CLI toolchain**: skeleton extraction, prompt rendering, intelligent splitting, quality validation, vector indexing — all standalone Python scripts
|
|
46
|
+
- **MCP Server**: zero-friction integration with any MCP-compatible AI Agent
|
|
47
|
+
- **Platform-agnostic**: works in Kiro / Cursor / Claude Code / Windsurf / any AI Agent
|
|
48
|
+
- **LLM-agnostic**: without an Agent, use CLI pipeline with any OpenAI-compatible API (Anthropic / OpenAI / DeepSeek / Ollama / vLLM, etc.)
|
|
49
|
+
- **Intelligent subagent splitting**: semantic grouping by business domain (LLM-based) or package-aware greedy algorithm (code-based)
|
|
50
|
+
- **Two-phase generation**: outline first, then expand — eliminates information isolation between shards
|
|
51
|
+
- **Method-level source injection**: prioritized by complexity (high=full body / medium=first 20 lines / low=signature only)
|
|
52
|
+
- **Real-time quality validation**: each subagent output is verified immediately, with automatic retry on failure
|
|
53
|
+
- **Document deduplication**: LLM-powered post-merge dedup (internal redundancy + cross-doc ownership)
|
|
54
|
+
- Any language support via preset system (java-spring built-in)
|
|
55
|
+
- Source code access through git remote (multi-repo & monorepo)
|
|
56
|
+
- Lightweight self-built RAG engine (ChromaDB + pluggable embedding)
|
|
57
|
+
|
|
58
|
+
## Quick Start
|
|
59
|
+
|
|
60
|
+
### Option 1: MCP Server (recommended)
|
|
61
|
+
|
|
62
|
+
Configure the MCP server in your AI Agent (Kiro / Claude Code / Cursor / Windsurf):
|
|
63
|
+
|
|
64
|
+
```json
|
|
65
|
+
{
|
|
66
|
+
"mcpServers": {
|
|
67
|
+
"source-kb": {
|
|
68
|
+
"command": "uvx",
|
|
69
|
+
"args": ["--from", "git+https://your-repo/source-kb.git", "source-kb-mcp"]
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Or for local development:
|
|
76
|
+
|
|
77
|
+
```json
|
|
78
|
+
{
|
|
79
|
+
"mcpServers": {
|
|
80
|
+
"source-kb": {
|
|
81
|
+
"command": "python",
|
|
82
|
+
"args": ["-m", "mcp_server"],
|
|
83
|
+
"cwd": "/path/to/source-kb"
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Once configured, the Agent discovers all tools automatically. Just ask:
|
|
90
|
+
|
|
91
|
+
```
|
|
92
|
+
Generate knowledge base documentation for this project
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
The Agent will call `discover()` → `detect_project()` → `get_workflow("kb-init")` to orchestrate the entire flow.
|
|
96
|
+
|
|
97
|
+
**Non-Java project?** Works the same way. `detect_project()` auto-detects project type; unrecognized projects use the `generic` preset:
|
|
98
|
+
|
|
99
|
+
```
|
|
100
|
+
Generate knowledge base documentation for this Python/Go/Node.js project
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
You can also specify the preset manually:
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
# Use generic preset (works for any language)
|
|
107
|
+
source-kb extract --repo .source-cache/my-app --preset generic --output knowledge/my-app
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
> The generic preset uses path-based rules + regex parser for file classification — no tree-sitter required. For higher accuracy, create a custom preset following `presets/java-spring/` as reference.
|
|
111
|
+
|
|
112
|
+
### Option 2: Manual Skill Mode
|
|
113
|
+
|
|
114
|
+
If your Agent doesn't support MCP, load skill files manually:
|
|
115
|
+
|
|
116
|
+
```
|
|
117
|
+
Please read skills/kb-init/SKILL.md and follow the steps to initialize the knowledge base.
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
Or add the guide to your project rules file (`.kiro/steering/`, `.cursorrules`, etc.). See [Getting Started](docs/getting-started.md).
|
|
121
|
+
|
|
122
|
+
### Option 3: CLI Mode (no Agent)
|
|
123
|
+
|
|
124
|
+
```bash
|
|
125
|
+
export LLM_BASE_URL="https://api.anthropic.com"
|
|
126
|
+
export LLM_MODEL="claude-sonnet-4-6"
|
|
127
|
+
export LLM_API_KEY="sk-xxx"
|
|
128
|
+
source-kb pipeline --kb my-project --action init
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
> Full guide: [Getting Started](docs/getting-started.md).
|
|
132
|
+
|
|
133
|
+
## CLI Quick Reference
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
# Skeleton extraction
|
|
137
|
+
source-kb extract --repo .source-cache/xxx --preset java-spring --summary --output knowledge/xxx
|
|
138
|
+
|
|
139
|
+
# Prompt rendering
|
|
140
|
+
source-kb render --template presets/java-spring/templates/subagent-business.md --module xxx --kb yyy --doc-type business-logic --mode readwrite
|
|
141
|
+
|
|
142
|
+
# File list extraction
|
|
143
|
+
source-kb file-list --skeleton knowledge/xxx/.meta/skeleton/skeleton.json --preset java-spring --doc-type business-logic --output knowledge/xxx/.meta/file-lists/business-logic.txt
|
|
144
|
+
|
|
145
|
+
# Coverage validation
|
|
146
|
+
source-kb validate coverage check --skeleton knowledge/xxx/.meta/skeleton/skeleton.json --docs-dir knowledge/xxx --type service
|
|
147
|
+
|
|
148
|
+
# Index & search
|
|
149
|
+
source-kb index --kb my-project
|
|
150
|
+
source-kb search --kb my-project "query"
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
## MCP Tools
|
|
154
|
+
|
|
155
|
+
| Tool | Purpose |
|
|
156
|
+
|------|---------|
|
|
157
|
+
| `discover` | Detect project state and available workflows |
|
|
158
|
+
| `detect_project` | Scan project structure, recommend config |
|
|
159
|
+
| `init_project` | Generate kb-project.yaml |
|
|
160
|
+
| `get_workflow` | Get step-by-step orchestration instructions |
|
|
161
|
+
| `get_subagent_prompt` | Render sub-agent prompt for doc generation |
|
|
162
|
+
| `skeleton_extract` | Extract code skeleton (AST-level structure) |
|
|
163
|
+
| `classify_files` | Classify source files into doc types |
|
|
164
|
+
| `dispatch_plan` | Compute generation plan (batches, splits) |
|
|
165
|
+
| `coverage_check` | Validate documentation coverage |
|
|
166
|
+
| `check_progress` | Monitor sub-agent generation progress |
|
|
167
|
+
| `generate_doc` | Direct LLM generation (fallback for agents without sub-agents) |
|
|
168
|
+
| `list_presets` | List available language presets |
|
|
169
|
+
|
|
170
|
+
## Skills
|
|
171
|
+
|
|
172
|
+
| Skill | Purpose |
|
|
173
|
+
|-------|---------|
|
|
174
|
+
| kb-init | Generate all docs from source + build index |
|
|
175
|
+
| kb-audit | Compare docs vs source, fix inconsistencies |
|
|
176
|
+
| kb-sync | Detect git changes, incrementally update docs and index |
|
|
177
|
+
| kb-search | Vector retrieval + contextual answers |
|
|
178
|
+
|
|
179
|
+
Skill files are Agent operation guides — no platform-specific instructions.
|
|
180
|
+
|
|
181
|
+
## Requirements
|
|
182
|
+
|
|
183
|
+
- Python 3.10~3.12 (⚠️ 3.13 not supported — tree-sitter-languages has no prebuilt wheel)
|
|
184
|
+
- Git
|
|
185
|
+
- Embedding backend (Ollama / OpenAI-compatible / DashScope / ChromaDB built-in)
|
|
186
|
+
|
|
187
|
+
## Documentation
|
|
188
|
+
|
|
189
|
+
- [Getting Started](docs/getting-started.md) — Installation, configuration, first run
|
|
190
|
+
- [Configuration Reference](docs/configuration.md) — Full kb-project.yaml field reference
|
|
191
|
+
- [Custom Presets](docs/custom-presets.md) — Create and customize language presets
|
|
192
|
+
- [Design Document](docs/design-v5.md) — Architecture design and technical decisions
|
|
193
|
+
- [CLI vs Agent Mode](docs/cli-vs-agent-mode-analysis.md) — Two modes compared
|
|
194
|
+
- [Preset Development](docs/presets.md) — Built-in preset internals
|