Skip to content

Auto-inject --head for in-box gh pr create#15

Merged
madarco merged 1 commit into
mainfrom
agentbox/agentbox-91c4911f
May 28, 2026
Merged

Auto-inject --head for in-box gh pr create#15
madarco merged 1 commit into
mainfrom
agentbox/agentbox-91c4911f

Conversation

@madarco
Copy link
Copy Markdown
Owner

@madarco madarco commented May 28, 2026

Summary

  • agentbox-ctl git pr create (and gh pr create) from inside a box forward args verbatim to the relay, which ran gh pr create in the host repo without --head. The host repo isn't checked out on the box's branch, and agentbox/* branches deliberately get no upstream tracking, so gh aborted with "you must first push the current branch to a remote, or use the --head flag". It only worked when --head was passed manually.
  • Fix: default --head to the box's branch at the relay (the single host-side executor for the in-box path), for create only when the caller didn't already pass --head.
  • Shared helper injectPrCreateHead(op, branch, args) added to @agentbox/relay; the host CLI's existing agentbox git pr create injection now delegates to it, so both surfaces use one rule.
  • Covers docker (registered worktree.branch) and cloud (probed sandbox HEAD).
  • Does not touch the intentional agentbox/* upstream-tracking skip on push.

Test plan

  • pnpm build, pnpm typecheck, pnpm lint clean
  • pnpm test (relay 90 -> 95: new gh.test.ts + no-double-inject case; full suite 335 passing)
  • Updated server.test.ts asserts gh pr create emits --head agentbox/box-one and never double-injects when the caller supplies --head
  • Manual on host (after this is built/installed): from inside a box, agentbox-ctl git push then agentbox-ctl git pr create --base main --title t --body b (no --head) succeeds and the PR head is the box branch

Note: this very PR was opened with an explicit --head because the running host relay predates the fix.


Note

Low Risk
Scoped to gh pr create argv shaping after existing auth/prompt gates; no changes to push upstream tracking or token binding.

Overview
Fixes in-box gh pr create when the relay runs gh in the host repo without --head: GitHub CLI would infer head from the host checkout (wrong branch or missing upstream) and fail unless --head was passed manually.

A shared injectPrCreateHead in @agentbox/relay prepends --head <box branch> for create only, when the caller did not already pass --head and a real branch name exists (not empty / detached HEAD). The host CLI’s agentbox git pr create path now delegates to the same helper instead of duplicating logic.

The relay applies injection on both execution paths: docker uses the registered worktree branch; cloud probes sandbox git rev-parse --abbrev-ref HEAD before injecting. Injection runs after host-initiated token validation so params hashing is unchanged.

New unit tests cover the helper and relay behavior (including no double-inject when --head is supplied).

Reviewed by Cursor Bugbot for commit 53dd191. Configure here.

`agentbox-ctl git pr create` (and `gh pr create`) forward args verbatim to
the relay, which ran `gh pr create` in the host repo without --head. The host
repo isn't on the box's branch and `agentbox/*` branches deliberately get no
upstream tracking, so gh aborted with "you must first push the current branch
to a remote, or use the --head flag".

Default --head to the box branch at the relay (the single host-side executor
for the in-box path), for `create` when the caller didn't pass --head. Mirrors
the host CLI's existing injectPrCreateHead, now shared from @agentbox/relay so
both surfaces use one rule. Covers docker (registered worktree branch) and
cloud (probed sandbox HEAD).
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 53dd191. Configure here.

Comment thread packages/relay/src/gh.ts
): string[] {
if (op !== 'create') return args;
if (!branch || branch === 'HEAD') return args;
if (args.some((a) => a === '--head' || a.startsWith('--head='))) return args;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing -H short-flag detection causes double injection

Medium Severity

The new injectPrCreateHead helper checks for --head and --head= but not -H, which is gh pr create's documented short form for --head. If a caller passes -H feat/x, the function won't detect it and will prepend an additional --head <box-branch>, resulting in conflicting head-branch arguments. The same incomplete check is duplicated in the cloud-path guard in host-actions.ts.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 53dd191. Configure here.

@madarco madarco merged commit 07608ab into main May 28, 2026
2 of 3 checks passed
madarco added a commit that referenced this pull request May 28, 2026
…ized pruneCloud

The orphan-sandbox prune was daytona-only. Generalize pruneDaytona into a
provider-agnostic pruneCloud over a CLOUD_PRUNE_PROVIDERS list so vercel and
hetzner (both previously unwired despite working backend.list()) enumerate
cloud sandboxes and offer to delete the ones missing from state.json.

Closes backlog #15.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant