Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

feat(prompts): add cursor prompt deeplinks to docs (#39439)

Greg Richardson2e097ee5be4d
diff --git a/apps/docs/app/guides/getting-started/ai-prompts/[slug]/AiPrompts.utils.ts b/apps/docs/app/guides/getting-started/ai-prompts/[slug]/AiPrompts.utils.ts
index bd82fbd4621..a1a8500395e 100644
--- a/apps/docs/app/guides/getting-started/ai-prompts/[slug]/AiPrompts.utils.ts
+++ b/apps/docs/app/guides/getting-started/ai-prompts/[slug]/AiPrompts.utils.ts
@@ -28,18 +28,28 @@ function parseMarkdown(markdown: string) {
}
})
+ return { heading, content: withoutFrontmatter.trim() }
+}
+
+/**
+ * Wraps content in a markdown code block.
+ *
+ * Uses `mdast` to ensure proper escaping of backticks within the content.
+ */
+export function wrapInMarkdownCodeBlock(content: string) {
+ const mdast = fromMarkdown(content)
+
const codeBlock: Code = {
type: 'code',
lang: 'markdown',
- value: markdown,
+ value: content,
}
const root: Root = {
type: 'root',
children: [codeBlock],
}
- const content = toMarkdown(root)
- return { heading, content }
+ return toMarkdown(root)
}
async function getAiPromptsImpl() {
@@ -106,3 +116,28 @@ export async function generateAiPromptsStaticParams() {
}
})
}
+
+/**
+ * Generates a deep link URL for Cursor that preloads the given prompt text.
+ *
+ * Cursor deep links have a maximum URL length of 8000 characters.
+ * If the generated URL exceeds this length, `url` will be undefined
+ * and an error will be returned.
+ */
+export function generateCursorPromptDeepLink(promptText: string) {
+ // Temporarily reject prompts that contain ".env" due to a bug in Cursor
+ if (promptText.includes('.env')) {
+ return { error: new Error('Prompt text cannot contain the text .env due to a temporary bug') }
+ }
+
+ const url = new URL('cursor://anysphere.cursor-deeplink/prompt')
+ url.searchParams.set('text', promptText)
+ const urlString = url.toString()
+
+ // Cursor has a max URL length of 8000 characters for deep links
+ if (urlString.length > 8000) {
+ return { error: new Error('Prompt text is too long to generate a Cursor deep link.') }
+ }
+
+ return { url: urlString }
+}
diff --git a/apps/docs/app/guides/getting-started/ai-prompts/[slug]/page.tsx b/apps/docs/app/guides/getting-started/ai-prompts/[slug]/page.tsx
index 055a4231d5a..82f3837575d 100644
--- a/apps/docs/app/guides/getting-started/ai-prompts/[slug]/page.tsx
+++ b/apps/docs/app/guides/getting-started/ai-prompts/[slug]/page.tsx
@@ -1,9 +1,12 @@
+import { source } from 'common-tags'
import { notFound } from 'next/navigation'
import { GuideTemplate, newEditLink } from '~/features/docs/GuidesMdx.template'
import {
generateAiPromptMetadata,
generateAiPromptsStaticParams,
+ generateCursorPromptDeepLink,
getAiPrompt,
+ wrapInMarkdownCodeBlock,
} from './AiPrompts.utils'
export const dynamicParams = false
@@ -19,17 +22,28 @@ export default async function AiPromptsPage(props: { params: Promise<{ slug: str
}
let { heading, content } = prompt
- content = `
-## How to use
+ const { url: cursorUrl } = generateCursorPromptDeepLink(content)
-Copy the prompt to a file in your repo.
+ content = source`
+ ## How to use
-Use the "include file" feature from your AI tool to include the prompt when chatting with your AI assistant. For example, with GitHub Copilot, use \`#<filename>\`, in Cursor, use \`@Files\`, and in Zed, use \`/file\`.
+ Copy the prompt to a file in your repo.
-## Prompt
+ Use the "include file" feature from your AI tool to include the prompt when chatting with your AI assistant. For example, with GitHub Copilot, use \`#<filename>\`, in Cursor, use \`@Files\`, and in Zed, use \`/file\`.
-${content}
-`.trim()
+ ${
+ cursorUrl
+ ? source`
+ You can also load the prompt directly into your IDE via the following links:
+ - [Open in Cursor](${cursorUrl})
+ `
+ : ''
+ }
+
+ ## Prompt
+
+ ${wrapInMarkdownCodeBlock(content)}
+ `
return (
<GuideTemplate