Open History to see the last commit
1/**
2 * Public Docs: https://cursor.com/docs/cli/acp#cursor-extension-methods
3 * Additional reference provided by the Cursor team: https://anysphere.enterprise.slack.com/files/U068SSJE141/F0APT1HSZRP/cursor-acp-extension-method-schemas.md
4 */
5import type { UserInputQuestion } from "@t3tools/contracts";
6import * as AcpSchema from "effect-acp/schema";
7import * as Schema from "effect/Schema";
8
9const CursorAskQuestionOption = Schema.Struct({
10 id: Schema.String,
11 label: Schema.String,
12});
13
14const CursorAskQuestion = Schema.Struct({
15 id: Schema.String,
16 prompt: Schema.String,
17 options: Schema.Array(CursorAskQuestionOption),
18 allowMultiple: Schema.optional(Schema.Boolean),
19});
20
21export const CursorAskQuestionRequest = Schema.Struct({
22 toolCallId: Schema.String,
23 title: Schema.optional(Schema.String),
24 questions: Schema.Array(CursorAskQuestion),
25});
26
27const CursorTodoStatus = Schema.String;
28
29const CursorTodo = Schema.Struct({
30 id: Schema.optional(Schema.String),
31 content: Schema.optional(Schema.String),
32 title: Schema.optional(Schema.String),
33 status: Schema.optional(CursorTodoStatus),
34});
35
36const CursorPlanPhase = Schema.Struct({
37 name: Schema.String,
38 todos: Schema.Array(CursorTodo),
39});
40
41export const CursorCreatePlanRequest = Schema.Struct({
42 toolCallId: Schema.String,
43 name: Schema.optional(Schema.String),
44 overview: Schema.optional(Schema.String),
45 plan: Schema.String,
46 todos: Schema.Array(CursorTodo),
47 isProject: Schema.optional(Schema.Boolean),
48 phases: Schema.optional(Schema.Array(CursorPlanPhase)),
49});
50
51export const CursorUpdateTodosRequest = Schema.Struct({
52 toolCallId: Schema.String,
53 todos: Schema.Array(CursorTodo),
54 merge: Schema.Boolean,
55});
56
57const CursorAvailableModel = Schema.Struct({
58 value: Schema.String,
59 name: Schema.String,
60 configOptions: Schema.optional(Schema.Array(AcpSchema.SessionConfigOption)),
61});
62
63export const CursorListAvailableModelsResponse = Schema.Struct({
64 models: Schema.Array(CursorAvailableModel),
65});
66
67export function extractAskQuestions(
68 params: typeof CursorAskQuestionRequest.Type,
69): ReadonlyArray<UserInputQuestion> {
70 return params.questions.map((question) => ({
71 id: question.id,
72 header: "Question",
73 question: question.prompt,
74 multiSelect: question.allowMultiple === true,
75 options:
76 question.options.length > 0
77 ? question.options.map((option) => ({
78 label: option.label,
79 description: option.label,
80 }))
81 : [{ label: "OK", description: "Continue" }],
82 }));
83}
84
85export function extractPlanMarkdown(params: typeof CursorCreatePlanRequest.Type): string {
86 return params.plan || "# Plan\n\n(Cursor did not supply plan text.)";
87}
88
89export function extractTodosAsPlan(params: typeof CursorUpdateTodosRequest.Type): {
90 readonly explanation?: string;
91 readonly plan: ReadonlyArray<{
92 readonly step: string;
93 readonly status: "pending" | "inProgress" | "completed";
94 }>;
95} {
96 const plan = params.todos.flatMap((todo) => {
97 // Fall back to the title when content is missing OR blank. `??` only
98 // covers a missing content, so a present-but-empty content ("" or
99 // whitespace) would shadow a real title and drop the step below.
100 const step = todo.content?.trim() || todo.title?.trim() || "";
101 if (step === "") {
102 return [];
103 }
104 const status: "pending" | "inProgress" | "completed" =
105 todo.status === "completed"
106 ? "completed"
107 : todo.status === "in_progress" || todo.status === "inProgress"
108 ? "inProgress"
109 : "pending";
110 return [{ step, status }];
111 });
112 return { plan };
113}