import type { Rule } from "../core/types.js"; import type { ConfigParser } from "./base.js"; import { nextRuleId, classifyRule, extractRuleBlocks } from "./base.js"; /** * Cursor config parser. * Reads: .cursor/rules/*.mdc (frontmatter + markdown body) * Also supports .cursorrules (legacy plain text, one rule per line) */ export const cursorParser: ConfigParser = { agent: "cursor", filePatterns: [".cursor/rules/*.mdc", ".cursorrules"], parse(content: string, filePath: string): Rule[] { let body = content; // .mdc files have YAML frontmatter if (filePath.endsWith(".mdc")) { const fmMatch = content.match(/^---\n([\s\S]*?)\n---\n([\s\S]*)$/); if (fmMatch) { body = fmMatch[2]; } } // .cursorrules: plain text, each line is its own rule if (filePath.endsWith(".cursorrules")) { return body .split("\n") .map((l) => l.trim()) .filter((l) => l.length > 5) .map((line) => ({ id: nextRuleId(), category: classifyRule(line), content: line, scope: "project" as const, source: { agent: "cursor" as const, file: filePath }, status: "active" as const, })); } const blocks = extractRuleBlocks(body); return blocks.map((block) => ({ id: nextRuleId(), category: classifyRule(block), content: block, scope: "project" as const, source: { agent: "cursor" as const, file: filePath }, status: "active" as const, })); }, };