|
| 1 | +# LocalGPT Project Context |
| 2 | + |
| 3 | +LocalGPT is a local-first, privacy-focused AI assistant built in Rust. It is inspired by the OpenClaw architecture but implemented as a fast, single-binary application with native OS security features. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +- **Core Goal**: Provide a powerful AI assistant that runs locally, maintains long-term memory via markdown files, and executes tasks autonomously while ensuring system security through sandboxing. |
| 8 | +- **Main Technologies**: |
| 9 | + - **Language**: Rust (Edition 2024) |
| 10 | + - **Async Runtime**: [Tokio](https://tokio.rs/) |
| 11 | + - **Database**: SQLite with FTS5 (keyword search) and `sqlite-vec` (semantic search) |
| 12 | + - **UI**: CLI (clap), Desktop/Web (egui/eframe), Telegram (teloxide) |
| 13 | + - **Security**: OS-level sandboxing (Landlock on Linux, Seatbelt on macOS) |
| 14 | + - **LLM Providers**: Support for Anthropic, OpenAI, Ollama, xAI, and OAuth-based subscriptions. |
| 15 | + |
| 16 | +## Workspace Structure |
| 17 | + |
| 18 | +The project is organized as a Rust workspace: |
| 19 | + |
| 20 | +- `crates/core/`: The "brain" of LocalGPT. Contains agent logic, memory management, configuration handling, and core security modules (signing, audit logs). |
| 21 | +- `crates/cli/`: The main entry point for the `localgpt` command. Handles subcommands like `chat`, `ask`, `daemon`, `config`, etc. |
| 22 | +- `crates/server/`: Implements the background daemon, HTTP REST API, embedded Web UI, and Telegram bot. |
| 23 | +- `crates/sandbox/`: Low-level OS-specific sandbox implementations used to confine shell commands executed by the agent. |
| 24 | +- `crates/gen/`: A specialized 3D world generation tool (`localgpt-gen`) built with the Bevy engine. |
| 25 | +- `crates/mobile/`: UniFFI bindings for embedding LocalGPT core into iOS/Android apps. |
| 26 | + |
| 27 | +## Key Concepts |
| 28 | + |
| 29 | +### Memory System |
| 30 | +LocalGPT uses a workspace directory (typically in XDG data dirs) containing: |
| 31 | +- `SOUL.md`: Defines the agent's personality, tone, and behavioral instructions. |
| 32 | +- `MEMORY.md`: Long-term, curated knowledge. |
| 33 | +- `HEARTBEAT.md`: A task queue for autonomous background operations. |
| 34 | +- `memory/YYYY-MM-DD.md`: Daily append-only logs of interactions. |
| 35 | + |
| 36 | +### Security Model |
| 37 | +- **Sandboxing**: All shell commands run via the `bash` tool are executed in a kernel-enforced sandbox that restricts filesystem and network access. |
| 38 | +- **Signed Policies**: A `LocalGPT.md` file can define custom safety rules. This file is HMAC-signed to prevent unauthorized modification. |
| 39 | +- **Audit Log**: Security events are recorded in an append-only, hash-chained JSONL file. |
| 40 | + |
| 41 | +## Development Commands |
| 42 | + |
| 43 | +### Building and Running |
| 44 | +```bash |
| 45 | +# Build the entire workspace |
| 46 | +cargo build |
| 47 | + |
| 48 | +# Run the CLI chat |
| 49 | +cargo run -- chat |
| 50 | + |
| 51 | +# Run the daemon (HTTP API + Heartbeat) |
| 52 | +cargo run -- daemon start --foreground |
| 53 | + |
| 54 | +# Run the 3D generation tool |
| 55 | +cargo run -p localgpt-gen |
| 56 | +``` |
| 57 | + |
| 58 | +### Testing and Quality |
| 59 | +```bash |
| 60 | +# Run all tests |
| 61 | +cargo test |
| 62 | + |
| 63 | +# Check formatting |
| 64 | +cargo fmt --all -- --check |
| 65 | + |
| 66 | +# Run linter |
| 67 | +cargo clippy --workspace -- -D warnings |
| 68 | +``` |
| 69 | + |
| 70 | +### Frontend (Egui Web) |
| 71 | +```bash |
| 72 | +# Build the WASM-based web UI |
| 73 | +./build-egui-web.sh |
| 74 | +``` |
| 75 | + |
| 76 | +## Coding Conventions |
| 77 | + |
| 78 | +- **Error Handling**: Use `anyhow::Result` for application-level logic and `thiserror` for library-level error types in `crates/core`. |
| 79 | +- **Logging**: Use the `tracing` crate. Debug information should be meaningful for troubleshooting agent reasoning. |
| 80 | +- **Async**: Use `tokio` for all I/O and concurrent tasks. |
| 81 | +- **Agent Tools**: When adding new tools, implement the `Tool` trait in `crates/core/src/agent/tools/mod.rs` (safe tools) or `crates/cli/src/tools.rs` (system tools). |
| 82 | +- **Safety**: Never bypass the sandbox for shell execution. Always ensure sensitive paths (like `.ssh`) are protected in `crates/core/src/security/protected_files.rs`. |
0 commit comments