Skip to content

Add getGitDiff read action and fix code-agent error semantics - #2976

Closed
George Ng (GeorgeNgMsft) wants to merge 2 commits into
mainfrom
georgengmsft-vscode-git-diff-action
Closed

Add getGitDiff read action and fix code-agent error semantics#2976
George Ng (GeorgeNgMsft) wants to merge 2 commits into
mainfrom
georgengmsft-vscode-git-diff-action

Conversation

@GeorgeNgMsft

Copy link
Copy Markdown
Contributor

What this does

Two small, related fixes to the Code Agent / Coda (VS Code extension bridge), both read-only:

  1. New getGitDiff action — a deterministic, catalog-discoverable fast action for the code agent that returns the actual local Git diff: changed files plus bounded unified-diff patch/hunk text, split into staged and unstaged sections by default, or diffed against an explicit base ref (base parameter) when given. It selects a repository explicitly or falls back to the single open repo/workspace folder (repository parameter, for multi-root workspaces). Binary files, renames, copies, and deletions are reported with clear status/flags instead of garbled or dropped patch text, and output is bounded (per-file byte cap, per-section byte cap, file-count cap) with truncation flags so callers always get a well-formed, complete response instead of a runaway payload.
  2. Fixed error semantics — when a Coda read action fails for an operational reason (e.g. no repo open, an unhandled action), the Code Agent now returns a failed ActionResult instead of a success-shaped result that merely happens to contain {"error": ...} in its text.

getWorkspaceChanges is unchanged.

Why this matters for external MCP clients

getGitDiff needs no separate MCP wiring — it's defined the same way as every other code-agent action, so it's automatically visible through the existing active schema/catalog (the same pipeline packages/actionSchema/test/regen.spec.ts round-trips and commandExecutor reads for discovery). A new test (codeActionsSchemaDiscovery.spec.ts) proves it's present with a concise description and a stable, typed parameter list — deterministic and usable by an external tool-selecting client without going through TypeAgent's natural-language reasoning path.

Highlights

  • packages/coda/src/gitDiffUtils.ts (new) — pure, unit-tested diff parsing: quoted/unquoted Git header paths (including non-ASCII under both core.quotePath settings), trailing-tab disambiguation on spaced paths, binary/mode-only/rename/copy/deletion handling, and bounded truncation with reported caps.
  • packages/coda/src/handleReadActions.tsgetGitDiff uses a single repo.diffWith() call per section (no serial per-file calls), filters output to paths inside an open workspace folder (checking both current and old paths for renames/copies), and reuses a shared getGitApi() helper.
  • packages/agents/code/src/codeActionsSchema.ts — new GetGitDiffAction schema with a concise, standalone description and base/repository parameters.
  • packages/agents/code/src/codeActionHandler.ts — operational failures (JSON {error} results, and the "action not handled" fallback) now produce a failed ActionResult.
  • Tests: 28 new unit tests in packages/coda/test/gitDiffUtils.spec.ts (new test:local harness for coda, matching existing agent conventions) and 2 new suites in packages/agents/code/test/ (codeActionErrorSemantics.spec.ts, codeActionsSchemaDiscovery.spec.ts) — 31/31 code-agent tests, 28/28 coda tests passing.
  • All CLAUDE.md ratchet gates (lint, complexity, circular deps, tech debt) pass against main.

Co-authored-by: Copilot App 223556219+Copilot@users.noreply.github.com

Implements the P0 VS Code read-capability improvements:

- New getGitDiff fast action for the code agent (MCP/catalog
  discoverable, deterministic parameters/results) that returns a real,
  bounded Git unified-diff patch (staged/unstaged/against an explicit
  base ref), with per-file and per-section byte caps, file-count caps,
  binary/rename/copy/deletion handling, and multi-root repository
  selection. Implemented via the coda VS Code extension's vscode.git
  API bridge (handleReadActions.ts / new gitDiffUtils.ts). Path
  containment filters every section (including rename/copy old paths)
  to files inside an open workspace folder.
- Fixes codeActionHandler.ts so operational read-action failures
  reported by the coda extension (JSON { error: string } results, and
  the "action not handled" fallback) resolve to a failed ActionResult
  (createActionResultFromError) instead of a success-shaped result
  whose display happens to mention an error.
- Preserves existing getWorkspaceChanges behavior unchanged.

Tests:
- packages/agents/code/test: new codeActionsSchemaDiscovery.spec.ts
  (asserts getGitDiff is discoverable via the same schema/catalog
  pipeline external MCP clients use, alongside
  packages/actionSchema/test/regen.spec.ts's generic round-trip) and
  codeActionErrorSemantics.spec.ts (extractOperationalError shape
  detection, including the "not handled" fallback). 31/31 tests
  passing across 4 suites.
- packages/coda/test: new gitDiffUtils.spec.ts (28 tests) covering
  diff parsing/bounding/truncation across quoted/unquoted, spaced,
  non-ASCII (both core.quotePath settings), binary, mode-only-change,
  rename/copy, and deletion cases, verified against real git diff
  byte output. Added a tsx --test based unit-test harness
  (test:local) matching the existing onboarding-agent/typeagent-studio
  convention, since coda previously had no unit-test infra.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@GeorgeNgMsft
George Ng (GeorgeNgMsft) marked this pull request as draft September 4, 2026 04:35
@GeorgeNgMsft

Copy link
Copy Markdown
Contributor Author

Closing for now, will reopen when ready for review

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