From ebd984dd4eac6a77e55b69d1ab8f7509e79ac177 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Tue, 10 Feb 2026 13:16:28 +0000 Subject: [PATCH] Share editor and shell-open input schemas in contracts Co-authored-by: Theo Browne --- apps/t3/src/runtimeApiServer.ts | 5 +--- packages/contracts/src/ipc.test.ts | 47 ++++++++++++++++++++++++++++++ packages/contracts/src/ipc.ts | 7 +++++ 3 files changed, 55 insertions(+), 4 deletions(-) diff --git a/apps/t3/src/runtimeApiServer.ts b/apps/t3/src/runtimeApiServer.ts index 9bf0ba1d5d..5e7877f36e 100644 --- a/apps/t3/src/runtimeApiServer.ts +++ b/apps/t3/src/runtimeApiServer.ts @@ -32,6 +32,7 @@ import { providerSessionSchema, providerStopSessionInputSchema, providerTurnStartResultSchema, + shellOpenInEditorInputSchema, terminalCommandResultSchema, terminalCommandInputSchema, todoListSchema, @@ -46,10 +47,6 @@ const agentWriteInputSchema = z.object({ sessionId: z.string().min(1), data: z.string(), }); -const shellOpenInEditorInputSchema = z.object({ - cwd: z.string().min(1), - editor: z.enum(EDITORS.map((entry) => entry.id) as [string, ...string[]]), -}); interface RuntimeApiServerOptions { port: number; diff --git a/packages/contracts/src/ipc.test.ts b/packages/contracts/src/ipc.test.ts index 13ffa5aba5..e41514f0e5 100644 --- a/packages/contracts/src/ipc.test.ts +++ b/packages/contracts/src/ipc.test.ts @@ -4,6 +4,8 @@ import { appBootstrapResultSchema, appHealthResultSchema, dialogsPickFolderResultSchema, + editorIdSchema, + shellOpenInEditorInputSchema, } from "./ipc"; describe("appBootstrapResultSchema", () => { @@ -141,3 +143,48 @@ describe("dialogsPickFolderResultSchema", () => { expect(() => dialogsPickFolderResultSchema.parse(123)).toThrow(); }); }); + +describe("editor and shell-open schemas", () => { + it("accepts known editor ids", () => { + expect(editorIdSchema.parse("cursor")).toBe("cursor"); + expect(editorIdSchema.parse("file-manager")).toBe("file-manager"); + }); + + it("rejects unknown editor ids", () => { + expect(() => editorIdSchema.parse("vscode")).toThrow(); + }); + + it("accepts valid shell.openInEditor payloads", () => { + const parsed = shellOpenInEditorInputSchema.parse({ + cwd: "/workspace", + editor: "cursor", + }); + + expect(parsed.cwd).toBe("/workspace"); + expect(parsed.editor).toBe("cursor"); + }); + + it("rejects invalid shell.openInEditor payloads", () => { + expect(() => + shellOpenInEditorInputSchema.parse({ + cwd: "", + editor: "cursor", + }), + ).toThrow(); + + expect(() => + shellOpenInEditorInputSchema.parse({ + cwd: "/workspace", + editor: "vscode", + }), + ).toThrow(); + + expect(() => + shellOpenInEditorInputSchema.parse({ + cwd: "/workspace", + editor: "cursor", + unexpected: true, + }), + ).toThrow(); + }); +}); diff --git a/packages/contracts/src/ipc.ts b/packages/contracts/src/ipc.ts index 5c66c58206..b67aee46f7 100644 --- a/packages/contracts/src/ipc.ts +++ b/packages/contracts/src/ipc.ts @@ -20,6 +20,7 @@ export const EDITORS = [ ] as const; export type EditorId = (typeof EDITORS)[number]["id"]; +export const editorIdSchema = z.enum(EDITORS.map((entry) => entry.id) as [EditorId, ...EditorId[]]); export const appBootstrapResultSchema = z.object({ launchCwd: z.string().min(1), @@ -37,6 +38,12 @@ export const appHealthResultSchema = z.object({ activeClientConnected: z.boolean(), }).strict(); export const dialogsPickFolderResultSchema = z.string().nullable(); +export const shellOpenInEditorInputSchema = z + .object({ + cwd: z.string().min(1), + editor: editorIdSchema, + }) + .strict(); export type AppBootstrapResult = z.infer; export type AppHealthResult = z.infer;