mcpField
C
cursor-rules-config

cursor-rules-config

github.com/jeremylongshoreエージェントワークフロー2.9k42 回インストール2 日前に更新
リポジトリ

cursor-rules-config について

Cursorのプロジェクトルールを管理する開発者向けのスキルです。ルールのスコープ設定、テスト、レビュー、バージョン管理を案内します。

主な機能

  1. 01スコープ付き .mdc ルールの作成
  2. 02ファイルパターンによるルール適用
  3. 03共有規約とローカル規約の管理
  4. 04ルールのテストと変更レビュー
  5. 05競合や機密情報への対処

活用シーン

  1. 01APIルートの検証規約を定義
  2. 02旧 .cursorrules をルールファイルに分割
  3. 03無関係なファイルへの適用を確認

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/jeremylongshore/tons-of-skills-marketplace --skill cursor-rules-config

インストール後、Claude Code で/cursor-rules-configを入力して読み込まれたか確認します。

同梱ファイル

SKILL.md と一緒にインストールされる参考資料やスクリプト。

references/
advanced-configuration.md
basic-configuration.md
errors.md
examples.md
framework-specific-templates.md
tips-for-effective-rules.md

詳細

Cursor ルール設定

概要

Cursor のルールを、AI のコンテキストと動作を形作るバージョン管理されたエンジニアリングポリシーとして管理します。ルールは具体的で、適用範囲が明確で、レビュー済みであり、リポジトリの信頼できる情報源と一貫している必要があります。

前提条件

  • リポジトリ所有者の承認、既存のエンジニアリング/セキュリティ基準、テスト用ワークスペース。
  • シークレット、生成ファイル、機密データに関する、レビュー済みの除外戦略。

手順

  1. 懸念事項ごとに、適用範囲、優先度、具体的な受け入れ動作を含む明確なルールを1つ作成します。
  2. 共有ルールはソース管理に置き、ローカルの規約にはパスで適用範囲を限定したルールを使用します。
  3. 機密情報を含まないフィクスチャで新しいルールをテストし、動作を確認してから、通常のレビューを経てマージします。
  4. 定期的に古くなったルールや競合するルールを削除し、意図的な例外があれば文書化します。

出力

  • 適用範囲が明確で、動作例によるテストを済ませた、レビュー済みのバージョン管理されたルールセット。

エラー処理

状況安全な対応
ルールが競合する1つの権威あるルールに統一し、修正したルールを展開前にテストします。
ルールが機密情報を露出させるルールを削除し、除外設定を修正して、露出の影響を評価します。
ルールの適用範囲が広すぎる共有ガバナンスをすべて無効にするのではなく、パスやタスクごとに適用範囲を限定します。

例

既存のバリデーションとテストを必須とする、パスで適用範囲を限定した API ルールを追加し、サニタイズ済みフィクスチャでテストします。このルールの PR を作成し、マージ前に、無関係なフロントエンドファイルには適用されないことを確認します。

Cursor のルールシステムを通じて、プロジェクト固有の AI の動作を設定します。現在の方法では .cursor/rules/*.mdc ファイルを使用します。従来の .cursorrules ファイルも引き続きサポートされていますが、非推奨です。

ルールシステムのアーキテクチャ

新しい形式のプロジェクトルール(.cursor/rules/*.mdc)

各 .mdc ファイルには、YAML フロントマターと、それに続く Markdown コンテンツが含まれます。

---
description: "Enforce TypeScript strict mode and functional patterns"
globs: "src/**/*.ts,src/**/*.tsx"
alwaysApply: false
---
# TypeScript Standards

- Use `const` over `let`, never `var`
- Prefer pure functions over classes
- All functions must have explicit return types
- Use discriminated unions over enums

フロントマターのフィールド:

フィールド型用途
descriptionstringルールの目的を簡潔に記述します(Cursor UI に表示されます)。
globsstring自動添付に使用する Gitignore 形式のパターンです。
alwaysApplybooleantrue = 常に有効、false = 一致するファイルが参照された場合のみ有効です。
alwaysApply と globs の組み合わせによるルールの種類
alwaysApplyglobs動作
true空すべてのプロンプトに常に挿入されます。
false設定済み一致するファイルがコンテキストに含まれると自動的に添付されます。
false空手動のみです。チャットで @Cursor Rules を指定して参照します。
ファイルの命名規則

.mdc 拡張子を付けた kebab-case を使用します。名前にはルールの適用範囲を記述します。

.cursor/rules/
  typescript-standards.mdc
  react-component-patterns.mdc
  api-error-handling.mdc
  testing-conventions.mdc
  database-migrations.mdc
  security-requirements.mdc

次の手順で新しいルールを作成します:Cmd+Shift+P > New Cursor Rule

プロジェクトルールの完全な例

.cursor/rules/project-context.mdc(常時有効):

---
description: "Core project context and conventions"
globs: ""
alwaysApply: true
---
# Project: E-Commerce Platform

Tech stack: Next.js 15, TypeScript 5.7, Prisma ORM, PostgreSQL, Tailwind CSS 4.
Package manager: pnpm. Monorepo with turborepo.

## Conventions
- API routes in `app/api/` using Route Handlers
- Server Components by default, `"use client"` only when needed
- Error boundaries at layout level
- All monetary values stored as integers (cents)
- Dates stored as UTC, displayed in user timezone

.cursor/rules/react-patterns.mdc(glob で適用範囲を限定):

---
description: "React component standards for TSX files"
globs: "src/**/*.tsx,app/**/*.tsx"
alwaysApply: false
---
# React Component Rules

- Export components as named exports, not default
- Props interface named `{Component}Props`
- Use `forwardRef` for components accepting `ref`
- Colocate styles in `.module.css` files
- Server Components: no `useState`, `useEffect`, or event handlers

```tsx
// Correct pattern
export interface ButtonProps {
  variant: 'primary' | 'secondary';
  children: React.ReactNode;
  onClick?: () => void;
}

export function Button({ variant, children, onClick }: ButtonProps) {
  return (
    <button className={styles[variant]} onClick={onClick}>
      {children}
    </button>
  );
}

**`.cursor/rules/api-routes.mdc`** (glob-scoped):
```yaml
---
description: "API route handler patterns"
globs: "app/api/**/*.ts"
alwaysApply: false
---
# API Route Standards

- Always validate request body with Zod
- Return typed `NextResponse.json()` responses
- Use consistent error response shape: `{ error: string, code: string }`
- Wrap handlers in try/catch with structured logging

```ts
import { NextRequest, NextResponse } from 'next/server';
import { z } from 'zod';

const CreateOrderSchema = z.object({
  items: z.array(z.object({
    productId: z.string().uuid(),
    quantity: z.number().int().positive(),
  })),
});

export async function POST(req: NextRequest) {
  try {
    const body = await req.json();
    const parsed = CreateOrderSchema.parse(body);
    const order = await createOrder(parsed);
    return NextResponse.json(order, { status: 201 });
  } catch (err) {
    if (err instanceof z.ZodError) {
      return NextResponse.json(
        { error: 'Validation failed', code: 'INVALID_INPUT', details: err.issues },
        { status: 400 }
      );
    }
    return NextResponse.json(
      { error: 'Internal server error', code: 'INTERNAL_ERROR' },
      { status: 500 }
    );
  }
}

## Legacy .cursorrules Format

Place a `.cursorrules` file in project root. Plain markdown, no frontmatter:

```markdown
# Project Rules

You are working on a Django REST Framework API.

## Stack
- Python 3.12, Django 5.1, DRF 3.15
- PostgreSQL 16 with pgvector extension
- Redis for caching and Celery broker
- pytest for testing

## Conventions
- ViewSets over function-based views
- Always use serializer validation
- Custom exceptions inherit from `APIException`
- All endpoints require authentication unless explicitly marked
- Use `select_related` and `prefetch_related` to avoid N+1 queries

## Code Style
- Type hints on all function signatures
- Docstrings on all public methods (Google style)
- Max function length: 30 lines

移行:.cursorrules から .cursor/rules/ へ

モノリシックな .cursorrules を、適用範囲を限定した複数の .mdc ファイルに分割します。

  1. .cursor/rules/ ディレクトリを作成します
  2. グローバルコンテキストを alwaysApply: true のルールに切り出します
  3. 言語/フレームワークのルールを、glob で適用範囲を限定したルールに切り出します
  4. すべてのルールが読み込まれることを確認した後、.cursorrules を削除します

ルールでのファイル参照

ルールが適用される際に追加のコンテキストファイルを含めるには、@file 構文を使用します。

---
description: "Database schema context for migration files"
globs: "prisma/**/*.prisma,drizzle/**/*.ts"
alwaysApply: false
---
Reference these files for schema context:
@prisma/schema.prisma
@docs/data-model.md

ルールのデバッグ

  1. チャットを開き、@Cursor Rules と入力して有効なルールを確認します
  2. glob パターンがファイルに一致することを確認します。ファイルを開き、コンテキストのピルにルールが表示されることを確認します
  3. alwaysApply: true のルールは常に表示されます。glob ルールは、一致するファイルがコンテキストに含まれる場合にのみ表示されます

エンタープライズでの考慮事項

  • バージョン管理:.cursor/rules/ を git にコミットします。ルールはプロジェクトのドキュメントです。
  • チーム内の調整:チーム全体の標準には alwaysApply: true を使用します。
  • 機密データ:API キー、シークレット、認証情報をルールファイルに記載しないでください。
  • ルールのサイズ:個々のルールは目的を絞り、200行未満に保ちます。大きなルールは複数のファイルに分割します。
  • 監査証跡:ルールの変更は git の履歴に記録され、コンプライアンスレビューに利用できます。

リソース

コメント