@damper/cli 0.9.8 → 0.9.9
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/dist/services/claude.js +42 -27
- package/package.json +1 -1
package/dist/services/claude.js
CHANGED
|
@@ -281,35 +281,48 @@ export async function postTaskFlow(options) {
|
|
|
281
281
|
}
|
|
282
282
|
else if (mergeAction === 'merge') {
|
|
283
283
|
// Merge directly to main — first merge main into feature to resolve conflicts
|
|
284
|
+
const { execa } = await import('execa');
|
|
285
|
+
// Fetch latest main
|
|
284
286
|
try {
|
|
285
|
-
const { execa } = await import('execa');
|
|
286
|
-
// Fetch latest main
|
|
287
287
|
await execa('git', ['fetch', 'origin', 'main'], { cwd, stdio: 'pipe' });
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
288
|
+
}
|
|
289
|
+
catch (err) {
|
|
290
|
+
console.log(pc.red('Failed to fetch origin/main. Check your network connection.\n'));
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
// Step 1: Merge origin/main INTO the feature branch (in worktree)
|
|
294
|
+
console.log(pc.dim('Merging main into feature branch...'));
|
|
295
|
+
let mainMergedIntoFeature = false;
|
|
296
|
+
try {
|
|
297
|
+
await execa('git', ['merge', 'origin/main', '--no-edit'], { cwd, stdio: 'pipe' });
|
|
298
|
+
mainMergedIntoFeature = true;
|
|
299
|
+
console.log(pc.green('✓ Main merged into feature branch (no conflicts)'));
|
|
300
|
+
}
|
|
301
|
+
catch {
|
|
302
|
+
// Merge conflicts — abort and launch Claude to resolve
|
|
303
|
+
console.log(pc.yellow('Merge conflicts detected. Launching Claude to resolve...'));
|
|
304
|
+
try {
|
|
305
|
+
await execa('git', ['merge', '--abort'], { cwd, stdio: 'pipe' });
|
|
306
|
+
}
|
|
307
|
+
catch {
|
|
308
|
+
// merge --abort can fail if repo is in a weird state, reset instead
|
|
309
|
+
console.log(pc.dim('Cleaning up merge state...'));
|
|
310
|
+
await execa('git', ['reset', '--merge'], { cwd, stdio: 'pipe' }).catch(() => { });
|
|
311
|
+
}
|
|
312
|
+
await launchClaudeForMerge({ cwd, apiKey });
|
|
313
|
+
// Verify merge was completed (origin/main should be ancestor of HEAD)
|
|
291
314
|
try {
|
|
292
|
-
await execa('git', ['merge', 'origin/main', '
|
|
315
|
+
await execa('git', ['merge-base', '--is-ancestor', 'origin/main', 'HEAD'], { cwd, stdio: 'pipe' });
|
|
293
316
|
mainMergedIntoFeature = true;
|
|
294
|
-
console.log(pc.green('✓
|
|
317
|
+
console.log(pc.green('✓ Claude resolved merge conflicts'));
|
|
295
318
|
}
|
|
296
319
|
catch {
|
|
297
|
-
|
|
298
|
-
console.log(pc.yellow('Merge conflicts detected. Launching Claude to resolve...'));
|
|
299
|
-
await execa('git', ['merge', '--abort'], { cwd, stdio: 'pipe' });
|
|
300
|
-
await launchClaudeForMerge({ cwd, apiKey });
|
|
301
|
-
// Verify merge was completed (origin/main should be ancestor of HEAD)
|
|
302
|
-
try {
|
|
303
|
-
await execa('git', ['merge-base', '--is-ancestor', 'origin/main', 'HEAD'], { cwd, stdio: 'pipe' });
|
|
304
|
-
mainMergedIntoFeature = true;
|
|
305
|
-
console.log(pc.green('✓ Claude resolved merge conflicts'));
|
|
306
|
-
}
|
|
307
|
-
catch {
|
|
308
|
-
console.log(pc.red('Claude did not complete the merge. Skipping merge to main.\n'));
|
|
309
|
-
}
|
|
320
|
+
console.log(pc.red('Claude did not complete the merge. Skipping merge to main.\n'));
|
|
310
321
|
}
|
|
311
|
-
|
|
312
|
-
|
|
322
|
+
}
|
|
323
|
+
// Step 2: Merge feature → main (should be clean now)
|
|
324
|
+
if (mainMergedIntoFeature) {
|
|
325
|
+
try {
|
|
313
326
|
console.log(pc.dim('Merging feature into main...'));
|
|
314
327
|
await execa('git', ['checkout', 'main'], { cwd: projectRoot, stdio: 'pipe' });
|
|
315
328
|
await execa('git', ['merge', currentBranch, '--no-edit'], { cwd: projectRoot, stdio: 'inherit' });
|
|
@@ -326,9 +339,9 @@ export async function postTaskFlow(options) {
|
|
|
326
339
|
console.log(pc.dim('Skipped push. Run `git push origin main` when ready.\n'));
|
|
327
340
|
}
|
|
328
341
|
}
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
342
|
+
catch (err) {
|
|
343
|
+
console.log(pc.red('Failed to merge feature into main. You may need to resolve this manually.\n'));
|
|
344
|
+
}
|
|
332
345
|
}
|
|
333
346
|
}
|
|
334
347
|
else {
|
|
@@ -538,12 +551,14 @@ export async function launchClaudeForReview(options) {
|
|
|
538
551
|
}
|
|
539
552
|
/**
|
|
540
553
|
* Launch Claude to resolve merge conflicts
|
|
554
|
+
* Uses --allowedTools to restrict Claude to only git/file operations
|
|
555
|
+
* so it doesn't pick up task context and try to work on the task
|
|
541
556
|
*/
|
|
542
557
|
async function launchClaudeForMerge(options) {
|
|
543
558
|
const { cwd, apiKey } = options;
|
|
544
|
-
const prompt = '
|
|
559
|
+
const prompt = 'IMPORTANT: Your ONLY job is to resolve merge conflicts. Do NOT read TASK_CONTEXT.md or work on any task. Run: git merge origin/main --no-edit. If there are conflicts, resolve them, stage, and commit. Do not use any MCP tools.';
|
|
545
560
|
await new Promise((resolve) => {
|
|
546
|
-
const child = spawn('claude', [prompt], {
|
|
561
|
+
const child = spawn('claude', ['--allowedTools', 'Bash,Read,Write,Edit,Glob,Grep', prompt], {
|
|
547
562
|
cwd,
|
|
548
563
|
stdio: 'inherit',
|
|
549
564
|
env: { ...process.env, DAMPER_API_KEY: apiKey },
|