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

# AI Assistant

> Chat with AI about your docs, get suggestions, and automate tasks

The Whilst AI Assistant (Sidekick) is a chat interface built into the web app that provides intelligent document management through natural language.

## Capabilities

* **Document Search & Discovery** — Semantic search with citation of relevant sources
* **Document Operations** — Create, edit, organize, summarize, and analyze docs via chat
* **Conversation Management** — Persistent history, automatic titling, context awareness
* **Surgical Editing** — Targeted changes to specific document sections without rewriting

## Chat Pipeline

The assistant uses a parallelized pipeline to minimize time-to-first-token:

```
User Message
    ↓
1. Create/Load Conversation
    ↓
2. [PARALLEL]
   ├─ Enrich Context
   ├─ Get Recent Messages
   └─ Smart Document Search
    ↓
3. [ASYNC/NON-BLOCKING]
   ├─ Classify Intent
   └─ Generate Title
    ↓
4. Build AI Context → Stream Response
```

**Performance**: \~1s time-to-first-token, \~2.5s total response time.

## Smart Document Search

The assistant skips unnecessary searches to save latency:

* Always searches on first message in a conversation
* Skips if the query is too short (likely a follow-up)
* Skips if the user is viewing a specific document (uses that as context)

## Surgical Edit System

Applies targeted changes to documents without rewriting the entire content:

```typescript theme={null}
const result = await applySurgicalEdit(
  currentContent,
  "Reformat the ingredients into a single list",
  docTitle
);
// Only the targeted section is modified
```

Rules enforced by the system prompt:

1. Only modify the specific part mentioned
2. Preserve 100% of all other content
3. Return the complete document with targeted changes

## Frontend

The chat UI is located at `apps/web-app/components/docs-ai-chat-enhanced.tsx` and features:

* Minimal single-panel design inspired by Cursor
* Chat history dropdown for resuming conversations
* Real-time streaming via Server-Sent Events
* Inline citations with similarity scores
* Custom loading animation (Whilst logo "running" effect)
* Keyboard shortcuts: `Cmd+U` for files, `Cmd+Shift+V` for voice
