cognitive-modules 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.
- cognitive_modules-0.1.0/LICENSE +21 -0
- cognitive_modules-0.1.0/PKG-INFO +295 -0
- cognitive_modules-0.1.0/README.md +247 -0
- cognitive_modules-0.1.0/pyproject.toml +95 -0
- cognitive_modules-0.1.0/setup.cfg +4 -0
- cognitive_modules-0.1.0/src/cognitive/__init__.py +12 -0
- cognitive_modules-0.1.0/src/cognitive/cli.py +423 -0
- cognitive_modules-0.1.0/src/cognitive/loader.py +133 -0
- cognitive_modules-0.1.0/src/cognitive/providers/__init__.py +236 -0
- cognitive_modules-0.1.0/src/cognitive/registry.py +276 -0
- cognitive_modules-0.1.0/src/cognitive/runner.py +140 -0
- cognitive_modules-0.1.0/src/cognitive/subagent.py +245 -0
- cognitive_modules-0.1.0/src/cognitive/templates.py +186 -0
- cognitive_modules-0.1.0/src/cognitive/validator.py +302 -0
- cognitive_modules-0.1.0/src/cognitive_modules.egg-info/PKG-INFO +295 -0
- cognitive_modules-0.1.0/src/cognitive_modules.egg-info/SOURCES.txt +24 -0
- cognitive_modules-0.1.0/src/cognitive_modules.egg-info/dependency_links.txt +1 -0
- cognitive_modules-0.1.0/src/cognitive_modules.egg-info/entry_points.txt +2 -0
- cognitive_modules-0.1.0/src/cognitive_modules.egg-info/requires.txt +27 -0
- cognitive_modules-0.1.0/src/cognitive_modules.egg-info/top_level.txt +1 -0
- cognitive_modules-0.1.0/tests/test_cli.py +112 -0
- cognitive_modules-0.1.0/tests/test_loader.py +130 -0
- cognitive_modules-0.1.0/tests/test_registry.py +75 -0
- cognitive_modules-0.1.0/tests/test_runner.py +125 -0
- cognitive_modules-0.1.0/tests/test_subagent.py +117 -0
- cognitive_modules-0.1.0/tests/test_validator.py +81 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 leizii
|
|
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,295 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: cognitive-modules
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Structured LLM task runner with schema validation, confidence scoring, and subagent orchestration
|
|
5
|
+
Author: leizii
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/leizii/cognitive-modules
|
|
8
|
+
Project-URL: Documentation, https://github.com/leizii/cognitive-modules#readme
|
|
9
|
+
Project-URL: Repository, https://github.com/leizii/cognitive-modules
|
|
10
|
+
Project-URL: Issues, https://github.com/leizii/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
|
+
Dynamic: license-file
|
|
48
|
+
|
|
49
|
+
# Cognitive Modules
|
|
50
|
+
|
|
51
|
+
> 可验证的结构化 AI 任务规范
|
|
52
|
+
|
|
53
|
+
Cognitive Modules 是一种 AI 任务定义规范,专为需要**强约束、可验证、可审计**的生成任务设计。
|
|
54
|
+
|
|
55
|
+
## 与 Skills 的区别
|
|
56
|
+
|
|
57
|
+
| | Skills | Cognitive Modules |
|
|
58
|
+
|---|--------|------------------|
|
|
59
|
+
| 定位 | 轻量指令扩展 | 可验证的结构化任务 |
|
|
60
|
+
| 输入校验 | 无 | JSON Schema |
|
|
61
|
+
| 输出校验 | 无 | JSON Schema |
|
|
62
|
+
| 置信度 | 无 | 必须 0-1 |
|
|
63
|
+
| 推理过程 | 无 | 必须 rationale |
|
|
64
|
+
| 适用场景 | 快捷命令 | 规范生成、设计文档 |
|
|
65
|
+
|
|
66
|
+
## 快速开始
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
# 克隆
|
|
70
|
+
git clone https://github.com/leizii/cognitive-modules.git
|
|
71
|
+
cd cognitive-modules
|
|
72
|
+
|
|
73
|
+
# 安装依赖
|
|
74
|
+
pip install typer rich jsonschema pyyaml
|
|
75
|
+
|
|
76
|
+
# 运行
|
|
77
|
+
./cog --help
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## CLI 命令
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
# 模块管理
|
|
84
|
+
cog list # 列出已安装模块
|
|
85
|
+
cog info <module> # 查看模块详情
|
|
86
|
+
cog validate <module> # 验证模块结构
|
|
87
|
+
|
|
88
|
+
# 创建模块
|
|
89
|
+
cog init <name> -d "描述" # 从模板创建新模块
|
|
90
|
+
|
|
91
|
+
# 运行模块
|
|
92
|
+
cog run <module> input.json -o output.json --pretty
|
|
93
|
+
|
|
94
|
+
# 直接传参数(无需 JSON 文件)
|
|
95
|
+
cog run <module> --args "你的需求描述" -o output.json
|
|
96
|
+
|
|
97
|
+
# 启用子代理模式(支持 @call 调用其他模块)
|
|
98
|
+
cog run <module> --args "需求" --subagent
|
|
99
|
+
|
|
100
|
+
# 安装/卸载
|
|
101
|
+
cog install <source> # 从 git/本地/注册表安装
|
|
102
|
+
cog uninstall <module> # 卸载模块
|
|
103
|
+
|
|
104
|
+
# 注册表
|
|
105
|
+
cog registry # 查看公共模块
|
|
106
|
+
cog search <query> # 搜索模块
|
|
107
|
+
|
|
108
|
+
# 环境检查
|
|
109
|
+
cog doctor # 检查 LLM 配置
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## 安装来源
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
# 从本地安装
|
|
116
|
+
cog install ./path/to/module
|
|
117
|
+
|
|
118
|
+
# 从 GitHub 安装
|
|
119
|
+
cog install github:leizii/cognitive-modules/cognitive/modules/ui-spec-generator
|
|
120
|
+
|
|
121
|
+
# 从注册表安装
|
|
122
|
+
cog install registry:ui-spec-generator
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## 模块格式
|
|
126
|
+
|
|
127
|
+
### 新格式(推荐,2 文件)
|
|
128
|
+
|
|
129
|
+
```
|
|
130
|
+
my-module/
|
|
131
|
+
├── MODULE.md # 元数据 + 指令
|
|
132
|
+
├── schema.json # 输入输出 Schema
|
|
133
|
+
└── examples/ # 可选
|
|
134
|
+
├── input.json
|
|
135
|
+
└── output.json
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### 旧格式(兼容,6 文件)
|
|
139
|
+
|
|
140
|
+
```
|
|
141
|
+
my-module/
|
|
142
|
+
├── module.md
|
|
143
|
+
├── input.schema.json
|
|
144
|
+
├── output.schema.json
|
|
145
|
+
├── constraints.yaml
|
|
146
|
+
├── prompt.txt
|
|
147
|
+
└── examples/
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
## MODULE.md 格式
|
|
151
|
+
|
|
152
|
+
```yaml
|
|
153
|
+
---
|
|
154
|
+
name: my-module
|
|
155
|
+
version: 1.0.0
|
|
156
|
+
responsibility: 一句话描述
|
|
157
|
+
|
|
158
|
+
excludes:
|
|
159
|
+
- 不做的事情
|
|
160
|
+
|
|
161
|
+
constraints:
|
|
162
|
+
no_network: true
|
|
163
|
+
no_inventing_data: true
|
|
164
|
+
require_confidence: true
|
|
165
|
+
require_rationale: true
|
|
166
|
+
---
|
|
167
|
+
|
|
168
|
+
# 指令内容
|
|
169
|
+
|
|
170
|
+
(这里写 prompt)
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
## 在 Codex / Cursor 中使用
|
|
174
|
+
|
|
175
|
+
### 方式 1:直接对话(零配置)
|
|
176
|
+
|
|
177
|
+
```
|
|
178
|
+
读取 ~/.cognitive/modules/ui-spec-generator/MODULE.md,
|
|
179
|
+
为电商首页生成 UI 规范,保存到 ui-spec.json
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
### 方式 2:AGENTS.md(项目约定)
|
|
183
|
+
|
|
184
|
+
在项目根目录创建 `AGENTS.md`:
|
|
185
|
+
|
|
186
|
+
```markdown
|
|
187
|
+
## UI 规范生成
|
|
188
|
+
|
|
189
|
+
当需要生成 UI 规范时:
|
|
190
|
+
1. 读取 `~/.cognitive/modules/ui-spec-generator/MODULE.md`
|
|
191
|
+
2. 按 schema.json 格式输出
|
|
192
|
+
3. 保存到 ui-spec.json
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
### 方式 3:包装成 Skill
|
|
196
|
+
|
|
197
|
+
```yaml
|
|
198
|
+
# ~/.claude/skills/ui-spec/SKILL.md
|
|
199
|
+
---
|
|
200
|
+
name: ui-spec
|
|
201
|
+
description: 生成 UI 规范
|
|
202
|
+
---
|
|
203
|
+
执行 ~/.cognitive/modules/ui-spec-generator/MODULE.md
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
## 配置 LLM(仅 CLI 需要)
|
|
207
|
+
|
|
208
|
+
```bash
|
|
209
|
+
# OpenAI
|
|
210
|
+
export LLM_PROVIDER=openai
|
|
211
|
+
export OPENAI_API_KEY=sk-xxx
|
|
212
|
+
|
|
213
|
+
# Anthropic Claude
|
|
214
|
+
export LLM_PROVIDER=anthropic
|
|
215
|
+
export ANTHROPIC_API_KEY=sk-ant-xxx
|
|
216
|
+
|
|
217
|
+
# Ollama(本地免费)
|
|
218
|
+
export LLM_PROVIDER=ollama
|
|
219
|
+
|
|
220
|
+
# 不配置则使用 stub(返回示例输出)
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
## 模块搜索路径
|
|
224
|
+
|
|
225
|
+
模块按以下顺序查找:
|
|
226
|
+
|
|
227
|
+
1. `./cognitive/modules/` - 项目本地
|
|
228
|
+
2. `~/.cognitive/modules/` - 用户全局
|
|
229
|
+
3. `$COGNITIVE_MODULES_PATH` - 自定义路径
|
|
230
|
+
|
|
231
|
+
## 创建新模块
|
|
232
|
+
|
|
233
|
+
```bash
|
|
234
|
+
# 1. 创建骨架
|
|
235
|
+
cog init my-module -d "模块职责描述"
|
|
236
|
+
|
|
237
|
+
# 2. 编辑 MODULE.md 添加指令
|
|
238
|
+
# 3. 编辑 schema.json 定义输入输出
|
|
239
|
+
# 4. 验证
|
|
240
|
+
cog validate my-module
|
|
241
|
+
|
|
242
|
+
# 5. 全局安装(可选)
|
|
243
|
+
cog install ./cognitive/modules/my-module
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
## 内置模块
|
|
247
|
+
|
|
248
|
+
### ui-spec-generator
|
|
249
|
+
|
|
250
|
+
将产品需求转换为前端可实现的 UI 规范。
|
|
251
|
+
|
|
252
|
+
**输出包含**:
|
|
253
|
+
- 信息架构(sections + hierarchy)
|
|
254
|
+
- 组件定义(type, props, states)
|
|
255
|
+
- 交互设计(events, transitions)
|
|
256
|
+
- 响应式规则(breakpoints, layout)
|
|
257
|
+
- 可访问性(WCAG 要求)
|
|
258
|
+
- 验收标准(可测试条件)
|
|
259
|
+
- 置信度 + 推理过程
|
|
260
|
+
|
|
261
|
+
```bash
|
|
262
|
+
cog run ui-spec-generator examples/input.json -o ui-spec.json --pretty
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
## 项目结构
|
|
266
|
+
|
|
267
|
+
```
|
|
268
|
+
cognitive-modules/
|
|
269
|
+
├── README.md # 本文件
|
|
270
|
+
├── SPEC.md # 规范文档
|
|
271
|
+
├── INTEGRATION.md # Agent 集成指南
|
|
272
|
+
├── AGENTS.md # Agent 约定示例
|
|
273
|
+
├── cognitive-registry.json # 公共模块注册表
|
|
274
|
+
├── src/cognitive/ # CLI 源码
|
|
275
|
+
│ ├── cli.py # 命令入口
|
|
276
|
+
│ ├── loader.py # 模块加载(支持新旧格式)
|
|
277
|
+
│ ├── runner.py # 模块执行
|
|
278
|
+
│ ├── validator.py # 模块验证
|
|
279
|
+
│ ├── registry.py # 模块发现与安装
|
|
280
|
+
│ ├── templates.py # 模块模板
|
|
281
|
+
│ └── providers/ # LLM 后端
|
|
282
|
+
├── cognitive/modules/ # 内置模块
|
|
283
|
+
│ └── ui-spec-generator/
|
|
284
|
+
└── pyproject.toml
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
## 文档
|
|
288
|
+
|
|
289
|
+
- [SPEC.md](SPEC.md) - 完整规范文档
|
|
290
|
+
- [INTEGRATION.md](INTEGRATION.md) - Agent 工具集成指南
|
|
291
|
+
- [AGENTS.md](AGENTS.md) - Agent 约定示例
|
|
292
|
+
|
|
293
|
+
## License
|
|
294
|
+
|
|
295
|
+
MIT
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
# Cognitive Modules
|
|
2
|
+
|
|
3
|
+
> 可验证的结构化 AI 任务规范
|
|
4
|
+
|
|
5
|
+
Cognitive Modules 是一种 AI 任务定义规范,专为需要**强约束、可验证、可审计**的生成任务设计。
|
|
6
|
+
|
|
7
|
+
## 与 Skills 的区别
|
|
8
|
+
|
|
9
|
+
| | Skills | Cognitive Modules |
|
|
10
|
+
|---|--------|------------------|
|
|
11
|
+
| 定位 | 轻量指令扩展 | 可验证的结构化任务 |
|
|
12
|
+
| 输入校验 | 无 | JSON Schema |
|
|
13
|
+
| 输出校验 | 无 | JSON Schema |
|
|
14
|
+
| 置信度 | 无 | 必须 0-1 |
|
|
15
|
+
| 推理过程 | 无 | 必须 rationale |
|
|
16
|
+
| 适用场景 | 快捷命令 | 规范生成、设计文档 |
|
|
17
|
+
|
|
18
|
+
## 快速开始
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
# 克隆
|
|
22
|
+
git clone https://github.com/leizii/cognitive-modules.git
|
|
23
|
+
cd cognitive-modules
|
|
24
|
+
|
|
25
|
+
# 安装依赖
|
|
26
|
+
pip install typer rich jsonschema pyyaml
|
|
27
|
+
|
|
28
|
+
# 运行
|
|
29
|
+
./cog --help
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## CLI 命令
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
# 模块管理
|
|
36
|
+
cog list # 列出已安装模块
|
|
37
|
+
cog info <module> # 查看模块详情
|
|
38
|
+
cog validate <module> # 验证模块结构
|
|
39
|
+
|
|
40
|
+
# 创建模块
|
|
41
|
+
cog init <name> -d "描述" # 从模板创建新模块
|
|
42
|
+
|
|
43
|
+
# 运行模块
|
|
44
|
+
cog run <module> input.json -o output.json --pretty
|
|
45
|
+
|
|
46
|
+
# 直接传参数(无需 JSON 文件)
|
|
47
|
+
cog run <module> --args "你的需求描述" -o output.json
|
|
48
|
+
|
|
49
|
+
# 启用子代理模式(支持 @call 调用其他模块)
|
|
50
|
+
cog run <module> --args "需求" --subagent
|
|
51
|
+
|
|
52
|
+
# 安装/卸载
|
|
53
|
+
cog install <source> # 从 git/本地/注册表安装
|
|
54
|
+
cog uninstall <module> # 卸载模块
|
|
55
|
+
|
|
56
|
+
# 注册表
|
|
57
|
+
cog registry # 查看公共模块
|
|
58
|
+
cog search <query> # 搜索模块
|
|
59
|
+
|
|
60
|
+
# 环境检查
|
|
61
|
+
cog doctor # 检查 LLM 配置
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## 安装来源
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
# 从本地安装
|
|
68
|
+
cog install ./path/to/module
|
|
69
|
+
|
|
70
|
+
# 从 GitHub 安装
|
|
71
|
+
cog install github:leizii/cognitive-modules/cognitive/modules/ui-spec-generator
|
|
72
|
+
|
|
73
|
+
# 从注册表安装
|
|
74
|
+
cog install registry:ui-spec-generator
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## 模块格式
|
|
78
|
+
|
|
79
|
+
### 新格式(推荐,2 文件)
|
|
80
|
+
|
|
81
|
+
```
|
|
82
|
+
my-module/
|
|
83
|
+
├── MODULE.md # 元数据 + 指令
|
|
84
|
+
├── schema.json # 输入输出 Schema
|
|
85
|
+
└── examples/ # 可选
|
|
86
|
+
├── input.json
|
|
87
|
+
└── output.json
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### 旧格式(兼容,6 文件)
|
|
91
|
+
|
|
92
|
+
```
|
|
93
|
+
my-module/
|
|
94
|
+
├── module.md
|
|
95
|
+
├── input.schema.json
|
|
96
|
+
├── output.schema.json
|
|
97
|
+
├── constraints.yaml
|
|
98
|
+
├── prompt.txt
|
|
99
|
+
└── examples/
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## MODULE.md 格式
|
|
103
|
+
|
|
104
|
+
```yaml
|
|
105
|
+
---
|
|
106
|
+
name: my-module
|
|
107
|
+
version: 1.0.0
|
|
108
|
+
responsibility: 一句话描述
|
|
109
|
+
|
|
110
|
+
excludes:
|
|
111
|
+
- 不做的事情
|
|
112
|
+
|
|
113
|
+
constraints:
|
|
114
|
+
no_network: true
|
|
115
|
+
no_inventing_data: true
|
|
116
|
+
require_confidence: true
|
|
117
|
+
require_rationale: true
|
|
118
|
+
---
|
|
119
|
+
|
|
120
|
+
# 指令内容
|
|
121
|
+
|
|
122
|
+
(这里写 prompt)
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## 在 Codex / Cursor 中使用
|
|
126
|
+
|
|
127
|
+
### 方式 1:直接对话(零配置)
|
|
128
|
+
|
|
129
|
+
```
|
|
130
|
+
读取 ~/.cognitive/modules/ui-spec-generator/MODULE.md,
|
|
131
|
+
为电商首页生成 UI 规范,保存到 ui-spec.json
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### 方式 2:AGENTS.md(项目约定)
|
|
135
|
+
|
|
136
|
+
在项目根目录创建 `AGENTS.md`:
|
|
137
|
+
|
|
138
|
+
```markdown
|
|
139
|
+
## UI 规范生成
|
|
140
|
+
|
|
141
|
+
当需要生成 UI 规范时:
|
|
142
|
+
1. 读取 `~/.cognitive/modules/ui-spec-generator/MODULE.md`
|
|
143
|
+
2. 按 schema.json 格式输出
|
|
144
|
+
3. 保存到 ui-spec.json
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### 方式 3:包装成 Skill
|
|
148
|
+
|
|
149
|
+
```yaml
|
|
150
|
+
# ~/.claude/skills/ui-spec/SKILL.md
|
|
151
|
+
---
|
|
152
|
+
name: ui-spec
|
|
153
|
+
description: 生成 UI 规范
|
|
154
|
+
---
|
|
155
|
+
执行 ~/.cognitive/modules/ui-spec-generator/MODULE.md
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
## 配置 LLM(仅 CLI 需要)
|
|
159
|
+
|
|
160
|
+
```bash
|
|
161
|
+
# OpenAI
|
|
162
|
+
export LLM_PROVIDER=openai
|
|
163
|
+
export OPENAI_API_KEY=sk-xxx
|
|
164
|
+
|
|
165
|
+
# Anthropic Claude
|
|
166
|
+
export LLM_PROVIDER=anthropic
|
|
167
|
+
export ANTHROPIC_API_KEY=sk-ant-xxx
|
|
168
|
+
|
|
169
|
+
# Ollama(本地免费)
|
|
170
|
+
export LLM_PROVIDER=ollama
|
|
171
|
+
|
|
172
|
+
# 不配置则使用 stub(返回示例输出)
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
## 模块搜索路径
|
|
176
|
+
|
|
177
|
+
模块按以下顺序查找:
|
|
178
|
+
|
|
179
|
+
1. `./cognitive/modules/` - 项目本地
|
|
180
|
+
2. `~/.cognitive/modules/` - 用户全局
|
|
181
|
+
3. `$COGNITIVE_MODULES_PATH` - 自定义路径
|
|
182
|
+
|
|
183
|
+
## 创建新模块
|
|
184
|
+
|
|
185
|
+
```bash
|
|
186
|
+
# 1. 创建骨架
|
|
187
|
+
cog init my-module -d "模块职责描述"
|
|
188
|
+
|
|
189
|
+
# 2. 编辑 MODULE.md 添加指令
|
|
190
|
+
# 3. 编辑 schema.json 定义输入输出
|
|
191
|
+
# 4. 验证
|
|
192
|
+
cog validate my-module
|
|
193
|
+
|
|
194
|
+
# 5. 全局安装(可选)
|
|
195
|
+
cog install ./cognitive/modules/my-module
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
## 内置模块
|
|
199
|
+
|
|
200
|
+
### ui-spec-generator
|
|
201
|
+
|
|
202
|
+
将产品需求转换为前端可实现的 UI 规范。
|
|
203
|
+
|
|
204
|
+
**输出包含**:
|
|
205
|
+
- 信息架构(sections + hierarchy)
|
|
206
|
+
- 组件定义(type, props, states)
|
|
207
|
+
- 交互设计(events, transitions)
|
|
208
|
+
- 响应式规则(breakpoints, layout)
|
|
209
|
+
- 可访问性(WCAG 要求)
|
|
210
|
+
- 验收标准(可测试条件)
|
|
211
|
+
- 置信度 + 推理过程
|
|
212
|
+
|
|
213
|
+
```bash
|
|
214
|
+
cog run ui-spec-generator examples/input.json -o ui-spec.json --pretty
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
## 项目结构
|
|
218
|
+
|
|
219
|
+
```
|
|
220
|
+
cognitive-modules/
|
|
221
|
+
├── README.md # 本文件
|
|
222
|
+
├── SPEC.md # 规范文档
|
|
223
|
+
├── INTEGRATION.md # Agent 集成指南
|
|
224
|
+
├── AGENTS.md # Agent 约定示例
|
|
225
|
+
├── cognitive-registry.json # 公共模块注册表
|
|
226
|
+
├── src/cognitive/ # CLI 源码
|
|
227
|
+
│ ├── cli.py # 命令入口
|
|
228
|
+
│ ├── loader.py # 模块加载(支持新旧格式)
|
|
229
|
+
│ ├── runner.py # 模块执行
|
|
230
|
+
│ ├── validator.py # 模块验证
|
|
231
|
+
│ ├── registry.py # 模块发现与安装
|
|
232
|
+
│ ├── templates.py # 模块模板
|
|
233
|
+
│ └── providers/ # LLM 后端
|
|
234
|
+
├── cognitive/modules/ # 内置模块
|
|
235
|
+
│ └── ui-spec-generator/
|
|
236
|
+
└── pyproject.toml
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
## 文档
|
|
240
|
+
|
|
241
|
+
- [SPEC.md](SPEC.md) - 完整规范文档
|
|
242
|
+
- [INTEGRATION.md](INTEGRATION.md) - Agent 工具集成指南
|
|
243
|
+
- [AGENTS.md](AGENTS.md) - Agent 约定示例
|
|
244
|
+
|
|
245
|
+
## License
|
|
246
|
+
|
|
247
|
+
MIT
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "cognitive-modules"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Structured LLM task runner with schema validation, confidence scoring, and subagent orchestration"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = {text = "MIT"}
|
|
11
|
+
requires-python = ">=3.9"
|
|
12
|
+
authors = [
|
|
13
|
+
{name = "leizii"}
|
|
14
|
+
]
|
|
15
|
+
keywords = [
|
|
16
|
+
"llm",
|
|
17
|
+
"cognitive",
|
|
18
|
+
"modules",
|
|
19
|
+
"ai",
|
|
20
|
+
"cli",
|
|
21
|
+
"schema",
|
|
22
|
+
"validation",
|
|
23
|
+
"prompt",
|
|
24
|
+
"agent",
|
|
25
|
+
"subagent"
|
|
26
|
+
]
|
|
27
|
+
classifiers = [
|
|
28
|
+
"Development Status :: 4 - Beta",
|
|
29
|
+
"Intended Audience :: Developers",
|
|
30
|
+
"License :: OSI Approved :: MIT License",
|
|
31
|
+
"Operating System :: OS Independent",
|
|
32
|
+
"Programming Language :: Python :: 3",
|
|
33
|
+
"Programming Language :: Python :: 3.9",
|
|
34
|
+
"Programming Language :: Python :: 3.10",
|
|
35
|
+
"Programming Language :: Python :: 3.11",
|
|
36
|
+
"Programming Language :: Python :: 3.12",
|
|
37
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
38
|
+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
39
|
+
]
|
|
40
|
+
|
|
41
|
+
dependencies = [
|
|
42
|
+
"jsonschema>=4.17.0",
|
|
43
|
+
"pyyaml>=6.0",
|
|
44
|
+
"typer>=0.9.0",
|
|
45
|
+
"rich>=13.0.0",
|
|
46
|
+
]
|
|
47
|
+
|
|
48
|
+
[project.optional-dependencies]
|
|
49
|
+
openai = ["openai>=1.0.0"]
|
|
50
|
+
anthropic = ["anthropic>=0.18.0"]
|
|
51
|
+
ollama = ["requests>=2.28.0"]
|
|
52
|
+
minimax = ["openai>=1.0.0"]
|
|
53
|
+
all = [
|
|
54
|
+
"openai>=1.0.0",
|
|
55
|
+
"anthropic>=0.18.0",
|
|
56
|
+
"requests>=2.28.0"
|
|
57
|
+
]
|
|
58
|
+
dev = [
|
|
59
|
+
"pytest>=7.0.0",
|
|
60
|
+
"pytest-cov>=4.0.0",
|
|
61
|
+
"build>=1.0.0",
|
|
62
|
+
"twine>=4.0.0"
|
|
63
|
+
]
|
|
64
|
+
|
|
65
|
+
[project.scripts]
|
|
66
|
+
cog = "cognitive.cli:app"
|
|
67
|
+
|
|
68
|
+
[project.urls]
|
|
69
|
+
Homepage = "https://github.com/leizii/cognitive-modules"
|
|
70
|
+
Documentation = "https://github.com/leizii/cognitive-modules#readme"
|
|
71
|
+
Repository = "https://github.com/leizii/cognitive-modules"
|
|
72
|
+
Issues = "https://github.com/leizii/cognitive-modules/issues"
|
|
73
|
+
|
|
74
|
+
[tool.setuptools.packages.find]
|
|
75
|
+
where = ["src"]
|
|
76
|
+
|
|
77
|
+
[tool.setuptools.package-data]
|
|
78
|
+
"*" = ["*.yaml", "*.json", "*.md", "*.txt"]
|
|
79
|
+
|
|
80
|
+
[tool.pytest.ini_options]
|
|
81
|
+
testpaths = ["tests"]
|
|
82
|
+
python_files = ["test_*.py"]
|
|
83
|
+
python_functions = ["test_*"]
|
|
84
|
+
addopts = "-v --tb=short"
|
|
85
|
+
|
|
86
|
+
[tool.coverage.run]
|
|
87
|
+
source = ["src/cognitive"]
|
|
88
|
+
branch = true
|
|
89
|
+
|
|
90
|
+
[tool.coverage.report]
|
|
91
|
+
exclude_lines = [
|
|
92
|
+
"pragma: no cover",
|
|
93
|
+
"if __name__ == .__main__.:",
|
|
94
|
+
"raise NotImplementedError",
|
|
95
|
+
]
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Cognitive Modules - Structured LLM task runner with schema validation.
|
|
3
|
+
|
|
4
|
+
Usage:
|
|
5
|
+
cog list # List installed modules
|
|
6
|
+
cog run <module> <input> # Run a module
|
|
7
|
+
cog validate <module> # Validate module structure
|
|
8
|
+
cog install <source> # Install module from git/local
|
|
9
|
+
cog doctor # Check environment setup
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
__version__ = "0.1.0"
|