From 21876804cddff5862bcb280e463526e7de9119e6 Mon Sep 17 00:00:00 2001 From: Adam Bowker Date: Tue, 31 Mar 2026 19:21:58 -0700 Subject: [PATCH] feat(code): new diff review panel --- apps/code/src/main/services/git/schemas.ts | 7 +++++++ apps/code/src/main/services/git/service.ts | 8 ++++++++ apps/code/src/main/trpc/routers/git.ts | 9 +++++++++ packages/git/src/queries.ts | 12 ++++++++++++ 4 files changed, 36 insertions(+) diff --git a/apps/code/src/main/services/git/schemas.ts b/apps/code/src/main/services/git/schemas.ts index 8aedbc93f..ddf9bba2c 100644 --- a/apps/code/src/main/services/git/schemas.ts +++ b/apps/code/src/main/services/git/schemas.ts @@ -120,6 +120,13 @@ export const getFileAtHeadInput = z.object({ }); export const getFileAtHeadOutput = z.string().nullable(); +// getDiffHead schemas +export const getDiffHeadInput = z.object({ + directoryPath: z.string(), + ignoreWhitespace: z.boolean().optional(), +}); +export const getDiffHeadOutput = z.string(); + // getDiffStats schemas export const getDiffStatsInput = directoryPathInput; export const getDiffStatsOutput = diffStatsSchema; diff --git a/apps/code/src/main/services/git/service.ts b/apps/code/src/main/services/git/service.ts index 5d1f62159..7483c6443 100644 --- a/apps/code/src/main/services/git/service.ts +++ b/apps/code/src/main/services/git/service.ts @@ -9,6 +9,7 @@ import { getCurrentBranch, getDefaultBranch, getDiffAgainstRemote, + getDiffHead, getDiffStats, getFileAtHead, getLatestCommit, @@ -275,6 +276,13 @@ export class GitService extends TypedEventEmitter { return getFileAtHead(directoryPath, filePath); } + public async getDiffHead( + directoryPath: string, + ignoreWhitespace?: boolean, + ): Promise { + return getDiffHead(directoryPath, { ignoreWhitespace }); + } + public async getDiffStats(directoryPath: string): Promise { const stats = await getDiffStats(directoryPath, { excludePatterns: [".claude", "CLAUDE.local.md"], diff --git a/apps/code/src/main/trpc/routers/git.ts b/apps/code/src/main/trpc/routers/git.ts index 5c3627839..dfd3eab07 100644 --- a/apps/code/src/main/trpc/routers/git.ts +++ b/apps/code/src/main/trpc/routers/git.ts @@ -29,6 +29,8 @@ import { getCommitConventionsOutput, getCurrentBranchInput, getCurrentBranchOutput, + getDiffHeadInput, + getDiffHeadOutput, getDiffStatsInput, getDiffStatsOutput, getFileAtHeadInput, @@ -136,6 +138,13 @@ export const gitRouter = router({ getService().getFileAtHead(input.directoryPath, input.filePath), ), + getDiffHead: publicProcedure + .input(getDiffHeadInput) + .output(getDiffHeadOutput) + .query(({ input }) => + getService().getDiffHead(input.directoryPath, input.ignoreWhitespace), + ), + getDiffStats: publicProcedure .input(getDiffStatsInput) .output(getDiffStatsOutput) diff --git a/packages/git/src/queries.ts b/packages/git/src/queries.ts index 1a01d2186..1705488dc 100644 --- a/packages/git/src/queries.ts +++ b/packages/git/src/queries.ts @@ -935,6 +935,18 @@ export async function getUnstagedDiff( }); } +export async function getDiffHead( + baseDir: string, + options?: CreateGitClientOptions & { ignoreWhitespace?: boolean }, +): Promise { + const manager = getGitOperationManager(); + const args = ["HEAD"]; + if (options?.ignoreWhitespace) args.push("--ignore-all-space"); + return manager.executeRead(baseDir, (git) => git.diff(args), { + signal: options?.abortSignal, + }); +} + export async function getDiffAgainstRemote( baseDir: string, baseBranch: string,