super-dev 2.0.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.
- super_dev/__init__.py +11 -0
- super_dev/analyzer/__init__.py +34 -0
- super_dev/analyzer/analyzer.py +440 -0
- super_dev/analyzer/detectors.py +511 -0
- super_dev/analyzer/models.py +285 -0
- super_dev/cli.py +3257 -0
- super_dev/config/__init__.py +11 -0
- super_dev/config/frontend.py +557 -0
- super_dev/config/manager.py +281 -0
- super_dev/creators/__init__.py +26 -0
- super_dev/creators/creator.py +134 -0
- super_dev/creators/document_generator.py +2473 -0
- super_dev/creators/frontend_builder.py +371 -0
- super_dev/creators/implementation_builder.py +789 -0
- super_dev/creators/prompt_generator.py +289 -0
- super_dev/creators/requirement_parser.py +354 -0
- super_dev/creators/spec_builder.py +195 -0
- super_dev/deployers/__init__.py +20 -0
- super_dev/deployers/cicd.py +1269 -0
- super_dev/deployers/delivery.py +229 -0
- super_dev/deployers/migration.py +1032 -0
- super_dev/design/__init__.py +74 -0
- super_dev/design/aesthetics.py +530 -0
- super_dev/design/charts.py +396 -0
- super_dev/design/codegen.py +379 -0
- super_dev/design/engine.py +528 -0
- super_dev/design/generator.py +395 -0
- super_dev/design/landing.py +422 -0
- super_dev/design/tech_stack.py +524 -0
- super_dev/design/tokens.py +269 -0
- super_dev/design/ux_guide.py +391 -0
- super_dev/exceptions.py +119 -0
- super_dev/experts/__init__.py +19 -0
- super_dev/experts/service.py +161 -0
- super_dev/integrations/__init__.py +7 -0
- super_dev/integrations/manager.py +264 -0
- super_dev/orchestrator/__init__.py +12 -0
- super_dev/orchestrator/engine.py +958 -0
- super_dev/orchestrator/experts.py +423 -0
- super_dev/orchestrator/knowledge.py +352 -0
- super_dev/orchestrator/quality.py +356 -0
- super_dev/reviewers/__init__.py +17 -0
- super_dev/reviewers/code_review.py +471 -0
- super_dev/reviewers/quality_gate.py +964 -0
- super_dev/reviewers/redteam.py +881 -0
- super_dev/skills/__init__.py +7 -0
- super_dev/skills/manager.py +307 -0
- super_dev/specs/__init__.py +44 -0
- super_dev/specs/generator.py +264 -0
- super_dev/specs/manager.py +428 -0
- super_dev/specs/models.py +348 -0
- super_dev/specs/validator.py +415 -0
- super_dev/utils/__init__.py +11 -0
- super_dev/utils/logger.py +133 -0
- super_dev/web/api.py +1402 -0
- super_dev-2.0.0.dist-info/METADATA +252 -0
- super_dev-2.0.0.dist-info/RECORD +61 -0
- super_dev-2.0.0.dist-info/WHEEL +5 -0
- super_dev-2.0.0.dist-info/entry_points.txt +2 -0
- super_dev-2.0.0.dist-info/licenses/LICENSE +21 -0
- super_dev-2.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
"""
|
|
2
|
+
AI 提示词生成器 - 生成可直接给 AI 的提示词
|
|
3
|
+
|
|
4
|
+
开发:Excellent(11964948@qq.com)
|
|
5
|
+
功能:将 Spec 转换为 AI 可理解的提示词
|
|
6
|
+
作用:用户复制给 AI 即可开始开发
|
|
7
|
+
创建时间:2025-12-30
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
|
|
12
|
+
from ..specs.models import TaskStatus
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class AIPromptGenerator:
|
|
16
|
+
"""AI 提示词生成器"""
|
|
17
|
+
|
|
18
|
+
def __init__(self, project_dir: Path, name: str):
|
|
19
|
+
"""初始化提示词生成器"""
|
|
20
|
+
self.project_dir = Path(project_dir).resolve()
|
|
21
|
+
self.name = name
|
|
22
|
+
|
|
23
|
+
def generate(self) -> str:
|
|
24
|
+
"""生成 AI 提示词"""
|
|
25
|
+
# 读取项目配置
|
|
26
|
+
import yaml # type: ignore[import-untyped]
|
|
27
|
+
config_path = self.project_dir / "super-dev.yaml"
|
|
28
|
+
project_config: dict = {}
|
|
29
|
+
if config_path.exists():
|
|
30
|
+
with open(config_path, encoding='utf-8') as f:
|
|
31
|
+
project_config = yaml.safe_load(f)
|
|
32
|
+
|
|
33
|
+
# 读取生成的文档
|
|
34
|
+
prd_content = self._read_document('prd')
|
|
35
|
+
arch_content = self._read_document('architecture')
|
|
36
|
+
uiux_content = self._read_document('uiux')
|
|
37
|
+
plan_content = self._read_document('execution-plan')
|
|
38
|
+
frontend_blueprint = self._read_document('frontend-blueprint')
|
|
39
|
+
|
|
40
|
+
# 读取 Spec 变更
|
|
41
|
+
change_content, change_id = self._read_change_spec()
|
|
42
|
+
|
|
43
|
+
# 组装提示词
|
|
44
|
+
prompt = f"""# {self.name} - AI 开发提示词
|
|
45
|
+
|
|
46
|
+
> 由 Super Dev 自动生成
|
|
47
|
+
> 生成时间: {self._get_timestamp()}
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
## 项目概述
|
|
52
|
+
|
|
53
|
+
**项目名称**: {self.name}
|
|
54
|
+
**项目描述**: {project_config.get('description', '见 PRD 文档')}
|
|
55
|
+
**目标平台**: {project_config.get('platform', 'web').upper()}
|
|
56
|
+
**技术栈**:
|
|
57
|
+
- 前端: {project_config.get('frontend', 'react')}
|
|
58
|
+
- 后端: {project_config.get('backend', 'node')}
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
## 你的任务
|
|
63
|
+
|
|
64
|
+
请根据以下规范和文档,实现 {self.name} 的所有功能。
|
|
65
|
+
|
|
66
|
+
**重要**:
|
|
67
|
+
1. **严格按照任务列表顺序实现**
|
|
68
|
+
2. **每完成一个任务,标记为 [x]**
|
|
69
|
+
3. **遵循规范中的所有要求**
|
|
70
|
+
4. **参考架构文档中的技术选型**
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
## 核心文档
|
|
75
|
+
|
|
76
|
+
### 1. PRD (产品需求文档)
|
|
77
|
+
|
|
78
|
+
{prd_content[:1000] if prd_content else f'请查看 output/{self.name}-prd.md'}
|
|
79
|
+
...
|
|
80
|
+
|
|
81
|
+
### 2. 架构设计文档
|
|
82
|
+
|
|
83
|
+
{arch_content[:1000] if arch_content else f'请查看 output/{self.name}-architecture.md'}
|
|
84
|
+
...
|
|
85
|
+
|
|
86
|
+
### 3. UI/UX 设计文档
|
|
87
|
+
|
|
88
|
+
{uiux_content[:1000] if uiux_content else f'请查看 output/{self.name}-uiux.md'}
|
|
89
|
+
...
|
|
90
|
+
|
|
91
|
+
### 4. 执行路线图
|
|
92
|
+
|
|
93
|
+
{plan_content[:1000] if plan_content else f'请查看 output/{self.name}-execution-plan.md'}
|
|
94
|
+
...
|
|
95
|
+
|
|
96
|
+
### 5. 前端蓝图
|
|
97
|
+
|
|
98
|
+
{frontend_blueprint[:1000] if frontend_blueprint else f'请查看 output/{self.name}-frontend-blueprint.md'}
|
|
99
|
+
...
|
|
100
|
+
|
|
101
|
+
---
|
|
102
|
+
|
|
103
|
+
## 任务列表
|
|
104
|
+
|
|
105
|
+
{change_content}
|
|
106
|
+
|
|
107
|
+
---
|
|
108
|
+
|
|
109
|
+
## 开发规范
|
|
110
|
+
|
|
111
|
+
### 代码规范
|
|
112
|
+
|
|
113
|
+
1. **遵循项目代码风格**
|
|
114
|
+
- 使用 Prettier 格式化
|
|
115
|
+
- 使用 ESLint 检查
|
|
116
|
+
- 遵循现有命名规范
|
|
117
|
+
|
|
118
|
+
2. **提交规范**
|
|
119
|
+
- Conventional Commits
|
|
120
|
+
- 一个功能一个 commit
|
|
121
|
+
- Commit message 清晰描述变更
|
|
122
|
+
|
|
123
|
+
3. **测试规范**
|
|
124
|
+
- 单元测试覆盖率 > 80%
|
|
125
|
+
- 每个功能点都有测试
|
|
126
|
+
- 使用 pytest / jest
|
|
127
|
+
|
|
128
|
+
### 图标使用规范
|
|
129
|
+
|
|
130
|
+
**严格禁止**:
|
|
131
|
+
- ❌ **禁止使用 emoji 表情作为图标**
|
|
132
|
+
- 不允许使用 emoji 来代替图标(如 💾 保存、🔍 搜索、⚙️ 设置)
|
|
133
|
+
- emoji 在不同平台显示不一致
|
|
134
|
+
- 可访问性差(屏幕阅读器支持不佳)
|
|
135
|
+
- 不够专业
|
|
136
|
+
|
|
137
|
+
**图标使用标准**(按优先级):
|
|
138
|
+
1. ✅ **首选**: UI 框架自带图标库
|
|
139
|
+
- Vue: Element Plus、Naive UI、Vuetify 自带图标
|
|
140
|
+
- React: Ant Design、Material-UI、Chakra UI 图标
|
|
141
|
+
- 其他: 使用项目选择的 UI 库官方图标
|
|
142
|
+
|
|
143
|
+
2. ✅ **专业图标库**:
|
|
144
|
+
- [Lucide Icons](https://lucide.dev/) - 推荐,轻量且现代
|
|
145
|
+
- [Heroicons](https://heroicons.com/) - Tailwind CSS 官方
|
|
146
|
+
- [Tabler Icons](https://tabler-icons.io/) - 开源免费
|
|
147
|
+
- [Phosphor Icons](https://phosphoricons.com/) - 精美免费
|
|
148
|
+
|
|
149
|
+
3. ✅ **自定义 SVG**:
|
|
150
|
+
- 如果需要自定义图标,使用 SVG 格式
|
|
151
|
+
- 确保遵循无障碍标准(添加 aria-label)
|
|
152
|
+
|
|
153
|
+
**代码示例**:
|
|
154
|
+
```typescript
|
|
155
|
+
// ✅ 正确:使用图标库
|
|
156
|
+
import {{ Save, Search, Settings }} from 'lucide-react';
|
|
157
|
+
<button><Save size={{20}} />保存</button>
|
|
158
|
+
|
|
159
|
+
// ❌ 错误:使用 emoji
|
|
160
|
+
<button>💾 保存</button>
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### 安全规范
|
|
164
|
+
|
|
165
|
+
1. **输入验证**: 所有用户输入必须验证
|
|
166
|
+
2. **SQL 注入**: 使用参数化查询
|
|
167
|
+
3. **XSS**: 输出转义
|
|
168
|
+
4. **认证**: JWT Token 认证
|
|
169
|
+
|
|
170
|
+
---
|
|
171
|
+
|
|
172
|
+
## 文件结构
|
|
173
|
+
|
|
174
|
+
请按照以下结构组织代码:
|
|
175
|
+
|
|
176
|
+
```
|
|
177
|
+
project-root/
|
|
178
|
+
├── frontend/ # 前端代码
|
|
179
|
+
│ ├── src/
|
|
180
|
+
│ │ ├── components/ # 组件
|
|
181
|
+
│ │ ├── pages/ # 页面
|
|
182
|
+
│ │ ├── services/ # API 服务
|
|
183
|
+
│ │ └── utils/ # 工具函数
|
|
184
|
+
│ ├── package.json
|
|
185
|
+
│ └── vite.config.js
|
|
186
|
+
│
|
|
187
|
+
├── backend/ # 后端代码
|
|
188
|
+
│ ├── src/
|
|
189
|
+
│ │ ├── controllers/ # 控制器
|
|
190
|
+
│ │ ├── models/ # 数据模型
|
|
191
|
+
│ │ ├── services/ # 业务逻辑
|
|
192
|
+
│ │ ├── routes/ # 路由
|
|
193
|
+
│ │ └── utils/ # 工具函数
|
|
194
|
+
│ ├── package.json
|
|
195
|
+
│ └── tsconfig.json
|
|
196
|
+
│
|
|
197
|
+
└── shared/ # 共享代码
|
|
198
|
+
├── types/ # 类型定义
|
|
199
|
+
└── constants/ # 常量
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
---
|
|
203
|
+
|
|
204
|
+
## 开始实现
|
|
205
|
+
|
|
206
|
+
请从任务 1.1 开始,按顺序实现所有任务。
|
|
207
|
+
|
|
208
|
+
**每完成一个任务**:
|
|
209
|
+
1. 更新 `.super-dev/changes/{change_id}/tasks.md`
|
|
210
|
+
2. 将任务标记为 [x] 完成状态
|
|
211
|
+
3. 提交代码 (可选)
|
|
212
|
+
4. 继续下一个任务
|
|
213
|
+
|
|
214
|
+
---
|
|
215
|
+
|
|
216
|
+
## 遇到问题?
|
|
217
|
+
|
|
218
|
+
如果遇到不清楚的地方:
|
|
219
|
+
1. 优先查看架构文档
|
|
220
|
+
2. 参考 PRD 中的需求说明
|
|
221
|
+
3. 查看 UI/UX 文档中的设计规范
|
|
222
|
+
|
|
223
|
+
---
|
|
224
|
+
|
|
225
|
+
## 完成标准
|
|
226
|
+
|
|
227
|
+
所有任务完成后:
|
|
228
|
+
- [ ] 所有功能正常运行
|
|
229
|
+
- [ ] 所有测试通过
|
|
230
|
+
- [ ] 代码符合规范
|
|
231
|
+
- [ ] 文档已更新
|
|
232
|
+
|
|
233
|
+
**祝开发顺利!**
|
|
234
|
+
"""
|
|
235
|
+
|
|
236
|
+
return prompt
|
|
237
|
+
|
|
238
|
+
def _read_document(self, doc_type: str) -> str | None:
|
|
239
|
+
"""读取生成的文档"""
|
|
240
|
+
doc_path = self.project_dir / "output" / f"{self.name}-{doc_type}.md"
|
|
241
|
+
if doc_path.exists():
|
|
242
|
+
return doc_path.read_text(encoding="utf-8")
|
|
243
|
+
return None
|
|
244
|
+
|
|
245
|
+
def _read_change_spec(self) -> tuple[str, str]:
|
|
246
|
+
"""读取 Spec 变更内容"""
|
|
247
|
+
from ..specs import ChangeManager
|
|
248
|
+
|
|
249
|
+
change_manager = ChangeManager(self.project_dir)
|
|
250
|
+
changes = change_manager.list_changes()
|
|
251
|
+
|
|
252
|
+
if not changes:
|
|
253
|
+
return "暂无 Spec,请先运行 super-dev spec init", "unknown-change"
|
|
254
|
+
|
|
255
|
+
change = changes[0] # 获取最新的变更
|
|
256
|
+
|
|
257
|
+
content = f"""
|
|
258
|
+
### 变更: {change.id}
|
|
259
|
+
|
|
260
|
+
**描述**: {change.title}
|
|
261
|
+
|
|
262
|
+
**状态**: {change.status.value}
|
|
263
|
+
|
|
264
|
+
#### 任务列表
|
|
265
|
+
"""
|
|
266
|
+
|
|
267
|
+
for task in change.tasks:
|
|
268
|
+
checkbox = "[x]" if task.status == TaskStatus.COMPLETED else "[ ]"
|
|
269
|
+
content += f"\n{checkbox} **{task.id}: {task.title}**\n"
|
|
270
|
+
if task.description:
|
|
271
|
+
content += f" - {task.description}\n"
|
|
272
|
+
if task.spec_refs:
|
|
273
|
+
content += f" - 规范引用: {', '.join(task.spec_refs)}\n"
|
|
274
|
+
|
|
275
|
+
if change.spec_deltas:
|
|
276
|
+
content += "\n#### 规范要求\n"
|
|
277
|
+
for delta in change.spec_deltas:
|
|
278
|
+
content += f"\n**{delta.spec_name}** ({delta.delta_type.value})\n"
|
|
279
|
+
for req in delta.requirements:
|
|
280
|
+
content += f"- {req.name}: {req.description}\n"
|
|
281
|
+
for scenario in req.scenarios:
|
|
282
|
+
content += f" - {scenario.when}: {scenario.then}\n"
|
|
283
|
+
|
|
284
|
+
return content, change.id
|
|
285
|
+
|
|
286
|
+
def _get_timestamp(self) -> str:
|
|
287
|
+
"""获取时间戳"""
|
|
288
|
+
from datetime import datetime
|
|
289
|
+
return datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
"""
|
|
2
|
+
需求解析器 - 将自然语言需求转换为可执行结构
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
7
|
+
import re
|
|
8
|
+
from dataclasses import dataclass
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
from typing import TypedDict
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class KeywordRule(TypedDict):
|
|
14
|
+
spec_name: str
|
|
15
|
+
req_name: str
|
|
16
|
+
keywords: tuple[str, ...]
|
|
17
|
+
description: str
|
|
18
|
+
scenario: dict[str, str]
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
@dataclass
|
|
22
|
+
class RequirementBlueprint:
|
|
23
|
+
"""结构化需求"""
|
|
24
|
+
|
|
25
|
+
spec_name: str
|
|
26
|
+
req_name: str
|
|
27
|
+
description: str
|
|
28
|
+
scenarios: list[dict]
|
|
29
|
+
|
|
30
|
+
def to_dict(self) -> dict:
|
|
31
|
+
return {
|
|
32
|
+
"spec_name": self.spec_name,
|
|
33
|
+
"req_name": self.req_name,
|
|
34
|
+
"description": self.description,
|
|
35
|
+
"scenarios": self.scenarios,
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class RequirementParser:
|
|
40
|
+
"""将一句话需求解析为规范、阶段和前端模块"""
|
|
41
|
+
|
|
42
|
+
_KEYWORD_RULES: list[KeywordRule] = [
|
|
43
|
+
{
|
|
44
|
+
"spec_name": "auth",
|
|
45
|
+
"req_name": "secure-authentication",
|
|
46
|
+
"keywords": ("登录", "注册", "认证", "oauth", "auth", "password", "账号"),
|
|
47
|
+
"description": "系统应支持安全认证与会话管理。",
|
|
48
|
+
"scenario": {
|
|
49
|
+
"given": "用户处于未登录状态",
|
|
50
|
+
"when": "提交有效凭据",
|
|
51
|
+
"then": "系统完成鉴权并建立安全会话",
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
"spec_name": "profile",
|
|
56
|
+
"req_name": "profile-management",
|
|
57
|
+
"keywords": ("用户中心", "个人资料", "profile", "account", "设置"),
|
|
58
|
+
"description": "用户应可查看和更新个人资料与偏好设置。",
|
|
59
|
+
"scenario": {
|
|
60
|
+
"given": "用户已经登录",
|
|
61
|
+
"when": "在个人中心提交更新",
|
|
62
|
+
"then": "资料变更被持久化并反馈成功状态",
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
"spec_name": "search",
|
|
67
|
+
"req_name": "search-and-filter",
|
|
68
|
+
"keywords": ("搜索", "筛选", "filter", "query", "检索"),
|
|
69
|
+
"description": "系统应提供可组合的搜索和筛选能力。",
|
|
70
|
+
"scenario": {
|
|
71
|
+
"given": "列表数据可访问",
|
|
72
|
+
"when": "用户输入关键词并选择筛选条件",
|
|
73
|
+
"then": "系统返回符合条件的数据结果",
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
"spec_name": "workflow",
|
|
78
|
+
"req_name": "workflow-orchestration",
|
|
79
|
+
"keywords": ("流程", "工作流", "pipeline", "审批", "自动化", "编排"),
|
|
80
|
+
"description": "系统应支持可追踪的流程编排与状态流转。",
|
|
81
|
+
"scenario": {
|
|
82
|
+
"given": "业务对象处于待处理状态",
|
|
83
|
+
"when": "触发流程节点执行",
|
|
84
|
+
"then": "状态按规则推进并记录审计信息",
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
"spec_name": "analytics",
|
|
89
|
+
"req_name": "dashboard-insights",
|
|
90
|
+
"keywords": ("报表", "统计", "dashboard", "分析", "指标", "图表"),
|
|
91
|
+
"description": "系统应提供关键指标看板与洞察视图。",
|
|
92
|
+
"scenario": {
|
|
93
|
+
"given": "业务数据已入库",
|
|
94
|
+
"when": "用户访问分析页面",
|
|
95
|
+
"then": "系统渲染最新指标并支持维度切换",
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
"spec_name": "notification",
|
|
100
|
+
"req_name": "notification-center",
|
|
101
|
+
"keywords": ("通知", "消息", "提醒", "订阅", "message"),
|
|
102
|
+
"description": "系统应提供通知中心和订阅推送能力。",
|
|
103
|
+
"scenario": {
|
|
104
|
+
"given": "触发业务事件",
|
|
105
|
+
"when": "事件匹配通知规则",
|
|
106
|
+
"then": "用户收到站内消息或外部通知",
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
"spec_name": "billing",
|
|
111
|
+
"req_name": "payment-and-billing",
|
|
112
|
+
"keywords": ("支付", "账单", "billing", "付款", "订阅计费"),
|
|
113
|
+
"description": "系统应支持支付流程、账单记录与对账。",
|
|
114
|
+
"scenario": {
|
|
115
|
+
"given": "用户发起付费行为",
|
|
116
|
+
"when": "支付网关返回交易结果",
|
|
117
|
+
"then": "系统更新订单状态并生成账单条目",
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
"spec_name": "content",
|
|
122
|
+
"req_name": "content-management",
|
|
123
|
+
"keywords": ("内容", "文章", "帖子", "cms", "发布", "管理"),
|
|
124
|
+
"description": "系统应支持内容的创建、审核与发布管理。",
|
|
125
|
+
"scenario": {
|
|
126
|
+
"given": "编辑已填写内容草稿",
|
|
127
|
+
"when": "提交发布申请",
|
|
128
|
+
"then": "内容进入审核并在通过后上线",
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
]
|
|
132
|
+
|
|
133
|
+
_SOURCE_DIRS = (
|
|
134
|
+
"src",
|
|
135
|
+
"app",
|
|
136
|
+
"backend",
|
|
137
|
+
"frontend",
|
|
138
|
+
"services",
|
|
139
|
+
"api",
|
|
140
|
+
"server",
|
|
141
|
+
"client",
|
|
142
|
+
"lib",
|
|
143
|
+
)
|
|
144
|
+
|
|
145
|
+
_PROJECT_FILES = (
|
|
146
|
+
"package.json",
|
|
147
|
+
"requirements.txt",
|
|
148
|
+
"go.mod",
|
|
149
|
+
"pom.xml",
|
|
150
|
+
"Cargo.toml",
|
|
151
|
+
"pyproject.toml",
|
|
152
|
+
)
|
|
153
|
+
|
|
154
|
+
def parse_requirements(self, description: str) -> list[dict]:
|
|
155
|
+
"""解析结构化需求列表"""
|
|
156
|
+
text = (description or "").strip()
|
|
157
|
+
lowered = text.lower()
|
|
158
|
+
parsed: list[RequirementBlueprint] = []
|
|
159
|
+
|
|
160
|
+
# 永远生成一个总览需求,确保流程可落地
|
|
161
|
+
parsed.append(
|
|
162
|
+
RequirementBlueprint(
|
|
163
|
+
spec_name="core",
|
|
164
|
+
req_name="business-core-flow",
|
|
165
|
+
description=f"系统应完整支持以下业务目标:{text or '核心业务流程实现'}",
|
|
166
|
+
scenarios=[
|
|
167
|
+
{
|
|
168
|
+
"given": "用户进入系统首页",
|
|
169
|
+
"when": "按业务路径完成主要操作",
|
|
170
|
+
"then": "系统成功返回结果并展示下一步引导",
|
|
171
|
+
}
|
|
172
|
+
],
|
|
173
|
+
)
|
|
174
|
+
)
|
|
175
|
+
|
|
176
|
+
for rule in self._KEYWORD_RULES:
|
|
177
|
+
if any(keyword.lower() in lowered for keyword in rule["keywords"]):
|
|
178
|
+
parsed.append(
|
|
179
|
+
RequirementBlueprint(
|
|
180
|
+
spec_name=rule["spec_name"],
|
|
181
|
+
req_name=rule["req_name"],
|
|
182
|
+
description=rule["description"],
|
|
183
|
+
scenarios=[rule["scenario"]],
|
|
184
|
+
)
|
|
185
|
+
)
|
|
186
|
+
|
|
187
|
+
# 如果没有命中任何规则,基于描述短语生成两个通用需求
|
|
188
|
+
if len(parsed) == 1:
|
|
189
|
+
subject = self._extract_subject(text)
|
|
190
|
+
parsed.extend(
|
|
191
|
+
[
|
|
192
|
+
RequirementBlueprint(
|
|
193
|
+
spec_name="experience",
|
|
194
|
+
req_name="task-oriented-interface",
|
|
195
|
+
description=f"系统应提供围绕“{subject}”的任务导向界面。",
|
|
196
|
+
scenarios=[
|
|
197
|
+
{
|
|
198
|
+
"given": "用户进入主界面",
|
|
199
|
+
"when": "执行一个完整任务",
|
|
200
|
+
"then": "任务可在最少步骤中完成",
|
|
201
|
+
}
|
|
202
|
+
],
|
|
203
|
+
),
|
|
204
|
+
RequirementBlueprint(
|
|
205
|
+
spec_name="operation",
|
|
206
|
+
req_name="observability-and-maintenance",
|
|
207
|
+
description="系统应具备可观测性、日志和可维护的运维能力。",
|
|
208
|
+
scenarios=[
|
|
209
|
+
{
|
|
210
|
+
"given": "系统在生产环境运行",
|
|
211
|
+
"when": "出现异常或性能下降",
|
|
212
|
+
"then": "可通过监控与日志快速定位问题",
|
|
213
|
+
}
|
|
214
|
+
],
|
|
215
|
+
),
|
|
216
|
+
]
|
|
217
|
+
)
|
|
218
|
+
|
|
219
|
+
return self._deduplicate_requirements(parsed)
|
|
220
|
+
|
|
221
|
+
def detect_scenario(self, project_dir: Path) -> str:
|
|
222
|
+
"""检测 0-1 / 1-N+1 场景"""
|
|
223
|
+
path = Path(project_dir).resolve()
|
|
224
|
+
has_source = any((path / item).exists() for item in self._SOURCE_DIRS)
|
|
225
|
+
has_project_file = any((path / item).exists() for item in self._PROJECT_FILES)
|
|
226
|
+
return "1-N+1" if (has_source or has_project_file) else "0-1"
|
|
227
|
+
|
|
228
|
+
def build_execution_phases(self, scenario: str, requirements: list[dict]) -> list[dict]:
|
|
229
|
+
"""生成执行阶段计划"""
|
|
230
|
+
req_titles = [req.get("req_name", "requirement") for req in requirements]
|
|
231
|
+
focus = ", ".join(req_titles[:4])
|
|
232
|
+
if len(req_titles) > 4:
|
|
233
|
+
focus += " ..."
|
|
234
|
+
|
|
235
|
+
if scenario == "0-1":
|
|
236
|
+
return [
|
|
237
|
+
{
|
|
238
|
+
"id": "phase-1",
|
|
239
|
+
"title": "需求对齐与文档冻结",
|
|
240
|
+
"objective": "冻结 PRD/架构/UIUX 文档并建立执行边界。",
|
|
241
|
+
"deliverables": ["PRD v1", "Architecture v1", "UIUX v1", "风险清单"],
|
|
242
|
+
},
|
|
243
|
+
{
|
|
244
|
+
"id": "phase-2",
|
|
245
|
+
"title": "前端先行交付",
|
|
246
|
+
"objective": "先交付可演示前端,以便快速验证业务流程。",
|
|
247
|
+
"deliverables": ["前端信息架构", "页面骨架", "设计令牌", "交互演示"],
|
|
248
|
+
},
|
|
249
|
+
{
|
|
250
|
+
"id": "phase-3",
|
|
251
|
+
"title": "后端与数据能力",
|
|
252
|
+
"objective": "围绕核心流程构建 API、数据模型和权限控制。",
|
|
253
|
+
"deliverables": ["API 契约", "数据库迁移", "服务模块", "鉴权策略"],
|
|
254
|
+
},
|
|
255
|
+
{
|
|
256
|
+
"id": "phase-4",
|
|
257
|
+
"title": "联调与质量门禁",
|
|
258
|
+
"objective": "完成端到端联调并通过质量门禁。",
|
|
259
|
+
"deliverables": ["红队审查报告", "质量门禁报告", "回归测试清单"],
|
|
260
|
+
},
|
|
261
|
+
{
|
|
262
|
+
"id": "phase-5",
|
|
263
|
+
"title": "上线与迭代计划",
|
|
264
|
+
"objective": "准备上线交付并规划 1-N+1 迭代路线。",
|
|
265
|
+
"deliverables": ["发布清单", "运维手册", "迭代 Backlog"],
|
|
266
|
+
},
|
|
267
|
+
]
|
|
268
|
+
|
|
269
|
+
return [
|
|
270
|
+
{
|
|
271
|
+
"id": "phase-1",
|
|
272
|
+
"title": "增量需求与影响分析",
|
|
273
|
+
"objective": "确认变更边界、兼容性和风险。",
|
|
274
|
+
"deliverables": ["变更影响矩阵", "兼容性策略", "回滚方案"],
|
|
275
|
+
},
|
|
276
|
+
{
|
|
277
|
+
"id": "phase-2",
|
|
278
|
+
"title": "前端模块扩展",
|
|
279
|
+
"objective": "优先扩展用户可感知模块并保持设计一致性。",
|
|
280
|
+
"deliverables": ["新增页面/组件", "交互更新", "文案与埋点更新"],
|
|
281
|
+
},
|
|
282
|
+
{
|
|
283
|
+
"id": "phase-3",
|
|
284
|
+
"title": "后端能力扩展",
|
|
285
|
+
"objective": "按规范增加接口与数据能力,避免破坏存量系统。",
|
|
286
|
+
"deliverables": ["增量 API", "迁移脚本", "灰度开关"],
|
|
287
|
+
},
|
|
288
|
+
{
|
|
289
|
+
"id": "phase-4",
|
|
290
|
+
"title": "回归验证与发布",
|
|
291
|
+
"objective": "覆盖关键链路并完成灰度/正式发布。",
|
|
292
|
+
"deliverables": ["回归测试结果", "发布报告", "监控告警确认"],
|
|
293
|
+
},
|
|
294
|
+
{
|
|
295
|
+
"id": "phase-5",
|
|
296
|
+
"title": "持续优化",
|
|
297
|
+
"objective": f"围绕 {focus or '核心需求'} 持续迭代优化。",
|
|
298
|
+
"deliverables": ["性能优化清单", "体验优化清单", "后续版本计划"],
|
|
299
|
+
},
|
|
300
|
+
]
|
|
301
|
+
|
|
302
|
+
def build_frontend_modules(self, requirements: list[dict]) -> list[dict]:
|
|
303
|
+
"""生成前端优先交付模块清单"""
|
|
304
|
+
modules = [
|
|
305
|
+
{
|
|
306
|
+
"name": "需求总览面板",
|
|
307
|
+
"goal": "集中展示需求摘要、优先级和执行状态。",
|
|
308
|
+
"core_elements": ["需求卡片", "优先级标签", "状态标识"],
|
|
309
|
+
},
|
|
310
|
+
{
|
|
311
|
+
"name": "文档工作台",
|
|
312
|
+
"goal": "统一管理 PRD、架构和 UIUX 文档入口。",
|
|
313
|
+
"core_elements": ["文档卡片", "版本信息", "快速跳转"],
|
|
314
|
+
},
|
|
315
|
+
{
|
|
316
|
+
"name": "执行路线图",
|
|
317
|
+
"goal": "可视化 0-1 / 1-N+1 阶段任务。",
|
|
318
|
+
"core_elements": ["阶段时间线", "里程碑", "风险提示"],
|
|
319
|
+
},
|
|
320
|
+
]
|
|
321
|
+
|
|
322
|
+
for req in requirements[:4]:
|
|
323
|
+
modules.append(
|
|
324
|
+
{
|
|
325
|
+
"name": f"{req.get('spec_name', 'core')} 模块",
|
|
326
|
+
"goal": req.get("description", "实现核心业务能力"),
|
|
327
|
+
"core_elements": [
|
|
328
|
+
f"{req.get('req_name', 'requirement')} 视图",
|
|
329
|
+
"关键交互入口",
|
|
330
|
+
"状态反馈组件",
|
|
331
|
+
],
|
|
332
|
+
}
|
|
333
|
+
)
|
|
334
|
+
|
|
335
|
+
return modules
|
|
336
|
+
|
|
337
|
+
def _extract_subject(self, description: str) -> str:
|
|
338
|
+
cleaned = re.sub(r"\s+", " ", description.strip())
|
|
339
|
+
if not cleaned:
|
|
340
|
+
return "核心业务"
|
|
341
|
+
separators = r"[,,。.!!?;;/]+"
|
|
342
|
+
segment = re.split(separators, cleaned)[0]
|
|
343
|
+
return segment[:40]
|
|
344
|
+
|
|
345
|
+
def _deduplicate_requirements(self, requirements: list[RequirementBlueprint]) -> list[dict]:
|
|
346
|
+
seen = set()
|
|
347
|
+
result = []
|
|
348
|
+
for item in requirements:
|
|
349
|
+
key = (item.spec_name, item.req_name)
|
|
350
|
+
if key in seen:
|
|
351
|
+
continue
|
|
352
|
+
seen.add(key)
|
|
353
|
+
result.append(item.to_dict())
|
|
354
|
+
return result
|