> ## Documentation Index
> Fetch the complete documentation index at: https://kasava.dev/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# AI Chat

> Context-aware coding assistant that understands your codebase

Kasava's AI Chat is a powerful coding assistant that understands your actual codebase. Unlike generic AI tools, it can reference your indexed repositories to provide accurate, relevant answers.

## Overview

AI Chat is powered by Claude, Anthropic's advanced language model. When combined with your indexed code, it can:

* **Answer questions** about how your code works
* **Explain implementations** with code references
* **Suggest improvements** based on your patterns
* **Debug issues** using your actual code context
* **Generate documentation** for your codebase
* **Analyze uploaded documents** and discuss their contents

## Getting Started

<Steps>
  <Step title="Index a Repository">
    [Index a repository](/docs/features/code-intelligence) to give the AI context about your codebase
  </Step>

  <Step title="Open Chat">
    Access Chat from the sidebar by expanding a Product and clicking on any sub-tab, or use the chat icon in the header to open the slide-out chat panel
  </Step>

  <Step title="Start a New Conversation">
    Click the "New Conversation" button in the header to start a fresh chat session
  </Step>

  <Step title="Ask Questions">
    Type your question in the input field at the bottom and press Enter or click the send button
  </Step>
</Steps>

## Accessing AI Chat

There are multiple ways to access AI Chat in Kasava:

### Global Chat Panel

Click the chat icon (message bubble) in the top-right header area of any page. This opens a slide-out panel where you can chat with the AI without leaving your current page.

**Keyboard shortcut:** Press `Cmd+J` (Mac) or `Ctrl+J` (Windows) to toggle the chat panel.

### Dedicated Chat Page

Navigate to `/chat` directly for a full-page chat experience with:

* **Conversation sidebar** on the left showing all your chat sessions
* **Main chat area** on the right for the active conversation
* **Resizable panels** - drag the divider to adjust sidebar width

## Managing Conversations

### Conversation Sidebar

The sidebar displays all your conversations organized by date:

* **Today** - Conversations from today
* **Yesterday** - Yesterday's conversations
* **This Week** - Conversations from the past 7 days
* **Older** - Conversations older than a week

### Conversation Actions

Hover over any conversation in the sidebar to reveal options:

* **Rename** - Click the pencil icon or right-click and select "Rename"
* **Delete** - Click the trash icon or right-click and select "Delete"

You can also access these options via the three-dot menu on each conversation.

### Starting Fresh

Click the "New Conversation" button at the top of the page to start a new chat session. The AI will automatically generate a title for the conversation based on your first message.

## Chat Features

### Streaming Responses

Responses stream in real-time, so you see the answer as it's being generated. A loading indicator shows when the AI is processing your request.

### Code References

The AI includes references to specific files and code patterns from your indexed repositories:

```
The authentication is handled in `src/middleware/auth.ts` at line 45...
```

### Multi-Turn Conversations

Continue conversations with follow-up questions. The AI remembers context from earlier in the chat, allowing you to dive deeper into topics without repeating context.

### Personalization

AI Chat learns from your corrections and preferences over time:

* **Terminology** — Uses your preferred terms (e.g., "customer" vs "user")
* **Categorization** — Follows your classification conventions
* **Formatting** — Matches your documentation style preferences

When you make corrections, those preferences are automatically applied to future chat sessions.

### Document Attachments

Upload documents directly into your conversation:

1. **Drag and drop** a file anywhere in the chat window
2. Or click the **attachment button** (+) in the input toolbar

Supported file types include PDFs, text files, and common document formats. The AI will analyze the document and make it available for discussion.

### Suggested Actions

When you start a new conversation, the chat may display helpful suggestions to get you started. Click any suggestion to quickly send that message.

## Asking Questions

### Effective Prompts

The AI works best with clear, specific questions:

| Good Prompt                                                   | Why It Works                  |
| ------------------------------------------------------------- | ----------------------------- |
| "How does the authentication middleware validate JWT tokens?" | Specific component and action |
| "Explain the data flow in the user registration process"      | Clear scope and request       |
| "What error handling patterns are used in the API routes?"    | Focused technical question    |
| "Where is the database connection configured?"                | Specific lookup request       |

### Less Effective Prompts

| Prompt               | Issue                          |
| -------------------- | ------------------------------ |
| "Explain everything" | Too broad                      |
| "Is my code good?"   | Vague evaluation criteria      |
| "Fix all bugs"       | No specific problem identified |

## Best Practices

<Tip>
  **Start specific, then broaden** - Begin with focused questions, then ask follow-ups for more detail.
</Tip>

<Tip>
  **Reference file names** - If you know which file to ask about, mention it for more accurate responses.
</Tip>

<Tip>
  **Ask for explanations** - "Explain how X works" often yields better results than "Show me X".
</Tip>

<Tip>
  **Use follow-ups** - After getting an answer, ask "Why is it done this way?" or "What are the alternatives?"
</Tip>

<Tip>
  **Upload documents** - When discussing requirements, designs, or external documentation, drag and drop the file into the chat for context.
</Tip>

## Example Conversations

### Understanding Code Flow

**You:** How does the checkout process work in this e-commerce app?

**AI:** The checkout process is implemented in `src/services/checkout.ts`. Here's the flow:

1. `initiateCheckout()` validates the cart contents
2. `calculateTotals()` computes prices, taxes, and shipping
3. `processPayment()` handles Stripe integration
4. `createOrder()` persists the order to the database

The entry point is the `POST /api/checkout` route in `src/routes/checkout.ts:42`.

***

### Debugging

**You:** Why might the user session be expiring too quickly?

**AI:** Looking at your session configuration in `src/config/auth.ts`, I see the session maxAge is set to 3600000ms (1 hour). However, in `src/middleware/session.ts:28`, there's a `rolling: false` setting which means the session timer isn't reset on activity.

To fix the quick expiration, you could either:

1. Increase `maxAge` in the config
2. Set `rolling: true` to refresh on each request

***

### Code Review

**You:** Are there any obvious issues with the error handling in the API routes?

**AI:** I noticed a few patterns that could be improved:

1. In `src/routes/users.ts`, errors are caught but not logged before returning a 500 response
2. The `src/routes/orders.ts` file doesn't have try-catch blocks around database operations
3. Some routes return raw error messages which could expose implementation details

Recommendation: Use a centralized error handler like the one partially implemented in `src/middleware/errorHandler.ts`.

## Limitations

Be aware of these limitations:

* **Only indexed code** - The AI can only reference repositories you've indexed
* **Point-in-time** - Answers are based on when the repository was last indexed
* **Not real-time** - The AI doesn't see uncommitted changes in your local environment
* **Token limits** - Very large codebases may have some files truncated in context

## Keyboard Shortcuts

| Shortcut        | Action              |
| --------------- | ------------------- |
| `Cmd/Ctrl + J`  | Toggle chat panel   |
| `Enter`         | Send message        |
| `Shift + Enter` | New line in message |

## Related

<CardGroup cols={2}>
  <Card title="Code Intelligence" icon="brain" href="/docs/features/code-intelligence">
    Index repositories and search code semantically
  </Card>

  <Card title="Plans" icon="file-lines" href="/docs/features/plans">
    Create and manage product specs
  </Card>
</CardGroup>
