Share editor and shell-open input schemas in contracts

Co-authored-by: Theo Browne <[email protected]>
This commit is contained in:
Cursor AgentandTheo Browne committed 2026-02-10 13:16:28 +00:00
1 parent 3b465089a4
commit ebd984dd4e
3 files changed
+55 -4

No files matched your search

+1 -4
View File
@@ -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;
+47
View File
@@ -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();
});
});
+7
View File
@@ -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<typeof appBootstrapResultSchema>;
export type AppHealthResult = z.infer<typeof appHealthResultSchema>;