From fde9849d48e3b92377aca2eecfd390ebce288692 Mon Sep 17 00:00:00 2001 From: christine betts Date: Wed, 6 Aug 2025 17:36:05 +0000 Subject: [ide-mode] Add support for in-IDE diff handling in the CLI (#5603) Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- packages/core/src/ide/ideContext.ts | 59 +++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) (limited to 'packages/core/src/ide/ideContext.ts') diff --git a/packages/core/src/ide/ideContext.ts b/packages/core/src/ide/ideContext.ts index 588e25ee..3052c029 100644 --- a/packages/core/src/ide/ideContext.ts +++ b/packages/core/src/ide/ideContext.ts @@ -36,10 +36,69 @@ export type IdeContext = z.infer; * Zod schema for validating the 'ide/contextUpdate' notification from the IDE. */ export const IdeContextNotificationSchema = z.object({ + jsonrpc: z.literal('2.0'), method: z.literal('ide/contextUpdate'), params: IdeContextSchema, }); +export const IdeDiffAcceptedNotificationSchema = z.object({ + jsonrpc: z.literal('2.0'), + method: z.literal('ide/diffAccepted'), + params: z.object({ + filePath: z.string(), + content: z.string(), + }), +}); + +export const IdeDiffClosedNotificationSchema = z.object({ + jsonrpc: z.literal('2.0'), + method: z.literal('ide/diffClosed'), + params: z.object({ + filePath: z.string(), + content: z.string().optional(), + }), +}); + +export const CloseDiffResponseSchema = z + .object({ + content: z + .array( + z.object({ + text: z.string(), + type: z.literal('text'), + }), + ) + .min(1), + }) + .transform((val, ctx) => { + try { + const parsed = JSON.parse(val.content[0].text); + const innerSchema = z.object({ content: z.string().optional() }); + const validationResult = innerSchema.safeParse(parsed); + if (!validationResult.success) { + validationResult.error.issues.forEach((issue) => ctx.addIssue(issue)); + return z.NEVER; + } + return validationResult.data; + } catch (_) { + ctx.addIssue({ + code: z.ZodIssueCode.custom, + message: 'Invalid JSON in text content', + }); + return z.NEVER; + } + }); + +export type DiffUpdateResult = + | { + status: 'accepted'; + content?: string; + } + | { + status: 'rejected'; + content: undefined; + }; + type IdeContextSubscriber = (ideContext: IdeContext | undefined) => void; /** -- cgit v1.2.3