Skip to content

fix(llms): narrow LLM rule globs to router-specific files#7064

Open
mixelburg wants to merge 1 commit intoTanStack:mainfrom
mixelburg:fix/llm-rules-globs
Open

fix(llms): narrow LLM rule globs to router-specific files#7064
mixelburg wants to merge 1 commit intoTanStack:mainfrom
mixelburg:fix/llm-rules-globs

Conversation

@mixelburg
Copy link
Copy Markdown

@mixelburg mixelburg commented Mar 27, 2026

Fixes #6935

Problem

The LLM rules use src/**/*.ts and src/**/*.tsx as globs. Per Cursor's docs, when alwaysApply: false rules have globs set, they auto-load whenever any matching file is in context. These broad globs match every TypeScript file in the project, so all five rules (~25-40k tokens combined) load whenever you open any source file in Cursor.

Fix

Narrow the globs to files where router context is actually useful:

  • Route rules (api, guide, routing): src/routes/**/*.ts, src/routes/**/*.tsx, **/routeTree.gen.ts, **/__root.tsx
  • Setup rules (installation, setup-and-architecture): package.json, vite.config.ts, tsconfig.json, app.config.ts

Now router rules only load when you're actually working with route files or config files, not when editing every file in the project.

Summary by CodeRabbit

  • Chores
    • Updated build script configuration to optimize the scope of generated rule packages.

The previous globs (src/**/*.ts, src/**/*.tsx) matched every TypeScript
file in the project, causing Cursor to load all five LLM rules (~25-40k
tokens) whenever any source file was in context - even unrelated files.

Replace with targeted globs:
- Route rules (api, guide, routing): src/routes/**/*.ts, src/routes/**/*.tsx,
  routeTree.gen.ts, __root.tsx - files where router context is actually useful
- Setup rules (installation, setup-and-architecture): package.json,
  vite.config.ts, tsconfig.json, app.config.ts - config files only

Rules will no longer auto-load when editing arbitrary source files.

Fixes TanStack#6935
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 27, 2026

📝 Walkthrough

Walkthrough

Modified glob patterns in scripts/llms-generate.mjs for generated LLM rule packages. Replaced broad source directory patterns with narrower, targeted paths: routing rules now target src/routes/**/* and generated route files; setup rules target configuration files only (package.json, vite.config.ts, tsconfig.json, app.config.ts).

Changes

Cohort / File(s) Summary
Glob Pattern Refinement
scripts/llms-generate.mjs
Updated glob arrays for api, guide, routing packages to target src/routes/**/*.{ts,tsx} and generated route files; updated installation and setup-and-architecture packages to target specific config files instead of broad src/**/* patterns.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 With focused paths and narrower sight,
We trim the globs to fit just right,
No more broad sweeps through every door,
Just routes and configs—less is more! 🎯

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: narrowing LLM rule globs from broad source patterns to router-specific files, which is the core objective.
Linked Issues check ✅ Passed The PR successfully addresses both primary objectives from #6935: narrowing globs so rules only load for router-relevant files (routes and config files), preventing context bloat when editing unrelated source files.
Out of Scope Changes check ✅ Passed All changes are narrowly scoped to the glob patterns in scripts/llms-generate.mjs, directly addressing the linked issue without introducing unrelated modifications.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
scripts/llms-generate.mjs (1)

26-31: Consider centralizing repeated glob lists to avoid drift.

route and setup glob sets are repeated across entries. Extracting them into constants would make future updates safer and keep behavior consistent.

♻️ Suggested refactor
+const ROUTE_RULE_GLOBS = [
+  'src/routes/**/*.ts',
+  'src/routes/**/*.tsx',
+  '**/routeTree.gen.ts',
+  '**/__root.tsx',
+]
+
+const SETUP_RULE_GLOBS = [
+  'package.json',
+  'vite.config.ts',
+  'tsconfig.json',
+  'app.config.ts',
+]
+
 const packages = {
   'react-router': [
     {
       paths: [`${DOCS_DIR}/router/api/router`],
       description: 'TanStack Router: API',
       name: 'api',
-      globs: [
-        'src/routes/**/*.ts',
-        'src/routes/**/*.tsx',
-        '**/routeTree.gen.ts',
-        '**/__root.tsx',
-      ],
+      globs: ROUTE_RULE_GLOBS,
     },
     {
       paths: [`${DOCS_DIR}/router/guide`],
       description: 'TanStack Router: Guide',
       name: 'guide',
-      globs: [
-        'src/routes/**/*.ts',
-        'src/routes/**/*.tsx',
-        '**/routeTree.gen.ts',
-        '**/__root.tsx',
-      ],
+      globs: ROUTE_RULE_GLOBS,
     },
     {
       paths: [`${DOCS_DIR}/router/routing`],
       description: 'TanStack Router: Routing',
       name: 'routing',
-      globs: [
-        'src/routes/**/*.ts',
-        'src/routes/**/*.tsx',
-        '**/routeTree.gen.ts',
-        '**/__root.tsx',
-      ],
+      globs: ROUTE_RULE_GLOBS,
     },
     {
       paths: [`${DOCS_DIR}/router/installation`],
       description: 'TanStack Router: Installation',
       name: 'installation',
-      globs: [
-        'package.json',
-        'vite.config.ts',
-        'tsconfig.json',
-        'app.config.ts',
-      ],
+      globs: SETUP_RULE_GLOBS,
     },
     {
       // ...
-      globs: [
-        'package.json',
-        'vite.config.ts',
-        'tsconfig.json',
-        'app.config.ts',
-      ],
+      globs: SETUP_RULE_GLOBS,
     },
   ],
 }

Also applies to: 37-42, 48-53, 59-64, 76-81

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@scripts/llms-generate.mjs` around lines 26 - 31, The repeated glob arrays
used in multiple "globs" properties should be centralized: define shared
constants (e.g., ROUTE_GLOBS and SETUP_GLOBS) at the top of the module and
replace each inline globs: [...] occurrence with the appropriate constant
reference; update every occurrence that currently uses the route and setup lists
(the objects that currently have globs: ['src/routes/**/*.ts',
'src/routes/**/*.tsx', '**/routeTree.gen.ts', '**/__root.tsx'] and similar
blocks at the other entries) so all entries consume the same constants to
prevent drift and simplify future changes.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@scripts/llms-generate.mjs`:
- Around line 26-31: The repeated glob arrays used in multiple "globs"
properties should be centralized: define shared constants (e.g., ROUTE_GLOBS and
SETUP_GLOBS) at the top of the module and replace each inline globs: [...]
occurrence with the appropriate constant reference; update every occurrence that
currently uses the route and setup lists (the objects that currently have globs:
['src/routes/**/*.ts', 'src/routes/**/*.tsx', '**/routeTree.gen.ts',
'**/__root.tsx'] and similar blocks at the other entries) so all entries consume
the same constants to prevent drift and simplify future changes.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e594661e-c4d0-44d9-afab-3d964bbb6715

📥 Commits

Reviewing files that changed from the base of the PR and between 21bd992 and f59697e.

📒 Files selected for processing (1)
  • scripts/llms-generate.mjs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LLM rules exceed Cursor's 500-line guideline and use overly broad globs

1 participant