knowflow 0.1.0__tar.gz

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.
Files changed (50) hide show
  1. knowflow-0.1.0/LICENSE +21 -0
  2. knowflow-0.1.0/MANIFEST.in +3 -0
  3. knowflow-0.1.0/PKG-INFO +264 -0
  4. knowflow-0.1.0/README.md +219 -0
  5. knowflow-0.1.0/knowflow/__init__.py +4 -0
  6. knowflow-0.1.0/knowflow/__main__.py +3 -0
  7. knowflow-0.1.0/knowflow/adapters/knowledge/__init__.py +42 -0
  8. knowflow-0.1.0/knowflow/adapters/knowledge/local.py +43 -0
  9. knowflow-0.1.0/knowflow/adapters/knowledge/obsidian.py +64 -0
  10. knowflow-0.1.0/knowflow/adapters/storage/__init__.py +62 -0
  11. knowflow-0.1.0/knowflow/adapters/storage/git.py +155 -0
  12. knowflow-0.1.0/knowflow/adapters/storage/local.py +110 -0
  13. knowflow-0.1.0/knowflow/adapters/storage/quark.py +225 -0
  14. knowflow-0.1.0/knowflow/adapters/storage/s3.py +118 -0
  15. knowflow-0.1.0/knowflow/adapters/storage/webdav.py +196 -0
  16. knowflow-0.1.0/knowflow/cli/__init__.py +265 -0
  17. knowflow-0.1.0/knowflow/cli/template_manager.py +100 -0
  18. knowflow-0.1.0/knowflow/core/__init__.py +10 -0
  19. knowflow-0.1.0/knowflow/core/knowledge.py +85 -0
  20. knowflow-0.1.0/knowflow/core/pipeline.py +119 -0
  21. knowflow-0.1.0/knowflow/core/storage.py +167 -0
  22. knowflow-0.1.0/knowflow/dashboard/__init__.py +355 -0
  23. knowflow-0.1.0/knowflow/templates/daily-journal/plugin.yaml +21 -0
  24. knowflow-0.1.0/knowflow/templates/football-prediction/plugin.yaml +22 -0
  25. knowflow-0.1.0/knowflow/templates/project-wiki/plugin.yaml +20 -0
  26. knowflow-0.1.0/knowflow/templates/research-notes/plugin.yaml +26 -0
  27. knowflow-0.1.0/knowflow/templates/stock-analysis/plugin.yaml +22 -0
  28. knowflow-0.1.0/knowflow/templates/web-monitor/plugin.yaml +20 -0
  29. knowflow-0.1.0/knowflow/templates/worldcup-tracker/plugin.yaml +18 -0
  30. knowflow-0.1.0/knowflow/transforms/__init__.py +6 -0
  31. knowflow-0.1.0/knowflow/transforms/archive.py +87 -0
  32. knowflow-0.1.0/knowflow/transforms/markdown_export.py +110 -0
  33. knowflow-0.1.0/knowflow/transforms/profile_index.py +89 -0
  34. knowflow-0.1.0/knowflow.egg-info/PKG-INFO +264 -0
  35. knowflow-0.1.0/knowflow.egg-info/SOURCES.txt +48 -0
  36. knowflow-0.1.0/knowflow.egg-info/dependency_links.txt +1 -0
  37. knowflow-0.1.0/knowflow.egg-info/entry_points.txt +2 -0
  38. knowflow-0.1.0/knowflow.egg-info/requires.txt +18 -0
  39. knowflow-0.1.0/knowflow.egg-info/top_level.txt +1 -0
  40. knowflow-0.1.0/pyproject.toml +57 -0
  41. knowflow-0.1.0/setup.cfg +4 -0
  42. knowflow-0.1.0/setup.py +32 -0
  43. knowflow-0.1.0/tests/test_cli.py +72 -0
  44. knowflow-0.1.0/tests/test_knowledge_local.py +76 -0
  45. knowflow-0.1.0/tests/test_markdown_export.py +117 -0
  46. knowflow-0.1.0/tests/test_pipeline.py +128 -0
  47. knowflow-0.1.0/tests/test_registry.py +88 -0
  48. knowflow-0.1.0/tests/test_storage_base.py +52 -0
  49. knowflow-0.1.0/tests/test_storage_git.py +81 -0
  50. knowflow-0.1.0/tests/test_storage_local.py +126 -0
knowflow-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 KnowFlow Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,3 @@
1
+ include knowflow/templates/*/plugin.yaml
2
+ include README.md
3
+ include LICENSE
@@ -0,0 +1,264 @@
1
+ Metadata-Version: 2.4
2
+ Name: knowflow
3
+ Version: 0.1.0
4
+ Summary: Agent Knowledge Pipeline — storage-agnostic, KB-agnostic, plug-and-play pipeline that turns raw agent JSON into versioned, human-readable docs
5
+ Author: qypvip
6
+ Author-email: qypvip <yanpeng898@gmail.com>
7
+ License: MIT
8
+ Project-URL: Homepage, https://github.com/qypvip/knowflow
9
+ Project-URL: Repository, https://github.com/qypvip/knowflow
10
+ Project-URL: Issues, https://github.com/qypvip/knowflow/issues
11
+ Project-URL: Changelog, https://github.com/qypvip/knowflow/commits/main
12
+ Keywords: agent,ai-agent,knowledge-base,pipeline,llm,markdown,obsidian,automation,data-pipeline,etl
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.8
19
+ Classifier: Programming Language :: Python :: 3.9
20
+ Classifier: Programming Language :: Python :: 3.10
21
+ Classifier: Programming Language :: Python :: 3.11
22
+ Classifier: Programming Language :: Python :: 3.12
23
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
24
+ Classifier: Topic :: Text Processing :: Markup :: Markdown
25
+ Classifier: Typing :: Typed
26
+ Requires-Python: >=3.8
27
+ Description-Content-Type: text/markdown
28
+ License-File: LICENSE
29
+ Requires-Dist: pyyaml>=5.1
30
+ Provides-Extra: s3
31
+ Requires-Dist: boto3; extra == "s3"
32
+ Provides-Extra: notion
33
+ Requires-Dist: notion-client; extra == "notion"
34
+ Provides-Extra: ima
35
+ Requires-Dist: requests; extra == "ima"
36
+ Provides-Extra: webdav
37
+ Requires-Dist: requests; extra == "webdav"
38
+ Provides-Extra: all
39
+ Requires-Dist: boto3; extra == "all"
40
+ Requires-Dist: notion-client; extra == "all"
41
+ Requires-Dist: requests; extra == "all"
42
+ Dynamic: author
43
+ Dynamic: license-file
44
+ Dynamic: requires-python
45
+
46
+ # KnowFlow 🧠
47
+
48
+ **Agent Knowledge Pipeline** — 存储无关、知识库无关、即装即用。
49
+
50
+ 让 AI Agent 产出的数据自动走完:**写入 → 版本控制 → 多端同步 → 人类可读** 的全流程。
51
+
52
+ ![CI](https://github.com/qypvip/knowflow/actions/workflows/ci.yml/badge.svg)
53
+ [![PyPI](https://img.shields.io/pypi/v/knowflow.svg)](https://pypi.org/project/knowflow/)
54
+ [![Python](https://img.shields.io/pypi/pyversions/knowflow.svg)](https://pypi.org/project/knowflow/)
55
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
56
+
57
+ ```bash
58
+ pip install knowflow
59
+
60
+ # 从模板创建新项目
61
+ knowflow init football-prediction --dir my-football-bot
62
+ cd my-football-bot
63
+
64
+ # Agent写入数据 → 自动转 Markdown 文档
65
+ echo '{"match": "巴西vs阿根廷", "prediction": "巴西胜"}' > football/data/prediction.json
66
+ knowflow run
67
+
68
+ # 查看报告
69
+ cat output/football/prediction.md
70
+ ```
71
+
72
+ ## 🤔 这解决什么问题
73
+
74
+ 如果你用 AI Agent 干活,大概率遇到过这三件事:
75
+
76
+ 1. **数据散落** —— Agent 每跑一次就吐几个 JSON,几十次之后你根本找不到“上周三那次分析结果在哪”。
77
+ 2. **机器看得懂,人看不懂** —— JSON 一行行挤在一起,想回顾得自己拼。
78
+ 3. **越用越乱** —— 数据只增不减,几个月后目录里几千个文件,不敢删也不知道删哪个。
79
+
80
+ KnowFlow 干的就是这三件:**Agent 只管往固定目录写 JSON,剩下的(转成人类可读的 Markdown、
81
+ 自动分热/温/冷三层归档、生成索引、Git 记录每次变更)全交给它。**
82
+
83
+ 一句话:**Agent 负责产出,KnowFlow 负责让它留下来还有用。**
84
+
85
+ ## ✨ 特性
86
+
87
+ | 特性 | 说明 | 状态 |
88
+ |------|------|------|
89
+ | 🔌 **存储无关** | Git / 本地 / S3 / 夸克网盘 / WebDAV | ✅ 已实现 |
90
+ | 📚 **知识库无关** | 本地目录 / Obsidian | ✅ 已实现 |
91
+ | 📦 **模板系统** | 足球预测、股票分析、日记、Wiki 等 **7 个** | ✅ 已实现 |
92
+ | 🗄️ **自动归档** | 热→温→冷三层,数据不会无限膨胀 | ✅ 已实现 |
93
+ | 🔄 **版本控制** | Git 后端自动记录每次变更 | ✅ 已实现 |
94
+ | 🧪 **测试** | 68 个单元测试 + GitHub Actions | ✅ 已实现 |
95
+ | 🔓 **开源** | MIT 协议,可商用可二次开发 | ✅ |
96
+
97
+ > 仅依赖 `pyyaml`(非"零依赖");Notion / IMA / MkDocs 后端**尚未实现**,欢迎 PR。
98
+
99
+ ## 🚀 安装
100
+
101
+ ```bash
102
+ pip install knowflow
103
+
104
+ # 可选后端
105
+ pip install "knowflow[s3]" # S3 / MinIO / R2
106
+ pip install "knowflow[all]" # 全部后端
107
+ ```
108
+
109
+ 从源码安装(开发用):
110
+
111
+ ```bash
112
+ git clone https://github.com/qypvip/knowflow.git
113
+ cd knowflow
114
+ pip install -e .
115
+ ```
116
+
117
+ 国内网络拉不动 GitHub 时,可用镜像前缀:
118
+
119
+ ```bash
120
+ git clone https://ghproxy.net/https://github.com/qypvip/knowflow.git
121
+ # 或从 Gitee 克隆
122
+ git clone git@gitee.com:qypvip/knowflow.git
123
+ ```
124
+
125
+ ## ⚡ 快速开始
126
+
127
+ ```bash
128
+ # 查看可用模板
129
+ knowflow list
130
+
131
+ # 初始化项目
132
+ knowflow init daily-journal --dir my-diary
133
+ cd my-diary
134
+
135
+ # 写入一些数据
136
+ mkdir -p diary/data/entries
137
+ cat > diary/data/entries/2026-10-02.json << 'EOF'
138
+ {
139
+ "date": "2026-10-02",
140
+ "title": "今天学习了 KnowFlow",
141
+ "mood": "开心",
142
+ "notes": "终于有了一个统一的知识管理工具"
143
+ }
144
+ EOF
145
+
146
+ # 运行管道(JSON → Markdown → 索引 → 归档)
147
+ knowflow run
148
+
149
+ # 查看输出
150
+ cat output/diary/2026-10-02.md
151
+ ```
152
+
153
+ ## 🧪 开发与测试
154
+
155
+ ```bash
156
+ pip install -e . pytest
157
+ pytest -q # 68 passed
158
+ python -m knowflow list
159
+ ```
160
+
161
+ CI 在 Python 3.9 / 3.11 / 3.12 上跑全量测试,另有一个"零额外依赖"冒烟任务
162
+ 验证核心模块在只装 `pyyaml` 时可 import、CLI 可用。
163
+
164
+ ## 📦 模板
165
+
166
+ | 模板 | 命令 | 适用场景 |
167
+ |------|------|---------|
168
+ | ⚽ football-prediction | `knowflow init football-prediction` | 比赛预测+复盘闭环 |
169
+ | 📈 stock-analysis | `knowflow init stock-analysis` | 多策略股票分析 |
170
+ | 🏆 worldcup-tracker | `knowflow init worldcup-tracker` | 赛事名单追踪 |
171
+ | 📝 daily-journal | `knowflow init daily-journal` | 个人日记+归档 |
172
+ | 📚 project-wiki | `knowflow init project-wiki` | 项目文档自动化 |
173
+ | 🌐 web-monitor | `knowflow init web-monitor` | 网页内容监控 |
174
+ | 🔬 research-notes | `knowflow init research-notes` | 学术笔记管理 |
175
+
176
+ ## 🔌 存储后端
177
+
178
+ | 后端 | 类 | 额外依赖 | 适用场景 |
179
+ |------|----|---------|---------|
180
+ | 🔄 `git`(默认) | `GitStorage` | git CLI | 本地 + 版本历史 |
181
+ | 📁 `local` | `LocalStorage` | 无 | 最简,无版本 |
182
+ | ☁️ `s3` | `S3Storage` | boto3 | AWS / MinIO / R2 |
183
+ | 🅰️ `quark` | `QuarkStorage` | kuake_cli | 夸克网盘 |
184
+ | 🌐 `webdav` | `WebDAVStorage` | requests | NextCloud / NAS |
185
+
186
+ ```bash
187
+ knowflow init football-prediction --storage git
188
+ knowflow init football-prediction --storage local
189
+ ```
190
+
191
+ ## 📚 知识库后端
192
+
193
+ | 后端 | 类 |
194
+ |------|----|
195
+ | 📁 `local`(默认) | `LocalKB` |
196
+ | 📝 `obsidian` | `ObsidianKB` |
197
+
198
+ ```bash
199
+ knowflow init football-prediction --kb obsidian
200
+ ```
201
+
202
+ Python 侧用法:
203
+
204
+ ```python
205
+ from knowflow.adapters.storage import create_storage
206
+ from knowflow.adapters.knowledge import create_knowledge # create_kb 为别名
207
+
208
+ store = create_storage("git", path="~/my-data") # 扁平参数
209
+ store = create_storage("git", config={"path": "~/my-data"}) # 或显式 config
210
+
211
+ kb = create_knowledge("local", path="~/my-output")
212
+ ```
213
+
214
+ ## 🧪 命令行
215
+
216
+ ```bash
217
+ knowflow list # 列出所有模板
218
+ knowflow init <name> # 从模板创建项目
219
+ knowflow run # 运行数据管道
220
+ knowflow status # 查看仓库状态
221
+ knowflow commit "msg" # 手动提交
222
+ knowflow archive # 手动归档旧数据
223
+ knowflow version # 查看版本
224
+ ```
225
+
226
+ ## 🏗️ 架构
227
+
228
+ ```
229
+ Agent写入数据
230
+ ↓
231
+ StorageAdapter ← 可插拔(Git/本地/S3/夸克/WebDAV)
232
+ ↓
233
+ Pipeline (Markdown导出→归档→索引)
234
+ ↓
235
+ KnowledgeAdapter ← 可插拔(本地/Obsidian)
236
+ ```
237
+
238
+ ### 加一个存储后端(两步)
239
+
240
+ ```python
241
+ from knowflow.core.storage import StorageAdapter
242
+
243
+ class MyStorage(StorageAdapter):
244
+ def read(self, path): ...
245
+ def read_binary(self, path): ...
246
+ def write(self, path, content): ...
247
+ def write_binary(self, path, content): ...
248
+ def delete(self, path): ...
249
+ def exists(self, path): ...
250
+ def list(self, prefix=""): ...
251
+ def walk(self, prefix=""): ...
252
+
253
+ from knowflow.adapters.storage import register
254
+ register("mystorage", MyStorage) # 完成
255
+ ```
256
+
257
+ ## 📄 协议
258
+
259
+ MIT
260
+
261
+ ## 🔗 镜像
262
+
263
+ - GitHub: <https://github.com/qypvip/knowflow>
264
+ - Gitee: <https://gitee.com/qypvip/knowflow>
@@ -0,0 +1,219 @@
1
+ # KnowFlow 🧠
2
+
3
+ **Agent Knowledge Pipeline** — 存储无关、知识库无关、即装即用。
4
+
5
+ 让 AI Agent 产出的数据自动走完:**写入 → 版本控制 → 多端同步 → 人类可读** 的全流程。
6
+
7
+ ![CI](https://github.com/qypvip/knowflow/actions/workflows/ci.yml/badge.svg)
8
+ [![PyPI](https://img.shields.io/pypi/v/knowflow.svg)](https://pypi.org/project/knowflow/)
9
+ [![Python](https://img.shields.io/pypi/pyversions/knowflow.svg)](https://pypi.org/project/knowflow/)
10
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
11
+
12
+ ```bash
13
+ pip install knowflow
14
+
15
+ # 从模板创建新项目
16
+ knowflow init football-prediction --dir my-football-bot
17
+ cd my-football-bot
18
+
19
+ # Agent写入数据 → 自动转 Markdown 文档
20
+ echo '{"match": "巴西vs阿根廷", "prediction": "巴西胜"}' > football/data/prediction.json
21
+ knowflow run
22
+
23
+ # 查看报告
24
+ cat output/football/prediction.md
25
+ ```
26
+
27
+ ## 🤔 这解决什么问题
28
+
29
+ 如果你用 AI Agent 干活,大概率遇到过这三件事:
30
+
31
+ 1. **数据散落** —— Agent 每跑一次就吐几个 JSON,几十次之后你根本找不到“上周三那次分析结果在哪”。
32
+ 2. **机器看得懂,人看不懂** —— JSON 一行行挤在一起,想回顾得自己拼。
33
+ 3. **越用越乱** —— 数据只增不减,几个月后目录里几千个文件,不敢删也不知道删哪个。
34
+
35
+ KnowFlow 干的就是这三件:**Agent 只管往固定目录写 JSON,剩下的(转成人类可读的 Markdown、
36
+ 自动分热/温/冷三层归档、生成索引、Git 记录每次变更)全交给它。**
37
+
38
+ 一句话:**Agent 负责产出,KnowFlow 负责让它留下来还有用。**
39
+
40
+ ## ✨ 特性
41
+
42
+ | 特性 | 说明 | 状态 |
43
+ |------|------|------|
44
+ | 🔌 **存储无关** | Git / 本地 / S3 / 夸克网盘 / WebDAV | ✅ 已实现 |
45
+ | 📚 **知识库无关** | 本地目录 / Obsidian | ✅ 已实现 |
46
+ | 📦 **模板系统** | 足球预测、股票分析、日记、Wiki 等 **7 个** | ✅ 已实现 |
47
+ | 🗄️ **自动归档** | 热→温→冷三层,数据不会无限膨胀 | ✅ 已实现 |
48
+ | 🔄 **版本控制** | Git 后端自动记录每次变更 | ✅ 已实现 |
49
+ | 🧪 **测试** | 68 个单元测试 + GitHub Actions | ✅ 已实现 |
50
+ | 🔓 **开源** | MIT 协议,可商用可二次开发 | ✅ |
51
+
52
+ > 仅依赖 `pyyaml`(非"零依赖");Notion / IMA / MkDocs 后端**尚未实现**,欢迎 PR。
53
+
54
+ ## 🚀 安装
55
+
56
+ ```bash
57
+ pip install knowflow
58
+
59
+ # 可选后端
60
+ pip install "knowflow[s3]" # S3 / MinIO / R2
61
+ pip install "knowflow[all]" # 全部后端
62
+ ```
63
+
64
+ 从源码安装(开发用):
65
+
66
+ ```bash
67
+ git clone https://github.com/qypvip/knowflow.git
68
+ cd knowflow
69
+ pip install -e .
70
+ ```
71
+
72
+ 国内网络拉不动 GitHub 时,可用镜像前缀:
73
+
74
+ ```bash
75
+ git clone https://ghproxy.net/https://github.com/qypvip/knowflow.git
76
+ # 或从 Gitee 克隆
77
+ git clone git@gitee.com:qypvip/knowflow.git
78
+ ```
79
+
80
+ ## ⚡ 快速开始
81
+
82
+ ```bash
83
+ # 查看可用模板
84
+ knowflow list
85
+
86
+ # 初始化项目
87
+ knowflow init daily-journal --dir my-diary
88
+ cd my-diary
89
+
90
+ # 写入一些数据
91
+ mkdir -p diary/data/entries
92
+ cat > diary/data/entries/2026-10-02.json << 'EOF'
93
+ {
94
+ "date": "2026-10-02",
95
+ "title": "今天学习了 KnowFlow",
96
+ "mood": "开心",
97
+ "notes": "终于有了一个统一的知识管理工具"
98
+ }
99
+ EOF
100
+
101
+ # 运行管道(JSON → Markdown → 索引 → 归档)
102
+ knowflow run
103
+
104
+ # 查看输出
105
+ cat output/diary/2026-10-02.md
106
+ ```
107
+
108
+ ## 🧪 开发与测试
109
+
110
+ ```bash
111
+ pip install -e . pytest
112
+ pytest -q # 68 passed
113
+ python -m knowflow list
114
+ ```
115
+
116
+ CI 在 Python 3.9 / 3.11 / 3.12 上跑全量测试,另有一个"零额外依赖"冒烟任务
117
+ 验证核心模块在只装 `pyyaml` 时可 import、CLI 可用。
118
+
119
+ ## 📦 模板
120
+
121
+ | 模板 | 命令 | 适用场景 |
122
+ |------|------|---------|
123
+ | ⚽ football-prediction | `knowflow init football-prediction` | 比赛预测+复盘闭环 |
124
+ | 📈 stock-analysis | `knowflow init stock-analysis` | 多策略股票分析 |
125
+ | 🏆 worldcup-tracker | `knowflow init worldcup-tracker` | 赛事名单追踪 |
126
+ | 📝 daily-journal | `knowflow init daily-journal` | 个人日记+归档 |
127
+ | 📚 project-wiki | `knowflow init project-wiki` | 项目文档自动化 |
128
+ | 🌐 web-monitor | `knowflow init web-monitor` | 网页内容监控 |
129
+ | 🔬 research-notes | `knowflow init research-notes` | 学术笔记管理 |
130
+
131
+ ## 🔌 存储后端
132
+
133
+ | 后端 | 类 | 额外依赖 | 适用场景 |
134
+ |------|----|---------|---------|
135
+ | 🔄 `git`(默认) | `GitStorage` | git CLI | 本地 + 版本历史 |
136
+ | 📁 `local` | `LocalStorage` | 无 | 最简,无版本 |
137
+ | ☁️ `s3` | `S3Storage` | boto3 | AWS / MinIO / R2 |
138
+ | 🅰️ `quark` | `QuarkStorage` | kuake_cli | 夸克网盘 |
139
+ | 🌐 `webdav` | `WebDAVStorage` | requests | NextCloud / NAS |
140
+
141
+ ```bash
142
+ knowflow init football-prediction --storage git
143
+ knowflow init football-prediction --storage local
144
+ ```
145
+
146
+ ## 📚 知识库后端
147
+
148
+ | 后端 | 类 |
149
+ |------|----|
150
+ | 📁 `local`(默认) | `LocalKB` |
151
+ | 📝 `obsidian` | `ObsidianKB` |
152
+
153
+ ```bash
154
+ knowflow init football-prediction --kb obsidian
155
+ ```
156
+
157
+ Python 侧用法:
158
+
159
+ ```python
160
+ from knowflow.adapters.storage import create_storage
161
+ from knowflow.adapters.knowledge import create_knowledge # create_kb 为别名
162
+
163
+ store = create_storage("git", path="~/my-data") # 扁平参数
164
+ store = create_storage("git", config={"path": "~/my-data"}) # 或显式 config
165
+
166
+ kb = create_knowledge("local", path="~/my-output")
167
+ ```
168
+
169
+ ## 🧪 命令行
170
+
171
+ ```bash
172
+ knowflow list # 列出所有模板
173
+ knowflow init <name> # 从模板创建项目
174
+ knowflow run # 运行数据管道
175
+ knowflow status # 查看仓库状态
176
+ knowflow commit "msg" # 手动提交
177
+ knowflow archive # 手动归档旧数据
178
+ knowflow version # 查看版本
179
+ ```
180
+
181
+ ## 🏗️ 架构
182
+
183
+ ```
184
+ Agent写入数据
185
+ ↓
186
+ StorageAdapter ← 可插拔(Git/本地/S3/夸克/WebDAV)
187
+ ↓
188
+ Pipeline (Markdown导出→归档→索引)
189
+ ↓
190
+ KnowledgeAdapter ← 可插拔(本地/Obsidian)
191
+ ```
192
+
193
+ ### 加一个存储后端(两步)
194
+
195
+ ```python
196
+ from knowflow.core.storage import StorageAdapter
197
+
198
+ class MyStorage(StorageAdapter):
199
+ def read(self, path): ...
200
+ def read_binary(self, path): ...
201
+ def write(self, path, content): ...
202
+ def write_binary(self, path, content): ...
203
+ def delete(self, path): ...
204
+ def exists(self, path): ...
205
+ def list(self, prefix=""): ...
206
+ def walk(self, prefix=""): ...
207
+
208
+ from knowflow.adapters.storage import register
209
+ register("mystorage", MyStorage) # 完成
210
+ ```
211
+
212
+ ## 📄 协议
213
+
214
+ MIT
215
+
216
+ ## 🔗 镜像
217
+
218
+ - GitHub: <https://github.com/qypvip/knowflow>
219
+ - Gitee: <https://gitee.com/qypvip/knowflow>
@@ -0,0 +1,4 @@
1
+ # KnowFlow
2
+ # Agent Knowledge Pipeline — Storage-agnostic, KB-agnostic, plug-and-play
3
+
4
+ __version__ = "0.1.0"
@@ -0,0 +1,3 @@
1
+ """knowflow.__main__ — Entry point for `python3 -m knowflow`"""
2
+ from knowflow.cli import main
3
+ main()
@@ -0,0 +1,42 @@
1
+ """knowflow/adapters/knowledge/__init__.py — Knowledge adapter registry"""
2
+ from typing import Optional
3
+
4
+ from knowflow.core.knowledge import KnowledgeAdapter, KnowledgePage
5
+
6
+ _REGISTRY = {}
7
+
8
+ def register(name: str, cls):
9
+ _REGISTRY[name.lower()] = cls
10
+
11
+ def create_knowledge(name: str, config: Optional[dict] = None, **kwargs) -> KnowledgeAdapter:
12
+ """Factory: create a knowledge-base adapter by name.
13
+
14
+ 两种调用方式都支持:
15
+ create_knowledge("obsidian", path="~/my-vault") # 扁平参数
16
+ create_knowledge("obsidian", config={"path": "..."}) # 显式 config 字典
17
+ """
18
+ name = name.lower()
19
+ if name not in _REGISTRY:
20
+ available = list(_REGISTRY.keys())
21
+ raise ValueError(
22
+ f"Unknown knowledge base: '{name}'. Available: {available}"
23
+ )
24
+ if config is None:
25
+ config = dict(kwargs) if kwargs else None
26
+ elif kwargs:
27
+ config = {**config, **kwargs}
28
+ return _REGISTRY[name](config)
29
+
30
+
31
+ # 别名:core/knowledge.py 的文档里写的是 create_kb,保持一致(曾导致 ImportError)
32
+ create_kb = create_knowledge
33
+
34
+ def list_backends() -> list[str]:
35
+ return sorted(_REGISTRY.keys())
36
+
37
+ # Built-in adapters
38
+ from . import local as _local
39
+ register("local", _local.LocalKB)
40
+
41
+ from . import obsidian as _obsidian
42
+ register("obsidian", _obsidian.ObsidianKB)
@@ -0,0 +1,43 @@
1
+ """
2
+ knowflow/adapters/knowledge/local.py — Local directory KB
3
+ Simple markdown files in a directory.
4
+ """
5
+ from pathlib import Path
6
+ from knowflow.core.knowledge import KnowledgeAdapter, KnowledgePage, KnowledgeError
7
+
8
+
9
+ class LocalKB(KnowledgeAdapter):
10
+ """Local markdown directory knowledge base"""
11
+
12
+ def __init__(self, config: dict = None):
13
+ super().__init__(config)
14
+ path = config.get("path", "~/knowflow-output") if config else "~/knowflow-output"
15
+ self.root = Path(path).expanduser().resolve()
16
+ self.root.mkdir(parents=True, exist_ok=True)
17
+
18
+ def name(self) -> str:
19
+ return f"Local ({self.root})"
20
+
21
+ def sync(self, pages: list[KnowledgePage]) -> dict:
22
+ synced = 0
23
+ errors = []
24
+ for page in pages:
25
+ try:
26
+ target = self.root / page.path
27
+ target.parent.mkdir(parents=True, exist_ok=True)
28
+ target.write_text(page.content, encoding="utf-8")
29
+ synced += 1
30
+ except Exception as e:
31
+ errors.append(f"{page.path}: {e}")
32
+ return {"synced": synced, "skipped": 0, "errors": errors}
33
+
34
+ def search(self, query: str, limit: int = 10) -> list[KnowledgePage]:
35
+ results = []
36
+ for md_file in sorted(self.root.rglob("*.md"))[:limit]:
37
+ if query.lower() in md_file.read_text(encoding="utf-8").lower():
38
+ results.append(KnowledgePage(
39
+ title=md_file.stem,
40
+ content=md_file.read_text(encoding="utf-8"),
41
+ path=str(md_file.relative_to(self.root)),
42
+ ))
43
+ return results
@@ -0,0 +1,64 @@
1
+ """
2
+ knowflow/adapters/knowledge/obsidian.py — Obsidian vault KB
3
+ Syncs markdown pages to an Obsidian-compatible vault directory.
4
+ """
5
+ from pathlib import Path
6
+ from knowflow.core.knowledge import KnowledgeAdapter, KnowledgePage, KnowledgeError
7
+
8
+
9
+ class ObsidianKB(KnowledgeAdapter):
10
+ """Obsidian vault knowledge base"""
11
+
12
+ def __init__(self, config: dict = None):
13
+ super().__init__(config)
14
+ path = config.get("path", "~/obsidian-vault") if config else "~/obsidian-vault"
15
+ self.root = Path(path).expanduser().resolve()
16
+ self.root.mkdir(parents=True, exist_ok=True)
17
+ self._ensure_vault()
18
+
19
+ def _ensure_vault(self):
20
+ """Ensure .obsidian/ config exists for vault detection"""
21
+ obsidian_dir = self.root / ".obsidian"
22
+ obsidian_dir.mkdir(exist_ok=True)
23
+ app_file = obsidian_dir / "app.json"
24
+ if not app_file.exists():
25
+ import json
26
+ app_file.write_text(json.dumps({"promptDelete": False}, indent=2))
27
+
28
+ def name(self) -> str:
29
+ return f"Obsidian ({self.root})"
30
+
31
+ def sync(self, pages: list[KnowledgePage]) -> dict:
32
+ synced = 0
33
+ errors = []
34
+ for page in pages:
35
+ try:
36
+ target = self.root / page.path
37
+ target.parent.mkdir(parents=True, exist_ok=True)
38
+ # Add Obsidian frontmatter tags if provided
39
+ content = page.content
40
+ if page.tags:
41
+ tags_line = "\n".join(f" - {t}" for t in page.tags)
42
+ frontmatter = f"---\ntags:\n{tags_line}\n---\n\n"
43
+ if not content.startswith("---"):
44
+ content = frontmatter + content
45
+ target.write_text(content, encoding="utf-8")
46
+ synced += 1
47
+ except Exception as e:
48
+ errors.append(f"{page.path}: {e}")
49
+ return {"synced": synced, "skipped": 0, "errors": errors}
50
+
51
+ def search(self, query: str, limit: int = 10) -> list[KnowledgePage]:
52
+ results = []
53
+ for md_file in sorted(self.root.rglob("*.md"))[:limit]:
54
+ try:
55
+ content = md_file.read_text(encoding="utf-8")
56
+ if query.lower() in content.lower():
57
+ results.append(KnowledgePage(
58
+ title=md_file.stem,
59
+ content=content,
60
+ path=str(md_file.relative_to(self.root)),
61
+ ))
62
+ except Exception:
63
+ continue
64
+ return results