Commit 5e50fe7
authored
[refactor] Extract shared service layer between CLI and MCP (#83)
* [refactor] Add operations foundation: ProgressFunc, deps helpers, ResolveMainBranch
Phase 0 of service layer extraction (#70, #81):
- Add ProgressFunc type and nil-safe notify helper for operation progress
- Move deps install helpers (InstallDeps, InstallDepsPreferSource,
WorktreePathsExcluding, RunPostCreateHooks) from cmd to operations
- Extract ResolveMainBranch into operations with configDefault parameter
* [refactor] Extract Remove operation into shared service layer
Phase 1 of service layer extraction (#70, #81):
- Add RemoveWorktree operation with RemoveResult struct
- Add removeAndCleanup private helper (used by remove, merge, clean)
- Convert cmd/remove.go to thin wrapper over operations
- Convert internal/mcp/tool_remove.go to thin wrapper over operations
* [refactor] Extract clean operations into shared service layer
Move FindMergedCandidates, FindStaleCandidates, and RemoveCandidates
from inline implementations in cmd/clean.go and mcp/tool_clean.go
into internal/operations/clean.go. Both CLI and MCP layers now call
the shared operations, keeping only formatting and output logic.
Also removes the force parameter from removeAndCleanup since all
callers pass false.
Phase 2 of #70 / #81
* [refactor] Extract merge operation into shared service layer
Move worktree resolution, concurrent dirty checks, merge execution,
and auto-cleanup logic from cmd/merge.go and mcp/tool_merge.go into
operations.MergeWorktree. Both layers now build MergeParams, call the
shared operation, and format the MergeResult for their output format.
Also removes checkMergeDirty from MCP (now handled by operations) and
fixes the dirtyResult type reference in cmd/merge_bench_test.go.
Phase 3 of #70 / #81
* [refactor] Phase 4: Extract Add operation into operations package
Move worktree creation logic from cmd/add.go and internal/mcp/tool_add.go
into internal/operations/add.go. Both layers are now thin wrappers.
Also moves deps/hooks helpers (installDeps, installDepsPreferSource,
runHooks, worktreePathsExcluding) into operations/deps_install.go,
updating cmd/duplicate.go and cmd/restore.go to use the shared functions.
* [refactor] Phase 5: Consolidate resolveMainBranch via operations
Remove duplicate resolveMainBranch from internal/mcp/tool_list.go.
Both cmd and MCP layers now delegate to operations.ResolveMainBranch.
* [test] Add coverage tests for operations package
Cover previously untested paths: InstallDeps/InstallDepsPreferSource
no-modules early return, RunPostCreateHooks, AddWorktree deps/hooks
branches, checkDirty error paths, FindMergedCandidates squash-merge
error, FindStaleCandidates commit-time error.
Brings total coverage from 96.4% to 97.1%.1 parent 146bccc commit 5e50fe7
35 files changed
Lines changed: 2048 additions & 1729 deletions
File tree
- cmd
- internal
- mcp
- operations
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
6 | 5 | | |
7 | 6 | | |
8 | 7 | | |
9 | | - | |
10 | | - | |
11 | 8 | | |
12 | 9 | | |
13 | | - | |
| 10 | + | |
14 | 11 | | |
15 | 12 | | |
16 | 13 | | |
| |||
55 | 52 | | |
56 | 53 | | |
57 | 54 | | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
| 55 | + | |
| 56 | + | |
74 | 57 | | |
75 | 58 | | |
76 | 59 | | |
| |||
81 | 64 | | |
82 | 65 | | |
83 | 66 | | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
88 | 70 | | |
89 | 71 | | |
90 | | - | |
91 | | - | |
92 | | - | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
93 | 85 | | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
| 86 | + | |
115 | 87 | | |
116 | 88 | | |
117 | | - | |
118 | | - | |
119 | 89 | | |
120 | 90 | | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
125 | 95 | | |
126 | | - | |
127 | | - | |
| 96 | + | |
| 97 | + | |
128 | 98 | | |
129 | 99 | | |
130 | | - | |
131 | | - | |
| 100 | + | |
| 101 | + | |
132 | 102 | | |
133 | 103 | | |
134 | 104 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
8 | 7 | | |
9 | 8 | | |
10 | 9 | | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
23 | 22 | | |
24 | 23 | | |
25 | 24 | | |
26 | 25 | | |
27 | 26 | | |
28 | 27 | | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | 28 | | |
40 | 29 | | |
41 | 30 | | |
| |||
127 | 116 | | |
128 | 117 | | |
129 | 118 | | |
130 | | - | |
| 119 | + | |
131 | 120 | | |
132 | 121 | | |
133 | 122 | | |
| |||
150 | 139 | | |
151 | 140 | | |
152 | 141 | | |
153 | | - | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
154 | 148 | | |
155 | 149 | | |
156 | 150 | | |
157 | 151 | | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | | - | |
181 | | - | |
182 | | - | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
193 | | - | |
194 | | - | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | | - | |
200 | | - | |
201 | | - | |
202 | | - | |
203 | | - | |
204 | | - | |
205 | | - | |
206 | | - | |
207 | | - | |
208 | | - | |
209 | | - | |
210 | | - | |
211 | | - | |
212 | | - | |
213 | | - | |
214 | | - | |
215 | | - | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | | - | |
220 | | - | |
221 | | - | |
222 | | - | |
223 | | - | |
224 | | - | |
225 | | - | |
226 | | - | |
227 | | - | |
228 | | - | |
229 | 152 | | |
230 | 153 | | |
231 | 154 | | |
| |||
246 | 169 | | |
247 | 170 | | |
248 | 171 | | |
249 | | - | |
| 172 | + | |
250 | 173 | | |
251 | 174 | | |
252 | 175 | | |
| |||
268 | 191 | | |
269 | 192 | | |
270 | 193 | | |
271 | | - | |
| 194 | + | |
272 | 195 | | |
273 | | - | |
| 196 | + | |
274 | 197 | | |
275 | 198 | | |
276 | | - | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
277 | 205 | | |
278 | 206 | | |
279 | 207 | | |
280 | 208 | | |
281 | | - | |
282 | | - | |
283 | | - | |
284 | | - | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
285 | 225 | | |
| 226 | + | |
286 | 227 | | |
287 | | - | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
288 | 235 | | |
289 | | - | |
290 | | - | |
291 | | - | |
292 | | - | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
293 | 240 | | |
294 | 241 | | |
295 | | - | |
296 | | - | |
297 | | - | |
298 | | - | |
299 | | - | |
300 | | - | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
301 | 247 | | |
302 | 248 | | |
303 | | - | |
304 | 249 | | |
305 | 250 | | |
306 | | - | |
307 | | - | |
308 | | - | |
309 | | - | |
310 | | - | |
311 | | - | |
312 | | - | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
313 | 257 | | |
| 258 | + | |
314 | 259 | | |
0 commit comments