Skip to content

feat(review): default --to to HEAD when only --from is given - #1936

Merged
lizhengfeng101 merged 2 commits into
alibaba:mainfrom
Walternater:feat/default-to-head
Nov 15, 2026
Merged

lizhengfeng101 merged 2 commits into
alibaba:mainfrom
Walternater:feat/default-to-head

Conversation

@Walternater

@Walternater Walternater commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Default a missing --to to HEAD when --from is supplied in all three commands:

  • ocr review --from main
  • ocr delegate preview --from main
  • ocr delegate rule --from main <path...>

Each shorthand behaves like its explicit --to HEAD form. Range review keeps the existing merge-base(from, HEAD)..HEAD semantics: committed changes only, excluding staged, unstaged, and untracked changes.

At the maintainer's request, this expands the original review-only scope of #1935 to make normal review and delegation consistent. Plain commands remain in workspace mode; explicit targets take precedence; missing-base and conflicting range/commit flags still fail.

Changes

  • Share conditional target normalization between review and delegate option validation, without setting an unconditional flag default.
  • Add CLI examples and synchronize both repository-provided skills, their plugin copies, and localized CLI/delegation documentation.
  • Add real-Git regression coverage on diverged branches for shorthand/explicit equivalence, delegate preview metadata, both delegate subcommands, and committed-range versus workspace selection.

Maintainer Verification

  • make check — passed.
  • make test — passed, including race detection.
  • make coverage — 91.7% (90% threshold).
  • make build and git diff --check — passed.
  • Repository plugin contract and documentation translation-sync checks — passed. The existing Cursor manifest resolution-base warning is unrelated and unchanged.
  • OCR review of the follow-up production changes — no findings.

Local verification uses project-local dist/tmp for TMPDIR and GOTMPDIR, with GIT_CEILING_DIRECTORIES set to the same directory so non-repository fixtures do not inherit the containing checkout.

Fixes #1935

AI Disclosure

Original author disclosure: Implemented with DeepSeek Harness (deepseek-v4.1-flash); the author reviewed the diff and ran the original checks.

The maintainer follow-up was prepared using OpenAI Codex and checked with ocr; the Codex session's model identifier was not exposed. The maintainer requested and authorized the scope expansion and update. No AI attribution trailers are included in the commits.

Reviewing the current branch against a known base is a common workflow,
but it previously required spelling out --to HEAD. Normalize a missing
target to HEAD inside review-option validation so the shorthand takes the
exact same merge-base range path, while plain review keeps workspace mode
and delegate keeps requiring --to.

Add a Git-backed preview test on diverged branches, and document the
conditional default in all five cli-reference locales.

Fixes alibaba#1935
@github-actions

github-actions Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

🔍 OpenCodeReview found 1 issue(s) in this PR.

  • ✅ Successfully posted inline: 1 comment(s)

func addDiffFlags(cmd *cobra.Command, from, to, commit *string) {
cmd.Flags().StringVar(from, "from", "", "source ref to start diff from (e.g., 'main')")
cmd.Flags().StringVar(to, "to", "", "target ref to end diff at (e.g., 'feature-branch')")
cmd.Flags().StringVar(to, "to", "", "target ref to end diff at (e.g., 'feature-branch'; defaults to HEAD when --from is given)")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

documentation · medium
The updated help text for --to states "defaults to HEAD when --from is given", but addDiffFlags is shared between both review and delegate commands. The HEAD-defaulting behavior only applies to ocr review (via validateReviewOptions); ocr delegate still requires --to explicitly and will error out without it. This help text will mislead delegate users.

Consider either: (1) keeping the generic help text here and documenting the shorthand only in the review command's example/long description (which already does this), or (2) splitting the flag registration so each command gets its own accurate help string.

@lizhengfeng101

Copy link
Copy Markdown
Contributor

@Walternater Thanks for implementing this. I would prefer to make the shorthand consistent across normal review and delegation in this PR, and update the repository-provided skills together.

I realize #1935 explicitly scoped the change to review, so this is a requested scope expansion, not a missed requirement in your implementation. Currently the shared --to help advertises a HEAD default for delegate commands too, while delegate validation still rejects the shorthand. Rather than only narrowing that help text, could you please:

  • Support --from <ref> without --to in ocr review, ocr delegate preview, and ocr delegate rule, consistently treating it as --to HEAD.
  • Preserve workspace mode when no range/commit flags are supplied. Keep explicit targets authoritative, retain errors for --to without --from and conflicting range/commit modes, and keep range semantics committed-only (merge-base(from, HEAD)..HEAD, excluding staged, unstaged, and untracked changes).
  • Update CLI help/docs and both skills/open-code-review/SKILL.md and skills/open-code-review-delegate/SKILL.md, including their corresponding plugin copies, with consistent shorthand examples and the committed-only caveat.
  • Replace the delegate rejection test with coverage for the new behavior. Add regression coverage for both delegate subcommands, checking shorthand/explicit-target equivalence and effective mode/ref metadata, while retaining the workspace and conflict guards. Run make test, make check, and make coverage.

This would give users and host agents one consistent convention across both modes, with implementation, documentation, and skills aligned.

@lizhengfeng101 lizhengfeng101 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed the original change and the maintainer follow-up at 99b958c. Conditional target normalization is consistent across review and both delegate subcommands, with workspace mode and conflict validation preserved. Local checks, race-enabled tests, build, and 91.7% coverage passed; OCR reported no findings in the follow-up production changes. The corresponding skills and localized documentation are synchronized. Waiting for the updated CI checks before merging.

@Walternater

Copy link
Copy Markdown
Contributor Author

I saw you pushed 99b958c implementing the delegate part, so I synced to it rather than pushing my local duplicate (it is discarded). Verified this head locally:

  • TMPDIR=/private/tmp go test ./... — all packages pass, including the new subprocess e2e for delegate preview and delegate rule
  • make check — passed
  • make coverage — 91.7% (threshold 90%)
  • The e2e confirms shorthand/explicit parity, mode=range metadata on preview, workspace remains the default with no refs, and the committed range excludes staged/unstaged/untracked files.

One small observation for machine-readable symmetry: delegateRulesJSON still has no mode/from/to/commit/merge_base fields, so the rule subcommand's effective ref metadata is only asserted via the loaded delegate context, not visible in its JSON output. If you want that symmetry I can add the optional fields plus test assertions; otherwise the current state looks good to me.

AI-assisted: implemented/verified with DeepSeek Harness (deepseek-v4.1-flash); commands and results above were run locally.

@lizhengfeng101
lizhengfeng101 merged commit 7e5ce06 into alibaba:main Nov 15, 2026
15 checks passed
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.

feat(review): default --to to HEAD when only --from is provided

2 participants