rulesync icon indicating copy to clipboard operation
rulesync copied to clipboard

rulesync import --targets cursor does not import .cursor/rules/*.mdc if one of the rules contains an empty glob key

Open codekiln opened this issue 1 year ago • 4 comments

Expected Behavior

Running rulesync import --targets cursor in a repository that has rules at .cursor/rules/*.mdc should import each rule

Actual Behavior

Running that command does not import any cursor rules from .cursor/rules/*.mdc.

Test environment

codekiln/logseq-encode-garden at 9532b2d85593a1870cc199202b22fc5a0d983cbe

Terminal output

 ✘ user@machine  ~/project-directory   main ±  mr rulesync --version
[rulesync] $ npx rulesync $@ --version
1.2.5
 user@machine  ~/project-directory   main ±  mr rulesync init     
[rulesync] $ npx rulesync $@ init
ℹ Initializing rulesync...                                                                                                                                   rulesync 9:18:02 AM
ℹ Skipped .rulesync/rules/overview.md (already exists)                                                                                                       rulesync 9:18:02 AM
✔ rulesync initialized successfully!                                                                                                                         rulesync 9:18:02 AM
ℹ Next steps:                                                                                                                                                rulesync 9:18:02 AM
ℹ 1. Edit rule files in .rulesync/rules/                                                                                                                     rulesync 9:18:02 AM
ℹ 2. Run 'rulesync generate' to create configuration files                                                                                                   rulesync 9:18:02 AM
 user@machine  ~/project-directory   main ±  ls .rulesync/rules                
overview.md
 user@machine  ~/project-directory   main ±  ls -la .cursor/rules                             
total 152
drwxr-xr-x@ 13 user  staff    416 Jul 29 13:24 .
drwxr-xr-x@  3 user  staff     96 Feb 18  2025 ..
-rw-r--r--@  1 user  staff   6148 Jul  9 09:57 .DS_Store
-rw-r--r--@  1 user  staff   4837 Mar  3  2025 cursor-project-rule-editor.mdc
-rw-r--r--@  1 user  staff   8376 Jul 29 13:30 diataxis-explanation.mdc
-rw-r--r--@  1 user  staff   8782 Mar  2  2025 diataxis-how-to.mdc
-rw-r--r--@  1 user  staff  10445 Mar 24  2025 diataxis-reference.mdc
-rw-r--r--@  1 user  staff   8513 Mar 24  2025 diataxis-tutorial.mdc
drwxr-xr-x@ 22 user  staff    704 Sep  9 10:14 logseq-cursor-rules
drwxr-xr-x@  3 user  staff     96 Mar  8  2025 subfolder
-rw-r--r--@  1 user  staff    192 Mar  8  2025 test-docs-at-reference-no-space.mdc
-rw-r--r--@  1 user  staff    160 Mar  8  2025 test-docs-at-reference-space.mdc
-rw-r--r--@  1 user  staff    138 Mar  8  2025 test-favorite-cars.mdc
 user@machine  ~/project-directory   main ±  mr rulesync import --targets cursor
[rulesync] $ npx rulesync $@ import --targets cursor
ℹ Found 0 root tool rule files                                                                                                                               rulesync 9:19:47 AM
(node:77630) ExperimentalWarning: globSync is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
ℹ No tool files found Invalid frontmatter in diataxis-explanation.mdc: [                                                                                     rulesync 9:19:47 AM
  {
    "expected": "string",
    "code": "invalid_type",
    "path": [
      "globs"
    ],
    "message": "Invalid input"
  }
]

    at _CursorRule.fromFile (/path/to/node_modules/rulesync/dist/index.js:4545:13)
    at async Promise.all (index 1)
    at async /path/to/node_modules/rulesync/dist/index.js:5500:14
    at async RulesProcessor.loadToolRulesDefault (/path/to/node_modules/rulesync/dist/index.js:5493:30)
    at async RulesProcessor.loadCursorRules (/path/to/node_modules/rulesync/dist/index.js:5661:12)
    at async RulesProcessor.loadToolFiles (/path/to/node_modules/rulesync/dist/index.js:5444:18)
    at async importCommand (/path/to/node_modules/rulesync/dist/index.js:6158:25)
    at async Command.<anonymous> (/path/to/node_modules/rulesync/dist/index.js:6336:7)
ℹ No tool files found ENOENT: no such file or directory, open '.cursorignore'                                                                                rulesync 9:19:47 AM

    at async open (node:internal/fs/promises:638:25)
    at async readFile (node:internal/fs/promises:1242:14)
    at async _CursorIgnore.fromFile (/path/to/node_modules/rulesync/dist/index.js:1835:25)
    at async IgnoreProcessor.loadToolIgnores (/path/to/node_modules/rulesync/dist/index.js:2183:17)
    at async IgnoreProcessor.loadToolFiles (/path/to/node_modules/rulesync/dist/index.js:2163:27)
    at async importCommand (/path/to/node_modules/rulesync/dist/index.js:6176:25)
    at async Command.<anonymous> (/path/to/node_modules/rulesync/dist/index.js:6336:7)
ℹ No MCP files found for tool target: cursor ENOENT: no such file or directory, open '.cursor/mcp.json'                                                      rulesync 9:19:47 AM

    at async open (node:internal/fs/promises:638:25)
    at async readFile (node:internal/fs/promises:1242:14)
    at async _CursorMcp.fromFile (/path/to/node_modules/rulesync/dist/index.js:2626:25)
    at async /path/to/node_modules/rulesync/dist/index.js:2799:15
    at async McpProcessor.loadToolFiles (/path/to/node_modules/rulesync/dist/index.js:2763:24)
    at async importCommand (/path/to/node_modules/rulesync/dist/index.js:6199:25)
    at async Command.<anonymous> (/path/to/node_modules/rulesync/dist/index.js:6336:7)
ℹ Successfully loaded 0 .cursor/commands commands      

Hypothesis

If the contents of the rule file vary even slightly from the schema expected by rulesync, all of the rules fail to import with cursor

The reason why this failed was because I had some old cursor project rules that had a globs key, which cursor used to add to all cursor rule files at the time I created the rules.

Suggestion for improving rulesync developer experience (DX)

Given that the schema of the files used by each AI tool drifts over time, consider creating a facility to improve the messaging of rulesync when a validation error is encountered.

Suggested Advice and Workarounds

  • Use npx rulesync config --init and then update rulesync.jsonc to have "verbose": true and try again to discover the issue
  • Remove the globs: keys from the markdown frontmatter of .cursor/rules/*.mdc prior to importing cursor rules

codekiln avatar Sep 29 '25 13:09 codekiln

Thank you for your request.

Your point should be resolved certainly, however my workforce is really limited, so it will be worked on later. So I will be happy if anyone contribute this repo through discussing specs and implementing that.

Now, I'm working for https://github.com/dyoshikawa/rulesync/issues/304 preferentially.

cm-dyoshikawa avatar Sep 30 '25 00:09 cm-dyoshikawa

This issue appears to be already fixed by https://github.com/dyoshikawa/rulesync/pull/1070

deepRemoveNullishObject() was added to parseFrontmatter(), stripping YAML null from bare keys like globs: before validation.

Verified with rulesync import --targets cursor (v7.12.0):

Frontmatter Result
globs: (empty) globs: []
globs: "*.ts" globs: ["*.ts"]
alwaysApply: true, no globs globs: ["**/*"]

All imported successfully. Could you confirm and close if resolved? @codekiln

saitota avatar Mar 02 '26 14:03 saitota

Mind closing this? @codekiln @dyoshikawa

saitota avatar Mar 05 '26 13:03 saitota

thanks.

dyoshikawa avatar Mar 10 '26 14:03 dyoshikawa