Skip to content

CLI: PR-aware upload context — concrete nudge, auto-default, and post-PR promote hint - #705

Merged
Zach Dunn (zachdunn) merged 1 commit into
mainfrom
claude/700-pr-aware-upload-context
Aug 18, 2026
Merged

CLI: PR-aware upload context — concrete nudge, auto-default, and post-PR promote hint#705
Zach Dunn (zachdunn) merged 1 commit into
mainfrom
claude/700-pr-aware-upload-context

Conversation

@zachdunn

Copy link
Copy Markdown
Member

Closes #700.

Three upgrades to the packages/uploads CLI's PR-context handling for bare uploads, in the issue's order of increasing ambition.

1. Concrete, machine-readable nudge

The existing bare-put nudge (#393) now names the actual open PR and appends a ready-made follow-up command naming the actual uploaded key(s):

note: on branch feature/thing (PR #1250 open) — rerun with --pr 1250 for a
stable key plus a managed comment that collects this PR's media, or stage
pre-PR files with: uploads attach <file> --branch. Already uploaded?
uploads attach --pr 1250 f/abc123.webp

It reuses the existing best-effort, 3s-bounded gh pr view lookup. It's now surfaced in the hint field for --format json and in the local stdio MCP put/screenshot tool responses, not just stderr. Same suppression as before (--quiet, UPLOADS_NO_NUDGE=1) and the same hint-slot precedence (a binding warning still wins where both could fire).

2. Auto-assume PR context (default behavior change)

When a bare put/screenshot runs on a branch that maps to exactly one open PR, it now behaves as if --pr <n> had been passed — stable gh/ key, managed comment sync — instead of the #403/#469 branch-staging default.

  • Opt out per-call with --no-pr, or globally with UPLOADS_NO_AUTO_PR=1 (env var and config-file key, alongside UPLOADS_NO_NUDGE etc.).
  • Never fires when any explicit destination flag is set (--pr/--issue/--branch/--key/--ref/--prefix/--destination), outside a git repo, on the default branch, with --no-git, or when the PR lookup fails/times out — those cases fall back to the existing staging/dated-layout behavior, silently.
  • put and screenshot (CLI and local stdio MCP tools) are all consistent.
  • A one-line note announces it when it fires, in the same places as the nudge above (stderr, --format json hint, MCP tool response).

Decisions on the issue's open questions

  • Opt-out vs. suggest-only per issue CLI: PR-aware upload context — concrete nudge, auto-default, and post-PR promote hint #700's question 1: went with opt-out (auto-apply by default) for both put and screenshot, not suggest-only for put. The branch→PR mapping via gh pr view <branch> is already unambiguous (one open PR per branch, or none) — there's no "ambiguous, more than one" state to worry about, and the fallback triggers (explicit flags, --no-pr, no PR found) cover the "this upload doesn't belong to the PR" cases well enough that suggest-only felt like it would under-deliver on the issue's actual motivating case (buildinternet/sunny#1250).
  • Private repos: no special-cased guard added — the existing gh/private/ prefix resolution (resolveGhPrefixSafe) already applies uniformly to any gh/ key, whether reached via explicit --pr or the new auto-PR path. Auto-PR doesn't change what "attaching to this PR" means, just how often it happens automatically.
  • Explicit --pr/--issue always wins, never fires outside git: implemented as specified.

3. Post-PR-creation promote suggestion

uploads hook pre-pr-screenshot (the existing gh pr create PreToolUse hook) now also suggests promoting staged-but-unattached files when it detects them (gh.status=staged) ahead of the PR being created:

2 files staged for branch 'feature/thing' on uploads.sh aren't attached to a
pull request yet. Once this PR opens, run `uploads attach --promote --pr <num>`
(or a bare `uploads attach --promote`, which infers the PR from the branch)
to collect them into the managed attachments comment.

This previously stayed silent whenever anything was already staged. The existing "stage screenshots first" advisory (for the no-staged-content case) is unchanged. Same fail-open contract (UPLOADS_HOOK_DISABLE=1, silent on any error).

Tests

Added coverage for all three behaviors:

  • packages/uploads/test/commands-put.test.ts — auto-PR context describe block (fires, opts out both ways, never fires with explicit flags/on default branch/with --no-git, falls back when no PR)
  • packages/uploads/test/commands-screenshot.test.ts — same matrix for screenshot
  • packages/uploads/test/mcp.test.ts, test/mcp-screenshot.test.ts — local stdio MCP put/screenshot tool auto-PR + hint field
  • packages/uploads/test/config-put-defaults.test.tsUPLOADS_NO_AUTO_PR config/env resolution
  • packages/uploads/test/hook-pre-pr-screenshot.test.ts — promote suggestion (singular/plural wording, fork note, fires even without UI-file changes)

pnpm test (root, all packages) and pnpm typecheck both pass.

Docs

docs/cli.md documents the auto-PR default, its opt-outs, the concrete nudge, and the hook's new promote suggestion.

Not requesting a CodeRabbit review for this one.

Three upgrades to the bare-upload flow:

1. Concrete nudge: the bare-put/screenshot nudge (#393) now names the
   actual open PR and a ready-made follow-up command naming the actual
   uploaded key(s) — surfaced in the `hint` field for --format json and
   in the local stdio MCP put/screenshot tool responses, not just stderr.

2. Auto-PR context (default behavior change): a bare put/screenshot on a
   git branch that maps to exactly one open PR now behaves as if --pr <n>
   had been passed (stable key, managed comment sync) instead of the
   #403/#469 branch-staging default. Opt out with --no-pr or
   UPLOADS_NO_AUTO_PR=1 (env/config). Never fires with any explicit
   destination flag, outside a git repo, on the default branch, with
   --no-git, or when no single open PR resolves.

3. uploads hook pre-pr-screenshot now suggests promoting
   staged-but-unattached files (uploads attach --promote --pr <num>)
   ahead of gh pr create, alongside its existing "stage first" advisory.

Adds a changeset and tests for all three behaviors across the CLI
(put/screenshot) and the local stdio MCP tools.
@changeset-bot

changeset-bot Bot commented Aug 18, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 47b67c8

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@buildinternet/uploads Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai

coderabbitai Bot commented Aug 18, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are limited based on label configuration.

🏷️ Required labels (at least one) (2)
  • coderabbit:review
  • review
🚫 Excluded labels (none allowed) (1)
  • wip

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: d4b8d6e8-f462-4b8c-bc32-4533e7deac09

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
uploads-auth 47b67c8 Commit Preview URL

Branch Preview URL
Aug 18 2026, 10:38 PM

@zachdunn
Zach Dunn (zachdunn) merged commit e62b445 into main Aug 18, 2026
4 checks passed
@zachdunn
Zach Dunn (zachdunn) deleted the claude/700-pr-aware-upload-context branch August 18, 2026 22:52
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.

CLI: PR-aware upload context — concrete nudge, auto-default, and post-PR promote hint

1 participant