Skip to content

Commit 39e469f

Browse files
asvishnyakovclaude
andauthored
chore: introduce AI-assisted development to the project (#2864)
Add CLAUDE.md, AGENTS.md, Serena MCP config, Claude Code settings, and Context7 library ID reference docs to enable AI coding agents to work effectively with the codebase. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Adds `Serena MCP` config, `Claude Code` permissions, and agent guidance docs to support agent-assisted development across the repo. Also documents a required `Co-Authored-By` trailer for any agent-assisted commit. - **New Features** - Added `AGENTS.md` with setup, build/test/lint flows, backward-compatibility rules, and required `Co-Authored-By` trailer. - Added `.serena/project.yml` and `.serena/.gitignore` to enable `Serena MCP` with TypeScript/Python language servers and tool access. - Added `.claude/settings.json` to allow safe commands: `pnpm`, `uv`, `pytest`, `ruff`, `tsc`. - Added `docs/context7.md` (pre-resolved Context7 MCP library IDs), `docs/README.md`, and `CLAUDE.md`. - **Migration** - No runtime or API changes. Optional adoption only (use `Serena MCP` or `Claude Code` if desired). <sup>Written for commit 9f9c54a. Summary will update on new commits.</sup> <!-- End of auto-generated description by cubic. --> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 1eb4fca commit 39e469f

File tree

7 files changed

+470
-0
lines changed

7 files changed

+470
-0
lines changed

.claude/settings.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"permissions": {
3+
"allow": [
4+
"Bash(tsc --noEmit)",
5+
"Bash(uv run dmypy*)",
6+
"Bash(uv run pytest*)",
7+
"Bash(uv run ruff*)",
8+
"Bash(uv run scripts/*)",
9+
"Bash(pnpm install*)",
10+
"Bash(pnpm run build*)",
11+
"Bash(pnpm run lint*)",
12+
"Bash(pnpm run format*)",
13+
"Bash(pnpm test*)",
14+
"Bash(pnpm run test*)"
15+
]
16+
}
17+
}

.serena/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/cache
2+
/project.local.yml

.serena/project.yml

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
# the name by which the project can be referenced within Serena
2+
project_name: "chainlit"
3+
4+
5+
# list of languages for which language servers are started; choose from:
6+
# al bash clojure cpp csharp
7+
# csharp_omnisharp dart elixir elm erlang
8+
# fortran fsharp go groovy haskell
9+
# java julia kotlin lua markdown
10+
# matlab nix pascal perl php
11+
# php_phpactor powershell python python_jedi r
12+
# rego ruby ruby_solargraph rust scala
13+
# swift terraform toml typescript typescript_vts
14+
# vue yaml zig
15+
# (This list may be outdated. For the current list, see values of Language enum here:
16+
# https://github.com/oraios/serena/blob/main/src/solidlsp/ls_config.py
17+
# For some languages, there are alternative language servers, e.g. csharp_omnisharp, ruby_solargraph.)
18+
# Note:
19+
# - For C, use cpp
20+
# - For JavaScript, use typescript
21+
# - For Free Pascal/Lazarus, use pascal
22+
# Special requirements:
23+
# Some languages require additional setup/installations.
24+
# See here for details: https://oraios.github.io/serena/01-about/020_programming-languages.html#language-servers
25+
# When using multiple languages, the first language server that supports a given file will be used for that file.
26+
# The first language is the default language and the respective language server will be used as a fallback.
27+
# Note that when using the JetBrains backend, language servers are not used and this list is correspondingly ignored.
28+
languages:
29+
- typescript
30+
- python
31+
- bash
32+
- markdown
33+
- toml
34+
- yaml
35+
36+
# the encoding used by text files in the project
37+
# For a list of possible encodings, see https://docs.python.org/3.11/library/codecs.html#standard-encodings
38+
encoding: "utf-8"
39+
40+
# line ending convention to use when writing source files.
41+
# Possible values: unset (use global setting), "lf", "crlf", or "native" (platform default)
42+
# This does not affect Serena's own files (e.g. memories and configuration files), which always use native line endings.
43+
line_ending:
44+
45+
# The language backend to use for this project.
46+
# If not set, the global setting from serena_config.yml is used.
47+
# Valid values: LSP, JetBrains
48+
# Note: the backend is fixed at startup. If a project with a different backend
49+
# is activated post-init, an error will be returned.
50+
language_backend:
51+
52+
# whether to use project's .gitignore files to ignore files
53+
ignore_all_files_in_gitignore: true
54+
55+
# advanced configuration option allowing to configure language server-specific options.
56+
# Maps the language key to the options.
57+
# Have a look at the docstring of the constructors of the LS implementations within solidlsp (e.g., for C# or PHP) to see which options are available.
58+
# No documentation on options means no options are available.
59+
ls_specific_settings: {}
60+
61+
# list of additional paths to ignore in this project.
62+
# Same syntax as gitignore, so you can use * and **.
63+
# Note: global ignored_paths from serena_config.yml are also applied additively.
64+
ignored_paths: []
65+
66+
# whether the project is in read-only mode
67+
# If set to true, all editing tools will be disabled and attempts to use them will result in an error
68+
# Added on 2025-04-18
69+
read_only: false
70+
71+
# list of tool names to exclude.
72+
# This extends the existing exclusions (e.g. from the global configuration)
73+
#
74+
# Below is the complete list of tools for convenience.
75+
# To make sure you have the latest list of tools, and to view their descriptions,
76+
# execute `uv run scripts/print_tool_overview.py`.
77+
#
78+
# * `activate_project`: Activates a project by name.
79+
# * `check_onboarding_performed`: Checks whether project onboarding was already performed.
80+
# * `create_text_file`: Creates/overwrites a file in the project directory.
81+
# * `delete_lines`: Deletes a range of lines within a file.
82+
# * `delete_memory`: Deletes a memory from Serena's project-specific memory store.
83+
# * `execute_shell_command`: Executes a shell command.
84+
# * `find_referencing_code_snippets`: Finds code snippets in which the symbol at the given location is referenced.
85+
# * `find_referencing_symbols`: Finds symbols that reference the symbol at the given location (optionally filtered by type).
86+
# * `find_symbol`: Performs a global (or local) search for symbols with/containing a given name/substring (optionally filtered by type).
87+
# * `get_current_config`: Prints the current configuration of the agent, including the active and available projects, tools, contexts, and modes.
88+
# * `get_symbols_overview`: Gets an overview of the top-level symbols defined in a given file.
89+
# * `initial_instructions`: Gets the initial instructions for the current project.
90+
# Should only be used in settings where the system prompt cannot be set,
91+
# e.g. in clients you have no control over, like Claude Desktop.
92+
# * `insert_after_symbol`: Inserts content after the end of the definition of a given symbol.
93+
# * `insert_at_line`: Inserts content at a given line in a file.
94+
# * `insert_before_symbol`: Inserts content before the beginning of the definition of a given symbol.
95+
# * `list_dir`: Lists files and directories in the given directory (optionally with recursion).
96+
# * `list_memories`: Lists memories in Serena's project-specific memory store.
97+
# * `onboarding`: Performs onboarding (identifying the project structure and essential tasks, e.g. for testing or building).
98+
# * `prepare_for_new_conversation`: Provides instructions for preparing for a new conversation (in order to continue with the necessary context).
99+
# * `read_file`: Reads a file within the project directory.
100+
# * `read_memory`: Reads the memory with the given name from Serena's project-specific memory store.
101+
# * `remove_project`: Removes a project from the Serena configuration.
102+
# * `replace_lines`: Replaces a range of lines within a file with new content.
103+
# * `replace_symbol_body`: Replaces the full definition of a symbol.
104+
# * `restart_language_server`: Restarts the language server, may be necessary when edits not through Serena happen.
105+
# * `search_for_pattern`: Performs a search for a pattern in the project.
106+
# * `summarize_changes`: Provides instructions for summarizing the changes made to the codebase.
107+
# * `switch_modes`: Activates modes by providing a list of their names
108+
# * `think_about_collected_information`: Thinking tool for pondering the completeness of collected information.
109+
# * `think_about_task_adherence`: Thinking tool for determining whether the agent is still on track with the current task.
110+
# * `think_about_whether_you_are_done`: Thinking tool for determining whether the task is truly completed.
111+
# * `write_memory`: Writes a named memory (for future reference) to Serena's project-specific memory store.
112+
excluded_tools: []
113+
114+
# list of tools to include that would otherwise be disabled (particularly optional tools that are disabled by default).
115+
# This extends the existing inclusions (e.g. from the global configuration).
116+
included_optional_tools: []
117+
118+
# fixed set of tools to use as the base tool set (if non-empty), replacing Serena's default set of tools.
119+
# This cannot be combined with non-empty excluded_tools or included_optional_tools.
120+
fixed_tools: []
121+
122+
# list of mode names to that are always to be included in the set of active modes
123+
# The full set of modes to be activated is base_modes + default_modes.
124+
# If the setting is undefined, the base_modes from the global configuration (serena_config.yml) apply.
125+
# Otherwise, this setting overrides the global configuration.
126+
# Set this to [] to disable base modes for this project.
127+
# Set this to a list of mode names to always include the respective modes for this project.
128+
base_modes:
129+
130+
# list of mode names that are to be activated by default.
131+
# The full set of modes to be activated is base_modes + default_modes.
132+
# If the setting is undefined, the default_modes from the global configuration (serena_config.yml) apply.
133+
# Otherwise, this overrides the setting from the global configuration (serena_config.yml).
134+
# This setting can, in turn, be overridden by CLI parameters (--mode).
135+
default_modes:
136+
137+
# initial prompt for the project. It will always be given to the LLM upon activating the project
138+
# (contrary to the memories, which are loaded on demand).
139+
initial_prompt: ""
140+
141+
# time budget (seconds) per tool call for the retrieval of additional symbol information
142+
# such as docstrings or parameter information.
143+
# This overrides the corresponding setting in the global configuration; see the documentation there.
144+
# If null or missing, use the setting from the global configuration.
145+
symbol_info_budget:
146+
147+
# list of regex patterns which, when matched, mark a memory entry as read‑only.
148+
# Extends the list from the global configuration, merging the two lists.
149+
read_only_memory_patterns: []
150+
151+
# list of regex patterns for memories to completely ignore.
152+
# Matching memories will not appear in list_memories or activate_project output
153+
# and cannot be accessed via read_memory or write_memory.
154+
# To access ignored memory files, use the read_file tool on the raw file path.
155+
# Extends the list from the global configuration, merging the two lists.
156+
# Example: ["_archive/.*", "_episodes/.*"]
157+
ignored_memory_patterns: []

AGENTS.md

Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
# AGENTS.md
2+
3+
This file provides guidance to AI agents when working with code in this repository.
4+
5+
## Backward Compatibility (CRITICAL)
6+
7+
All changes MUST be backward-compatible. If a refactor or breaking change is unavoidable, notify the user and stop — do not proceed without explicit approval. When approved, prefer adding a compatibility layer over keeping legacy code in place.
8+
9+
## Overview
10+
11+
Chainlit is a Python framework for building production-ready conversational AI applications. It consists of a Python/FastAPI backend and a React frontend, with a pnpm monorepo for the JS packages.
12+
13+
## Prerequisites
14+
15+
- Python: **3.13** (3.10+ is the framework's minimum, but development targets 3.13)
16+
- Node.js: **24+**
17+
- [uv](https://docs.astral.sh/uv/) — Python package manager
18+
- [pnpm 9](https://pnpm.io/) — Node.js package manager (Corepack)
19+
20+
## Quick Start
21+
22+
### Install
23+
24+
| | Command | Directory |
25+
|---|---|---|
26+
| Backend | `uv sync --all-extras` | `backend/` |
27+
| Frontend | `pnpm install` | repo root |
28+
29+
### Build
30+
31+
| | Command | Directory | What it does |
32+
|---|---|---|---|
33+
| Backend | `uv build` | `backend/` | Build Python package — runs `pnpm buildUi`, then copies assets into `backend/chainlit/frontend/dist/` and `backend/chainlit/copilot/dist/` |
34+
| Frontend | `pnpm run buildUi` | repo root | Build libs + frontend JS assets |
35+
| Frontend (libs only) | `pnpm run build:libs` | repo root | Build only `react-client` and `copilot` libs |
36+
37+
### Dev servers
38+
39+
| | Command | Directory | URL |
40+
|---|---|---|---|
41+
| Backend | `uv run chainlit run chainlit/sample/hello.py -h` | `backend/` | http://localhost:8000 |
42+
| Frontend | `pnpm run dev` | `frontend/` | http://localhost:5173 (proxies to :8000) |
43+
44+
### Tests
45+
46+
| | Command | Directory |
47+
|---|---|---|
48+
| Backend (all) | `uv run pytest --cov=chainlit/` | `backend/` |
49+
| Backend (single file) | `uv run pytest tests/test_file.py` | `backend/` |
50+
| Frontend unit | `pnpm test` | `frontend/` |
51+
| E2E (Cypress) | `pnpm test` | repo root |
52+
53+
### Lint & Format
54+
55+
| | Command | Directory |
56+
|---|---|---|
57+
| Lint all | `pnpm run lint` | repo root |
58+
| Lint frontend only | `pnpm run lintUi` | repo root |
59+
| Format Python | `uv run ruff format chainlit/ tests/` | `backend/` |
60+
| Format JS/TS | `pnpm run formatUi` | repo root |
61+
62+
### Type checking
63+
64+
| | Command | Directory |
65+
|---|---|---|
66+
| Python (mypy) | `uv run dmypy run -- chainlit/ tests/` | `backend/` |
67+
| TypeScript | `tsc --noemit` | `frontend/` |
68+
69+
Run `pnpm run lint` before committing — CI enforces this.
70+
71+
### Commits
72+
73+
This project uses [Conventional Commits](https://www.conventionalcommits.org/). Format: `<type>(<optional scope>): <description>`.
74+
75+
Common types: `feat`, `fix`, `chore`, `docs`, `refactor`, `test`, `ci`. Scope is optional but encouraged (e.g. `fix(data): ...`, `feat(i18n): ...`).
76+
77+
All commits made with AI assistance **must** include a `Co-Authored-By` trailer identifying the AI agent. Add it as the last line of the commit message body:
78+
79+
```
80+
Co-Authored-By: <Agent Name> <agent-email-or-noreply>
81+
```
82+
83+
Examples:
84+
- `Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>`
85+
- `Co-Authored-By: GitHub Copilot <noreply@github.com>`
86+
- `Co-Authored-By: Gemini CLI <noreply@google.com>`
87+
88+
## Tech Stack
89+
90+
| Layer | Stack |
91+
|---|---|
92+
| **Frontend** | React 18, TypeScript 5.2, Vite 5, Tailwind CSS 3, Vitest, Zod 3 |
93+
| **Frontend (state & routing)** | Recoil, React Router 6, react-hook-form, socket.io-client, SWR |
94+
| **Frontend (rendering)** | react-markdown + remark-gfm/math + rehype-katex/raw, highlight.js, lucide-react (icons), Radix UI (primitives), Plotly.js |
95+
| **Backend** | Python 3.13, FastAPI, Starlette, Uvicorn, python-socketio, Pydantic 2, PyJWT, httpx |
96+
| **LLM integrations** | MCP, LangChain, LlamaIndex, OpenAI SDK, Semantic Kernel, MistralAI |
97+
| **Infra / persistence** | SQLAlchemy (PostgreSQL/SQLite), DynamoDB + S3 (boto3), Azure Blob / Data Lake, Google Cloud Storage, LiteralAI |
98+
| **DX** | Husky (pre-commit), ESLint, Prettier, ruff, mypy (dmypy), pytest, Cypress |
99+
100+
## Architecture
101+
102+
### Monorepo structure
103+
104+
```
105+
backend/ # Python package (published to PyPI as "chainlit")
106+
frontend/ # React app (built output served by backend)
107+
libs/
108+
react-client/ # @chainlit/react-client — published npm package with React hooks
109+
copilot/ # Copilot widget (embedded chat bubble)
110+
cypress/ # E2E tests
111+
```
112+
113+
The pnpm workspace includes `frontend/`, `libs/react-client/`, and `libs/copilot/`. The built frontend assets are copied into `backend/chainlit/frontend/dist/` and served as static files.
114+
115+
### Backend (`backend/chainlit/`)
116+
117+
**Entry point for user apps**: `__init__.py` re-exports all public API decorators and classes.
118+
119+
**Key files:**
120+
- `server.py` — FastAPI app, all REST routes (auth, elements, threads, file upload), serves the built frontend SPA, mounts the SocketIO app
121+
- `socket.py` — SocketIO event handlers for real-time WebSocket communication (connect, message, audio, etc.)
122+
- `callbacks.py` — Decorator functions registered via `@cl.on_message`, `@cl.on_chat_start`, `@cl.on_audio_chunk`, etc. These store functions on `config.code.*`
123+
- `config.py` — Reads `.chainlit/config.toml` from `APP_ROOT`. `ChainlitConfig` holds both static TOML config and runtime user-registered callbacks. `APP_ROOT` defaults to `os.getcwd()`.
124+
- `session.py``WebsocketSession` (per-connection state: user, files, MCP connections, message queue) and `HTTPSession`
125+
- `context.py``ChainlitContext` per-coroutine context variable (similar to thread-local), providing access to the current session and emitter
126+
- `emitter.py` — Sends events back to the frontend through the SocketIO session
127+
- `data/base.py``BaseDataLayer` ABC for persistence (threads, steps, elements, users, feedback). Implementations: `sql_alchemy.py`, `dynamodb.py`, `literalai.py`
128+
- `auth/` — JWT creation/validation (`jwt.py`), OAuth state cookies (`cookie.py`)
129+
- `types.py` — Shared Pydantic models for API request/response types
130+
131+
**Data layer pattern**: The data layer is optional (no persistence by default). Register a custom implementation with `@cl.data_layer` decorator or use the built-in SQLAlchemy/DynamoDB/LiteralAI implementations. The `@queue_until_user_message()` decorator on `BaseDataLayer` methods queues write operations until the first user message arrives.
132+
133+
**Integrations**: `langchain/`, `llama_index/`, `openai/`, `semantic_kernel/`, `mistralai/` — each provides callback handlers that bridge those frameworks into Chainlit steps/messages.
134+
135+
### Frontend (`frontend/src/`)
136+
137+
React 18 + TypeScript + Vite, styled with Tailwind CSS and Radix UI primitives.
138+
139+
- `main.tsx` — React root, wraps app in `RecoilRoot` and `ChainlitContext.Provider`
140+
- `App.tsx` — Handles auth readiness, chat profile selection, and WebSocket connection lifecycle
141+
- `router.tsx` — Client-side routes: `/` (Home), `/thread/:id`, `/element/:id`, `/login`, `/login/callback`, `/share/:id`, `/env`
142+
- `state/` — Recoil atoms: `chat.ts` (messages, elements, tasks), `project.ts` (config, session), `user.ts` (env vars)
143+
- `components/chat/` — Core chat UI (message list, input bar, elements, audio)
144+
- `components/header/` — Top navigation bar
145+
- `components/LeftSidebar/` — Thread history sidebar
146+
147+
### `@chainlit/react-client` (`libs/react-client/src/`)
148+
149+
Publishable npm package — the bridge between the React UI and the backend WebSocket.
150+
151+
- `api.ts``ChainlitAPI` class: HTTP calls to backend REST endpoints
152+
- `useChatSession.ts` — Manages socket.io connection lifecycle
153+
- `useChatMessages.ts` — Exposes message tree state
154+
- `useChatData.ts` — Exposes elements, actions, tasklists, connection status
155+
- `useChatInteract.ts``sendMessage`, `replyMessage`, `callAction`, `stopTask`, `clear`
156+
- `state.ts` — Recoil atoms shared between the lib and consuming apps
157+
158+
State is managed via Recoil; consuming apps must wrap the tree in `<RecoilRoot>` and provide a `ChainlitAPI` instance via `ChainlitContext.Provider`.
159+
160+
### Communication flow
161+
162+
1. User sends a message → `useChatInteract.sendMessage` → emits `client_message` over SocketIO
163+
2. Backend `socket.py` handler receives it → calls `config.code.on_message(message)`
164+
3. User's app calls `cl.Message(...).send()``emitter.py` emits `new_message` back over SocketIO
165+
4. Frontend `useChatMessages` updates Recoil state → component re-renders
166+
167+
### App configuration
168+
169+
Apps configure Chainlit via `.chainlit/config.toml` (created automatically on first run). Key sections: `[project]` (auth, session timeouts, CORS), `[UI]` (name, theme, layout).
170+
171+
---
172+
173+
## Documentation Verification Requirements
174+
175+
Before writing/modifying code, verify against official docs.
176+
177+
**Lookup order**: Context7 MCP (preferred) → WebFetch → WebSearch.
178+
179+
Pre-resolved Context7 library IDs: [docs/context7.md](docs/context7.md)
180+
181+
Cross-reference API signatures and patterns during implementation. When uncertain, always check docs rather than relying on training data.

CLAUDE.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
@AGENTS.md

docs/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Documentation for Chainlit developers, contributors, and AI coding assistants.
2+
3+
See also:
4+
- [CONTRIBUTING.md](../CONTRIBUTING.md) — contribution guidelines
5+
- [CHANGELOG.md](../CHANGELOG.md) — release history

0 commit comments

Comments
 (0)