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 { Schema } from "effect";
7
8const CursorAskQuestionOption = Schema.Struct({
9 id: Schema.String,
10 label: Schema.String,
11});
12
13const CursorAskQuestion = Schema.Struct({
14 id: Schema.String,
15 prompt: Schema.String,
16 options: Schema.Array(CursorAskQuestionOption),
17 allowMultiple: Schema.optional(Schema.Boolean),
18});
19
20export const CursorAskQuestionRequest = Schema.Struct({
21 toolCallId: Schema.String,
22 title: Schema.optional(Schema.String),
23 questions: Schema.Array(CursorAskQuestion),
24});
25
26const CursorTodoStatus = Schema.String;
27
28const CursorTodo = Schema.Struct({
29 id: Schema.optional(Schema.String),
30 content: Schema.optional(Schema.String),
31 title: Schema.optional(Schema.String),
32 status: Schema.optional(CursorTodoStatus),
33});
34
35const CursorPlanPhase = Schema.Struct({
36 name: Schema.String,
37 todos: Schema.Array(CursorTodo),
38});
39
40export const CursorCreatePlanRequest = Schema.Struct({
41 toolCallId: Schema.String,
42 name: Schema.optional(Schema.String),
43 overview: Schema.optional(Schema.String),
44 plan: Schema.String,
45 todos: Schema.Array(CursorTodo),
46 isProject: Schema.optional(Schema.Boolean),
47 phases: Schema.optional(Schema.Array(CursorPlanPhase)),
48});
49
50export const CursorUpdateTodosRequest = Schema.Struct({
51 toolCallId: Schema.String,
52 todos: Schema.Array(CursorTodo),
53 merge: Schema.Boolean,
54});
55
56export function extractAskQuestions(
57 params: typeof CursorAskQuestionRequest.Type,
58): ReadonlyArray<UserInputQuestion> {
59 return params.questions.map((question) => ({
60 id: question.id,
61 header: "Question",
62 question: question.prompt,
63 multiSelect: question.allowMultiple === true,
64 options:
65 question.options.length > 0
66 ? question.options.map((option) => ({
67 label: option.label,
68 description: option.label,
69 }))
70 : [{ label: "OK", description: "Continue" }],
71 }));
72}
73
74export function extractPlanMarkdown(params: typeof CursorCreatePlanRequest.Type): string {
75 return params.plan || "# Plan\n\n(Cursor did not supply plan text.)";
76}
77
78export function extractTodosAsPlan(params: typeof CursorUpdateTodosRequest.Type): {
79 readonly explanation?: string;
80 readonly plan: ReadonlyArray<{
81 readonly step: string;
82 readonly status: "pending" | "inProgress" | "completed";
83 }>;
84} {
85 const plan = params.todos.flatMap((todo) => {
86 const step = todo.content?.trim() ?? todo.title?.trim() ?? "";
87 if (step === "") {
88 return [];
89 }
90 const status: "pending" | "inProgress" | "completed" =
91 todo.status === "completed"
92 ? "completed"
93 : todo.status === "in_progress" || todo.status === "inProgress"
94 ? "inProgress"
95 : "pending";
96 return [{ step, status }];
97 });
98 return { plan };
99}