This project is a standalone Rust **web server binary** that serves a Vite/React frontend and exposes a **WebSocket API**. The built frontend assets are packaged with the binary (in a `frontend` directory) and served as static files. It functions as an **Agentic Code Assistant** capable of safely executing tools on the host system.
## Core Stack
***Backend:** Rust (Web Server)
***MSRV:** Stable (latest)
***Framework:** Poem HTTP server with WebSocket support for streaming; HTTP APIs should use Poem OpenAPI (Swagger) for non-streaming endpoints.
***Frontend:** TypeScript + React
***Build Tool:** Vite
***Package Manager:** npm
***Styling:** CSS Modules or Tailwind (TBD - Defaulting to CSS Modules)
***State Management:** React Context / Hooks
***Chat UI:** Rendered Markdown with syntax highlighting.
## Agent Architecture
The application follows a **Tool-Use (Function Calling)** architecture:
1.**Frontend:** Collects user input and sends it to the LLM.
2.**LLM:** Decides to generate text OR request a **Tool Call** (e.g., `execute_shell`, `read_file`).
3.**Web Server Backend (The "Hand"):**
* Intercepts Tool Calls.
* Validates the request against the **Safety Policy**.
* Executes the native code (File I/O, Shell Process, Search).
* Returns the output (stdout/stderr/file content) to the LLM.
***Streaming:** The backend sends real-time updates over WebSocket to keep the UI responsive during long-running Agent tasks.
## LLM Provider Abstraction
To support both Remote and Local models, the system implements a `ModelProvider` abstraction layer.
***Strategy:**
* Abstract the differences between API formats (OpenAI-compatible vs Anthropic vs Gemini).
* Normalize "Tool Use" definitions, as each provider handles function calling schemas differently.
***Supported Providers:**
***Ollama:** Local inference (e.g., Llama 3, DeepSeek Coder) for privacy and offline usage.
***Anthropic:** Claude 3.5 models (Sonnet, Haiku) via API for coding tasks (Story 12).
***Provider Selection:**
* Automatic detection based on model name prefix:
*`claude-` → Anthropic API
* Otherwise → Ollama
* Single unified model dropdown with section headers ("Anthropic", "Ollama")
***API Key Management:**
* Anthropic API key stored server-side and persisted securely
* On first use of Claude model, user prompted to enter API key
* Key persists across sessions (no re-entry needed)
## Tooling Capabilities
### 1. Filesystem (Native)
***Scope:** Strictly limited to the user-selected `project_root`.
***Operations:** Read, Write, List, Delete.
***Constraint:** Modifications to `.git/` are strictly forbidden via file APIs (use Git tools instead).
### 2. Shell Execution
***Library:**`tokio::process` for async execution.
***Constraint:** We do **not** run an interactive shell (repl). We run discrete, stateless commands.
***Allowlist:** The agent may only execute specific binaries:
*`git`
*`cargo`, `rustc`, `rustfmt`, `clippy`
*`npm`, `node`, `yarn`, `pnpm`, `bun`
*`ls`, `find`, `grep` (if not using internal search)
- **Backend:** Set `HUSKIES_PORT` to a unique port (default is 3001). Example: `HUSKIES_PORT=3002 cargo run`
- **Frontend:** Run `npm run dev` from `frontend/`. It auto-selects the next unused port. It reads `HUSKIES_PORT` to know which backend to talk to, so export it before running: `export HUSKIES_PORT=3002 && cd frontend && npm run dev`