AnyBot/README.en.md

177 lines
7.6 KiB
Markdown
Raw Normal View History

<p align="center">
<img src="icons/anybot.svg" alt="AnyBot" width="120">
</p>
<h1 align="center">AnyBot</h1>
<p align="center">
<b>An AI assistant that runs on your own computers.</b><br>
It chats, and it does things: files, commands, web pages, the screen in front of you, and jobs on a clock.
</p>
<p align="center">
<a href="README.md">中文</a> · English
</p>
<p align="center">
<a href="LICENSE"><img src="https://img.shields.io/badge/license-Apache--2.0-blue" alt="Apache-2.0"></a>
<img src="https://img.shields.io/badge/macOS%20%C2%B7%20Linux%20%C2%B7%20Windows-1c1c1c" alt="macOS, Linux, Windows">
<img src="https://img.shields.io/badge/Rust%201.95-orange" alt="Rust 1.95">
<img src="https://img.shields.io/badge/self--hosted-green" alt="self-hosted">
</p>
<p align="center">
<img src="shots/readme/chat.png" alt="A list of bots on the left, a chat with one of them on the right" width="960">
</p>
You bring the model key: xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama at home, or anything that speaks the OpenAI API. Chats, files, and passwords stay on your machines instead of landing in someone else's account server. Each row on the left is a bot — research, writing, “touch the computer” — and each can use a different model.
---
## Install in 30 seconds
Open a terminal and paste one line.
```sh
# macOS, Linux (not Ubuntu-only: apt, dnf, yum, pacman, zypper, apk, xbps)
curl -fsSL https://code.30cm.net/daniel.w/AnyBot/raw/branch/main/install.sh | sh
```
```powershell
# Windows 10/11 (x64, arm64)
irm https://code.30cm.net/daniel.w/AnyBot/raw/branch/main/install.ps1 | iex
```
It installs what it needs, asks which piece you want, and walks through the first setup. The first build takes 5–15 minutes, later updates 1–2. It lives in your user folder and needs no administrator account.
Then open AnyBot (on a Mac, the first time: right-click the icon › Open), paste an API key under Settings › Models, make a bot, and talk to it. No key? Pick Ollama and it runs on your own machine.
**Account server + brain** (any Linux with Docker, 2 GB RAM or more; it asks for a domain, a user, a password, and handles HTTPS itself):
```sh
curl -fsSL https://code.30cm.net/daniel.w/AnyBot/raw/branch/main/install.sh | sh -s -- server
```
**Headless hands** (a computer for the bot to use; a screen is optional). The URL and the pairing code come from “Add a computer” in AnyBot:
```sh
curl -fsSL https://code.30cm.net/daniel.w/AnyBot/raw/branch/main/install.sh \
| sh -s -- hands https://your-address 482913
```
```powershell
# Hands on Windows
$env:ANYBOT_MODE='hands'
$env:ANYBOT_PAIR_URL='https://your-address'
$env:ANYBOT_PAIR_CODE='482913'
irm https://code.30cm.net/daniel.w/AnyBot/raw/branch/main/install.ps1 | iex
```
Running this from an agent, with no questions asked: `sh install.sh --print` reports what fits this machine, then use the environment variables — see [install/AGENT.md](install/AGENT.md).
---
## It asks before it acts
Say “do this on my computer” and it does not just run it. You see the exact step and choose allow once, always, or no. Sending, paying, and deleting are asked every time, even when you turned the other prompts off.
<p align="center">
<img src="shots/readme/computer-phone.png" alt="Left: a card asking permission before a command runs on your computer. Right: the phone page, asking you to sign in" width="960">
</p>
- **Files and commands** — it asks first. Or it works only inside its own computer, a small desktop kept apart from yours.
- **Web pages and forms** — its own browser. Passwords and card numbers are filled by the app, not read out to the model.
- **The screen you are using** — it reads the buttons in the screenshot, then clicks. If it needs you to sign in, it hands you the screen.
- **A clock** — “every weekday at 9, three news items” becomes a routine.
- **A phone, from anywhere** — open your URL in a browser, sign in, and it is the same chat; watch it from outside.
<p align="center">
<img src="shots/readme/routines.png" alt="A weekday 9:00 news routine created from the chat" width="960">
</p>
---
## One machine thinks, others get used
One machine remembers and thinks (the **brain**). Others are there to be used (the **hands**). The phone is only a window. They all meet on an **account server you run**, so the computers at home do not open a port or need a public address.
```
you on the phone you on a laptop a computer with no screen
\ | /
└───── account server (it only connects them) ─────┘
|
brain: bots, chats, memory, routines live here
|
hands: the brain asks this machine to see, click, read, browse
```
| Role | What you do |
|---|---|
| Brain | Set up the server once, or use a Mac that stays awake |
| Screen | Install the desktop app and sign in to the same account |
| Hands | Press “Add a computer” and paste the line it shows |
| Phone | Open your URL in a browser and add it to the Home screen |
No server yet? Use one always-on Mac as the brain — see option B in [docs/multi-device.md](docs/multi-device.md).
---
## What happens to a sentence
```mermaid
flowchart TD
you[You: desktop app or phone]
relay[Account server<br/>relays only, stores no chats]
brain[AnyBot on the brain]
model[The model you picked]
ask[Touch the computer? Ask first]
box[The bot's own computer<br/>a small desktop in Docker]
hands[One of the hands<br/>your Mac, Linux, or Windows]
you --> relay --> brain
brain --> model
brain --> ask
ask --> box
ask --> hands
```
1. You send a message on the desktop or the phone. The phone does not think for itself; it reads the same chat on the brain.
2. The brain hands that sentence, the bot's instructions, and its tools to the model you picked.
3. If the model only answers, it writes back. If it wants to read a file, open a page, or click something, it proposes an action.
4. That action goes through AnyBot's own rules first — the model does not decide whether it is allowed.
5. Once you allow it, the action runs on **the computer you chose**: the isolated desktop, the one you are using, or a paired hand.
6. The result goes back into the chat. Phone and laptop show the same thing because both read the brain.
Three programs are enough, and there is no database server: `anybot` (the desktop, the background service `anybot --serve`, and the terminal setup `anybot setup` are this one file), `anybot-relay` (the account server; computers connect out to it), and the phone page (one file, built into the app). Details in [docs/architecture.md](docs/architecture.md).
---
## Documents
| You want… | Read |
|---|---|
| Phone, brain, hands, “it will not connect” | [docs/multi-device.md](docs/multi-device.md) |
| A platform failed, build it yourself | [docs/install.md](docs/install.md) |
| How the code is layered | [docs/architecture.md](docs/architecture.md) |
記憶: a page to see it, a few lines picked while typing, a local model The memory had grown into a list carried whole, a top-14 recalled by a trigram index and pasted into the system prompt with the clock, and a page that broke its own layout. Nobody could see what went to the model, the prompt cache missed every message, and 「記住」 kept saying the same thing twice. Rebuilt per the spec (docs/memory.md): - Three kinds in memory.db: 記得的事 (fact), 做過的事 (event, a line per finished turn), 整理過的 (rollup). Each keeps pinned, uses, last_used, deleted, superseded_by, span. state.json keeps the facts as the copy that syncs; the page reads SQLite. - Search: jieba words ∪ CJK bigrams in an FTS5 unicode61 table (Traditional text goes through Simplified first), weighted share of query terms hit; plus local vectors, vec = clamp((cos−0.35)/0.35). score = max + 0.15×min, events ×0.9. ≥0.15 suggested, ≥0.5 ticked, ≥0.55 carried when nobody chose (3 at most). - What the model gets: the system prompt has the time zone and the pinned memories only, the same every turn. Each person message gets 〔送出時間〕 and 〔相關記憶〕 from Message.memories, built in group_history into a transient Message.context, so the beginning of a chat reads the same next turn (cache hits) and the event log, skills and audit see only what was typed. A memory already carried in view isn't carried again; each carry counts a use. - Picks travel with the message: Cmd::Send / POST send / sync act "memories" (empty = none; absent = the brain chooses, once, saved). - remember finds the like one (cos ≥ 0.85 or the same words) and asks for `replaces`; the old one is superseded, never carried. A fact forgotten and remembered again comes back. New search_memory (query, kind), with dates; read-only. - Nightly on the brain, no model: events past 30 days fold into a line per week (「11/3–11/9 做過的事(14 件):整理照片 ×3…」, ≤400 chars, like with like by words or vectors), weeks past 180 days into months; the folded go to 最近刪除 for 30 days. Facts are never removed. The page offers duplicates, facts unused for half a year, and what can fold now. - Local model: minishlab/potion-multilingual-128M through m2v.rs (same token ids as model2vec-rs on 13/13 sentences, cos ≥ 0.9999, without tokenizers' 1.1 GB). Converted while downloading: vocab.bin, table.i8 (int8 + row scales), dims.json, 137 MB kept of 530 MB; ANYBOT_HF_BASE picks a mirror (now passed into the server's brain container too). Loaded when first needed (34 ms), let go after 10 idle minutes. The brain loads it; a screen only with a document folder set; hands and phones never. 設定 › 一般 › 語意搜尋: 本機模型/Ollama/關閉; a new engine clears every vector. - Three files, three connections: memory.db (backed up nightly, 7 kept), docs.db (a cache), oplog/audit.db (30 days). An old audit.db hands its memories and documents over once and shrinks (a real one: 172 MB → 16 KB). docs_search scans every chunk now, vectors cached in RAM (it stopped at 8000); FTS optimize + VACUUM daily (260 MB of tombstones over 31 MB of text). - API: POST /api/memory (owner) and /api/sync/memory (mirror). Reads answer on the HTTP thread; writes go through phone_act("memory"). - Screens: a memory dialog (Bot menu 記憶…, Bot settings 打開記憶) with counts, live search, filters, suggestions, per-item kind/date/uses and pin/edit/forget/restore; chips above the composer 300 ms after typing stops, with a token estimate; 「帶了 N 條記憶」 under person messages. The phone has the same as a 記憶 tab, chips and tag. Checked: make test passes (app 297, relay 16), with new tests for the scores and thresholds, Traditional Chinese segmentation, remember's dedupe and replaces, two turns sending the same beginning, no double carry, weekly/monthly folding and the trash, and the audit.db move. Brain idle 37 MB as before, ~230 MB with the model loaded; search on the brain 0.2–0.5 ms, 7–44 ms from the phone page. A deadlock found on the way (stats re-taking the lock) is fixed and tested. Docs: docs/memory.md has the whole design; FEATURES.md, protocol, architecture (zh/en), multi-device and install say what changed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Uirha3SYw9JJ9dXwaNvYh4
2026-11-10 23:46:50 +00:00
| What a bot remembers, and how much reaches the model (Chinese) | [docs/memory.md](docs/memory.md) |
| The account server's API | [docs/protocol.md](docs/protocol.md) |
| Trust boundaries, where keys live | [SECURITY.md](SECURITY.md) |
| Every feature, listed | [FEATURES.md](FEATURES.md) |
| Packaging, CI | [docs/release.md](docs/release.md) |
Chinese is the source of truth; `docs/en/` is a summary for people who do not read Chinese.
## Hack on it
```sh
git clone https://code.30cm.net/daniel.w/AnyBot.git
cd AnyBot
make deps && make && make install
```
`make run` opens it, `make test` runs the tests, `make help` lists everything.
## License
Apache-2.0, see [LICENSE](LICENSE).