summaryrefslogtreecommitdiff
path: root/packages/core/src/ide/ideContext.ts
diff options
context:
space:
mode:
authorchristine betts <[email protected]>2025-08-06 17:36:05 +0000
committerGitHub <[email protected]>2025-08-06 17:36:05 +0000
commitfde9849d48e3b92377aca2eecfd390ebce288692 (patch)
tree90c09c3dfce161ed6adb1d71c33fb432c1708614 /packages/core/src/ide/ideContext.ts
parent487818df276dc66827ce0f469f84bcae56a70801 (diff)
[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>
Diffstat (limited to 'packages/core/src/ide/ideContext.ts')
-rw-r--r--packages/core/src/ide/ideContext.ts59
1 files changed, 59 insertions, 0 deletions
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<typeof IdeContextSchema>;
* 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;
/**