cognitive-modules 0.3.0__py3-none-any.whl → 0.5.0__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.
@@ -1,418 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: cognitive-modules
3
- Version: 0.3.0
4
- Summary: Structured LLM task runner with schema validation, confidence scoring, and subagent orchestration
5
- Author: ziel-io
6
- License: MIT
7
- Project-URL: Homepage, https://github.com/ziel-io/cognitive-modules
8
- Project-URL: Documentation, https://github.com/ziel-io/cognitive-modules#readme
9
- Project-URL: Repository, https://github.com/ziel-io/cognitive-modules
10
- Project-URL: Issues, https://github.com/ziel-io/cognitive-modules/issues
11
- Keywords: llm,cognitive,modules,ai,cli,schema,validation,prompt,agent,subagent
12
- Classifier: Development Status :: 4 - Beta
13
- Classifier: Intended Audience :: Developers
14
- Classifier: License :: OSI Approved :: MIT License
15
- Classifier: Operating System :: OS Independent
16
- Classifier: Programming Language :: Python :: 3
17
- Classifier: Programming Language :: Python :: 3.9
18
- Classifier: Programming Language :: Python :: 3.10
19
- Classifier: Programming Language :: Python :: 3.11
20
- Classifier: Programming Language :: Python :: 3.12
21
- Classifier: Topic :: Software Development :: Libraries :: Python Modules
22
- Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
23
- Requires-Python: >=3.9
24
- Description-Content-Type: text/markdown
25
- License-File: LICENSE
26
- Requires-Dist: jsonschema>=4.17.0
27
- Requires-Dist: pyyaml>=6.0
28
- Requires-Dist: typer>=0.9.0
29
- Requires-Dist: rich>=13.0.0
30
- Provides-Extra: openai
31
- Requires-Dist: openai>=1.0.0; extra == "openai"
32
- Provides-Extra: anthropic
33
- Requires-Dist: anthropic>=0.18.0; extra == "anthropic"
34
- Provides-Extra: ollama
35
- Requires-Dist: requests>=2.28.0; extra == "ollama"
36
- Provides-Extra: minimax
37
- Requires-Dist: openai>=1.0.0; extra == "minimax"
38
- Provides-Extra: all
39
- Requires-Dist: openai>=1.0.0; extra == "all"
40
- Requires-Dist: anthropic>=0.18.0; extra == "all"
41
- Requires-Dist: requests>=2.28.0; extra == "all"
42
- Provides-Extra: dev
43
- Requires-Dist: pytest>=7.0.0; extra == "dev"
44
- Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
45
- Requires-Dist: build>=1.0.0; extra == "dev"
46
- Requires-Dist: twine>=4.0.0; extra == "dev"
47
- Requires-Dist: ruff>=0.1.0; extra == "dev"
48
- Provides-Extra: docs
49
- Requires-Dist: mkdocs-material>=9.0.0; extra == "docs"
50
- Requires-Dist: pymdown-extensions>=10.0.0; extra == "docs"
51
- Dynamic: license-file
52
-
53
- # Cognitive Modules
54
-
55
- [![CI](https://github.com/ziel-io/cognitive-modules/actions/workflows/ci.yml/badge.svg)](https://github.com/ziel-io/cognitive-modules/actions/workflows/ci.yml)
56
- [![PyPI version](https://badge.fury.io/py/cognitive-modules.svg)](https://pypi.org/project/cognitive-modules/)
57
- [![Python 3.9+](https://img.shields.io/badge/python-3.9+-blue.svg)](https://www.python.org/downloads/)
58
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
59
-
60
- > 可验证的结构化 AI 任务规范
61
-
62
- Cognitive Modules 是一种 AI 任务定义规范,专为需要**强约束、可验证、可审计**的生成任务设计。
63
-
64
- ## 特性
65
-
66
- - **强类型契约** - JSON Schema 双向验证输入输出
67
- - **可解释输出** - 强制输出 `confidence` + `rationale`
68
- - **子代理编排** - `@call:module` 支持模块间调用
69
- - **参数传递** - `$ARGUMENTS` 运行时替换
70
- - **多 LLM 支持** - OpenAI / Anthropic / MiniMax / Ollama
71
- - **公共注册表** - `cog install registry:module-name`
72
-
73
- ## 安装
74
-
75
- ```bash
76
- # 基础安装
77
- pip install cognitive-modules
78
-
79
- # 带 LLM 支持
80
- pip install cognitive-modules[openai] # OpenAI
81
- pip install cognitive-modules[anthropic] # Claude
82
- pip install cognitive-modules[all] # 全部
83
- ```
84
-
85
- ## 快速开始
86
-
87
- ```bash
88
- # 配置 LLM
89
- export LLM_PROVIDER=openai
90
- export OPENAI_API_KEY=sk-xxx
91
-
92
- # 或使用 MiniMax
93
- export LLM_PROVIDER=minimax
94
- export MINIMAX_API_KEY=sk-xxx
95
-
96
- # 运行代码审查
97
- cog run code-reviewer --args "def login(u,p): return db.query(f'SELECT * FROM users WHERE name={u}')" --pretty
98
-
99
- # 运行任务排序
100
- cog run task-prioritizer --args "修复bug(紧急), 写文档, 优化性能" --pretty
101
-
102
- # 运行 API 设计
103
- cog run api-designer --args "用户系统 CRUD API" --pretty
104
- ```
105
-
106
- ## 与 Skills 对比
107
-
108
- | | Skills | Cognitive Modules |
109
- |---|--------|------------------|
110
- | 定位 | 轻量指令扩展 | 可验证的结构化任务 |
111
- | 输入校验 | ❌ | ✅ JSON Schema |
112
- | 输出校验 | ❌ | ✅ JSON Schema |
113
- | 置信度 | ❌ | ✅ 必须 0-1 |
114
- | 推理过程 | ❌ | ✅ 必须 rationale |
115
- | 参数传递 | ✅ $ARGUMENTS | ✅ $ARGUMENTS |
116
- | 子代理 | ✅ context: fork | ✅ @call + context |
117
- | 验证工具 | ❌ | ✅ cog validate |
118
- | 注册表 | ❌ | ✅ cog install |
119
-
120
- ## CLI 命令
121
-
122
- ```bash
123
- # 模块管理
124
- cog list # 列出已安装模块
125
- cog info <module> # 查看模块详情
126
- cog validate <module> # 验证模块结构
127
-
128
- # 运行模块
129
- cog run <module> input.json -o output.json --pretty
130
- cog run <module> --args "需求描述" --pretty
131
- cog run <module> --args "需求" --subagent # 启用子代理
132
-
133
- # 创建模块
134
- cog init <name> -d "描述"
135
-
136
- # 安装/卸载
137
- cog install github:user/repo/path
138
- cog install registry:module-name
139
- cog uninstall <module>
140
-
141
- # 注册表
142
- cog registry # 查看公共模块
143
- cog search <query> # 搜索模块
144
-
145
- # 环境检查
146
- cog doctor
147
- ```
148
-
149
- ## 内置模块
150
-
151
- | 模块 | 功能 | 示例 |
152
- |------|------|------|
153
- | `code-reviewer` | 代码审查 | `cog run code-reviewer --args "你的代码"` |
154
- | `code-simplifier` | 代码简化 | `cog run code-simplifier --args "复杂代码"` |
155
- | `task-prioritizer` | 任务优先级排序 | `cog run task-prioritizer --args "任务1,任务2"` |
156
- | `api-designer` | REST API 设计 | `cog run api-designer --args "订单系统"` |
157
- | `ui-spec-generator` | UI 规范生成 | `cog run ui-spec-generator --args "电商首页"` |
158
- | `product-analyzer` | 产品分析(子代理示例) | `cog run product-analyzer --args "健康产品" -s` |
159
-
160
- ## 模块格式
161
-
162
- ### 新格式(推荐)
163
-
164
- ```
165
- my-module/
166
- ├── MODULE.md # 元数据 + 指令
167
- ├── schema.json # 输入输出 Schema
168
- └── examples/
169
- ├── input.json
170
- └── output.json
171
- ```
172
-
173
- ### MODULE.md
174
-
175
- ```yaml
176
- ---
177
- name: my-module
178
- version: 1.0.0
179
- responsibility: 一句话描述
180
-
181
- excludes:
182
- - 不做的事情
183
-
184
- constraints:
185
- no_network: true
186
- no_inventing_data: true
187
- require_confidence: true
188
- require_rationale: true
189
-
190
- context: fork # 可选:隔离执行
191
- ---
192
-
193
- # 指令
194
-
195
- 根据用户需求 $ARGUMENTS 执行任务。
196
-
197
- 可以调用其他模块:
198
- @call:other-module($ARGUMENTS)
199
- ```
200
-
201
- ## 在 AI 工具中使用
202
-
203
- ### Cursor / Codex CLI
204
-
205
- 在项目根目录创建 `AGENTS.md`:
206
-
207
- ```markdown
208
- ## 代码审查
209
-
210
- 当需要审查代码时:
211
- 1. 读取 `~/.cognitive/modules/code-reviewer/MODULE.md`
212
- 2. 按 schema.json 格式输出
213
- 3. 包含 issues、summary、rationale、confidence
214
- ```
215
-
216
- ### 直接对话
217
-
218
- ```
219
- 读取 ~/.cognitive/modules/code-reviewer/MODULE.md,
220
- 审查这段代码:def login(u,p): ...
221
- ```
222
-
223
- ## 配置 LLM
224
-
225
- ```bash
226
- # OpenAI
227
- export LLM_PROVIDER=openai
228
- export OPENAI_API_KEY=sk-xxx
229
-
230
- # Anthropic Claude
231
- export LLM_PROVIDER=anthropic
232
- export ANTHROPIC_API_KEY=sk-ant-xxx
233
-
234
- # MiniMax
235
- export LLM_PROVIDER=minimax
236
- export MINIMAX_API_KEY=sk-xxx
237
-
238
- # Ollama(本地)
239
- export LLM_PROVIDER=ollama
240
-
241
- # 检查配置
242
- cog doctor
243
- ```
244
-
245
- ## 创建新模块(完整流程)
246
-
247
- 以 `code-simplifier` 为例:
248
-
249
- ### Step 1: 创建目录结构
250
-
251
- ```bash
252
- mkdir -p cognitive/modules/code-simplifier
253
- ```
254
-
255
- ### Step 2: 编写 MODULE.md
256
-
257
- ```bash
258
- cat > cognitive/modules/code-simplifier/MODULE.md << 'EOF'
259
- ---
260
- name: code-simplifier
261
- version: 1.0.0
262
- responsibility: Simplify complex code while preserving functionality
263
-
264
- excludes:
265
- - Changing the code's behavior
266
- - Adding new features
267
- - Removing functionality
268
-
269
- constraints:
270
- no_network: true
271
- no_side_effects: true
272
- require_confidence: true
273
- require_rationale: true
274
- ---
275
-
276
- # Code Simplifier Module
277
-
278
- You are an expert at refactoring and simplifying code.
279
-
280
- ## Input
281
-
282
- Code to simplify: $ARGUMENTS
283
-
284
- ## Simplification Strategies
285
-
286
- 1. **Remove redundancy** - Eliminate duplicate code
287
- 2. **Improve naming** - Use clear, descriptive names
288
- 3. **Reduce nesting** - Flatten deep conditionals
289
- 4. **Simplify logic** - Use built-in functions
290
-
291
- ## Output Requirements
292
-
293
- Return JSON containing:
294
- - `simplified_code`: The simplified version
295
- - `changes`: List of changes made
296
- - `summary`: Brief description
297
- - `rationale`: Explanation of decisions
298
- - `confidence`: Confidence score [0-1]
299
- EOF
300
- ```
301
-
302
- ### Step 3: 编写 schema.json
303
-
304
- ```bash
305
- cat > cognitive/modules/code-simplifier/schema.json << 'EOF'
306
- {
307
- "$schema": "https://ziel-io.github.io/cognitive-modules/schema/v1.json",
308
- "input": {
309
- "type": "object",
310
- "properties": {
311
- "code": { "type": "string" },
312
- "language": { "type": "string" },
313
- "$ARGUMENTS": { "type": "string" }
314
- }
315
- },
316
- "output": {
317
- "type": "object",
318
- "required": ["simplified_code", "changes", "summary", "rationale", "confidence"],
319
- "properties": {
320
- "simplified_code": { "type": "string" },
321
- "changes": {
322
- "type": "array",
323
- "items": {
324
- "type": "object",
325
- "properties": {
326
- "type": { "type": "string" },
327
- "description": { "type": "string" }
328
- }
329
- }
330
- },
331
- "summary": { "type": "string" },
332
- "rationale": { "type": "string" },
333
- "confidence": { "type": "number", "minimum": 0, "maximum": 1 }
334
- }
335
- }
336
- }
337
- EOF
338
- ```
339
-
340
- ### Step 4: 验证模块
341
-
342
- ```bash
343
- cog validate code-simplifier
344
- cog list # 确认模块出现在列表中
345
- ```
346
-
347
- ### Step 5: 测试运行
348
-
349
- ```bash
350
- cog run code-simplifier --args "def calc(x): if x > 0: if x < 10: return x * 2 else: return x else: return 0" --pretty
351
- ```
352
-
353
- ### Step 6: 添加示例(可选)
354
-
355
- ```bash
356
- mkdir -p cognitive/modules/code-simplifier/examples
357
- # 添加 input.json 和 output.json 作为测试用例
358
- ```
359
-
360
- ### 模块设计要点
361
-
362
- | 要素 | 必须 | 说明 |
363
- |------|------|------|
364
- | `name` | ✅ | 唯一标识符,kebab-case |
365
- | `version` | ✅ | 语义化版本 |
366
- | `responsibility` | ✅ | 一句话描述职责 |
367
- | `excludes` | ✅ | 明确列出不做的事 |
368
- | `$ARGUMENTS` | ✅ | 支持命令行参数 |
369
- | `confidence` | ✅ | 输出必须包含 0-1 置信度 |
370
- | `rationale` | ✅ | 输出必须包含推理过程 |
371
- | `schema.json` | ✅ | 定义输入输出契约 |
372
-
373
- ## 开发
374
-
375
- ```bash
376
- # 克隆
377
- git clone https://github.com/ziel-io/cognitive-modules.git
378
- cd cognitive-modules
379
-
380
- # 安装开发依赖
381
- pip install -e ".[dev]"
382
-
383
- # 运行测试
384
- pytest tests/ -v
385
-
386
- # 创建新模块(使用模板)
387
- cog init my-module -d "模块描述"
388
- cog validate my-module
389
- ```
390
-
391
- ## 项目结构
392
-
393
- ```
394
- cognitive-modules/
395
- ├── src/cognitive/ # CLI 源码
396
- │ ├── cli.py # 命令入口
397
- │ ├── loader.py # 模块加载
398
- │ ├── runner.py # 模块执行
399
- │ ├── subagent.py # 子代理编排
400
- │ ├── validator.py # 模块验证
401
- │ ├── registry.py # 模块安装
402
- │ ├── templates.py # 模块模板
403
- │ └── providers/ # LLM 后端
404
- ├── cognitive/modules/ # 内置模块
405
- ├── tests/ # 单元测试
406
- ├── SPEC.md # 规范文档
407
- ├── INTEGRATION.md # 集成指南
408
- └── cognitive-registry.json # 公共注册表
409
- ```
410
-
411
- ## 文档
412
-
413
- - [SPEC.md](SPEC.md) - 完整规范(含上下文哲学)
414
- - [INTEGRATION.md](INTEGRATION.md) - Agent 工具集成指南
415
-
416
- ## License
417
-
418
- MIT
@@ -1,15 +0,0 @@
1
- cognitive/__init__.py,sha256=uSX5NuOWyW0qtq1bnxbzabZ0OQakAtsjF0MWbjQBvwE,401
2
- cognitive/cli.py,sha256=q0vHCHFmig9gQ85KRyIrX6vrJZFm5nXF_bW5qQRGEPU,14608
3
- cognitive/loader.py,sha256=3_ShEfefOMP2EJjpQ1VGTGio4K_GUWLZMQHa0RgvBwg,8715
4
- cognitive/registry.py,sha256=aBkkpg5PtL_tKDIOXpv6vblB7x_Ax0eVaWgejuQTfCE,8851
5
- cognitive/runner.py,sha256=KFO_pV7YTluYaL98_5bPp_HTNgwsTvlUjgNYlI8mo-w,8467
6
- cognitive/subagent.py,sha256=fb7LWwNF6YcJtC_T1dK0EvzqWMBnav-kiCIpvVohEBw,8142
7
- cognitive/templates.py,sha256=lKC197X9aQIA-npUvVCaplSwvhxjsH_KYVCQtrTZrL4,4712
8
- cognitive/validator.py,sha256=1v1HUHYOlAc2sYCkIq_gnUMMnca0fdtQwr7UMBFpp04,12200
9
- cognitive/providers/__init__.py,sha256=hqhVA1IEXpVtyCAteXhO5yD8a8ikQpVIPEKJVHLtRFY,7492
10
- cognitive_modules-0.3.0.dist-info/licenses/LICENSE,sha256=NXFYUy2hPJdh3NHRxMChTnMiQD9k8zFxkmR7gWefexc,1064
11
- cognitive_modules-0.3.0.dist-info/METADATA,sha256=PcUIJeGz7wr78MHPEdmDRxqKuFLEzX5aEgpMRHfGN-w,11381
12
- cognitive_modules-0.3.0.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
13
- cognitive_modules-0.3.0.dist-info/entry_points.txt,sha256=PKHlfrFmve5K2349ryipySKbOOsKxo_vIq1NNT-iBV0,42
14
- cognitive_modules-0.3.0.dist-info/top_level.txt,sha256=kGIfDucCKylo8cRBtxER_v3DHIea-Sol9x9YSJo1u3Y,10
15
- cognitive_modules-0.3.0.dist-info/RECORD,,
@@ -1,2 +0,0 @@
1
- [console_scripts]
2
- cog = cognitive.cli:app