"""
Rules file templates for different AI coding clients.

Each template contains instructions that tell the client agent to prefer
Manhattan MCP tools over built-in equivalents for codebase navigation.
"""

# ============================================================================
# Cursor: .cursor/rules/manhattan.mdc
# Uses MDC format with YAML frontmatter. alwaysApply: true ensures
# these rules are injected into every interaction.
# ============================================================================

CURSOR_RULES = """\
---
description: Manhattan MCP code navigation — prefer cached, token-efficient tools
alwaysApply: true
---

# Manhattan MCP — Code Navigation

You have access to Manhattan MCP tools that provide **cached, compressed code context**.
ALWAYS prefer these over your built-in equivalents:

| Instead of…        | Use this Manhattan tool   | Why                              |
|--------------------|---------------------------|----------------------------------|
| `view_file`        | `read_file_context`       | Returns compressed context, saves 50-80% tokens |
| `grep_search`      | `search_codebase`         | Semantic + keyword hybrid search |
| `view_file_outline` | `get_file_outline`       | Compact structural overview      |
| `list_dir` (indexed) | `list_directory`        | Shows indexed files with metadata |

## After editing files

After modifying any file, call `index_file(file_path)` to update the cached context.
This keeps search results and file context fresh.

## When to use built-in tools instead

- Use built-in `view_file` only when you need exact line content for a code edit
- Use built-in `grep_search` only for exact string/regex matches not found via `search_codebase`
"""

# ============================================================================
# Claude Desktop / Claude Code: CLAUDE.md
# Placed in project root. Claude reads this as project context.
# Keep concise — Claude reliably follows ~100-150 custom instructions.
# ============================================================================

CLAUDE_RULES = """\

## Manhattan MCP — Code Navigation

ALWAYS prefer Manhattan MCP tools over built-in equivalents:

- `read_file_context` instead of `View` / `Read` — returns compressed cached context
- `search_codebase` instead of `Grep` / `Search` — semantic + keyword hybrid search
- `get_file_outline` instead of `View` outline — compact structural overview

After editing any file, call `index_file(file_path)` to update the cache.

Only fall back to built-in tools when you need exact line content for edits.
"""

# ============================================================================
# Gemini (Antigravity / Gemini CLI): GEMINI.md
# Placed in project root. Similar to CLAUDE.md.
# ============================================================================

GEMINI_RULES = """\

## Manhattan MCP — Code Navigation

ALWAYS prefer Manhattan MCP tools over built-in equivalents:

- `read_file_context` instead of `view_file` — returns compressed cached context (50-80% fewer tokens)
- `search_codebase` instead of `grep_search` — semantic + keyword hybrid search across indexed files
- `get_file_outline` instead of `view_file_outline` — compact structural overview (~10% of file tokens)
- `list_directory` — browse indexed files with metadata

After editing any file, call `index_file(file_path)` to update the cached context.

Only fall back to built-in tools when you need exact line content for a code edit.
"""

# ============================================================================
# Windsurf: .windsurfrules
# Placed in project root. Markdown format.
# ============================================================================

WINDSURF_RULES = """\

## Manhattan MCP — Code Navigation

ALWAYS prefer Manhattan MCP tools over built-in equivalents:

- `read_file_context` instead of `view_file` — returns compressed cached context
- `search_codebase` instead of `grep_search` — semantic + keyword hybrid search
- `get_file_outline` instead of `view_file_outline` — compact structural overview

After editing any file, call `index_file(file_path)` to update the cache.

Only fall back to built-in tools when you need exact line content for edits.
"""

# ============================================================================
# GitHub Copilot: .github/copilot-instructions.md
# Auto-applied to all Copilot interactions in the repo.
# ============================================================================

COPILOT_RULES = """\
## Manhattan MCP — Code Navigation

This project uses Manhattan MCP for token-efficient codebase navigation.
ALWAYS prefer these tools over built-in equivalents:

- `read_file_context` instead of reading files directly — returns compressed cached context
- `search_codebase` instead of grep/search — semantic + keyword hybrid search
- `get_file_outline` instead of file outline — compact structural overview

After editing any file, call `index_file(file_path)` to update the cached context.

Only fall back to built-in tools when you need exact line content for a code edit.
"""

# ============================================================================
# Registry: maps client names to (filename, content, mode)
#   mode: "create" = create new file, "append" = append to existing
# ============================================================================

CLIENT_RULES = {
    "cursor": {
        "path": ".cursor/rules/manhattan.mdc",
        "content": CURSOR_RULES,
        "mode": "create",  # Cursor rules are standalone files
        "description": "Cursor rules (.cursor/rules/manhattan.mdc)",
    },
    "claude": {
        "path": "CLAUDE.md",
        "content": CLAUDE_RULES,
        "mode": "append",
        "description": "Claude instructions (CLAUDE.md)",
    },
    "gemini": {
        "path": "GEMINI.md",
        "content": GEMINI_RULES,
        "mode": "append",
        "description": "Gemini instructions (GEMINI.md)",
    },
    "copilot": {
        "path": ".github/copilot-instructions.md",
        "content": COPILOT_RULES,
        "mode": "append",
        "description": "GitHub Copilot instructions (.github/copilot-instructions.md)",
    },
    "windsurf": {
        "path": ".windsurfrules",
        "content": WINDSURF_RULES,
        "mode": "append",
        "description": "Windsurf rules (.windsurfrules)",
    },
}

SUPPORTED_CLIENTS = list(CLIENT_RULES.keys())
