Class: CursorFormatter¶
Defined in: formatters/src/formatters/cursor.ts:114
Formatter for Cursor rules and commands.
Supports four 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) - agents-md: Plain markdown at AGENTS.md (Cursor 2.4+) — no frontmatter
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¶
Properties¶
defaultConvention¶
readonlydefaultConvention:"markdown"='markdown'
Defined in: formatters/src/formatters/cursor.ts:118
Default convention for this formatter
Overrides¶
BaseFormatter.defaultConvention
description¶
readonlydescription:"Cursor rules (MDC with frontmatter)"='Cursor rules (MDC with frontmatter)'
Defined in: formatters/src/formatters/cursor.ts:117
Human-readable description
Overrides¶
name¶
readonlyname:"cursor"='cursor'
Defined in: formatters/src/formatters/cursor.ts:115
Unique formatter identifier
Overrides¶
outputPath¶
readonlyoutputPath:".cursor/rules/project.mdc"=CURSOR_VERSIONS.modern.outputPath
Defined in: formatters/src/formatters/cursor.ts:116
Default output file path
Overrides¶
standardsExtractor¶
protectedreadonlystandardsExtractor:StandardsExtractor
Defined in: formatters/src/base-formatter.ts:28
Shared standards extractor for consistent extraction across all formatters.
Inherited from¶
BaseFormatter.standardsExtractor
Methods¶
createRenderer()¶
protectedcreateRenderer(options?):ConventionRenderer
Defined in: formatters/src/base-formatter.ts:34
Create a convention renderer for this formatter. Uses the provided convention from options or falls back to the default.
Parameters¶
options?¶
Returns¶
Inherited from¶
dedent()¶
protecteddedent(text):string
Defined in: formatters/src/base-formatter.ts:452
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¶
extractExamples()¶
protectedextractExamples(ast):object[]
Defined in: formatters/src/base-formatter.ts:532
Extract examples from the
Parameters¶
ast¶
Returns¶
object[]
Examples¶
block. Returns an array of example definitions with name, input, output, and optional description.
Inherited from¶
extractSectionWithCodeBlock()¶
protectedextractSectionWithCodeBlock(text,header):string|null
Defined in: formatters/src/base-formatter.ts:176
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
header¶
string
Returns¶
string | null
Inherited from¶
BaseFormatter.extractSectionWithCodeBlock
extractSkillExamples()¶
protectedextractSkillExamples(skillProps):object[]
Defined in: formatters/src/base-formatter.ts:545
Extract examples from a skill's nested examples property. Returns the same shape as extractExamples.
Parameters¶
skillProps¶
Record\<string, Value>
Returns¶
object[]
Inherited from¶
BaseFormatter.extractSkillExamples
extractText()¶
protectedextractText(content):string
Defined in: formatters/src/base-formatter.ts:69
Extract text from block content.
Parameters¶
content¶
Returns¶
string
Inherited from¶
findBlock()¶
protectedfindBlock(ast,name):Block|undefined
Defined in: formatters/src/base-formatter.ts:62
Find a block by name, ignoring internal blocks (starting with __).
Parameters¶
ast¶
name¶
string
Returns¶
Block | undefined
Inherited from¶
format()¶
format(
ast,options?):FormatterOutput
Defined in: formatters/src/formatters/cursor.ts:131
Transform AST to tool-specific format
Parameters¶
ast¶
options?¶
Returns¶
Overrides¶
formatArray()¶
protectedformatArray(arr):string
Defined in: formatters/src/base-formatter.ts:120
Format an array as comma-separated string.
Parameters¶
arr¶
unknown[]
Returns¶
string
Inherited from¶
formatStandardsList()¶
protectedformatStandardsList(items):string[]
Defined in: formatters/src/base-formatter.ts:112
Format standards list from array of values (pass-through). Returns array of strings for rendering as bullet list.
Parameters¶
items¶
Returns¶
string[]
Inherited from¶
BaseFormatter.formatStandardsList
getArrayElements()¶
protectedgetArrayElements(content):Value[]
Defined in: formatters/src/base-formatter.ts:144
Extract array elements from block content.
Parameters¶
content¶
Returns¶
Value[]
Inherited from¶
BaseFormatter.getArrayElements
getMetaField()¶
protectedgetMetaField(ast,key):string|undefined
Defined in: formatters/src/base-formatter.ts:134
Get meta field value as string.
Parameters¶
ast¶
key¶
string
Returns¶
string | undefined
Inherited from¶
getOutputPath()¶
protectedgetOutputPath(options?):string
Defined in: formatters/src/base-formatter.ts:55
Get the output path, respecting options override.
Parameters¶
options?¶
Returns¶
string
Inherited from¶
getPrettierOptions()¶
protectedgetPrettierOptions(options?):Required\<PrettierMarkdownOptions>
Defined in: formatters/src/base-formatter.ts:45
Get resolved Prettier options, merging provided options with defaults.
Parameters¶
options?¶
Returns¶
Required\<PrettierMarkdownOptions>
Inherited from¶
BaseFormatter.getPrettierOptions
getProp()¶
protectedgetProp(content,key):Value|undefined
Defined in: formatters/src/base-formatter.ts:83
Get a specific property from block content.
Parameters¶
content¶
key¶
string
Returns¶
Value | undefined
Inherited from¶
getProps()¶
protectedgetProps(content):Record\<string,Value>
Defined in: formatters/src/base-formatter.ts:97
Get all properties from block content.
Parameters¶
content¶
Returns¶
Record\<string, Value>
Inherited from¶
getSkillBasePath()¶
getSkillBasePath():
string|null
Defined in: formatters/src/base-formatter.ts:593
Base path for skills, or null if formatter has no skill support.
Returns¶
string | null
Inherited from¶
BaseFormatter.getSkillBasePath
getSkillFileName()¶
getSkillFileName():
string|null
Defined in: formatters/src/base-formatter.ts:598
Skill file name, or null if formatter has no skill support.
Returns¶
string | null
Inherited from¶
BaseFormatter.getSkillFileName
isSafeSkillName()¶
protectedisSafeSkillName(name):boolean
Defined in: formatters/src/base-formatter.ts:622
Check if a skill name is safe for use in file paths.
Parameters¶
name¶
string
Returns¶
boolean
Inherited from¶
normalizeMarkdownForPrettier()¶
protectednormalizeMarkdownForPrettier(content):string
Defined in: formatters/src/base-formatter.ts:204
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
referenceProvenance()¶
protectedreferenceProvenance(sourcePath):string
Defined in: formatters/src/base-formatter.ts:615
Generate a provenance comment for a reference file.
Parameters¶
sourcePath¶
string
Returns¶
string
Inherited from¶
BaseFormatter.referenceProvenance
referencesMode()¶
referencesMode():
"none"|"directory"|"inline"
Defined in: formatters/src/formatters/cursor.ts:127
How this formatter handles skill references. - 'directory': emit as separate files in references/ subdirectory - 'inline': append as sections in the main output file - 'none': references not supported
Returns¶
"none" | "directory" | "inline"
Overrides¶
renderCodeFence()¶
protectedrenderCodeFence(content,lang?):string
Defined in: formatters/src/base-formatter.ts:630
Render content inside a code fence, using a longer fence if the content itself contains triple backticks (prevents code fence injection).
Parameters¶
content¶
string
lang?¶
string = ''
Returns¶
string
Inherited from¶
renderExamplesSection()¶
protectedrenderExamplesSection(ast,renderer,sectionName?):string|null
Defined in: formatters/src/base-formatter.ts:561
Render an examples section from the
Parameters¶
ast¶
renderer¶
sectionName?¶
string = 'Examples'
Custom section heading name (default: 'Examples')
Returns¶
string | null
Examples¶
block. Shared rendering logic used by Claude, GitHub, and MarkdownInstructionFormatter.
Inherited from¶
BaseFormatter.renderExamplesSection
sanitizeResourceFiles()¶
protectedsanitizeResourceFiles(resources,targetDir):FormatterOutput[]
Defined in: formatters/src/base-formatter.ts:483
Filter resource files to only include safe paths. Rejects paths with traversal, absolute paths, and unsafe names.
Parameters¶
resources¶
object[] | undefined
targetDir¶
string
Returns¶
Inherited from¶
BaseFormatter.sanitizeResourceFiles
stripAllIndent()¶
protectedstripAllIndent(content):string
Defined in: formatters/src/base-formatter.ts:348
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¶
truncate()¶
protectedtruncate(str,max):string
Defined in: formatters/src/base-formatter.ts:127
Truncate string to max length with ellipsis.
Parameters¶
str¶
string
max¶
number
Returns¶
string
Inherited from¶
valueToString()¶
protectedvalueToString(value):string
Defined in: formatters/src/base-formatter.ts:154
Convert value to string representation.
Parameters¶
value¶
Returns¶
string
Inherited from¶
getSupportedVersions()¶
staticgetSupportedVersions():object
Defined in: formatters/src/formatters/cursor.ts:123
Get supported versions for this formatter.
Returns¶
object
agents-md¶
readonlyagents-md:object
agents-md.cursorVersion¶
readonlycursorVersion:"2.4+"='2.4+'
agents-md.description¶
readonlydescription:"Plain markdown at AGENTS.md (Cursor 2.4+) — no frontmatter required"='Plain markdown at AGENTS.md (Cursor 2.4+) — no frontmatter required'
agents-md.introduced¶
readonlyintroduced:"2025-06"='2025-06'
agents-md.name¶
readonlyname:"agents-md"='agents-md'
agents-md.outputPath¶
readonlyoutputPath:"AGENTS.md"='AGENTS.md'
legacy¶
readonlylegacy:object
legacy.cursorVersion¶
readonlycursorVersion:"< 0.45"='< 0.45'
legacy.deprecated¶
readonlydeprecated:true=true
legacy.deprecatedSince¶
readonlydeprecatedSince:"2024-12"='2024-12'
legacy.description¶
readonlydescription:"Plain text format (.cursorrules) - DEPRECATED"='Plain text format (.cursorrules) - DEPRECATED'
legacy.name¶
readonlyname:"legacy"='legacy'
legacy.outputPath¶
readonlyoutputPath:".cursorrules"='.cursorrules'
modern¶
readonlymodern:object
modern.cursorVersion¶
readonlycursorVersion:"0.45+"='0.45+'
modern.description¶
readonlydescription:"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¶
readonlyintroduced:"2024-12"='2024-12'
modern.name¶
readonlyname:"modern"='modern'
modern.outputPath¶
readonlyoutputPath:".cursor/rules/project.mdc"='.cursor/rules/project.mdc'
multifile¶
readonlymultifile:object
multifile.cursorVersion¶
readonlycursorVersion:"0.45+"='0.45+'
multifile.description¶
readonlydescription:"Multiple MDC files with glob-based targeting + slash commands"='Multiple MDC files with glob-based targeting + slash commands'
multifile.introduced¶
readonlyintroduced:"2024-12"='2024-12'
multifile.name¶
readonlyname:"multifile"='multifile'
multifile.outputPath¶
readonlyoutputPath:".cursor/rules/project.mdc"='.cursor/rules/project.mdc'