Skip to content

refactor(vcs): isolate repository operations behind providers - #1912

Draft
Qiyuanqiii wants to merge 1 commit into
alibaba:mainfrom
Qiyuanqiii:Qiyuanqiii/vcs-provider-split
Draft

Qiyuanqiii wants to merge 1 commit into
alibaba:mainfrom
Qiyuanqiii:Qiyuanqiii/vcs-provider-split

Conversation

@Qiyuanqiii

Copy link
Copy Markdown
Contributor

Behavior

Review, scan and code tools currently use Git-specific runners and revision rules directly. This change puts repository operations behind internal/vcs contracts and supplies the built-in Git adapter, preserving the existing CLI modes and Git-backed review behavior.

This is an independent PR against main, adapted from the earlier fork's VCS implementation as part of the #1738 split. It does not depend on local rule plugins or the MCP HTTPS change (#1910).

Boundaries

flowchart LR
    consumers["Review / scan / rules / code tools"] --> contracts["internal/vcs contracts"]
    contracts --> adapter["internal/vcs/git adapter"]
    adapter --> existing["Git runner and diff engine"]
Loading
  • Review specifications resolve once to comparison endpoints and content references. Rules, diffs and code tools consume that same prepared comparison.
  • File access, listing, search and optional branch metadata have separate contracts. Git syntax and NUL-record parsing stay in the adapter.
  • Preserve root-commit empty parents, two-sided code access, exclusion ordering, filename handling, plain-directory fallback and search truncation summaries.
  • Scan providers remain local-workspace file sources; this PR does not add remote/historical scans or a second VCS backend.
  • Keep existing Git manifest and resume identities compatible. No external VCS plugin loader is added here.

Review order

  1. internal/vcs/vcs.go and docs/vcs-provider-boundary.md.
  2. internal/vcs/git: resolved comparisons, bounded file access, listing and search.
  3. internal/agent/repository.go and CLI preparation: shared comparison and identity.
  4. Rule sniffing, scan and code-tool adapters, followed by provider and Git contract tests.

Validation

Windows, Go 1.26.10:

  • make license-add and make check passed.
  • Race-enabled make test passed for VCS, Git runner, tools, diff, rules, scan, agent and CLI packages.
  • Full make coverage passed: 91.1% overall.
  • OCR reviewed 25 selected implementation files. Confirmed extraction regressions were corrected and covered by focused tests: historical content references, workspace seals, localized Git failures, unreadable directory entries, comparison resolution and cancellation. Related diagnostic and unused-helper findings were also addressed.
  • Local-workspace scan semantics, provider exclusion-order obligations and existing Git identity compatibility remain explicit contracts. A Unix permission test is skipped on Windows; Linux CI exercises it.

AI assistance and contributor review

OpenAI Codex (GPT-6), a GPT-6.1 Sol agent at xhigh, and OCR with the configured DeepSeek provider assisted with the extraction and review. The earlier VCS implementation was authored on the contributor's fork. No unrelated plugin co-author trailers are carried into this PR.

  • Contributor self-review is complete.

Related: #1738, #1910.

@Qiyuanqiii

Copy link
Copy Markdown
Contributor Author

This PR is split out from #1738, so we'll wait it for the time being.

@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

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

  • ✅ Successfully posted inline: 2 comment(s)

Comment thread internal/diff/git.go
Comment on lines 245 to 247
if base == "" {
return DiffSet{}, fmt.Errorf("cannot find merge-base between %s and %s", p.from, p.to)
}

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.

bug · medium
When ModeDirect is used with an empty from, this error message says "cannot find merge-base" which is misleading — ModeDirect does not compute a merge-base. While the current sole caller (vcs/git/review.go) guards against an empty base before constructing a ModeDirect provider, this is a public constructor (NewDirectProvider) and the error should accurately describe the failure for both modes.

Suggestion:

Suggested change
if base == "" {
return DiffSet{}, fmt.Errorf("cannot find merge-base between %s and %s", p.from, p.to)
}
if base == "" {
if p.mode == ModeDirect {
return DiffSet{}, fmt.Errorf("direct comparison base is empty (from=%s, to=%s)", p.from, p.to)
}
return DiffSet{}, fmt.Errorf("cannot find merge-base between %s and %s", p.from, p.to)
}

Comment on lines +27 to +34
func (r *Repository) CurrentBranch(ctx context.Context) (string, error) {
runner := r.Runner
if runner == nil {
runner = gitcmd.New(1)
}
out, err := runner.Output(ctx, r.RepoDir, "rev-parse", "--abbrev-ref", "HEAD")
return strings.TrimSpace(string(out)), err
}

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.

bug · medium
When r.Runner is nil, this creates a new gitcmd.Runner (with its own semaphore channel) on every call instead of reusing the shared defaultRunner via r.commandRunner(). Every other method in this package uses commandRunner() for the nil-fallback path. This both allocates unnecessarily per call and bypasses the shared concurrency limit, potentially allowing unbounded subprocess creation if CurrentBranch is called concurrently.

Suggestion:

Suggested change
func (r *Repository) CurrentBranch(ctx context.Context) (string, error) {
runner := r.Runner
if runner == nil {
runner = gitcmd.New(1)
}
out, err := runner.Output(ctx, r.RepoDir, "rev-parse", "--abbrev-ref", "HEAD")
return strings.TrimSpace(string(out)), err
}
func (r *Repository) CurrentBranch(ctx context.Context) (string, error) {
out, err := r.commandRunner().Output(ctx, r.RepoDir, "rev-parse", "--abbrev-ref", "HEAD")
return strings.TrimSpace(string(out)), err
}

This branch has not been deployed

No deployments
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