openalex-mcp-server 1.0.1
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.
- package/.claude/README.md +680 -0
- package/.claude/commands/prd.md +138 -0
- package/.claude/commands/ralph-yolo.md +346 -0
- package/.claude/commands/ralph.md +226 -0
- package/.claude/ralph-config.json +17 -0
- package/.claude/scripts/prompt.md +108 -0
- package/.claude/scripts/ralph.sh +127 -0
- package/.claude/skills/prd.md +270 -0
- package/.claude/skills/ralph-yolo.md +613 -0
- package/.claude/skills/ralph.md +315 -0
- package/.claude/templates/prd.json.example +64 -0
- package/.env.example +8 -0
- package/.github/workflows/npm-publish.yml +48 -0
- package/README.md +525 -0
- package/config/mcp-config.json +77 -0
- package/docs/PRD.md +897 -0
- package/docs/api-document.md +973 -0
- package/docs/document-mcp.txt +1 -0
- package/package.json +49 -0
- package/prd-progress.txt +66 -0
- package/src/cache-manager.js +204 -0
- package/src/cli.js +47 -0
- package/src/fulltext-downloader.js +333 -0
- package/src/index.js +603 -0
- package/src/json-optimizer.js +153 -0
- package/src/openalex-client.js +305 -0
- package/src/types/pdf-parse.d.ts +13 -0
- package/src/utils.js +90 -0
- package/tests/cli.test.js +31 -0
- package/tsconfig.json +22 -0
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Generate a Product Requirements Document (PRD) for a new feature
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# PRD Generator
|
|
6
|
+
|
|
7
|
+
You are creating a detailed Product Requirements Document (PRD) that is clear, actionable, and suitable for implementation with the Ralph autonomous agent system.
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Step 1: Ask Clarifying Questions
|
|
12
|
+
|
|
13
|
+
Ask the user 3-5 clarifying questions to understand the feature requirements. Each question should have lettered options (a, b, c, etc.).
|
|
14
|
+
|
|
15
|
+
Example format:
|
|
16
|
+
```
|
|
17
|
+
**Question 1**: What type of authentication do you need?
|
|
18
|
+
a) Email/password with session
|
|
19
|
+
b) OAuth (Google, GitHub)
|
|
20
|
+
c) Magic link authentication
|
|
21
|
+
d) Other (please specify)
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## Step 2: Generate PRD
|
|
27
|
+
|
|
28
|
+
Once you have enough information, generate a PRD in markdown format with the following structure:
|
|
29
|
+
|
|
30
|
+
```markdown
|
|
31
|
+
# [Feature Name]
|
|
32
|
+
|
|
33
|
+
## Overview
|
|
34
|
+
[Brief description of what this feature does and why it matters]
|
|
35
|
+
|
|
36
|
+
## User Stories
|
|
37
|
+
|
|
38
|
+
### US-001: [Story Title]
|
|
39
|
+
**As a** [user type],
|
|
40
|
+
**I want** [feature],
|
|
41
|
+
**So that** [benefit].
|
|
42
|
+
|
|
43
|
+
**Acceptance Criteria:**
|
|
44
|
+
- [ ] [Specific, verifiable criterion 1]
|
|
45
|
+
- [ ] [Specific, verifiable criterion 2]
|
|
46
|
+
- [ ] Typecheck passes
|
|
47
|
+
|
|
48
|
+
### US-002: [Story Title]
|
|
49
|
+
[...]
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
## Critical Rules for Ralph Compatibility
|
|
55
|
+
|
|
56
|
+
### Story Sizing (MOST IMPORTANT)
|
|
57
|
+
Each user story MUST be completable in ONE iteration (one context window).
|
|
58
|
+
|
|
59
|
+
**Right-sized stories:**
|
|
60
|
+
- Add a database column and migration
|
|
61
|
+
- Add a UI component to an existing page
|
|
62
|
+
- Update a server action with new logic
|
|
63
|
+
- Add a filter dropdown to a list
|
|
64
|
+
|
|
65
|
+
**Too big (split these):**
|
|
66
|
+
- "Build the entire dashboard" → Split into: schema, queries, UI components, filters
|
|
67
|
+
- "Add authentication" → Split into: schema, middleware, login UI, session handling
|
|
68
|
+
|
|
69
|
+
**Rule of thumb:** If you cannot describe the change in 2-3 sentences, it is too big.
|
|
70
|
+
|
|
71
|
+
### Story Ordering
|
|
72
|
+
Stories execute in priority order. Earlier stories must NOT depend on later ones.
|
|
73
|
+
|
|
74
|
+
**Correct order:**
|
|
75
|
+
1. Schema/database changes (migrations)
|
|
76
|
+
2. Server actions / backend logic
|
|
77
|
+
3. UI components that use the backend
|
|
78
|
+
4. Dashboard/summary views that aggregate data
|
|
79
|
+
|
|
80
|
+
### Acceptance Criteria
|
|
81
|
+
All criteria must be verifiable (not vague).
|
|
82
|
+
|
|
83
|
+
**Good:**
|
|
84
|
+
- "Add `status` column to tasks table with default 'pending'"
|
|
85
|
+
- "Filter dropdown has options: All, Active, Completed"
|
|
86
|
+
- "Typecheck passes"
|
|
87
|
+
|
|
88
|
+
**Bad:**
|
|
89
|
+
- "Works correctly"
|
|
90
|
+
- "Good UX"
|
|
91
|
+
- "Handles edge cases"
|
|
92
|
+
|
|
93
|
+
**Always include "Typecheck passes"** as the final criterion for every story.
|
|
94
|
+
|
|
95
|
+
**For UI stories, also include:** "Verify in browser using dev-browser skill"
|
|
96
|
+
|
|
97
|
+
---
|
|
98
|
+
|
|
99
|
+
## Step 3: Save PRD
|
|
100
|
+
|
|
101
|
+
Save the generated PRD to `tasks/prd-[feature-name].md` (convert feature name to kebab-case).
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
## Output Example
|
|
106
|
+
|
|
107
|
+
```
|
|
108
|
+
User: /prd Add a task status feature
|
|
109
|
+
|
|
110
|
+
AI: Let me ask a few questions to understand your requirements...
|
|
111
|
+
|
|
112
|
+
**Question 1**: What statuses do you need?
|
|
113
|
+
a) Pending/Done only
|
|
114
|
+
b) Pending/In Progress/Done
|
|
115
|
+
c) Custom statuses
|
|
116
|
+
d) Other (please specify)
|
|
117
|
+
|
|
118
|
+
User: b
|
|
119
|
+
|
|
120
|
+
[Continue questions...]
|
|
121
|
+
|
|
122
|
+
**Question 5**: Should the status persist?
|
|
123
|
+
a) Yes, in the database
|
|
124
|
+
b) No, just in-memory
|
|
125
|
+
c) Other
|
|
126
|
+
|
|
127
|
+
User: a
|
|
128
|
+
|
|
129
|
+
Great! Here's your PRD...
|
|
130
|
+
|
|
131
|
+
[Generate PRD]
|
|
132
|
+
|
|
133
|
+
Saving to tasks/prd-task-status.md...
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
---
|
|
137
|
+
|
|
138
|
+
**User, describe the feature you want to build:**
|
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: YOLO模式 - 直接使用Claude Code子Agent实现PRD,无需Amp CLI
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# Ralph YOLO - 自主 Agent 循环(无 Amp 依赖)
|
|
6
|
+
|
|
7
|
+
Ralph YOLO 是 Ralph 的轻量版本,直接使用 Claude Code 的 Task tool 管理子 agent 完成任务,无需 Amp CLI。
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## 使用方法
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
/ralph-yolo [path-to-prd.md]
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
**示例:**
|
|
18
|
+
```bash
|
|
19
|
+
/ralph-yolo tasks/prd-my-feature.md # 从 PRD 转换并执行
|
|
20
|
+
/ralph-yolo prd.json # 使用现有 prd.json 执行
|
|
21
|
+
/ralph-yolo # 自动查找 prd.json
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## Phase 1: PRD 转换(如果提供 markdown PRD)
|
|
27
|
+
|
|
28
|
+
### Step 1: 检查输入
|
|
29
|
+
|
|
30
|
+
检查用户是否提供了 PRD 文件路径。如果没有,查找项目根目录的 `prd.json`。
|
|
31
|
+
|
|
32
|
+
**用户输入格式:**
|
|
33
|
+
- `/ralph-yolo tasks/prd-my-feature.md` - 转换 PRD 并运行 Ralph YOLO
|
|
34
|
+
- `/ralph-yolo prd.json` - 使用现有 prd.json 运行
|
|
35
|
+
- `/ralph-yolo` - 运行(查找 prd.json)
|
|
36
|
+
|
|
37
|
+
### Step 2: 归档旧运行(如需要)
|
|
38
|
+
|
|
39
|
+
检查是否存在 `prd.json` 且 `branchName` 不同。如果是:
|
|
40
|
+
1. 读取当前 `prd.json` 提取 `branchName`
|
|
41
|
+
2. 比较新功能的分支名
|
|
42
|
+
3. 如果不同且 `prd-progress.txt` 有内容:
|
|
43
|
+
- 创建归档文件夹:`.claude/archive/YYYY-MM-DD-[feature-name]/`
|
|
44
|
+
- 复制当前 `prd.json` 和 `prd-progress.txt` 到归档
|
|
45
|
+
- 重置 `prd-progress.txt` 为新的头部信息
|
|
46
|
+
|
|
47
|
+
### Step 3: 转换为 prd.json
|
|
48
|
+
|
|
49
|
+
解析 PRD 并生成项目根目录的 `prd.json`:
|
|
50
|
+
|
|
51
|
+
```json
|
|
52
|
+
{
|
|
53
|
+
"project": "[从 PRD 提取或自动检测的项目名]",
|
|
54
|
+
"branchName": "ralph/[feature-name-kebab-case]",
|
|
55
|
+
"description": "[从 PRD 提取的功能描述]",
|
|
56
|
+
"userStories": [
|
|
57
|
+
{
|
|
58
|
+
"id": "US-001",
|
|
59
|
+
"title": "[故事标题]",
|
|
60
|
+
"description": "As a [用户], I want [功能] so that [收益]",
|
|
61
|
+
"acceptanceCriteria": [
|
|
62
|
+
"标准 1",
|
|
63
|
+
"标准 2",
|
|
64
|
+
"Typecheck passes"
|
|
65
|
+
],
|
|
66
|
+
"priority": 1,
|
|
67
|
+
"passes": false,
|
|
68
|
+
"notes": ""
|
|
69
|
+
}
|
|
70
|
+
]
|
|
71
|
+
}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### 转换规则
|
|
75
|
+
|
|
76
|
+
1. **每个用户故事成为一个 JSON 条目**
|
|
77
|
+
2. **ID**:顺序编号(US-001, US-002 等)
|
|
78
|
+
3. **Priority**:基于依赖顺序(schema → backend → UI)
|
|
79
|
+
4. **所有故事**:初始 `passes: false`,`notes` 为空
|
|
80
|
+
5. **branchName**:从功能名派生,kebab-case,前缀 `ralph/`
|
|
81
|
+
6. **始终添加**:"Typecheck passes" 到每个故事
|
|
82
|
+
7. **UI 故事**:添加 "Verify in browser"
|
|
83
|
+
|
|
84
|
+
### 故事大小关键原则
|
|
85
|
+
|
|
86
|
+
每个故事必须在一个上下文窗口内完成。
|
|
87
|
+
|
|
88
|
+
**合适大小:**
|
|
89
|
+
- 添加数据库列和迁移
|
|
90
|
+
- 向现有页面添加 UI 组件
|
|
91
|
+
- 更新服务器操作
|
|
92
|
+
- 添加过滤下拉菜单
|
|
93
|
+
|
|
94
|
+
**太大(需拆分):**
|
|
95
|
+
- "构建整个仪表板" → 拆分为:schema, queries, UI 组件, filters
|
|
96
|
+
- "添加认证" → 拆分为:schema, middleware, 登录 UI, session handling
|
|
97
|
+
|
|
98
|
+
**经验法则:** 如果不能用 2-3 句话描述变更,就太大了。
|
|
99
|
+
|
|
100
|
+
### 故事排序
|
|
101
|
+
|
|
102
|
+
故事按 `priority` 顺序执行。前面的故事不能依赖后面的。
|
|
103
|
+
|
|
104
|
+
**正确顺序:**
|
|
105
|
+
1. Schema/数据库变更(migrations)
|
|
106
|
+
2. Server actions / 后端逻辑
|
|
107
|
+
3. 使用后端的 UI 组件
|
|
108
|
+
4. 汇总数据的 Dashboard/summary 视图
|
|
109
|
+
|
|
110
|
+
### 执行前验证
|
|
111
|
+
|
|
112
|
+
运行 Ralph YOLO 前,验证:
|
|
113
|
+
- [ ] 旧运行已归档(如适用)
|
|
114
|
+
- [ ] 每个故事可在一个迭代内完成
|
|
115
|
+
- [ ] 故事按依赖关系排序
|
|
116
|
+
- [ ] 每个故事有 "Typecheck passes"
|
|
117
|
+
- [ ] UI 故事有 "Verify in browser"
|
|
118
|
+
- [ ] 验收标准可验证(不模糊)
|
|
119
|
+
|
|
120
|
+
---
|
|
121
|
+
|
|
122
|
+
## Phase 2: Ralph YOLO 执行
|
|
123
|
+
|
|
124
|
+
### Step 1: 预检
|
|
125
|
+
|
|
126
|
+
验证以下条件:
|
|
127
|
+
|
|
128
|
+
**1. Git 工作区干净**
|
|
129
|
+
```bash
|
|
130
|
+
git status --porcelain
|
|
131
|
+
```
|
|
132
|
+
如果不干净,要求用户提交或暂存更改
|
|
133
|
+
|
|
134
|
+
**2. prd.json 存在且有效**
|
|
135
|
+
```bash
|
|
136
|
+
cat prd.json | jq .
|
|
137
|
+
```
|
|
138
|
+
如果无效,显示错误并退出
|
|
139
|
+
|
|
140
|
+
### Step 2: 创建或检出功能分支
|
|
141
|
+
|
|
142
|
+
读取 `prd.json` 中的 `branchName`:
|
|
143
|
+
```bash
|
|
144
|
+
jq -r '.branchName' prd.json
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
如果分支不存在,从 main 创建:
|
|
148
|
+
```bash
|
|
149
|
+
git checkout -b $(jq -r '.branchName' prd.json)
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
如果分支存在,检出它:
|
|
153
|
+
```bash
|
|
154
|
+
git checkout $(jq -r '.branchName' prd.json)
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
### Step 3: 初始化进度文件
|
|
158
|
+
|
|
159
|
+
如果 `prd-progress.txt` 不存在,创建它:
|
|
160
|
+
```bash
|
|
161
|
+
echo "# Ralph YOLO Progress Log" > prd-progress.txt
|
|
162
|
+
echo "Started: $(date)" >> prd-progress.txt
|
|
163
|
+
echo "---" >> prd-progress.txt
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### Step 4: 顺序执行用户故事
|
|
167
|
+
|
|
168
|
+
**核心工作流程:**
|
|
169
|
+
|
|
170
|
+
对于每个未完成的用户故事(`passes: false`),按 `priority` 升序:
|
|
171
|
+
|
|
172
|
+
1. **选择故事**:找到最低 `priority` 且 `passes: false` 的故事
|
|
173
|
+
2. **创建子 Agent**:使用 `Task` tool 创建合适的子 agent
|
|
174
|
+
3. **等待完成**:同步等待子 agent 完成(不使用 `run_in_background`)
|
|
175
|
+
4. **验证完成**:检查 git 提交、工作区状态、质量检查
|
|
176
|
+
5. **更新状态**:设置 `prd.json` 中该故事 `passes: true`
|
|
177
|
+
6. **记录进度**:追加到 `prd-progress.txt`
|
|
178
|
+
7. **继续下一个**:重复直到所有故事完成
|
|
179
|
+
|
|
180
|
+
### 子 Agent 提示词模板
|
|
181
|
+
|
|
182
|
+
```
|
|
183
|
+
你是一个独立的开发 agent,正在完成一个用户故事。
|
|
184
|
+
|
|
185
|
+
## 用户故事
|
|
186
|
+
|
|
187
|
+
**ID**: {story.id}
|
|
188
|
+
**标题**: {story.title}
|
|
189
|
+
**描述**: {story.description}
|
|
190
|
+
|
|
191
|
+
## 验收标准
|
|
192
|
+
|
|
193
|
+
{逐条列出 acceptanceCriteria}
|
|
194
|
+
|
|
195
|
+
## 上下文信息
|
|
196
|
+
|
|
197
|
+
- 项目: {prd.project}
|
|
198
|
+
- 功能分支: {prd.branchName}
|
|
199
|
+
- 功能描述: {prd.description}
|
|
200
|
+
|
|
201
|
+
## 你需要做的事情
|
|
202
|
+
|
|
203
|
+
1. 阅读并理解该用户故事
|
|
204
|
+
2. 阅读项目的现有代码,了解代码结构
|
|
205
|
+
3. 实现该用户故事
|
|
206
|
+
4. 运行质量检查(typecheck, lint, test 等)
|
|
207
|
+
5. 如果检查通过,提交代码:
|
|
208
|
+
- 提交信息格式: `feat: {story.id} - {story.title}`
|
|
209
|
+
- 使用 Co-Authored-By: Claude <noreply@anthropic.com>
|
|
210
|
+
6. 如果检查失败,修复问题直到通过
|
|
211
|
+
7. 确保所有验收标准都满足
|
|
212
|
+
|
|
213
|
+
## 重要约束
|
|
214
|
+
|
|
215
|
+
- 只工作于这一个用户故事
|
|
216
|
+
- 不要修改其他无关代码
|
|
217
|
+
- 遵循项目现有的代码模式和约定
|
|
218
|
+
- 提交前确保所有检查通过
|
|
219
|
+
|
|
220
|
+
完成后,请明确报告:
|
|
221
|
+
- 实现了什么
|
|
222
|
+
- 修改了哪些文件
|
|
223
|
+
- 是否成功提交
|
|
224
|
+
- 遇到的任何问题或学习点
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
### Agent 类型选择
|
|
228
|
+
|
|
229
|
+
| 任务类型 | Agent 类型 | 说明 |
|
|
230
|
+
|---------|-----------|------|
|
|
231
|
+
| UI 设计需求 | `ui-ux-designer` | 设计界面和用户体验 |
|
|
232
|
+
| 一般开发 | `Full-stack-developer` | 日常全栈开发任务 |
|
|
233
|
+
| 复杂任务 | `general-purpose` | 多步骤复杂任务 |
|
|
234
|
+
|
|
235
|
+
### 进度报告
|
|
236
|
+
|
|
237
|
+
每个子 agent 完成后,向用户报告:
|
|
238
|
+
|
|
239
|
+
```
|
|
240
|
+
✓ 完成 US-001: Add priority field to database
|
|
241
|
+
- Agent: Full-stack-developer
|
|
242
|
+
- 提交: abc1234
|
|
243
|
+
- 文件: src/db/schema.sql, migrations/001_add_priority.sql
|
|
244
|
+
|
|
245
|
+
进度: 1/4 (25%)
|
|
246
|
+
剩余故事:
|
|
247
|
+
- US-002: Display priority indicator (priority: 2)
|
|
248
|
+
- US-003: Add priority selector (priority: 3)
|
|
249
|
+
- US-004: Filter by priority (priority: 4)
|
|
250
|
+
|
|
251
|
+
正在启动下一个 agent...
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
### Step 5: 完成检测
|
|
255
|
+
|
|
256
|
+
当所有用户故事的 `passes` 都为 `true` 时:
|
|
257
|
+
|
|
258
|
+
1. 输出完成信号:
|
|
259
|
+
```
|
|
260
|
+
<promise>COMPLETE</promise>
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
2. 显示完成摘要:
|
|
264
|
+
```
|
|
265
|
+
═══════════════════════════════════════════════════════
|
|
266
|
+
Ralph YOLO 完成所有任务!
|
|
267
|
+
═══════════════════════════════════════════════════════
|
|
268
|
+
总计完成: X 个用户故事
|
|
269
|
+
进度文件: prd-progress.txt
|
|
270
|
+
Git 提交: git log --oneline
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
3. 退出循环
|
|
274
|
+
|
|
275
|
+
---
|
|
276
|
+
|
|
277
|
+
## 示例会话
|
|
278
|
+
|
|
279
|
+
```
|
|
280
|
+
User: /ralph-yolo tasks/prd-task-priority.md
|
|
281
|
+
|
|
282
|
+
AI:
|
|
283
|
+
✓ 正在转换 PRD 到 prd.json...
|
|
284
|
+
✓ 已创建包含 4 个用户故事的 prd.json
|
|
285
|
+
✓ 检查前置条件...
|
|
286
|
+
✓ Git 工作区干净
|
|
287
|
+
✓ 创建分支 ralph/task-priority...
|
|
288
|
+
|
|
289
|
+
══════════════════════════════════════════════════════
|
|
290
|
+
Ralph YOLO - 自主 Agent 循环
|
|
291
|
+
══════════════════════════════════════════════════════
|
|
292
|
+
找到 4 个用户故事
|
|
293
|
+
开始执行...
|
|
294
|
+
|
|
295
|
+
────────────────────────────────────────────────────────────
|
|
296
|
+
[Agent 1/4] Full-stack-developer
|
|
297
|
+
任务: US-001 - Add priority field to database
|
|
298
|
+
────────────────────────────────────────────────────────────
|
|
299
|
+
|
|
300
|
+
[子 agent 执行中...]
|
|
301
|
+
|
|
302
|
+
✓ 完成 US-001: Add priority field to database
|
|
303
|
+
- Agent: Full-stack-developer
|
|
304
|
+
- 提交: abc1234
|
|
305
|
+
- 文件: src/db/schema.sql, migrations/001_add_priority.sql
|
|
306
|
+
|
|
307
|
+
进度: 1/4 (25%)
|
|
308
|
+
正在启动下一个 agent...
|
|
309
|
+
|
|
310
|
+
[继续执行...]
|
|
311
|
+
|
|
312
|
+
══════════════════════════════════════════════════════
|
|
313
|
+
Ralph YOLO 完成所有任务!══════════════════════════════════════════════════════
|
|
314
|
+
总计完成: 4 个用户故事
|
|
315
|
+
分支: ralph/task-priority
|
|
316
|
+
|
|
317
|
+
查看详情:
|
|
318
|
+
cat prd-progress.txt
|
|
319
|
+
git log --oneline
|
|
320
|
+
|
|
321
|
+
<promise>COMPLETE</promise>
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
---
|
|
325
|
+
|
|
326
|
+
## 关键文件
|
|
327
|
+
|
|
328
|
+
| 文件 | 用途 |
|
|
329
|
+
|------|------|
|
|
330
|
+
| `prd.json` | 用户故事及其 `passes` 状态 |
|
|
331
|
+
| `prd-progress.txt` | 追踪学习进度的追加日志 |
|
|
332
|
+
| `.claude/archive/` | 旧运行的存档 |
|
|
333
|
+
|
|
334
|
+
---
|
|
335
|
+
|
|
336
|
+
## 提示
|
|
337
|
+
|
|
338
|
+
1. **保持故事小** - 每个必须在一个上下文窗口内完成
|
|
339
|
+
2. **按依赖排序** - schema 在前,然后是后端,然后是 UI
|
|
340
|
+
3. **可验证的标准** - "Typecheck passes" 而不是 "工作正常"
|
|
341
|
+
4. **干净的 git 状态** - 从干净的工作区开始
|
|
342
|
+
5. **监控进度** - 定期检查 `prd-progress.txt` 和 git log
|
|
343
|
+
|
|
344
|
+
---
|
|
345
|
+
|
|
346
|
+
**准备好运行 Ralph YOLO。提供 PRD 路径进行转换,或者浮浮酱会使用现有的 prd.json** φ(≧ω≦*)♪
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Convert PRD to Ralph format and run the autonomous agent loop
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# Ralph - Autonomous Agent Loop
|
|
6
|
+
|
|
7
|
+
Ralph implements PRDs by repeatedly spawning fresh AI instances to complete user stories one by one.
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Phase 1: PRD Conversion (if markdown PRD provided)
|
|
12
|
+
|
|
13
|
+
### Step 1: Check Input
|
|
14
|
+
|
|
15
|
+
Check if the user provided a path to a PRD file. If not, look for `prd.json` in the project root.
|
|
16
|
+
|
|
17
|
+
**User input formats:**
|
|
18
|
+
- `/ralph tasks/prd-my-feature.md` - Convert PRD and run Ralph
|
|
19
|
+
- `/ralph prd.json` - Run Ralph with existing prd.json
|
|
20
|
+
- `/ralph` - Run Ralph (looks for prd.json)
|
|
21
|
+
|
|
22
|
+
### Step 2: Archive Previous Run (if needed)
|
|
23
|
+
|
|
24
|
+
Check if `prd.json` exists with a different `branchName`. If so:
|
|
25
|
+
1. Read current `prd.json` and extract `branchName`
|
|
26
|
+
2. Check if it differs from the new feature's branch
|
|
27
|
+
3. If different AND `prd-progress.txt` has content:
|
|
28
|
+
- Create archive folder: `.claude/archive/YYYY-MM-DD-[feature-name]/`
|
|
29
|
+
- Copy current `prd.json` and `prd-progress.txt` to archive
|
|
30
|
+
- Reset `prd-progress.txt` with fresh header
|
|
31
|
+
|
|
32
|
+
### Step 3: Convert to prd.json
|
|
33
|
+
|
|
34
|
+
Parse the PRD and generate `prd.json` in the project root:
|
|
35
|
+
|
|
36
|
+
```json
|
|
37
|
+
{
|
|
38
|
+
"project": "[Project Name from PRD or auto-detected]",
|
|
39
|
+
"branchName": "ralph/[feature-name-kebab-case]",
|
|
40
|
+
"description": "[Feature description from PRD]",
|
|
41
|
+
"userStories": [
|
|
42
|
+
{
|
|
43
|
+
"id": "US-001",
|
|
44
|
+
"title": "[Story title]",
|
|
45
|
+
"description": "As a [user], I want [feature] so that [benefit]",
|
|
46
|
+
"acceptanceCriteria": [
|
|
47
|
+
"Criterion 1",
|
|
48
|
+
"Criterion 2",
|
|
49
|
+
"Typecheck passes"
|
|
50
|
+
],
|
|
51
|
+
"priority": 1,
|
|
52
|
+
"passes": false,
|
|
53
|
+
"notes": ""
|
|
54
|
+
}
|
|
55
|
+
]
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Conversion Rules
|
|
60
|
+
|
|
61
|
+
1. **Each user story becomes one JSON entry**
|
|
62
|
+
2. **IDs**: Sequential (US-001, US-002, etc.)
|
|
63
|
+
3. **Priority**: Based on dependency order (schema → backend → UI)
|
|
64
|
+
4. **All stories**: `passes: false` and empty `notes`
|
|
65
|
+
5. **branchName**: Derive from feature name, kebab-case, prefixed with `ralph/`
|
|
66
|
+
6. **Always add**: "Typecheck passes" to every story
|
|
67
|
+
7. **For UI stories**: Add "Verify in browser using dev-browser skill"
|
|
68
|
+
|
|
69
|
+
### Story Sizing is Critical
|
|
70
|
+
|
|
71
|
+
Each story MUST be completable in ONE Ralph iteration.
|
|
72
|
+
|
|
73
|
+
**Right-sized stories:**
|
|
74
|
+
- Add a database column and migration
|
|
75
|
+
- Add a UI component to an existing page
|
|
76
|
+
- Update a server action with new logic
|
|
77
|
+
- Add a filter dropdown to a list
|
|
78
|
+
|
|
79
|
+
**Too big (must split):**
|
|
80
|
+
- "Build the entire dashboard" → Split into: schema, queries, UI components, filters
|
|
81
|
+
- "Add authentication" → Split into: schema, middleware, login UI, session handling
|
|
82
|
+
|
|
83
|
+
**Rule of thumb:** If you cannot describe the change in 2-3 sentences, it is too big.
|
|
84
|
+
|
|
85
|
+
### Story Ordering
|
|
86
|
+
|
|
87
|
+
Stories execute in `priority` order. Earlier stories must NOT depend on later ones.
|
|
88
|
+
|
|
89
|
+
**Correct order:**
|
|
90
|
+
1. Schema/database changes (migrations)
|
|
91
|
+
2. Server actions / backend logic
|
|
92
|
+
3. UI components that use the backend
|
|
93
|
+
4. Dashboard/summary views that aggregate data
|
|
94
|
+
|
|
95
|
+
### Verification Before Proceeding
|
|
96
|
+
|
|
97
|
+
Before running Ralph, verify:
|
|
98
|
+
- [ ] Previous run archived (if applicable)
|
|
99
|
+
- [ ] Each story is completable in one iteration
|
|
100
|
+
- [ ] Stories are ordered by dependencies
|
|
101
|
+
- [ ] Every story has "Typecheck passes"
|
|
102
|
+
- [ ] UI stories have "Verify in browser using dev-browser skill"
|
|
103
|
+
- [ ] Acceptance criteria are verifiable (not vague)
|
|
104
|
+
|
|
105
|
+
---
|
|
106
|
+
|
|
107
|
+
## Phase 2: Ralph Execution
|
|
108
|
+
|
|
109
|
+
### Step 1: Pre-flight Checks
|
|
110
|
+
|
|
111
|
+
Verify the following before starting:
|
|
112
|
+
|
|
113
|
+
**1. Amp CLI installed**
|
|
114
|
+
```bash
|
|
115
|
+
which amp
|
|
116
|
+
```
|
|
117
|
+
If not found, instruct user to install from https://ampcode.com
|
|
118
|
+
|
|
119
|
+
**2. jq installed**
|
|
120
|
+
```bash
|
|
121
|
+
which jq
|
|
122
|
+
```
|
|
123
|
+
If not found, instruct user to install (brew install jq on macOS)
|
|
124
|
+
|
|
125
|
+
**3. Git working directory clean**
|
|
126
|
+
```bash
|
|
127
|
+
git status --porcelain
|
|
128
|
+
```
|
|
129
|
+
If not clean, ask user to commit or stash changes
|
|
130
|
+
|
|
131
|
+
**4. prd.json exists and is valid**
|
|
132
|
+
```bash
|
|
133
|
+
cat prd.json | jq .
|
|
134
|
+
```
|
|
135
|
+
If invalid, show error and exit
|
|
136
|
+
|
|
137
|
+
### Step 2: Create or Checkout Feature Branch
|
|
138
|
+
|
|
139
|
+
Read `branchName` from `prd.json`:
|
|
140
|
+
```bash
|
|
141
|
+
jq -r '.branchName' prd.json
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
If branch doesn't exist, create it from main:
|
|
145
|
+
```bash
|
|
146
|
+
git checkout -b $(jq -r '.branchName' prd.json)
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
If branch exists, checkout it:
|
|
150
|
+
```bash
|
|
151
|
+
git checkout $(jq -r '.branchName' prd.json)
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### Step 3: Run Ralph Loop
|
|
155
|
+
|
|
156
|
+
Execute the Ralph script:
|
|
157
|
+
```bash
|
|
158
|
+
bash .claude/scripts/ralph.sh [max_iterations]
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
Default is 10 iterations. The script will:
|
|
162
|
+
|
|
163
|
+
1. Spawn a fresh Amp instance with `.claude/scripts/prompt.md`
|
|
164
|
+
2. Amp picks the highest priority story with `passes: false`
|
|
165
|
+
3. Amp implements that single story
|
|
166
|
+
4. Amp runs quality checks (typecheck, lint, test)
|
|
167
|
+
5. If checks pass, Amp commits with message: `feat: [Story ID] - [Story Title]`
|
|
168
|
+
6. Amp updates `prd.json` to set `passes: true` for the story
|
|
169
|
+
7. Amp appends progress to `prd-progress.txt`
|
|
170
|
+
8. Loop repeats until all stories pass or max iterations reached
|
|
171
|
+
|
|
172
|
+
### Step 4: Monitor Progress
|
|
173
|
+
|
|
174
|
+
Show the user how to monitor:
|
|
175
|
+
```bash
|
|
176
|
+
# See which stories are done
|
|
177
|
+
cat prd.json | jq '.userStories[] | {id, title, passes}'
|
|
178
|
+
|
|
179
|
+
# See learnings from previous iterations
|
|
180
|
+
cat prd-progress.txt
|
|
181
|
+
|
|
182
|
+
# Check git history
|
|
183
|
+
git log --oneline -10
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
### Step 5: Completion
|
|
187
|
+
|
|
188
|
+
When ALL stories have `passes: true`, Ralph will output:
|
|
189
|
+
```
|
|
190
|
+
<promise>COMPLETE</promise>
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
And the loop exits successfully.
|
|
194
|
+
|
|
195
|
+
---
|
|
196
|
+
|
|
197
|
+
## Example Session
|
|
198
|
+
|
|
199
|
+
```
|
|
200
|
+
User: /ralph tasks/prd-task-priority.md
|
|
201
|
+
|
|
202
|
+
AI:
|
|
203
|
+
- Converting PRD to prd.json...
|
|
204
|
+
- Created prd.json with 4 user stories
|
|
205
|
+
- Checking prerequisites...
|
|
206
|
+
✓ Amp CLI installed
|
|
207
|
+
✓ jq installed
|
|
208
|
+
✓ Git working directory clean
|
|
209
|
+
- Creating branch ralph/task-priority...
|
|
210
|
+
- Starting Ralph loop...
|
|
211
|
+
|
|
212
|
+
[Ralph executes iterations...]
|
|
213
|
+
|
|
214
|
+
Iteration 1: US-001 - Add priority field to database ✓
|
|
215
|
+
Iteration 2: US-002 - Display priority indicator on task cards ✓
|
|
216
|
+
Iteration 3: US-003 - Add priority selector to task edit ✓
|
|
217
|
+
Iteration 4: US-004 - Filter tasks by priority ✓
|
|
218
|
+
|
|
219
|
+
<promise>COMPLETE</promise>
|
|
220
|
+
|
|
221
|
+
All stories completed! Check prd-progress.txt for details.
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
---
|
|
225
|
+
|
|
226
|
+
**Ready to run Ralph. Provide a PRD path to convert, or I'll use existing prd.json.**
|