Skip to content

feat(tools): support reading both comparison sides - #1903

Merged
lizhengfeng101 merged 5 commits into
mainfrom
feat/code-tools-comparison-sides
Nov 12, 2026
Merged

lizhengfeng101 merged 5 commits into
mainfrom
feat/code-tools-comparison-sides

Conversation

@lizhengfeng101

Copy link
Copy Markdown
Contributor

Description

Add deterministic before/after code access as a foundation for Behavior and Impact analysis, without adding a new agent or changing the scan tool protocol.

  • Expose optional side: "new" | "old" on file_read, code_search, and file_find for commit and range reviews. Omitting it preserves existing new-side behavior and output.
  • Freeze comparison endpoints: the old side is the merge-base for ranges, the first parent for commits, or an empty tree for genuine root commits. Old-side results identify their source and never fall back to the workspace or new side.
  • Keep scan and workspace schemas unchanged, reject side in current-only execution, and derive comparison schemas without mutating the base tool catalog.
  • Persist current-only/v1 or comparison-sides/v1 in session execution metadata. Resumed sessions retain their profile; legacy sessions remain current-only and unknown profiles fail explicitly.
  • Reject shallow-boundary commits until the clone is deepened, including when parent objects exist locally but remain hidden from Git's history traversal. This prevents old-side tools from disagreeing with git show.

Older binaries do not enforce the new profile field. Use a compatible version to resume a comparison-side session.

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 (describe below)

  • make check: passed.

  • make test: passed, including race detection.

  • make coverage: passed, 91.6% overall coverage (90% required).

  • git diff --cached --check: passed; staged files use LF line endings.

  • Required OCR review: complete for all 15 selected production source files, with no critical/high/medium findings after the shallow-boundary fix. One low-priority error-message suggestion remains. Tests and documentation were inspected separately.

Regression coverage includes default-output compatibility, unchanged scan/workspace tool definitions, renamed/deleted files, empty and missing trees, concurrent side access, frozen refs, raw/parsed schema consistency, and session profiles. A fake-model HTTP integration test exercises all three old-side tools through the CLI and reloads the persisted session profile.

The shallow-boundary regression fails before the fix and covers success after unshallowing. Automated checks run with project-local TMPDIR/GOTMPDIR and GIT_CEILING_DIRECTORIES to respect local execution restrictions.

No real-model Behavior/Impact quality or distillation evaluation was run; the integration test verifies the tool contract, not analysis quality.

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
  • I did not use AI/LLM to create this PR, or I disclosed the tool/model below and reviewed its output; I did not attribute commits to AI and will answer maintainer questions and review comments myself without AI/LLM.

AI/LLM Disclosure

Implementation and PR preparation used Codex CLI with gpt-6-astra (the model identifier recorded in the session metadata). The required automated pre-commit review used OpenCodeReview (ocr) with gpt-6-astra.

No AI attribution trailers are included in commits. Human self-review, CLA status, and the author-understanding/responsibility checklist remain unchecked for the author to confirm; automated checks do not establish those attestations.

Related Issues

None.

@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

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

  • ✅ Successfully posted inline: 1 comment(s)

}
updatedProperties = append(updatedProperties, []byte(`"side":{"type":"string","enum":["new","old"],"description":"The side of the current comparison to access. Defaults to new. Paths and line numbers belong to the selected side."}}`)...)
parameters["properties"] = updatedProperties
fields["parameters"], _ = json.Marshal(parameters)

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 · low
The error from json.Marshal(parameters) is silently discarded. While marshaling a map[string]json.RawMessage is very unlikely to fail, if it does, fields["parameters"] becomes nil, and the function proceeds to return a FunctionDef with a null parameters field and no error indication. This would produce a malformed tool definition sent to the LLM.

Consider propagating the error:

var err error
fields["parameters"], err = json.Marshal(parameters)
if err != nil {
    return llm.FunctionDef{}, fmt.Errorf("marshal updated parameters: %w", err)
}

@lizhengfeng101
lizhengfeng101 force-pushed the feat/code-tools-comparison-sides branch from 6094c87 to 063c70f Compare November 11, 2026 11:46

@css521 css521 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.

LGTM

@MuoDoo MuoDoo 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.

LGTM.

@lizhengfeng101
lizhengfeng101 merged commit 4236c87 into main Nov 12, 2026
15 checks passed
@lizhengfeng101
lizhengfeng101 deleted the feat/code-tools-comparison-sides branch November 12, 2026 02:18
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.

3 participants