Skip to content

feat(cli): support per-run LLM provider and model overrides - #687

Open
Makishima wants to merge 9 commits into
alibaba:mainfrom
Makishima:feat/per-run-provider-model-overrides
Open

feat(cli): support per-run LLM provider and model overrides#687
Makishima wants to merge 9 commits into
alibaba:mainfrom
Makishima:feat/per-run-provider-model-overrides

Conversation

@Makishima

@Makishima Makishima commented Aug 3, 2026

Copy link
Copy Markdown

Description

Implements #680 by adding per-run LLM provider and model selection for both review and scan.

  • Adds the --provider flag alongside the existing --model flag.
  • Supports providers configured under both providers and custom_providers.
  • Applies strict configuration precedence: CLI flags > environment variables > config file.
  • Prevents partial configuration strategies from being mixed.
  • Preserves environment credential fallback for the selected built-in provider.
  • Prevents a model configured for one provider from leaking into another provider selection.
  • Adds the resolved provider and model to JSON output through the llm field.
  • Documents the new flags, precedence rules, and JSON output in all localized READMEs.

Compatibility note: a complete OCR_LLM_* environment configuration now takes precedence over file-based provider configuration.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Refactoring (no functional changes)
  • Documentation update
  • CI / Build / Tooling

How Has This Been Tested?

  • make test passes locally
  • Manual testing:
    • Verified review --help exposes --provider and --model.
    • Verified scan --help exposes --provider and --model.

Additional verification:

  • go vet ./...
  • make build
  • Focused resolver regression tests for cross-provider model selection
  • Git diff formatting and scope checks

Checklist

  • My code follows the project's coding style (go fmt, go vet)
  • I have performed a self-review of my code
  • I have added tests that prove my fix is effective or my feature works
  • New and existing unit tests pass locally with my changes
  • I have updated the documentation accordingly (if applicable)
  • I have signed the CLA

Related Issues

Closes #680

@CLAassistant

CLAassistant commented Aug 3, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@github-actions

github-actions Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

OpenCodeReview: Review complete: 0 finding(s) across 6 selected item(s).

@lizhengfeng101 lizhengfeng101 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It is not recommended to add too much content to the README; instead, it is suggested to add the descriptions of these commands to the official documentation section.

ref:pages/src/pages/DocsPage.tsx

@Makishima

Copy link
Copy Markdown
Author

Addressed in 1afd06e: the per-run provider/model documentation was removed from the localized READMEs and moved to the official localized CLI reference pages rendered by DocsPage.

One clarification regarding the added command-summary row: ocr scan and its ocr s alias are not introduced by this PR. They already exist in cmd/opencodereview/scan_cmd.go:

  • Use: "scan [flags]"
  • Aliases: []string{"s"}

The row only documents this existing command because the PR adds --provider and --model support to both review and scan. If you prefer keeping the documentation diff strictly limited to the new flags, I can remove the command-summary row.

It is not recommended to add too much content to the README; instead, it is suggested to add the descriptions of these commands to the official documentation section.

ref:pages/src/pages/DocsPage.tsx

@lizhengfeng101 lizhengfeng101 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for this PR! The feature design is solid, with thorough tests and documentation.

One change needed: please keep the strategy resolution order unchanged for the non---provider path (i.e., maintain config → env → Claude Code env → Shell RC).

Reasons:

  • The --provider short-circuit logic is independent of the strategy list order — the feature works either way
  • The precedence change is a separate breaking change that would silently alter behavior for existing users
  • There is no need to take on this compatibility risk

Specifically, the strategies slice in ResolveEndpointWithOptions should be restored to:

strategies := []struct {
    name string
    fn   func() (ResolvedEndpoint, bool, error)
}{
    {"OCR config file", func() (ResolvedEndpoint, bool, error) { return tryOCRConfig(configPath, opts) }},
    {"OCR environment", func() (ResolvedEndpoint, bool, error) { return tryOCREnv(opts.Model) }},
    {"Claude Code environment", func() (ResolvedEndpoint, bool, error) { return tryCCEnv(opts.Model) }},
    {"Shell rc file", func() (ResolvedEndpoint, bool, error) { return tryShellRC(opts.Model) }},
}

The corresponding tests (e.g., TestResolveEndpoint_OCREnvironmentPrecedesConfig) should be adjusted accordingly. Everything else LGTM.

@lizhengfeng101 lizhengfeng101 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@Makishima please keep the strategy resolution order unchanged for the non---provider path

@Makishima

Copy link
Copy Markdown
Author

Addressed in 67a0b14. Restored the legacy non---provider resolution order:

  1. OCR config file
  2. OCR environment
  3. Claude Code environment
  4. Shell rc file

The explicit --provider path still short-circuits before the strategy list, so per-run provider selection is unaffected. I also updated the precedence/fallback tests and all three localized CLI reference pages to match the restored behavior.

@Makishima please keep the strategy resolution order unchanged for the non---provider path

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.

Allow selecting provider/model per invocation (e.g. ocr review --provider X --model Y)

3 participants