ralph-mcp 1.0.0 → 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/README.md +136 -12
- package/README.zh-CN.md +255 -0
- package/dist/tools/start.js +1 -1
- package/dist/utils/worktree.d.ts +2 -2
- package/dist/utils/worktree.js +27 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,16 +1,23 @@
|
|
|
1
1
|
# Ralph MCP
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/ralph-mcp)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
|
|
3
6
|
MCP server for autonomous PRD execution with Claude Code. Git worktree isolation, progress tracking, auto-merge.
|
|
4
7
|
|
|
5
8
|
Based on [Geoffrey Huntley's Ralph pattern](https://ghuntley.com/ralph/).
|
|
6
9
|
|
|
10
|
+
[中文文档](./README.zh-CN.md)
|
|
11
|
+
|
|
7
12
|
## Features
|
|
8
13
|
|
|
9
14
|
- **PRD Parsing** - Extracts User Stories from markdown PRD files
|
|
10
15
|
- **Git Worktree Isolation** - Each PRD runs in isolated worktree
|
|
16
|
+
- **Background Execution** - Works with Claude Code's Task tool for parallel PRD execution
|
|
11
17
|
- **Progress Tracking** - Real-time status via `ralph_status()`
|
|
12
18
|
- **Auto Merge** - One-click merge with conflict resolution
|
|
13
19
|
- **Notifications** - Windows Toast when PRD completes
|
|
20
|
+
- **State Persistence** - Survives Claude Code restarts (JSON storage)
|
|
14
21
|
|
|
15
22
|
## Installation
|
|
16
23
|
|
|
@@ -74,40 +81,125 @@ Restart Claude Code to load.
|
|
|
74
81
|
|
|
75
82
|
## Usage
|
|
76
83
|
|
|
84
|
+
### Basic Workflow
|
|
85
|
+
|
|
77
86
|
```javascript
|
|
78
|
-
// Start PRD execution
|
|
87
|
+
// 1. Start PRD execution
|
|
79
88
|
ralph_start({ prdPath: "tasks/prd-feature.md" })
|
|
80
89
|
|
|
81
|
-
// Check
|
|
90
|
+
// 2. Check status anytime
|
|
91
|
+
ralph_status()
|
|
92
|
+
|
|
93
|
+
// 3. Merge when complete
|
|
94
|
+
ralph_merge({ branch: "ralph/prd-feature" })
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### Parallel Execution with Claude Code Task Tool
|
|
98
|
+
|
|
99
|
+
Ralph MCP is designed to work with Claude Code's Task tool for parallel PRD execution:
|
|
100
|
+
|
|
101
|
+
```
|
|
102
|
+
1. Analyze PRDs to identify independent tasks that can run in parallel
|
|
103
|
+
2. Start multiple PRDs via ralph_start()
|
|
104
|
+
3. Launch background Task agents for each PRD
|
|
105
|
+
4. Continue chatting - plan next features, review code, etc.
|
|
106
|
+
5. Get Windows Toast notification when PRDs complete
|
|
107
|
+
6. Merge completed PRDs to main via ralph_merge()
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
**Example session:**
|
|
111
|
+
|
|
112
|
+
```
|
|
113
|
+
User: Execute these 3 PRDs in parallel
|
|
114
|
+
|
|
115
|
+
Claude: Let me analyze the PRDs...
|
|
116
|
+
- prd-auth.md (independent)
|
|
117
|
+
- prd-dashboard.md (independent)
|
|
118
|
+
- prd-api.md (independent)
|
|
119
|
+
|
|
120
|
+
All 3 can run in parallel. Starting...
|
|
121
|
+
|
|
122
|
+
[Calls ralph_start() for each PRD]
|
|
123
|
+
[Launches 3 background Task agents]
|
|
124
|
+
|
|
125
|
+
PRDs are running in background. You can continue working.
|
|
126
|
+
I'll notify you when they complete.
|
|
127
|
+
|
|
128
|
+
User: Great, let's plan the next feature while waiting...
|
|
129
|
+
|
|
130
|
+
[Later - Windows Toast notification appears]
|
|
131
|
+
|
|
132
|
+
Claude: All 3 PRDs completed successfully!
|
|
133
|
+
- ralph/prd-auth: 4/4 US ✓
|
|
134
|
+
- ralph/prd-dashboard: 3/3 US ✓
|
|
135
|
+
- ralph/prd-api: 5/5 US ✓
|
|
136
|
+
|
|
137
|
+
Ready to merge?
|
|
138
|
+
|
|
139
|
+
User: Yes, merge all
|
|
140
|
+
|
|
141
|
+
Claude: [Calls ralph_merge() for each branch]
|
|
142
|
+
All PRDs merged to main successfully.
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### API Reference
|
|
146
|
+
|
|
147
|
+
```javascript
|
|
148
|
+
// Start PRD execution (returns agent prompt)
|
|
149
|
+
ralph_start({ prdPath: "tasks/prd-feature.md" })
|
|
150
|
+
|
|
151
|
+
// View all PRD status
|
|
82
152
|
ralph_status()
|
|
83
153
|
|
|
84
154
|
// Get single PRD details
|
|
85
155
|
ralph_get({ branch: "ralph/prd-feature" })
|
|
86
156
|
|
|
87
|
-
// Update
|
|
157
|
+
// Update User Story status (called by agent)
|
|
88
158
|
ralph_update({ branch: "ralph/prd-feature", storyId: "US-1", passes: true, notes: "..." })
|
|
89
159
|
|
|
90
|
-
//
|
|
160
|
+
// Stop execution
|
|
161
|
+
ralph_stop({ branch: "ralph/prd-feature" })
|
|
162
|
+
|
|
163
|
+
// Merge to main
|
|
91
164
|
ralph_merge({ branch: "ralph/prd-feature" })
|
|
165
|
+
|
|
166
|
+
// Record Task agent ID (for tracking)
|
|
167
|
+
ralph_set_agent_id({ branch: "ralph/prd-feature", agentTaskId: "abc123" })
|
|
92
168
|
```
|
|
93
169
|
|
|
94
170
|
## PRD Format
|
|
95
171
|
|
|
96
|
-
Ralph parses markdown PRD files
|
|
172
|
+
Ralph parses markdown PRD files. Example:
|
|
97
173
|
|
|
98
174
|
```markdown
|
|
99
|
-
|
|
175
|
+
---
|
|
176
|
+
title: User Authentication
|
|
177
|
+
priority: high
|
|
178
|
+
---
|
|
179
|
+
|
|
180
|
+
# User Authentication
|
|
181
|
+
|
|
182
|
+
Implement user login and registration.
|
|
100
183
|
|
|
101
184
|
## User Stories
|
|
102
185
|
|
|
103
|
-
### US-1:
|
|
186
|
+
### US-1: User Registration
|
|
187
|
+
|
|
188
|
+
Users can create new accounts.
|
|
104
189
|
|
|
105
190
|
**Acceptance Criteria:**
|
|
106
|
-
- [ ]
|
|
107
|
-
- [ ]
|
|
191
|
+
- [ ] Email validation
|
|
192
|
+
- [ ] Password strength check
|
|
193
|
+
- [ ] Confirmation email sent
|
|
194
|
+
|
|
195
|
+
### US-2: User Login
|
|
108
196
|
|
|
109
|
-
|
|
110
|
-
|
|
197
|
+
Users can log into their accounts.
|
|
198
|
+
|
|
199
|
+
**Acceptance Criteria:**
|
|
200
|
+
- [ ] Email/password authentication
|
|
201
|
+
- [ ] Remember me option
|
|
202
|
+
- [ ] Forgot password flow
|
|
111
203
|
```
|
|
112
204
|
|
|
113
205
|
## Conflict Resolution
|
|
@@ -123,9 +215,41 @@ Ralph parses markdown PRD files with User Stories:
|
|
|
123
215
|
|
|
124
216
|
## Data Storage
|
|
125
217
|
|
|
126
|
-
- State: `~/.ralph/state.json`
|
|
218
|
+
- State: `~/.ralph/state.json`
|
|
127
219
|
- Logs: `~/.ralph/logs/`
|
|
128
220
|
|
|
221
|
+
Override data directory with `RALPH_DATA_DIR` environment variable.
|
|
222
|
+
|
|
223
|
+
## Advanced Options
|
|
224
|
+
|
|
225
|
+
### ralph_start options
|
|
226
|
+
|
|
227
|
+
| Option | Default | Description |
|
|
228
|
+
|--------|---------|-------------|
|
|
229
|
+
| `prdPath` | required | Path to PRD markdown file |
|
|
230
|
+
| `projectRoot` | cwd | Project root directory |
|
|
231
|
+
| `worktree` | `true` | Create isolated git worktree |
|
|
232
|
+
| `autoStart` | `true` | Return agent prompt for immediate execution |
|
|
233
|
+
| `autoMerge` | `false` | Auto-merge when all stories pass |
|
|
234
|
+
| `notifyOnComplete` | `true` | Show Windows notification on completion |
|
|
235
|
+
| `onConflict` | `"agent"` | Conflict resolution: `auto_theirs`, `auto_ours`, `notify`, `agent` |
|
|
236
|
+
|
|
237
|
+
### Example with options
|
|
238
|
+
|
|
239
|
+
```javascript
|
|
240
|
+
ralph_start({
|
|
241
|
+
prdPath: "tasks/prd-feature.md",
|
|
242
|
+
autoMerge: true, // Auto-merge when done
|
|
243
|
+
notifyOnComplete: true, // Windows Toast notification
|
|
244
|
+
onConflict: "auto_theirs" // Prefer main on conflicts
|
|
245
|
+
})
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
## Credits
|
|
249
|
+
|
|
250
|
+
- [Geoffrey Huntley](https://ghuntley.com/) - Original Ralph pattern
|
|
251
|
+
- [Anthropic](https://anthropic.com/) - Claude Code & MCP protocol
|
|
252
|
+
|
|
129
253
|
## License
|
|
130
254
|
|
|
131
255
|
MIT
|
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
# Ralph MCP
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/ralph-mcp)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
|
|
6
|
+
用于 Claude Code 自主执行 PRD 的 MCP 服务器。支持 Git worktree 隔离、进度追踪、自动合并。
|
|
7
|
+
|
|
8
|
+
基于 [Geoffrey Huntley 的 Ralph 模式](https://ghuntley.com/ralph/)。
|
|
9
|
+
|
|
10
|
+
[English](./README.md)
|
|
11
|
+
|
|
12
|
+
## 特性
|
|
13
|
+
|
|
14
|
+
- **PRD 解析** - 从 markdown PRD 文件中提取 User Stories
|
|
15
|
+
- **Git Worktree 隔离** - 每个 PRD 在独立的 worktree 中运行
|
|
16
|
+
- **后台执行** - 配合 Claude Code 的 Task 工具并行执行多个 PRD
|
|
17
|
+
- **进度追踪** - 通过 `ralph_status()` 实时查看状态
|
|
18
|
+
- **自动合并** - 一键合并,支持冲突解决策略
|
|
19
|
+
- **完成通知** - PRD 完成时弹出 Windows Toast 通知
|
|
20
|
+
- **状态持久化** - 重启 Claude Code 不丢失状态(JSON 存储)
|
|
21
|
+
|
|
22
|
+
## 安装
|
|
23
|
+
|
|
24
|
+
### 从 npm 安装
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
npm install -g ralph-mcp
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### 从源码安装
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
git clone https://github.com/G0d2i11a/ralph-mcp.git
|
|
34
|
+
cd ralph-mcp
|
|
35
|
+
npm install
|
|
36
|
+
npm run build
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## 配置
|
|
40
|
+
|
|
41
|
+
添加到 `~/.claude/mcp.json`:
|
|
42
|
+
|
|
43
|
+
```json
|
|
44
|
+
{
|
|
45
|
+
"mcpServers": {
|
|
46
|
+
"ralph": {
|
|
47
|
+
"command": "npx",
|
|
48
|
+
"args": ["ralph-mcp"]
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
或者从源码安装时:
|
|
55
|
+
|
|
56
|
+
```json
|
|
57
|
+
{
|
|
58
|
+
"mcpServers": {
|
|
59
|
+
"ralph": {
|
|
60
|
+
"command": "node",
|
|
61
|
+
"args": ["/path/to/ralph-mcp/dist/index.js"]
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
重启 Claude Code 生效。
|
|
68
|
+
|
|
69
|
+
## 工具列表
|
|
70
|
+
|
|
71
|
+
| 工具 | 说明 |
|
|
72
|
+
|------|------|
|
|
73
|
+
| `ralph_start` | 启动 PRD 执行(解析 PRD,创建 worktree,返回 agent prompt) |
|
|
74
|
+
| `ralph_status` | 查看所有 PRD 执行状态 |
|
|
75
|
+
| `ralph_get` | 获取单个 PRD 详情 |
|
|
76
|
+
| `ralph_update` | 更新 User Story 状态(agent 调用) |
|
|
77
|
+
| `ralph_stop` | 停止执行 |
|
|
78
|
+
| `ralph_merge` | 合并到 main + 清理 worktree |
|
|
79
|
+
| `ralph_merge_queue` | 管理串行合并队列 |
|
|
80
|
+
| `ralph_set_agent_id` | 记录 Task agent ID |
|
|
81
|
+
|
|
82
|
+
## 使用方法
|
|
83
|
+
|
|
84
|
+
### 基本流程
|
|
85
|
+
|
|
86
|
+
```javascript
|
|
87
|
+
// 1. 启动 PRD 执行
|
|
88
|
+
ralph_start({ prdPath: "tasks/prd-feature.md" })
|
|
89
|
+
|
|
90
|
+
// 2. 随时查看状态
|
|
91
|
+
ralph_status()
|
|
92
|
+
|
|
93
|
+
// 3. 完成后合并
|
|
94
|
+
ralph_merge({ branch: "ralph/prd-feature" })
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### 配合 Claude Code Task 工具并行执行
|
|
98
|
+
|
|
99
|
+
Ralph MCP 设计为配合 Claude Code 的 Task 工具实现并行 PRD 执行:
|
|
100
|
+
|
|
101
|
+
```
|
|
102
|
+
1. 分析 PRD,识别可以并行执行的独立任务
|
|
103
|
+
2. 通过 ralph_start() 启动多个 PRD
|
|
104
|
+
3. 为每个 PRD 启动后台 Task agent
|
|
105
|
+
4. 继续聊天 - 规划下一个功能、审查代码等
|
|
106
|
+
5. PRD 完成时收到 Windows Toast 通知
|
|
107
|
+
6. 通过 ralph_merge() 将完成的 PRD 合并到 main
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
**示例会话:**
|
|
111
|
+
|
|
112
|
+
```
|
|
113
|
+
用户: 并行执行这 3 个 PRD
|
|
114
|
+
|
|
115
|
+
Claude: 让我分析一下这些 PRD...
|
|
116
|
+
- prd-auth.md(独立)
|
|
117
|
+
- prd-dashboard.md(独立)
|
|
118
|
+
- prd-api.md(独立)
|
|
119
|
+
|
|
120
|
+
3 个都可以并行执行。正在启动...
|
|
121
|
+
|
|
122
|
+
[为每个 PRD 调用 ralph_start()]
|
|
123
|
+
[启动 3 个后台 Task agent]
|
|
124
|
+
|
|
125
|
+
PRD 正在后台运行。你可以继续其他工作。
|
|
126
|
+
完成后我会通知你。
|
|
127
|
+
|
|
128
|
+
用户: 好的,等待的时候我们来规划下一个功能...
|
|
129
|
+
|
|
130
|
+
[稍后 - Windows Toast 通知弹出]
|
|
131
|
+
|
|
132
|
+
Claude: 3 个 PRD 全部完成!
|
|
133
|
+
- ralph/prd-auth: 4/4 US ✓
|
|
134
|
+
- ralph/prd-dashboard: 3/3 US ✓
|
|
135
|
+
- ralph/prd-api: 5/5 US ✓
|
|
136
|
+
|
|
137
|
+
准备合并吗?
|
|
138
|
+
|
|
139
|
+
用户: 是的,全部合并
|
|
140
|
+
|
|
141
|
+
Claude: [为每个分支调用 ralph_merge()]
|
|
142
|
+
所有 PRD 已成功合并到 main。
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### API 参考
|
|
146
|
+
|
|
147
|
+
```javascript
|
|
148
|
+
// 启动 PRD 执行(返回 agent prompt)
|
|
149
|
+
ralph_start({ prdPath: "tasks/prd-feature.md" })
|
|
150
|
+
|
|
151
|
+
// 查看所有 PRD 状态
|
|
152
|
+
ralph_status()
|
|
153
|
+
|
|
154
|
+
// 获取单个 PRD 详情
|
|
155
|
+
ralph_get({ branch: "ralph/prd-feature" })
|
|
156
|
+
|
|
157
|
+
// 更新 User Story 状态(agent 调用)
|
|
158
|
+
ralph_update({ branch: "ralph/prd-feature", storyId: "US-1", passes: true, notes: "..." })
|
|
159
|
+
|
|
160
|
+
// 停止执行
|
|
161
|
+
ralph_stop({ branch: "ralph/prd-feature" })
|
|
162
|
+
|
|
163
|
+
// 合并到 main
|
|
164
|
+
ralph_merge({ branch: "ralph/prd-feature" })
|
|
165
|
+
|
|
166
|
+
// 记录 Task agent ID(用于追踪)
|
|
167
|
+
ralph_set_agent_id({ branch: "ralph/prd-feature", agentTaskId: "abc123" })
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
## PRD 格式
|
|
171
|
+
|
|
172
|
+
Ralph 解析 markdown 格式的 PRD 文件。示例:
|
|
173
|
+
|
|
174
|
+
```markdown
|
|
175
|
+
---
|
|
176
|
+
title: 用户认证
|
|
177
|
+
priority: high
|
|
178
|
+
---
|
|
179
|
+
|
|
180
|
+
# 用户认证
|
|
181
|
+
|
|
182
|
+
实现用户登录和注册功能。
|
|
183
|
+
|
|
184
|
+
## User Stories
|
|
185
|
+
|
|
186
|
+
### US-1: 用户注册
|
|
187
|
+
|
|
188
|
+
用户可以创建新账户。
|
|
189
|
+
|
|
190
|
+
**Acceptance Criteria:**
|
|
191
|
+
- [ ] 邮箱验证
|
|
192
|
+
- [ ] 密码强度检查
|
|
193
|
+
- [ ] 发送确认邮件
|
|
194
|
+
|
|
195
|
+
### US-2: 用户登录
|
|
196
|
+
|
|
197
|
+
用户可以登录账户。
|
|
198
|
+
|
|
199
|
+
**Acceptance Criteria:**
|
|
200
|
+
- [ ] 邮箱/密码认证
|
|
201
|
+
- [ ] 记住我选项
|
|
202
|
+
- [ ] 忘记密码流程
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
## 冲突解决
|
|
206
|
+
|
|
207
|
+
`ralph_merge` 支持以下策略:
|
|
208
|
+
|
|
209
|
+
| 策略 | 行为 |
|
|
210
|
+
|------|------|
|
|
211
|
+
| `auto_theirs` | `git merge -X theirs`,优先 main |
|
|
212
|
+
| `auto_ours` | `git merge -X ours`,优先 branch |
|
|
213
|
+
| `notify` | 暂停,通知用户手动处理 |
|
|
214
|
+
| `agent` | 启动 merge subagent 解决冲突(默认) |
|
|
215
|
+
|
|
216
|
+
## 数据存储
|
|
217
|
+
|
|
218
|
+
- 状态文件:`~/.ralph/state.json`
|
|
219
|
+
- 日志目录:`~/.ralph/logs/`
|
|
220
|
+
|
|
221
|
+
可通过 `RALPH_DATA_DIR` 环境变量覆盖数据目录。
|
|
222
|
+
|
|
223
|
+
## 高级选项
|
|
224
|
+
|
|
225
|
+
### ralph_start 参数
|
|
226
|
+
|
|
227
|
+
| 参数 | 默认值 | 说明 |
|
|
228
|
+
|------|--------|------|
|
|
229
|
+
| `prdPath` | 必填 | PRD markdown 文件路径 |
|
|
230
|
+
| `projectRoot` | 当前目录 | 项目根目录 |
|
|
231
|
+
| `worktree` | `true` | 创建隔离的 git worktree |
|
|
232
|
+
| `autoStart` | `true` | 返回 agent prompt 以便立即执行 |
|
|
233
|
+
| `autoMerge` | `false` | 所有 story 通过后自动合并 |
|
|
234
|
+
| `notifyOnComplete` | `true` | 完成时显示 Windows 通知 |
|
|
235
|
+
| `onConflict` | `"agent"` | 冲突解决策略:`auto_theirs`, `auto_ours`, `notify`, `agent` |
|
|
236
|
+
|
|
237
|
+
### 带参数示例
|
|
238
|
+
|
|
239
|
+
```javascript
|
|
240
|
+
ralph_start({
|
|
241
|
+
prdPath: "tasks/prd-feature.md",
|
|
242
|
+
autoMerge: true, // 完成后自动合并
|
|
243
|
+
notifyOnComplete: true, // Windows Toast 通知
|
|
244
|
+
onConflict: "auto_theirs" // 冲突时优先 main
|
|
245
|
+
})
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
## 致谢
|
|
249
|
+
|
|
250
|
+
- [Geoffrey Huntley](https://ghuntley.com/) - 原始 Ralph 模式
|
|
251
|
+
- [Anthropic](https://anthropic.com/) - Claude Code 和 MCP 协议
|
|
252
|
+
|
|
253
|
+
## 许可证
|
|
254
|
+
|
|
255
|
+
MIT
|
package/dist/tools/start.js
CHANGED
|
@@ -10,7 +10,7 @@ export const startInputSchema = z.object({
|
|
|
10
10
|
projectRoot: z.string().optional().describe("Project root directory (defaults to cwd)"),
|
|
11
11
|
worktree: z.boolean().default(true).describe("Create a worktree for isolation"),
|
|
12
12
|
autoStart: z.boolean().default(true).describe("Generate agent prompt for auto-start"),
|
|
13
|
-
autoMerge: z.boolean().default(
|
|
13
|
+
autoMerge: z.boolean().default(true).describe("Auto add to merge queue when all stories pass"),
|
|
14
14
|
notifyOnComplete: z.boolean().default(true).describe("Show Windows notification when all stories complete"),
|
|
15
15
|
onConflict: z
|
|
16
16
|
.enum(["auto_theirs", "auto_ours", "notify", "agent"])
|
package/dist/utils/worktree.d.ts
CHANGED
|
@@ -8,9 +8,9 @@ export interface WorktreeInfo {
|
|
|
8
8
|
*/
|
|
9
9
|
export declare function createWorktree(projectRoot: string, branch: string): Promise<string>;
|
|
10
10
|
/**
|
|
11
|
-
* Remove a git worktree
|
|
11
|
+
* Remove a git worktree and optionally delete the branch
|
|
12
12
|
*/
|
|
13
|
-
export declare function removeWorktree(projectRoot: string, worktreePath: string): Promise<void>;
|
|
13
|
+
export declare function removeWorktree(projectRoot: string, worktreePath: string, deleteBranch?: boolean): Promise<void>;
|
|
14
14
|
/**
|
|
15
15
|
* List all worktrees
|
|
16
16
|
*/
|
package/dist/utils/worktree.js
CHANGED
|
@@ -28,16 +28,35 @@ export async function createWorktree(projectRoot, branch) {
|
|
|
28
28
|
return worktreePath;
|
|
29
29
|
}
|
|
30
30
|
/**
|
|
31
|
-
* Remove a git worktree
|
|
31
|
+
* Remove a git worktree and optionally delete the branch
|
|
32
32
|
*/
|
|
33
|
-
export async function removeWorktree(projectRoot, worktreePath) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
export async function removeWorktree(projectRoot, worktreePath, deleteBranch = true) {
|
|
34
|
+
// Get branch name before removing worktree
|
|
35
|
+
let branchToDelete = null;
|
|
36
|
+
if (deleteBranch) {
|
|
37
|
+
const worktrees = listWorktrees(projectRoot);
|
|
38
|
+
const worktree = worktrees.find((w) => w.path === worktreePath);
|
|
39
|
+
if (worktree?.branch) {
|
|
40
|
+
branchToDelete = worktree.branch;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (existsSync(worktreePath)) {
|
|
44
|
+
await execAsync(`git worktree remove "${worktreePath}" --force`, {
|
|
45
|
+
cwd: projectRoot,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
// Delete the branch after worktree is removed
|
|
49
|
+
if (branchToDelete) {
|
|
50
|
+
try {
|
|
51
|
+
await execAsync(`git branch -D "${branchToDelete}"`, {
|
|
52
|
+
cwd: projectRoot,
|
|
53
|
+
});
|
|
54
|
+
console.log(`Deleted branch: ${branchToDelete}`);
|
|
55
|
+
}
|
|
56
|
+
catch (e) {
|
|
57
|
+
console.error(`Failed to delete branch ${branchToDelete}:`, e);
|
|
58
|
+
}
|
|
37
59
|
}
|
|
38
|
-
await execAsync(`git worktree remove "${worktreePath}" --force`, {
|
|
39
|
-
cwd: projectRoot,
|
|
40
|
-
});
|
|
41
60
|
}
|
|
42
61
|
/**
|
|
43
62
|
* List all worktrees
|
package/package.json
CHANGED