cursor-lint 0.13.0 → 0.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cursor-lint",
3
- "version": "0.13.0",
3
+ "version": "0.15.0",
4
4
  "description": "Lint your Cursor rules — catch common mistakes before they break your workflow",
5
5
  "main": "src/index.js",
6
6
  "bin": {
package/src/cli.js CHANGED
@@ -7,6 +7,11 @@ const { initProject } = require('./init');
7
7
  const { fixProject } = require('./fix');
8
8
  const { generateRules, suggestSkills, listPresets, generateFromPreset } = require('./generate');
9
9
  const { checkVersions, checkRuleVersionMismatches } = require('./versions');
10
+ const { showStats } = require('./stats');
11
+ const { migrate } = require('./migrate');
12
+ const { doctor } = require('./doctor');
13
+ const { saveSnapshot, diffSnapshot } = require('./diff');
14
+ const { lintPlugin } = require('./plugin');
10
15
 
11
16
  const VERSION = '0.13.0';
12
17
 
@@ -18,6 +23,8 @@ const BLUE = '\x1b[34m';
18
23
  const DIM = '\x1b[2m';
19
24
  const RESET = '\x1b[0m';
20
25
 
26
+ const SNAPSHOT_FILE = '.cursor-lint-snapshot.json';
27
+
21
28
  function showHelp() {
22
29
  console.log(`
23
30
  ${CYAN}cursor-lint${RESET} v${VERSION}
@@ -38,6 +45,12 @@ ${YELLOW}Options:${RESET}
38
45
  --generate --preset list Show available presets
39
46
  --order Show rule load order, priority tiers, and token estimates
40
47
  --version-check Detect installed package versions and show relevant rule tips
48
+ --stats Show rule health dashboard (counts, tokens, coverage)
49
+ --migrate Convert .cursorrules to .cursor/rules/*.mdc format
50
+ --doctor Full project health check with letter grade
51
+ --diff save Save current rules as snapshot
52
+ --diff Compare current rules to saved snapshot
53
+ --plugin Validate Cursor 2.5 plugin structure
41
54
 
42
55
  ${YELLOW}What it checks (default):${RESET}
43
56
  • .cursorrules files (warns about agent mode compatibility)
@@ -105,6 +118,11 @@ async function main() {
105
118
  const isGenerate = args.includes('--generate');
106
119
  const isOrder = args.includes('--order');
107
120
  const isVersionCheck = args.includes('--version-check');
121
+ const isStats = args.includes('--stats');
122
+ const isMigrate = args.includes('--migrate');
123
+ const isDoctor = args.includes('--doctor');
124
+ const isDiff = args.includes('--diff');
125
+ const isPlugin = args.includes('--plugin');
108
126
 
109
127
  if (isVersionCheck) {
110
128
  console.log(`\n📦 cursor-lint v${VERSION} --version-check\n`);
@@ -142,6 +160,239 @@ async function main() {
142
160
  console.log(`${DIM}Use these notes to customize your .mdc rules for your exact versions.${RESET}\n`);
143
161
  process.exit(mismatches.length > 0 ? 1 : 0);
144
162
 
163
+ } else if (isStats) {
164
+ console.log(`\n📊 cursor-lint v${VERSION} --stats\n`);
165
+ console.log(`Scanning ${cwd}...\n`);
166
+ const stats = showStats(cwd);
167
+
168
+ // Summary
169
+ console.log(`${CYAN}Rule files:${RESET}`);
170
+ console.log(` .mdc files: ${stats.mdcFiles.length}`);
171
+ if (stats.hasCursorrules) console.log(` .cursorrules: 1 (legacy — run --migrate)`);
172
+ console.log(` Skill files: ${stats.skillFiles.length}`);
173
+ console.log(` Total tokens: ~${stats.totalTokens}`);
174
+ console.log();
175
+
176
+ // Tier breakdown
177
+ console.log(`${CYAN}Rule tiers:${RESET}`);
178
+ console.log(` Always active: ${stats.tiers.always}`);
179
+ console.log(` Glob-matched: ${stats.tiers.glob}`);
180
+ console.log(` Manual only: ${stats.tiers.manual}`);
181
+ console.log();
182
+
183
+ // Token breakdown by file
184
+ if (stats.mdcFiles.length > 0) {
185
+ console.log(`${CYAN}Token breakdown:${RESET}`);
186
+ const sorted = [...stats.mdcFiles].sort((a, b) => b.tokens - a.tokens);
187
+ for (const f of sorted) {
188
+ const bar = '█'.repeat(Math.max(1, Math.round(f.tokens / 50)));
189
+ const pct = Math.round((f.tokens / stats.totalTokens) * 100);
190
+ console.log(` ${f.file.padEnd(30)} ${String(f.tokens).padStart(5)} tokens (${String(pct).padStart(2)}%) ${DIM}${bar}${RESET}`);
191
+ }
192
+ console.log();
193
+ }
194
+
195
+ // Coverage gaps
196
+ if (stats.coverageGaps.length > 0) {
197
+ console.log(`${YELLOW}Coverage gaps:${RESET}`);
198
+ for (const gap of stats.coverageGaps) {
199
+ console.log(` ${YELLOW}⚠${RESET} ${gap.ext} files found but no matching rule`);
200
+ console.log(` ${DIM}→ Try: --generate (suggests ${gap.suggestedRules.join(', ')})${RESET}`);
201
+ }
202
+ } else if (stats.mdcFiles.length > 0) {
203
+ console.log(`${GREEN}✓ No coverage gaps detected${RESET}`);
204
+ }
205
+
206
+ console.log();
207
+ process.exit(0);
208
+
209
+ } else if (isMigrate) {
210
+ console.log(`\n🔄 cursor-lint v${VERSION} --migrate\n`);
211
+ const result = migrate(cwd);
212
+
213
+ if (result.error) {
214
+ console.log(`${RED}✗${RESET} ${result.error}`);
215
+ process.exit(1);
216
+ }
217
+
218
+ console.log(`${CYAN}Source:${RESET} .cursorrules (${result.source.lines} lines, ${result.source.chars} chars)\n`);
219
+
220
+ if (result.created.length > 0) {
221
+ console.log(`${GREEN}Created:${RESET}`);
222
+ for (const f of result.created) {
223
+ console.log(` ${GREEN}✓${RESET} .cursor/rules/${f}`);
224
+ }
225
+ }
226
+
227
+ if (result.skipped.length > 0) {
228
+ console.log(`${YELLOW}Skipped (already exists):${RESET}`);
229
+ for (const f of result.skipped) {
230
+ console.log(` ${YELLOW}⚠${RESET} .cursor/rules/${f}`);
231
+ }
232
+ }
233
+
234
+ console.log();
235
+ console.log(`${DIM}Your .cursorrules file was NOT deleted — verify the migration, then remove it manually.${RESET}`);
236
+ console.log(`${DIM}Run cursor-lint to check the new rules.${RESET}\n`);
237
+ process.exit(0);
238
+
239
+ } else if (isDoctor) {
240
+ const dir = args.find(a => !a.startsWith('-')) ? path.resolve(args.find(a => !a.startsWith('-'))) : cwd;
241
+ console.log(`\n🏥 cursor-lint v${VERSION} --doctor\n`);
242
+ console.log(`Running full health check on ${dir}...\n`);
243
+ const report = await doctor(dir);
244
+
245
+ // Grade display
246
+ const gradeColors = { A: GREEN, B: GREEN, C: YELLOW, D: YELLOW, F: RED };
247
+ const gradeColor = gradeColors[report.grade] || RESET;
248
+ console.log(` ${gradeColor}${'━'.repeat(30)}${RESET}`);
249
+ console.log(` ${gradeColor} Project Health: ${report.grade} (${report.percentage}%) ${RESET}`);
250
+ console.log(` ${gradeColor}${'━'.repeat(30)}${RESET}\n`);
251
+
252
+ // Check results
253
+ for (const check of report.checks) {
254
+ let icon;
255
+ if (check.status === 'pass') icon = `${GREEN}✓${RESET}`;
256
+ else if (check.status === 'warn') icon = `${YELLOW}⚠${RESET}`;
257
+ else if (check.status === 'fail') icon = `${RED}✗${RESET}`;
258
+ else icon = `${BLUE}ℹ${RESET}`;
259
+
260
+ console.log(` ${icon} ${check.name}`);
261
+ console.log(` ${DIM}${check.detail}${RESET}`);
262
+ }
263
+
264
+ console.log();
265
+
266
+ // Suggestions based on grade
267
+ if (report.grade === 'F' || report.grade === 'D') {
268
+ console.log(`${YELLOW}Quick wins:${RESET}`);
269
+ console.log(` • Run ${CYAN}cursor-lint --init${RESET} to create starter rules`);
270
+ console.log(` • Run ${CYAN}cursor-lint --generate${RESET} to download rules for your stack`);
271
+ if (report.checks.some(c => c.name === 'No legacy .cursorrules' && c.status === 'warn')) {
272
+ console.log(` • Run ${CYAN}cursor-lint --migrate${RESET} to convert .cursorrules to .mdc`);
273
+ }
274
+ } else if (report.grade === 'C') {
275
+ console.log(`${YELLOW}Improvements:${RESET}`);
276
+ console.log(` • Run ${CYAN}cursor-lint --fix${RESET} to auto-repair common issues`);
277
+ console.log(` • Run ${CYAN}cursor-lint --stats${RESET} to find token waste`);
278
+ }
279
+
280
+ console.log();
281
+ process.exit(report.grade === 'F' ? 1 : 0);
282
+
283
+ } else if (isDiff) {
284
+ const isDiffSave = args.includes('save');
285
+
286
+ if (isDiffSave) {
287
+ console.log(`\n📸 cursor-lint v${VERSION} --diff save\n`);
288
+ const { path: snapPath, state } = saveSnapshot(cwd);
289
+ const ruleCount = Object.keys(state.rules).length;
290
+ console.log(`${GREEN}✓${RESET} Snapshot saved to ${path.basename(snapPath)}`);
291
+ console.log(` ${DIM}${ruleCount} rule${ruleCount !== 1 ? 's' : ''} captured at ${state.timestamp}${RESET}\n`);
292
+ console.log(`${DIM}Add ${SNAPSHOT_FILE} to .gitignore, or commit it to track rule changes.${RESET}\n`);
293
+ process.exit(0);
294
+ }
295
+
296
+ console.log(`\n📊 cursor-lint v${VERSION} --diff\n`);
297
+ const changes = diffSnapshot(cwd);
298
+
299
+ if (changes.error) {
300
+ console.log(`${RED}✗${RESET} ${changes.error}\n`);
301
+ process.exit(1);
302
+ }
303
+
304
+ console.log(`${DIM}Comparing to snapshot from ${changes.savedAt}${RESET}\n`);
305
+
306
+ if (!changes.hasChanges) {
307
+ console.log(`${GREEN}✓ No changes since last snapshot${RESET}\n`);
308
+ process.exit(0);
309
+ }
310
+
311
+ if (changes.added.length > 0) {
312
+ console.log(`${GREEN}Added:${RESET}`);
313
+ for (const f of changes.added) {
314
+ console.log(` ${GREEN}+${RESET} ${f.file} (${f.tokens} tokens, ${f.lines} lines)`);
315
+ }
316
+ console.log();
317
+ }
318
+
319
+ if (changes.removed.length > 0) {
320
+ console.log(`${RED}Removed:${RESET}`);
321
+ for (const f of changes.removed) {
322
+ console.log(` ${RED}-${RESET} ${f.file} (${f.tokens} tokens, ${f.lines} lines)`);
323
+ }
324
+ console.log();
325
+ }
326
+
327
+ if (changes.modified.length > 0) {
328
+ console.log(`${YELLOW}Modified:${RESET}`);
329
+ for (const f of changes.modified) {
330
+ const tokenDiff = f.newTokens - f.oldTokens;
331
+ const sign = tokenDiff >= 0 ? '+' : '';
332
+ console.log(` ${YELLOW}~${RESET} ${f.file} (${sign}${tokenDiff} tokens, ${f.oldLines}→${f.newLines} lines)`);
333
+ }
334
+ console.log();
335
+ }
336
+
337
+ // Summary
338
+ const sign = changes.tokenDelta >= 0 ? '+' : '';
339
+ console.log(`${CYAN}Summary:${RESET} ${changes.added.length} added, ${changes.removed.length} removed, ${changes.modified.length} modified (${sign}${changes.tokenDelta} tokens)\n`);
340
+
341
+ // Exit 1 if changes detected (useful for CI)
342
+ process.exit(1);
343
+
344
+ } else if (isPlugin) {
345
+ const dir = args.find(a => !a.startsWith('-')) ? path.resolve(args.find(a => !a.startsWith('-'))) : cwd;
346
+
347
+ console.log(`\n🔌 cursor-lint v${VERSION} --plugin\n`);
348
+ console.log(`Validating Cursor plugin in ${dir}...\n`);
349
+
350
+ const results = await lintPlugin(dir);
351
+
352
+ if (results.length === 0) {
353
+ console.log(`${GREEN}✓ Plugin validation passed${RESET}\n`);
354
+ process.exit(0);
355
+ }
356
+
357
+ let totalErrors = 0;
358
+ let totalWarnings = 0;
359
+
360
+ for (const result of results) {
361
+ console.log(result.file);
362
+
363
+ if (result.issues.length === 0) {
364
+ console.log(` ${GREEN}✓ All checks passed${RESET}`);
365
+ } else {
366
+ for (const issue of result.issues) {
367
+ let icon;
368
+ if (issue.severity === 'error') {
369
+ icon = `${RED}✗${RESET}`;
370
+ totalErrors++;
371
+ } else if (issue.severity === 'warning') {
372
+ icon = `${YELLOW}⚠${RESET}`;
373
+ totalWarnings++;
374
+ } else {
375
+ icon = `${BLUE}ℹ${RESET}`;
376
+ }
377
+
378
+ console.log(` ${icon} ${issue.message}`);
379
+ if (issue.hint) {
380
+ console.log(` ${DIM}→ ${issue.hint}${RESET}`);
381
+ }
382
+ }
383
+ }
384
+ console.log();
385
+ }
386
+
387
+ console.log('─'.repeat(50));
388
+ const parts = [];
389
+ if (totalErrors > 0) parts.push(`${RED}${totalErrors} error${totalErrors !== 1 ? 's' : ''}${RESET}`);
390
+ if (totalWarnings > 0) parts.push(`${YELLOW}${totalWarnings} warning${totalWarnings !== 1 ? 's' : ''}${RESET}`);
391
+ if (parts.length === 0) parts.push(`${GREEN}All checks passed${RESET}`);
392
+ console.log(parts.join(', ') + '\n');
393
+
394
+ process.exit(totalErrors > 0 ? 1 : 0);
395
+
145
396
  } else if (isOrder) {
146
397
  const { showLoadOrder } = require('./order');
147
398
  console.log(`\n📋 cursor-lint v${VERSION} --order\n`);
package/src/diff.js ADDED
@@ -0,0 +1,93 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const crypto = require('crypto');
4
+
5
+ const SNAPSHOT_FILE = '.cursor-lint-snapshot.json';
6
+
7
+ function hashContent(content) {
8
+ return crypto.createHash('md5').update(content).digest('hex');
9
+ }
10
+
11
+ function estimateTokens(text) {
12
+ return Math.ceil(text.length / 4);
13
+ }
14
+
15
+ function captureState(dir) {
16
+ const state = { rules: {}, cursorrules: null, timestamp: new Date().toISOString() };
17
+
18
+ // .cursorrules
19
+ const cursorrules = path.join(dir, '.cursorrules');
20
+ if (fs.existsSync(cursorrules)) {
21
+ const content = fs.readFileSync(cursorrules, 'utf-8');
22
+ state.cursorrules = { hash: hashContent(content), tokens: estimateTokens(content), lines: content.split('\n').length };
23
+ }
24
+
25
+ // .cursor/rules/*.mdc
26
+ const rulesDir = path.join(dir, '.cursor', 'rules');
27
+ if (fs.existsSync(rulesDir) && fs.statSync(rulesDir).isDirectory()) {
28
+ for (const entry of fs.readdirSync(rulesDir).filter(f => f.endsWith('.mdc')).sort()) {
29
+ const content = fs.readFileSync(path.join(rulesDir, entry), 'utf-8');
30
+ state.rules[entry] = { hash: hashContent(content), tokens: estimateTokens(content), lines: content.split('\n').length };
31
+ }
32
+ }
33
+
34
+ return state;
35
+ }
36
+
37
+ function saveSnapshot(dir) {
38
+ const state = captureState(dir);
39
+ const snapshotPath = path.join(dir, SNAPSHOT_FILE);
40
+ fs.writeFileSync(snapshotPath, JSON.stringify(state, null, 2), 'utf-8');
41
+ return { path: snapshotPath, state };
42
+ }
43
+
44
+ function diffSnapshot(dir) {
45
+ const snapshotPath = path.join(dir, SNAPSHOT_FILE);
46
+ if (!fs.existsSync(snapshotPath)) {
47
+ return { error: 'No snapshot found. Run cursor-lint --diff save first.' };
48
+ }
49
+
50
+ const saved = JSON.parse(fs.readFileSync(snapshotPath, 'utf-8'));
51
+ const current = captureState(dir);
52
+
53
+ const changes = { added: [], removed: [], modified: [], unchanged: [], tokenDelta: 0, savedAt: saved.timestamp };
54
+
55
+ // Compare rules
56
+ const allFiles = new Set([...Object.keys(saved.rules), ...Object.keys(current.rules)]);
57
+
58
+ for (const file of allFiles) {
59
+ const s = saved.rules[file];
60
+ const c = current.rules[file];
61
+
62
+ if (!s && c) {
63
+ changes.added.push({ file, tokens: c.tokens, lines: c.lines });
64
+ changes.tokenDelta += c.tokens;
65
+ } else if (s && !c) {
66
+ changes.removed.push({ file, tokens: s.tokens, lines: s.lines });
67
+ changes.tokenDelta -= s.tokens;
68
+ } else if (s.hash !== c.hash) {
69
+ changes.modified.push({ file, oldTokens: s.tokens, newTokens: c.tokens, oldLines: s.lines, newLines: c.lines });
70
+ changes.tokenDelta += (c.tokens - s.tokens);
71
+ } else {
72
+ changes.unchanged.push(file);
73
+ }
74
+ }
75
+
76
+ // .cursorrules changes
77
+ if (!saved.cursorrules && current.cursorrules) {
78
+ changes.added.push({ file: '.cursorrules', tokens: current.cursorrules.tokens, lines: current.cursorrules.lines });
79
+ changes.tokenDelta += current.cursorrules.tokens;
80
+ } else if (saved.cursorrules && !current.cursorrules) {
81
+ changes.removed.push({ file: '.cursorrules', tokens: saved.cursorrules.tokens, lines: saved.cursorrules.lines });
82
+ changes.tokenDelta -= saved.cursorrules.tokens;
83
+ } else if (saved.cursorrules && current.cursorrules && saved.cursorrules.hash !== current.cursorrules.hash) {
84
+ changes.modified.push({ file: '.cursorrules', oldTokens: saved.cursorrules.tokens, newTokens: current.cursorrules.tokens, oldLines: saved.cursorrules.lines, newLines: current.cursorrules.lines });
85
+ changes.tokenDelta += (current.cursorrules.tokens - saved.cursorrules.tokens);
86
+ }
87
+
88
+ changes.hasChanges = changes.added.length > 0 || changes.removed.length > 0 || changes.modified.length > 0;
89
+
90
+ return changes;
91
+ }
92
+
93
+ module.exports = { saveSnapshot, diffSnapshot, captureState };
package/src/doctor.js ADDED
@@ -0,0 +1,162 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const { lintProject } = require('./index');
4
+ const { showStats } = require('./stats');
5
+ const { lintPlugin } = require('./plugin');
6
+
7
+ async function doctor(dir) {
8
+ const report = {
9
+ checks: [],
10
+ score: 0,
11
+ maxScore: 0,
12
+ grade: 'F',
13
+ };
14
+
15
+ // 1. Check if any rules exist at all
16
+ report.maxScore += 20;
17
+ const rulesDir = path.join(dir, '.cursor', 'rules');
18
+ const hasMdc = fs.existsSync(rulesDir) && fs.readdirSync(rulesDir).filter(f => f.endsWith('.mdc')).length > 0;
19
+ const hasCursorrules = fs.existsSync(path.join(dir, '.cursorrules'));
20
+
21
+ if (hasMdc) {
22
+ report.score += 20;
23
+ report.checks.push({ name: 'Rules exist', status: 'pass', detail: '.cursor/rules/ found with .mdc files' });
24
+ } else if (hasCursorrules) {
25
+ report.score += 5;
26
+ report.checks.push({ name: 'Rules exist', status: 'warn', detail: 'Only .cursorrules found — run --migrate to convert to .mdc format' });
27
+ } else {
28
+ report.checks.push({ name: 'Rules exist', status: 'fail', detail: 'No rules found. Run --init or --generate to create rules.' });
29
+ }
30
+
31
+ // 2. Check for .cursorrules (should be migrated)
32
+ report.maxScore += 10;
33
+ if (hasCursorrules && hasMdc) {
34
+ report.score += 5;
35
+ report.checks.push({ name: 'No legacy .cursorrules', status: 'warn', detail: '.cursorrules exists alongside .mdc rules — may cause conflicts. Consider removing it.' });
36
+ } else if (!hasCursorrules) {
37
+ report.score += 10;
38
+ report.checks.push({ name: 'No legacy .cursorrules', status: 'pass', detail: 'Good — using modern .mdc format only' });
39
+ } else {
40
+ report.checks.push({ name: 'No legacy .cursorrules', status: 'warn', detail: 'Using legacy .cursorrules — run --migrate to convert' });
41
+ }
42
+
43
+ // 3. Run lint checks and count issues
44
+ report.maxScore += 30;
45
+ const lintResults = await lintProject(dir);
46
+ let errors = 0;
47
+ let warnings = 0;
48
+ for (const r of lintResults) {
49
+ for (const i of r.issues) {
50
+ if (i.severity === 'error') errors++;
51
+ else if (i.severity === 'warning') warnings++;
52
+ }
53
+ }
54
+
55
+ if (errors === 0 && warnings === 0) {
56
+ report.score += 30;
57
+ report.checks.push({ name: 'Lint checks', status: 'pass', detail: 'All rules pass lint checks' });
58
+ } else if (errors === 0) {
59
+ report.score += 20;
60
+ report.checks.push({ name: 'Lint checks', status: 'warn', detail: `${warnings} warning${warnings !== 1 ? 's' : ''} found. Run cursor-lint to see details.` });
61
+ } else {
62
+ report.score += Math.max(0, 10 - errors * 2);
63
+ report.checks.push({ name: 'Lint checks', status: 'fail', detail: `${errors} error${errors !== 1 ? 's' : ''}, ${warnings} warning${warnings !== 1 ? 's' : ''}. Run cursor-lint to fix.` });
64
+ }
65
+
66
+ // 4. Token budget check
67
+ report.maxScore += 15;
68
+ const stats = showStats(dir);
69
+ if (stats.totalTokens === 0) {
70
+ report.checks.push({ name: 'Token budget', status: 'info', detail: 'No rules to measure' });
71
+ } else if (stats.totalTokens < 2000) {
72
+ report.score += 15;
73
+ report.checks.push({ name: 'Token budget', status: 'pass', detail: `~${stats.totalTokens} tokens — well within budget` });
74
+ } else if (stats.totalTokens < 5000) {
75
+ report.score += 10;
76
+ report.checks.push({ name: 'Token budget', status: 'warn', detail: `~${stats.totalTokens} tokens — getting heavy. Consider trimming or splitting rules.` });
77
+ } else {
78
+ report.score += 5;
79
+ report.checks.push({ name: 'Token budget', status: 'fail', detail: `~${stats.totalTokens} tokens — very heavy. This eats into your context window every request.` });
80
+ }
81
+
82
+ // 5. Coverage gaps
83
+ report.maxScore += 15;
84
+ if (stats.coverageGaps.length === 0) {
85
+ report.score += 15;
86
+ report.checks.push({ name: 'Coverage', status: 'pass', detail: 'Rules cover your project file types' });
87
+ } else if (stats.coverageGaps.length <= 2) {
88
+ report.score += 10;
89
+ const gaps = stats.coverageGaps.map(g => g.ext).join(', ');
90
+ report.checks.push({ name: 'Coverage', status: 'warn', detail: `Missing rules for: ${gaps}. Run --generate to add them.` });
91
+ } else {
92
+ report.score += 5;
93
+ const gaps = stats.coverageGaps.map(g => g.ext).join(', ');
94
+ report.checks.push({ name: 'Coverage', status: 'fail', detail: `Missing rules for: ${gaps}. Run --generate to add them.` });
95
+ }
96
+
97
+ // 6. Skills check
98
+ report.maxScore += 10;
99
+ const skillDirs = [
100
+ path.join(dir, '.claude', 'skills'),
101
+ path.join(dir, '.cursor', 'skills'),
102
+ path.join(dir, 'skills'),
103
+ ];
104
+ const hasSkills = skillDirs.some(sd => {
105
+ if (!fs.existsSync(sd)) return false;
106
+ try {
107
+ return fs.readdirSync(sd).some(e => {
108
+ const sub = path.join(sd, e);
109
+ return fs.statSync(sub).isDirectory() && fs.existsSync(path.join(sub, 'SKILL.md'));
110
+ });
111
+ } catch { return false; }
112
+ });
113
+
114
+ if (hasSkills) {
115
+ report.score += 10;
116
+ report.checks.push({ name: 'Agent skills', status: 'pass', detail: 'Skills directory found' });
117
+ } else {
118
+ report.score += 5; // not having skills is fine, just not optimal
119
+ report.checks.push({ name: 'Agent skills', status: 'info', detail: 'No agent skills found. Skills are optional but can improve agent behavior for complex workflows.' });
120
+ }
121
+
122
+ // 7. Plugin validation (if this is a plugin)
123
+ const pluginManifestPath = path.join(dir, '.cursor-plugin', 'plugin.json');
124
+ if (fs.existsSync(pluginManifestPath)) {
125
+ report.maxScore += 10;
126
+ const pluginResults = await lintPlugin(dir);
127
+ let pluginErrors = 0;
128
+ let pluginWarnings = 0;
129
+
130
+ for (const r of pluginResults) {
131
+ for (const i of r.issues) {
132
+ if (i.severity === 'error') pluginErrors++;
133
+ else if (i.severity === 'warning') pluginWarnings++;
134
+ }
135
+ }
136
+
137
+ if (pluginErrors === 0 && pluginWarnings === 0) {
138
+ report.score += 10;
139
+ report.checks.push({ name: 'Plugin validation', status: 'pass', detail: 'Plugin structure is valid' });
140
+ } else if (pluginErrors === 0) {
141
+ report.score += 7;
142
+ report.checks.push({ name: 'Plugin validation', status: 'warn', detail: `${pluginWarnings} warning${pluginWarnings !== 1 ? 's' : ''} in plugin structure. Run cursor-lint --plugin to see details.` });
143
+ } else {
144
+ report.score += 3;
145
+ report.checks.push({ name: 'Plugin validation', status: 'fail', detail: `${pluginErrors} error${pluginErrors !== 1 ? 's' : ''} in plugin structure. Run cursor-lint --plugin to fix.` });
146
+ }
147
+ }
148
+
149
+ // Calculate grade
150
+ const pct = (report.score / report.maxScore) * 100;
151
+ if (pct >= 90) report.grade = 'A';
152
+ else if (pct >= 75) report.grade = 'B';
153
+ else if (pct >= 60) report.grade = 'C';
154
+ else if (pct >= 40) report.grade = 'D';
155
+ else report.grade = 'F';
156
+
157
+ report.percentage = Math.round(pct);
158
+
159
+ return report;
160
+ }
161
+
162
+ module.exports = { doctor };
package/src/migrate.js ADDED
@@ -0,0 +1,118 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+
4
+ function migrate(dir) {
5
+ const cursorrules = path.join(dir, '.cursorrules');
6
+ const result = { created: [], skipped: [], source: null, error: null };
7
+
8
+ if (!fs.existsSync(cursorrules)) {
9
+ result.error = 'No .cursorrules file found in this directory';
10
+ return result;
11
+ }
12
+
13
+ const content = fs.readFileSync(cursorrules, 'utf-8').trim();
14
+ result.source = { file: '.cursorrules', chars: content.length, lines: content.split('\n').length };
15
+
16
+ if (content.length === 0) {
17
+ result.error = '.cursorrules file is empty';
18
+ return result;
19
+ }
20
+
21
+ const rulesDir = path.join(dir, '.cursor', 'rules');
22
+ fs.mkdirSync(rulesDir, { recursive: true });
23
+
24
+ // Try to split by markdown headings (## or #)
25
+ const sections = splitBySections(content);
26
+
27
+ if (sections.length <= 1) {
28
+ // Single file migration
29
+ const filename = 'project-rules.mdc';
30
+ const destPath = path.join(rulesDir, filename);
31
+ if (fs.existsSync(destPath)) {
32
+ result.skipped.push(filename);
33
+ } else {
34
+ const mdc = wrapInMdc(content, 'Project rules migrated from .cursorrules');
35
+ fs.writeFileSync(destPath, mdc, 'utf-8');
36
+ result.created.push(filename);
37
+ }
38
+ } else {
39
+ // Multi-file migration
40
+ for (const section of sections) {
41
+ const filename = slugify(section.title) + '.mdc';
42
+ const destPath = path.join(rulesDir, filename);
43
+ if (fs.existsSync(destPath)) {
44
+ result.skipped.push(filename);
45
+ } else {
46
+ const mdc = wrapInMdc(section.body, section.title);
47
+ fs.writeFileSync(destPath, mdc, 'utf-8');
48
+ result.created.push(filename);
49
+ }
50
+ }
51
+ }
52
+
53
+ return result;
54
+ }
55
+
56
+ function splitBySections(content) {
57
+ const lines = content.split('\n');
58
+ const sections = [];
59
+ let currentTitle = null;
60
+ let currentBody = [];
61
+
62
+ for (const line of lines) {
63
+ const headingMatch = line.match(/^#{1,2}\s+(.+)/);
64
+ if (headingMatch) {
65
+ if (currentTitle !== null) {
66
+ sections.push({ title: currentTitle, body: currentBody.join('\n').trim() });
67
+ }
68
+ currentTitle = headingMatch[1].trim();
69
+ currentBody = [];
70
+ } else {
71
+ currentBody.push(line);
72
+ }
73
+ }
74
+
75
+ // Push last section
76
+ if (currentTitle !== null) {
77
+ sections.push({ title: currentTitle, body: currentBody.join('\n').trim() });
78
+ }
79
+
80
+ // If no headings found, check for content before first heading
81
+ if (sections.length === 0) {
82
+ return [{ title: 'Project Rules', body: content }];
83
+ }
84
+
85
+ // If there's content before the first heading, include it
86
+ const firstHeadingIdx = content.search(/^#{1,2}\s+/m);
87
+ if (firstHeadingIdx > 0) {
88
+ const preamble = content.slice(0, firstHeadingIdx).trim();
89
+ if (preamble.length > 20) {
90
+ sections.unshift({ title: 'General', body: preamble });
91
+ }
92
+ }
93
+
94
+ // Filter out empty sections
95
+ return sections.filter(s => s.body.length > 10);
96
+ }
97
+
98
+ function slugify(title) {
99
+ return title
100
+ .toLowerCase()
101
+ .replace(/[^a-z0-9\s-]/g, '')
102
+ .replace(/\s+/g, '-')
103
+ .replace(/-+/g, '-')
104
+ .replace(/^-|-$/g, '')
105
+ .slice(0, 40) || 'rule';
106
+ }
107
+
108
+ function wrapInMdc(body, description) {
109
+ return `---
110
+ description: "${description.replace(/"/g, '\\"')}"
111
+ alwaysApply: true
112
+ ---
113
+
114
+ ${body}
115
+ `;
116
+ }
117
+
118
+ module.exports = { migrate };