Skip to content

PromptScript API


Class: CursorFormatter

Defined in: formatters/src/formatters/cursor.ts:101

Formatter for Cursor rules and commands.

Supports three versions: - modern (default): .cursor/rules/project.mdc with YAML frontmatter + .cursor/commands/*.md for multi-line shortcuts - multifile: Multiple MDC files with glob-based targeting + commands - legacy: .cursorrules plain text (deprecated, no commands)

Slash Commands (Cursor 1.6+)

Multi-line @shortcuts are automatically converted to executable slash commands in .cursor/commands/:

@shortcuts {
  // Single-line  stays in rules as documentation
  "/review": "Review code quality"

  // Multi-line  becomes .cursor/commands/test.md
  "/test": \"""
    Write unit tests using:
    - Vitest as the test runner
    - AAA pattern
  \"""
}

Example

# Modern format (default)
targets:
  - cursor

# Legacy format for older Cursor versions
targets:
  - cursor:
      version: legacy

See

Extends

Constructors

Constructor

new CursorFormatter(): CursorFormatter

Returns

CursorFormatter

Inherited from

BaseFormatter.constructor

Properties

defaultConvention

readonly defaultConvention: "markdown" = 'markdown'

Defined in: formatters/src/formatters/cursor.ts:105

Default convention for this formatter

Overrides

BaseFormatter.defaultConvention


description

readonly description: "Cursor rules (MDC with frontmatter)" = 'Cursor rules (MDC with frontmatter)'

Defined in: formatters/src/formatters/cursor.ts:104

Human-readable description

Overrides

BaseFormatter.description


name

readonly name: "cursor" = 'cursor'

Defined in: formatters/src/formatters/cursor.ts:102

Unique formatter identifier

Overrides

BaseFormatter.name


outputPath

readonly outputPath: ".cursor/rules/project.mdc" = CURSOR_VERSIONS.modern.outputPath

Defined in: formatters/src/formatters/cursor.ts:103

Default output file path

Overrides

BaseFormatter.outputPath


standardsExtractor

protected readonly standardsExtractor: StandardsExtractor

Defined in: formatters/src/base-formatter.ts:27

Shared standards extractor for consistent extraction across all formatters.

Inherited from

BaseFormatter.standardsExtractor

Methods

createRenderer()

protected createRenderer(options?): ConventionRenderer

Defined in: formatters/src/base-formatter.ts:33

Create a convention renderer for this formatter. Uses the provided convention from options or falls back to the default.

Parameters

options?

FormatOptions

Returns

ConventionRenderer

Inherited from

BaseFormatter.createRenderer


dedent()

protected dedent(text): string

Defined in: formatters/src/base-formatter.ts:451

Remove common leading whitespace from all lines (dedent). Handles the case where trim() was already called, causing the first line to lose its indentation while subsequent lines retain theirs. Calculates minimum indent from lines 2+ only.

Parameters

text

string

Returns

string

Inherited from

BaseFormatter.dedent


extractSectionWithCodeBlock()

protected extractSectionWithCodeBlock(text, header): string | null

Defined in: formatters/src/base-formatter.ts:175

Safe extraction of a section that contains a header + content + code block + content Avoids ReDoS by using string search instead of backtracking regex. Matches pattern: Header ... ...

Parameters

text

string

string

Returns

string | null

Inherited from

BaseFormatter.extractSectionWithCodeBlock


extractText()

protected extractText(content): string

Defined in: formatters/src/base-formatter.ts:68

Extract text from block content.

Parameters

content

BlockContent

Returns

string

Inherited from

BaseFormatter.extractText


findBlock()

protected findBlock(ast, name): Block | undefined

Defined in: formatters/src/base-formatter.ts:61

Find a block by name, ignoring internal blocks (starting with __).

Parameters

ast

Program

name

string

Returns

Block | undefined

Inherited from

BaseFormatter.findBlock


format()

format(ast, options?): FormatterOutput

Defined in: formatters/src/formatters/cursor.ts:114

Transform AST to tool-specific format

Parameters

ast

Program

options?

FormatOptions

Returns

FormatterOutput

Overrides

BaseFormatter.format


formatArray()

protected formatArray(arr): string

Defined in: formatters/src/base-formatter.ts:119

Format an array as comma-separated string.

Parameters

arr

unknown[]

Returns

string

Inherited from

BaseFormatter.formatArray


formatStandardsList()

protected formatStandardsList(items): string[]

Defined in: formatters/src/base-formatter.ts:111

Format standards list from array of values (pass-through). Returns array of strings for rendering as bullet list.

Parameters

items

Value

Returns

string[]

Inherited from

BaseFormatter.formatStandardsList


getArrayElements()

protected getArrayElements(content): Value[]

Defined in: formatters/src/base-formatter.ts:143

Extract array elements from block content.

Parameters

content

BlockContent

Returns

Value[]

Inherited from

BaseFormatter.getArrayElements


getMetaField()

protected getMetaField(ast, key): string | undefined

Defined in: formatters/src/base-formatter.ts:133

Get meta field value as string.

Parameters

ast

Program

key

string

Returns

string | undefined

Inherited from

BaseFormatter.getMetaField


getOutputPath()

protected getOutputPath(options?): string

Defined in: formatters/src/base-formatter.ts:54

Get the output path, respecting options override.

Parameters

options?

FormatOptions

Returns

string

Inherited from

BaseFormatter.getOutputPath


getPrettierOptions()

protected getPrettierOptions(options?): Required\<PrettierMarkdownOptions>

Defined in: formatters/src/base-formatter.ts:44

Get resolved Prettier options, merging provided options with defaults.

Parameters

options?

FormatOptions

Returns

Required\<PrettierMarkdownOptions>

Inherited from

BaseFormatter.getPrettierOptions


getProp()

protected getProp(content, key): Value | undefined

Defined in: formatters/src/base-formatter.ts:82

Get a specific property from block content.

Parameters

content

BlockContent

key

string

Returns

Value | undefined

Inherited from

BaseFormatter.getProp


getProps()

protected getProps(content): Record\<string, Value>

Defined in: formatters/src/base-formatter.ts:96

Get all properties from block content.

Parameters

content

BlockContent

Returns

Record\<string, Value>

Inherited from

BaseFormatter.getProps


normalizeMarkdownForPrettier()

protected normalizeMarkdownForPrettier(content): string

Defined in: formatters/src/base-formatter.ts:203

Normalize markdown content to match Prettier formatting. - Strips common leading indentation from lines - Trims trailing whitespace from lines - Normalizes markdown table formatting - Adds blank lines before lists when preceded by text - Adds blank lines before code blocks when preceded by text - Escapes markdown special characters in paths

Parameters

content

string

Returns

string

Inherited from

BaseFormatter.normalizeMarkdownForPrettier


stripAllIndent()

protected stripAllIndent(content): string

Defined in: formatters/src/base-formatter.ts:347

Strip all leading indentation from markdown content. Used for AGENTS.md where content from multiple sources has inconsistent indentation. Preserves indentation inside code blocks.

Parameters

content

string

Returns

string

Inherited from

BaseFormatter.stripAllIndent


truncate()

protected truncate(str, max): string

Defined in: formatters/src/base-formatter.ts:126

Truncate string to max length with ellipsis.

Parameters

str

string

max

number

Returns

string

Inherited from

BaseFormatter.truncate


valueToString()

protected valueToString(value): string

Defined in: formatters/src/base-formatter.ts:153

Convert value to string representation.

Parameters

value

Value

Returns

string

Inherited from

BaseFormatter.valueToString


getSupportedVersions()

static getSupportedVersions(): object

Defined in: formatters/src/formatters/cursor.ts:110

Get supported versions for this formatter.

Returns

object

frontmatter

readonly frontmatter: object

frontmatter.cursorVersion

readonly cursorVersion: "0.45+" = '0.45+'

frontmatter.description

readonly description: "Alias for modern format (MDC with YAML frontmatter + slash commands)" = 'Alias for modern format (MDC with YAML frontmatter + slash commands)'

frontmatter.introduced

readonly introduced: "2024-12" = '2024-12'

frontmatter.name

readonly name: "frontmatter" = 'frontmatter'

frontmatter.outputPath

readonly outputPath: ".cursor/rules/project.mdc" = '.cursor/rules/project.mdc'

legacy

readonly legacy: object

legacy.cursorVersion

readonly cursorVersion: "< 0.45" = '< 0.45'

legacy.deprecated

readonly deprecated: true = true

legacy.deprecatedSince

readonly deprecatedSince: "2024-12" = '2024-12'

legacy.description

readonly description: "Plain text format (.cursorrules) - DEPRECATED" = 'Plain text format (.cursorrules) - DEPRECATED'

legacy.name

readonly name: "legacy" = 'legacy'

legacy.outputPath

readonly outputPath: ".cursorrules" = '.cursorrules'

modern

readonly modern: object

modern.cursorVersion

readonly cursorVersion: "0.45+" = '0.45+'

modern.description

readonly description: "MDC format with YAML frontmatter (.cursor/rules/project.mdc) + slash commands (.cursor/commands/)" = 'MDC format with YAML frontmatter (.cursor/rules/project.mdc) + slash commands (.cursor/commands/)'

modern.introduced

readonly introduced: "2024-12" = '2024-12'

modern.name

readonly name: "modern" = 'modern'

modern.outputPath

readonly outputPath: ".cursor/rules/project.mdc" = '.cursor/rules/project.mdc'

multifile

readonly multifile: object

multifile.cursorVersion

readonly cursorVersion: "0.45+" = '0.45+'

multifile.description

readonly description: "Multiple MDC files with glob-based targeting + slash commands" = 'Multiple MDC files with glob-based targeting + slash commands'

multifile.introduced

readonly introduced: "2024-12" = '2024-12'

multifile.name

readonly name: "multifile" = 'multifile'

multifile.outputPath

readonly outputPath: ".cursor/rules/project.mdc" = '.cursor/rules/project.mdc'