@blogic-cz/agent-tools 0.14.59 → 0.14.60

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blogic-cz/agent-tools",
3
- "version": "0.14.59",
3
+ "version": "0.14.60",
4
4
  "description": "CLI tools for AI coding agent workflows — GitHub, database, Kubernetes, Azure DevOps, logs, sessions, and audit",
5
5
  "keywords": [
6
6
  "agent",
@@ -520,7 +520,9 @@ export const prMergeCommand = Command.make(
520
520
  Flag.withDefault(false),
521
521
  ),
522
522
  deleteBranch: Flag.boolean("delete-branch").pipe(
523
- Flag.withDescription("Delete branch after merge"),
523
+ Flag.withDescription(
524
+ "Delete the remote branch after merge (local/worktree cleanup is separate)",
525
+ ),
524
526
  Flag.withDefault(DEFAULT_DELETE_BRANCH),
525
527
  ),
526
528
  format: formatOption,
@@ -733,7 +733,7 @@ export const mergePR = Effect.fn("pr.mergePR")(function* (opts: {
733
733
  yield* Console.log(
734
734
  `DRY RUN: Would merge PR #${info.number} "${info.title}" via ${opts.strategy.toUpperCase()}. ` +
735
735
  `Branch \`${info.headRefName}\` → \`${info.baseRefName}\`. ` +
736
- (opts.deleteBranch ? `Branch \`${info.headRefName}\` will be deleted. ` : "") +
736
+ (opts.deleteBranch ? `Remote branch \`${info.headRefName}\` will be deleted. ` : "") +
737
737
  dependentNote +
738
738
  mergeableNote,
739
739
  );
@@ -752,10 +752,9 @@ export const mergePR = Effect.fn("pr.mergePR")(function* (opts: {
752
752
  let willDeleteBranch = opts.deleteBranch;
753
753
  let branchDeleteSkipped = false;
754
754
  const retargetedChildren: number[] = [];
755
+ const repo = opts.deleteBranch ? yield* gh.getRepoInfo() : null;
755
756
 
756
- if (opts.deleteBranch && dependentOpenPrs.length > 0) {
757
- const repo = yield* gh.getRepoInfo();
758
-
757
+ if (opts.deleteBranch && dependentOpenPrs.length > 0 && repo) {
759
758
  for (const child of dependentOpenPrs) {
760
759
  const retargeted = yield* gh
761
760
  .runGh([
@@ -783,10 +782,6 @@ export const mergePR = Effect.fn("pr.mergePR")(function* (opts: {
783
782
 
784
783
  const mergeArgs = ["pr", "merge", String(opts.pr), `--${opts.strategy}`];
785
784
 
786
- if (willDeleteBranch) {
787
- mergeArgs.push("--delete-branch");
788
- }
789
-
790
785
  const mergeResult = yield* gh.runGh(mergeArgs).pipe(
791
786
  Effect.catchTag("GitHubCommandError", (error) => {
792
787
  const stderr = error.stderr.toLowerCase();
@@ -837,6 +832,27 @@ export const mergePR = Effect.fn("pr.mergePR")(function* (opts: {
837
832
 
838
833
  const shaMatch = mergeResult.stdout.match(/([0-9a-f]{7,40})/);
839
834
 
835
+ // `gh pr merge --delete-branch` aborts its remote delete when the head branch is checked out in a
836
+ // worktree; deleting the remote ref explicitly is worktree-independent. Local cleanup is separate.
837
+ if (willDeleteBranch && repo && info.headRefName) {
838
+ const remoteDeleted = yield* gh
839
+ .runGh([
840
+ "api",
841
+ "--method",
842
+ "DELETE",
843
+ `repos/${repo.owner}/${repo.name}/git/refs/heads/${info.headRefName}`,
844
+ ])
845
+ .pipe(
846
+ Effect.as(true),
847
+ Effect.orElseSucceed(() => false),
848
+ );
849
+
850
+ if (!remoteDeleted) {
851
+ willDeleteBranch = false;
852
+ branchDeleteSkipped = true;
853
+ }
854
+ }
855
+
840
856
  const result: MergeResult = {
841
857
  merged: true,
842
858
  strategy: opts.strategy,