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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
---
|
| 4 |
+
<div align="center">
|
| 5 |
+
<pre style="color: #CD7F32; font-size: 3em; font-weight: bold; line-height: 1.2; margin: 0;">
|
| 6 |
+
|
| 7 |
+
██████╗ ██╗ ██╗███████╗████████╗██╗ ██╗ ██████╗██╗ █████╗ ██╗ ██╗
|
| 8 |
+
██╔══██╗██║ ██║██╔════╝╚══██╔══╝╚██╗ ██╔╝██╔════╝██║ ██╔══██╗██║ ██║
|
| 9 |
+
██████╔╝██║ ██║███████╗ ██║ ╚████╔╝ ██║ ██║ ███████║██║ █╗ ██║
|
| 10 |
+
██╔══██╗██║ ██║╚════██║ ██║ ╚██╔╝ ██║ ██║ ██╔══██║██║███╗██║
|
| 11 |
+
██║ ██║╚██████╔╝███████║ ██║ ██║ ╚██████╗███████╗██║ ██║╚███╔███╔╝
|
| 12 |
+
╚═╝ ╚═╝ ╚═════╝ ╚══════╝ ╚═╝ ╚═╝ ╚═════╝╚══════╝╚═╝ ╚═╝ ╚══╝╚══╝
|
| 13 |
+
|
| 14 |
+
</pre>
|
| 15 |
+
</div>
|
| 16 |
+
|
| 17 |
+
# 🦞 RustyClaw – Local Agent Harness
|
| 18 |
+
|
| 19 |
+
[](https://www.rust-lang.org/)
|
| 20 |
+
[](https://opensource.org/licenses/MIT)
|
| 21 |
+
|
| 22 |
+
**RustyClaw** is a terminal‑based, minimal barebones and OEM local‑only agent harness powered by [Ollama](https://ollama.com/).
|
| 23 |
+
|
| 24 |
+
It combines a TUI chat interface, file system operations, Git versioning, memory consolidation, and a REST API – all inside a single Rust binary.
|
| 25 |
+
|
| 26 |
+
---
|
| 27 |
+
|
| 28 |
+
## ✨ Features
|
| 29 |
+
|
| 30 |
+
- 🧠 **Persistent memory** – `bio.md` evolves with every conversation.
|
| 31 |
+
- 🖥️ **Full‑screen TUI** – built with `ratatui` and `crossterm`.
|
| 32 |
+
- 🤖 **Local Ollama** – no data leaves your machine (supports any model).
|
| 33 |
+
- 📁 **Sandboxed file ops** – read/write files inside `~/.rustyclaw/data/`.
|
| 34 |
+
- 🔐 **Whitelisted shell commands** – `ls`, `cat`, `echo`, `git`, `pwd`.
|
| 35 |
+
- 📦 **Git versioning** – every file change is auto‑committed (optional).
|
| 36 |
+
- 🧠 **Memory consolidation** – periodic summarisation of conversations into `bio.md`.
|
| 37 |
+
- 🌐 **REST API** – `GET /api/bio` to fetch the current `bio.md`.
|
| 38 |
+
- 🎨 **Permanent ASCII logo** – RustyClaw branding stays on screen.
|
| 39 |
+
- ⚡ **Non‑blocking runtime** – smooth TUI even while background tasks run.
|
| 40 |
+
|
| 41 |
+
---
|
| 42 |
+
|
| 43 |
+
## File Structure
|
| 44 |
+
|
| 45 |
+
```
|
| 46 |
+
rustyclaw/
|
| 47 |
+
├── src/
|
| 48 |
+
│ └── main.rs # single‑file application
|
| 49 |
+
├── Cargo.toml # dependencies
|
| 50 |
+
├── start.sh # launcher script (build + run)
|
| 51 |
+
├── config.yaml # optional – auto‑created on first run
|
| 52 |
+
├── data/ # sandboxed file storage (Git repo)
|
| 53 |
+
│ └── logs/
|
| 54 |
+
│ └── app.log # JSON log (tracing)
|
| 55 |
+
└── ~/.rustyclaw/ # user data directory
|
| 56 |
+
├── bio.md # living agent identity (persistent memory)
|
| 57 |
+
└── data/ # symlink or actual copy of sandbox
|
| 58 |
+
```
|
| 59 |
+
|
| 60 |
+
> **Note:** `~/.rustyclaw/` is created automatically on first launch.
|
| 61 |
+
> The `data/` folder inside it is initialised as a Git repository if `git` is available.
|
| 62 |
+
|
| 63 |
+
---
|
| 64 |
+
|
| 65 |
+
## 🛠️ Installation
|
| 66 |
+
|
| 67 |
+
### 1. Install Rust (if not already)
|
| 68 |
+
```bash
|
| 69 |
+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
|
| 70 |
+
source ~/.cargo/env
|
| 71 |
+
```
|
| 72 |
+
|
| 73 |
+
### 2. Install Ollama
|
| 74 |
+
```bash
|
| 75 |
+
curl -fsSL https://ollama.com/install.sh | sh
|
| 76 |
+
ollama serve & # start the server
|
| 77 |
+
ollama pull qwen2.5:0.5b # pull a small model (or any you like)
|
| 78 |
+
```
|
| 79 |
+
|
| 80 |
+
### 3. Install Git (optional but recommended)
|
| 81 |
+
```bash
|
| 82 |
+
sudo apt install git # Debian/Ubuntu
|
| 83 |
+
# or brew install git on macOS
|
| 84 |
+
```
|
| 85 |
+
|
| 86 |
+
### 4. Clone and build
|
| 87 |
+
```bash
|
| 88 |
+
git clone https://github.com/yourusername/rustyclaw.git
|
| 89 |
+
cd rustyclaw
|
| 90 |
+
chmod +x start.sh
|
| 91 |
+
./start.sh
|
| 92 |
+
```
|
| 93 |
+
|
| 94 |
+
The first build may take a few minutes. Subsequent runs will reuse the cached binary.
|
| 95 |
+
|
| 96 |
+
---
|
| 97 |
+
|
| 98 |
+
## Configuration
|
| 99 |
+
|
| 100 |
+
On first launch, a default `config.yaml` is created in the current directory.
|
| 101 |
+
You can edit it to change behaviour:
|
| 102 |
+
|
| 103 |
+
```yaml
|
| 104 |
+
ollama_url: "http://localhost:11434"
|
| 105 |
+
ollama_model: "qwen2.5:0.5b"
|
| 106 |
+
api_port: 3030
|
| 107 |
+
root_dir: "/home/you/.rustyclaw"
|
| 108 |
+
bio_file: "/home/you/.rustyclaw/bio.md"
|
| 109 |
+
heartbeat_log: "/home/you/.rustyclaw/data/logs/heartbeat.log"
|
| 110 |
+
memory_sync_interval_secs: 3600 # consolidate every hour
|
| 111 |
+
max_log_lines: 200
|
| 112 |
+
git_auto_commit: true
|
| 113 |
+
```
|
| 114 |
+
|
| 115 |
+
| Field | Description |
|
| 116 |
+
|----------------------------|-----------------------------------------------------------------------------|
|
| 117 |
+
| `ollama_url` | Ollama API endpoint (default `http://localhost:11434`) |
|
| 118 |
+
| `ollama_model` | Model to use for chat and consolidation |
|
| 119 |
+
| `api_port` | Port for the REST API |
|
| 120 |
+
| `root_dir` | Where `bio.md` and `data/` live (default `~/.rustyclaw`) |
|
| 121 |
+
| `git_auto_commit` | Automatically commit file writes in the `data/` folder |
|
| 122 |
+
| `memory_sync_interval_secs`| How often to run automatic memory consolidation |
|
| 123 |
+
|
| 124 |
+
---
|
| 125 |
+
|
| 126 |
+
## `bio.md` – The Living Agent Memory
|
| 127 |
+
|
| 128 |
+
`bio.md` is a Markdown file that acts as the agent’s **persistent long‑term memory**.
|
| 129 |
+
It is read on every chat and updated during `/consolidate`. The file is structured into five sections:
|
| 130 |
+
|
| 131 |
+
### 1. `# BIO.MD – Living Agent Identity`
|
| 132 |
+
- Contains the **last updated** timestamp (auto‑refreshed after each chat).
|
| 133 |
+
|
| 134 |
+
### 2. `## SOUL`
|
| 135 |
+
- Core personality, values, constraints, and behavioural rules.
|
| 136 |
+
- Example: *“Stay sandboxed, respect security, be concise and helpful.”*
|
| 137 |
+
|
| 138 |
+
### 3. `## SKILLS`
|
| 139 |
+
- Reusable capabilities and “how‑to” instructions.
|
| 140 |
+
- Example: *“Read/write local files, run whitelisted shell commands.”*
|
| 141 |
+
|
| 142 |
+
### 4. `## MEMORY`
|
| 143 |
+
- Curated long‑term knowledge.
|
| 144 |
+
- During `/consolidate`, the agent summarises recent conversations and appends a new entry here (e.g., `### Summary for 2025-04-02 14:30 …`).
|
| 145 |
+
|
| 146 |
+
### 5. `## CONTEXT`
|
| 147 |
+
- Current runtime state (OS, working directory, active model).
|
| 148 |
+
|
| 149 |
+
### 6. `## SESSION TREE`
|
| 150 |
+
- Pointers or summaries of active conversation branches (currently a placeholder – can be extended).
|
| 151 |
+
|
| 152 |
+
> **You can edit `bio.md` manually** – the agent will respect your changes in future chats.
|
| 153 |
+
|
| 154 |
+
---
|
| 155 |
+
|
| 156 |
+
## Usage – TUI Commands
|
| 157 |
+
|
| 158 |
+
Launch the TUI with `./start.sh`.
|
| 159 |
+
All commands are typed at the bottom input line and sent with **Enter**.
|
| 160 |
+
|
| 161 |
+
| Command | Description |
|
| 162 |
+
|---------|-------------|
|
| 163 |
+
| `/help` | Show all commands |
|
| 164 |
+
| `/bio` | Display the current `bio.md` content |
|
| 165 |
+
| `/consolidate` | Force memory consolidation (summarises recent chats into `## MEMORY`) |
|
| 166 |
+
| `/write_file <path> <content>` | Write a file inside `data/` (supports folders) |
|
| 167 |
+
| `/read_file <path>` | Read and display a file from `data/` |
|
| 168 |
+
| `/model list` | List all available Ollama models |
|
| 169 |
+
| `/model select <name>` | Switch to a different model (persists in `config.yaml`) |
|
| 170 |
+
| `/list_dir [path]` | List contents of `data/` or a subfolder |
|
| 171 |
+
| `/search <query>` | Search for text in all files under `data/` (regex) |
|
| 172 |
+
| `/run <command>` | Run a whitelisted shell command (`ls`, `cat`, `echo`, `git`, `pwd`) inside `data/` |
|
| 173 |
+
| `/git status` | Show `git status --short` of the `data/` folder |
|
| 174 |
+
| `/git log [n]` | Show last `n` commits (default 10) |
|
| 175 |
+
| `/git commit <msg>` | Commit all changes in `data/` with a message |
|
| 176 |
+
| `/quit` or `/exit` | Exit RustyClaw |
|
| 177 |
+
|
| 178 |
+
**Any text not starting with `/` is sent as a chat message to the AI.**
|
| 179 |
+
|
| 180 |
+
---
|
| 181 |
+
|
| 182 |
+
## REST API
|
| 183 |
+
|
| 184 |
+
While the TUI is running, a simple HTTP server listens on `http://127.0.0.1:3030`.
|
| 185 |
+
|
| 186 |
+
- `GET /health` → `{"status":"ok"}`
|
| 187 |
+
- `GET /api/bio` → returns the current `bio.md` as JSON:
|
| 188 |
+
```json
|
| 189 |
+
{"bio": "# BIO.MD – Living Agent Identity\n**Last Updated:** ..."}
|
| 190 |
+
```
|
| 191 |
+
|
| 192 |
+
You can use `curl` to fetch the agent’s memory:
|
| 193 |
+
```bash
|
| 194 |
+
curl http://127.0.0.1:3030/api/bio
|
| 195 |
+
```
|
| 196 |
+
|
| 197 |
+
---
|
| 198 |
+
|
| 199 |
+
## How Memory Consolidation Works
|
| 200 |
+
|
| 201 |
+
1. Every chat interaction is logged as a JSON line in `~/.rustyclaw/data/logs/heartbeat.log`.
|
| 202 |
+
2. Periodically (default every 3600 seconds), the agent reads the last 20 entries.
|
| 203 |
+
3. It sends a summarisation prompt to Ollama.
|
| 204 |
+
4. The summary is inserted into the `## MEMORY` section of `bio.md` with a timestamp.
|
| 205 |
+
5. The agent’s future chats include the updated `bio.md`, giving it long‑term recall.
|
| 206 |
+
|
| 207 |
+
You can also trigger consolidation manually with `/consolidate`.
|
| 208 |
+
|
| 209 |
+
---
|
| 210 |
+
|
| 211 |
+
## Tool Functions Explained
|
| 212 |
+
|
| 213 |
+
The core of RustyClaw is the `run_command` dispatcher in `main.rs`.
|
| 214 |
+
Each command is handled in a non‑blocking worker task.
|
| 215 |
+
|
| 216 |
+
| Function | Description |
|
| 217 |
+
|-------------------|-------------|
|
| 218 |
+
| `Chat` | Sends user message to Ollama together with the full `bio.md` as system prompt. Logs the exchange and updates the timestamp in `bio.md`. |
|
| 219 |
+
| `ConsolidateMemory` | Reads heartbeat log, asks Ollama to summarise, inserts summary into `bio.md`. |
|
| 220 |
+
| `WriteFile` | Sanitises path (stays inside `data/`), creates parent directories, writes content, then optionally `git add` + `commit`. |
|
| 221 |
+
| `ReadFile` | Reads a file from `data/` and displays its content in the logs. |
|
| 222 |
+
| `ListModels` | Calls Ollama’s `/api/tags` endpoint and lists available models. |
|
| 223 |
+
| `SelectModel` | Updates `config.yaml` with the new model name. |
|
| 224 |
+
| `ListDir` | Uses `walkdir` to show one‑level directory listing. |
|
| 225 |
+
| `SearchFiles` | Recursively walks `data/` and prints paths of files containing a regex match. |
|
| 226 |
+
| `RunCommand` | Executes a whitelisted command (`ls`, `cat`, `echo`, `git`, `pwd`) inside `data/`. |
|
| 227 |
+
| `GitStatus`, `GitLog`, `GitCommit` | Thin wrappers around `git` commands, always run inside `data/`. |
|
| 228 |
+
| `Quit` | Signals the main loop to exit. |
|
| 229 |
+
|
| 230 |
+
All file operations are **sandboxed** – the `sanitize_path` function ensures no path can escape `~/.rustyclaw/data/`.
|
| 231 |
+
|
| 232 |
+
---
|
| 233 |
+
|
| 234 |
+
## Development
|
| 235 |
+
|
| 236 |
+
To hack on RustyClaw:
|
| 237 |
+
|
| 238 |
+
The project is a single Rust file (`src/main.rs`). No modules – easy to experiment.
|
| 239 |
+
|
| 240 |
+
### Adding a new command
|
| 241 |
+
1. Add a variant to `enum AppCommand`.
|
| 242 |
+
2. Add a branch in `handle_command` (inside `AppState`).
|
| 243 |
+
3. Add a matching branch in `run_command` (the dispatcher).
|
| 244 |
+
4. Send the command to the worker via `cmd_tx`.
|
| 245 |
+
|
| 246 |
+
### Changing the UI
|
| 247 |
+
The `ui()` function controls layout. The logo is drawn at the top as a `Paragraph`.
|
| 248 |
+
You can adjust colours, add more status lines, or change key bindings.
|
| 249 |
+
|
| 250 |
+
---
|
| 251 |
+
|
| 252 |
+
## 📜 License
|
| 253 |
+
|
| 254 |
+
MIT License
|