* progress * refactor * backend refactor * test * minor stdio changes * streeeeeaming * stream statuses * change required user input * something * progress * new beginnings * progress * edge case * uuhh the claude wrapper def worked before this commit * progress * ai slop that works * tests * tests * plan mode handling * progress * clean up * bump * migrations * readmes * no text truncation * consistent poll interval * fix time --------- Co-authored-by: Kartik Sarangmath <kartiksarangmath@Kartiks-MacBook-Air.local>
6.7 KiB
Claude Code Development Guide for Omnara
Welcome Claude! This document contains everything you need to know to work effectively on the Omnara project.
Project Overview
Omnara is a platform that allows users to communicate with their AI agents (like you!) from anywhere. It uses the Model Context Protocol (MCP) to enable real-time communication between agents and users through a web dashboard.
Quick Context
- Purpose: Let users see what their AI agents are doing and communicate with them in real-time
- Key Innovation: Agents can ask questions and receive feedback while working
- Architecture: Separate read (backend) and write (servers) operations for optimal performance
- Open Source: This is a community project - code quality and clarity matter!
Project Structure
omnara/
├── backend/ # FastAPI - Web dashboard API (read operations)
├── servers/ # FastAPI + MCP - Agent communication server (write operations)
├── shared/ # Shared database models and infrastructure
├── omnara/ # Python package directory
│ └── sdk/ # Python SDK for agent integration
├── cli/ # Node.js CLI tool for MCP configuration
├── scripts/ # Utility scripts (JWT generation, linting, etc.)
├── tests/ # Integration tests
└── webhooks/ # Webhook handlers (e.g., claude_code.py)
Key Technical Decisions
Authentication Architecture
- Two separate JWT systems:
- Backend: Supabase JWTs for web users
- Servers: Custom JWT with weaker RSA (shorter API keys for agents)
- API keys are hashed (SHA256) before storage - never store raw tokens
Database Design
- PostgreSQL with SQLAlchemy 2.0+
- Alembic for migrations - ALWAYS create migrations for schema changes
- Multi-tenant design - all data is scoped by user_id
- Key tables: users, user_agents, agent_instances, messages, api_keys
- Unified messaging system: All agent interactions (steps, questions, feedback) are now stored in the
messagestable withsender_typeandrequires_user_inputfields
Server Architecture
- Unified server (
servers/app.py) supports both MCP and REST - MCP endpoint:
/mcp/ - REST endpoints:
/api/v1/* - Both use the same authentication and business logic
Development Workflow
Setting Up
-
Always activate the virtual environment first:
source .venv/bin/activate # macOS/Linux .venv\Scripts\activate # Windows -
Install pre-commit hooks (one-time):
make pre-commit-install
Before Making Changes
- Check current branch: Ensure you're on the right branch
- Update dependencies: Run
pip install -r requirements.txtif needed - Check migrations: Run
alembic currentinshared/directory
Making Changes
Database Changes
- Modify models in
shared/models/ - Generate migration:
cd shared/ alembic revision --autogenerate -m "Descriptive message" - Review the generated migration file
- Test migration:
alembic upgrade head - Include migration file in your commit
Code Changes
- Follow existing patterns - check similar files first
- Use type hints - We use Python 3.12 with full type annotations
- Import style: Prefer absolute imports from project root
Testing
make test # Run all tests
make test-integration # Integration tests (needs Docker)
Before Committing
-
Run linting and formatting:
make lint # Check for issues make format # Auto-fix formatting -
Verify your changes work:
- Test the specific functionality you changed
- Run relevant test suites
- Check that migrations apply cleanly
-
Update documentation if you changed functionality
Common Tasks
Working with Messages
The unified messaging system uses a single messages table:
- Agent messages: Set
sender_type=AGENT, userequires_user_input=Truefor questions - User messages: Set
sender_type=USERfor feedback/responses - Reading messages: Use
last_read_message_idto track reading progress - Queued messages: Agent receives unread user messages when sending new messages
Adding a New API Endpoint
- Add route in
backend/api/orservers/fastapi_server/routers.py - Create Pydantic models for request/response in
models.py - Add database queries in appropriate query files
- Write tests for the endpoint
Adding a New MCP Tool
- Add tool definition in
servers/mcp_server/tools.py - Register tool in
servers/mcp_server/server.py - Share logic with REST endpoint if applicable
- Update agent documentation
Modifying Database Schema
- Change models in
shared/models/ - Generate and review migration
- Update any affected queries
- Update Pydantic models if needed
- Test thoroughly with existing data
Important Files to Know
shared/config.py- Central configuration using Pydantic settingsshared/models/base.py- SQLAlchemy base configurationservers/app.py- Unified server entry pointbackend/auth/- Authentication logic for web usersservers/fastapi_server/auth.py- Agent authentication
Environment Variables
Key variables you might need:
DATABASE_URL- PostgreSQL connectionJWT_PUBLIC_KEY/JWT_PRIVATE_KEY- For agent authSUPABASE_URL/SUPABASE_ANON_KEY- For web authENVIRONMENT- Set to "development" for auto-reload
Common Pitfalls to Avoid
- Don't commit without migrations - Pre-commit hooks will catch this
- Don't store raw JWT tokens - Always hash API keys
- Don't mix authentication systems - Backend uses Supabase, Servers use custom JWT
- Don't forget user scoping - All queries must filter by user_id
- Don't skip type hints - Pyright will complain
Debugging Tips
- Database issues: Check migrations are up to date
- Auth failures: Verify JWT keys are properly formatted (with newlines)
- Import errors: Ensure you're using absolute imports
- Type errors: Run
make typecheckto catch issues early
Getting Help
- Check existing code for patterns
- Read test files for usage examples
- Error messages usually indicate what's wrong
- The codebase is well-structured - similar things are grouped together
Your Superpowers on This Project
As Claude Code, you're particularly good at:
- Understanding the full codebase quickly
- Maintaining consistency across files
- Catching potential security issues
- Writing comprehensive tests
- Suggesting architectural improvements
Remember: This is an open-source project that helps AI agents communicate with humans. Your work here directly improves the AI-human collaboration experience!