Skip to content

Commit 12b06b7

Browse files
committed
add CLAUDE.md and AGENTS.md
1 parent 1466890 commit 12b06b7

File tree

2 files changed

+143
-0
lines changed

2 files changed

+143
-0
lines changed

AGENTS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CLAUDE.md

CLAUDE.md

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Project Overview
6+
7+
This is `jupyter_ai_router`, a core message routing layer for Jupyter AI. It's a JupyterLab extension that provides foundational message routing functionality, automatically detecting new chat sessions and routing messages to registered callbacks based on message type (slash commands vs regular messages).
8+
9+
## Architecture
10+
11+
### Core Components
12+
13+
- **MessageRouter** (`jupyter_ai_router/router.py`): Central routing class that manages chat connections and message callbacks
14+
- **RouterExtension** (`jupyter_ai_router/extension.py`): Jupyter server extension that initializes the router and listens for chat events
15+
- **Frontend Plugin** (`src/index.ts`): JupyterLab frontend extension for client-side integration
16+
- **API Handler** (`jupyter_ai_router/handlers.py`): Simple health check endpoint
17+
18+
### Key Dependencies
19+
20+
- `jupyterlab-chat>=0.17.0`: Core chat functionality and YChat document handling
21+
- `jupyter-collaboration>=4.0.0`: Real-time collaboration features and event system
22+
- `pycrdt`: CRDT (Conflict-free Replicated Data Type) for message handling
23+
24+
### Message Flow
25+
26+
1. RouterExtension listens for `jupyter_collaboration` chat room initialization events
27+
2. When new chat detected, retrieves YChat document and connects to MessageRouter
28+
3. MessageRouter observes YChat message streams and routes to registered callbacks
29+
4. Messages are classified as slash commands (starting with `/`) or regular messages
30+
5. Appropriate callbacks are invoked with `(room_id, message)` parameters
31+
32+
## Development Commands
33+
34+
### Initial Setup
35+
```bash
36+
# Install development dependencies
37+
jlpm
38+
39+
# Install Python package in development mode
40+
pip install -e ".[test]"
41+
42+
# Link extension to JupyterLab
43+
jupyter labextension develop . --overwrite
44+
45+
# Enable server extension
46+
jupyter server extension enable jupyter_ai_router
47+
```
48+
49+
### Building
50+
```bash
51+
# Build TypeScript and JupyterLab extension (development)
52+
jlpm build
53+
54+
# Production build
55+
jlpm build:prod
56+
57+
# Watch mode (rebuilds on changes)
58+
jlpm watch
59+
```
60+
61+
### Testing
62+
```bash
63+
# Run Python tests with coverage
64+
pytest -vv -r ap --cov jupyter_ai_router
65+
66+
# Run JavaScript/TypeScript tests
67+
jlpm test
68+
69+
# Run integration tests (Playwright)
70+
cd ui-tests && jlpm test
71+
```
72+
73+
### Code Quality
74+
```bash
75+
# Run all linting and formatting
76+
jlpm lint
77+
78+
# Check code style without fixing
79+
jlpm lint:check
80+
81+
# Individual tools
82+
jlpm eslint # Fix TypeScript/JavaScript issues
83+
jlpm prettier # Fix formatting
84+
jlpm stylelint # Fix CSS issues
85+
```
86+
87+
### Development Workflow
88+
```bash
89+
# Clean build artifacts
90+
jlpm clean:all
91+
92+
# Full development setup from scratch
93+
jlpm dev:install
94+
95+
# Uninstall development setup
96+
jlpm dev:uninstall
97+
```
98+
99+
## Code Style
100+
101+
### TypeScript/JavaScript
102+
- Single quotes for strings
103+
- No trailing commas
104+
- Arrow functions preferred
105+
- Interface names must start with `I` and be PascalCase
106+
- 2-space indentation
107+
108+
### Python
109+
- Follow standard Python conventions
110+
- Use type hints where appropriate
111+
- Inherit from `LoggingConfigurable` for components that need logging
112+
113+
## Extension Integration
114+
115+
Other Jupyter extensions can access the router via settings:
116+
117+
```python
118+
router = self.serverapp.web_app.settings.get("jupyter-ai", {}).get("router")
119+
120+
# Register callbacks
121+
def on_new_chat(room_id: str, ychat: YChat):
122+
print(f"New chat: {room_id}")
123+
124+
def on_slash_command(room_id: str, message: Message):
125+
print(f"Slash command: {message.body}")
126+
127+
router.observe_chat_init(on_new_chat)
128+
router.observe_slash_cmd_msg(room_id, on_slash_command)
129+
router.observe_chat_msg(room_id, on_regular_message)
130+
```
131+
132+
## Version Compatibility
133+
134+
- Python 3.9-3.13
135+
- JupyterLab 4.x
136+
- Handles both jupyter-collaboration v3+ and v2.x compatibility through version detection
137+
138+
## Testing Strategy
139+
140+
- **Unit tests**: Jest for TypeScript, pytest for Python
141+
- **Integration tests**: Playwright via Galata for full JupyterLab integration
142+
- **Coverage**: Aim for comprehensive test coverage, especially for routing logic

0 commit comments

Comments
 (0)