AnyBot/README.md

177 lines
7.4 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>跑在你自己電腦上的 AI 助理。</b><br>
會聊天,也會做事:整理檔案、跑指令、看網頁、操作螢幕、到點自己排。
</p>
<p align="center">
中文 · <a href="README.en.md">English</a>
</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="左邊是不同的 Bot,右邊是跟其中一個聊天" width="960">
</p>
模型用你自己的金鑰:xAI、OpenAI、Claude、Gemini、OpenRouter、OpenCode Go、家裡的 Ollama,或任何講 OpenAI 那套介面的服務。聊天記錄、檔案、密碼留在你的機器上,不會先存進別人的帳號伺服器。左邊每一行都是一個 Bot:研究、寫作、管電腦,可以各用各的模型。
---
## 30 秒裝好
打開終端機,貼一行。
```sh
# macOS、Linux(不限 Ubuntu: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
```
它會自己裝好需要的東西、問你要裝哪一種,然後做第一次設定。第一次編譯 5–15 分鐘,之後更新 1–2 分鐘;裝在你的使用者資料夾,不需要系統管理員。
裝好打開 AnyBot(Mac 第一次要對圖示按右鍵 › 打開),「設定 › 模型」貼上 API 金鑰,建一個 Bot 就能開始聊。沒有金鑰可以選 Ollama,在你自己的電腦上跑。
**帳號伺服器 + 大腦**(任何有 Docker 的 Linux,2 GB 以上;只問網址、帳號、密碼,HTTPS 它自己處理):
```sh
curl -fsSL https://code.30cm.net/daniel.w/AnyBot/raw/branch/main/install.sh | sh -s -- server
```
**無頭手腳**(給 Bot 操控的電腦,沒螢幕也行)。網址和配對碼在 AnyBot 按「加一台電腦」就會看到:
```sh
curl -fsSL https://code.30cm.net/daniel.w/AnyBot/raw/branch/main/install.sh \
| sh -s -- hands https://你的網址 482913
```
```powershell
# Windows 手腳
$env:ANYBOT_MODE='hands'
$env:ANYBOT_PAIR_URL='https://你的網址'
$env:ANYBOT_PAIR_CODE='482913'
irm https://code.30cm.net/daniel.w/AnyBot/raw/branch/main/install.ps1 | iex
```
給代理程式跑、不要出現問句:`sh install.sh --print` 先問這台適合什麼,再用環境變數,見 [install/AGENT.md](install/AGENT.md)。
---
## 它會先問你,再動手
你說「在我的電腦上做」,它不會默默執行。畫面上出現要做的事,你按允許才繼續。付款、寄出、刪除這類動作,每次都會再問一次,即使你關掉了別的詢問。
<p align="center">
<img src="shots/readme/computer-phone.png" alt="左:Bot 要在你的電腦上執行指令前,先跳出允許一次、一律允許或拒絕。右:手機瀏覽器打開你的網址,先登入" width="960">
</p>
- **整理檔案、跑指令** — 做之前先問。也可以只讓它用「它自己的電腦」,一個跟你隔開的小桌面。
- **看網頁、填表** — 用它自己的瀏覽器。密碼和卡號由程式直接填,不會先念給模型聽。
- **操作你正在用的畫面** — 看截圖上的按鈕再點。點不到,或是要你登入時,把畫面交給你。
- **到點自己做** — 「每個工作日早上 9 點整理三則新聞」變成例行任務。
- **手機隨時插手** — 瀏覽器打開你的網址、登入,就是同一個聊天,在外面也能看它做到哪。
<p align="center">
<img src="shots/readme/routines.png" alt="跟 Bot 說每個工作日早上九點整理新聞,它就排好例行任務" width="960">
</p>
---
## 一台想,幾台被用
一台負責想和記(**大腦**),其他電腦負責被操作(**手腳**),手機只是一個視窗。它們都連到你自己的**帳號伺服器**,所以家裡的電腦不用開連接埠、也不用固定 IP。
```
你在手機上說話 你在筆電上說話 沒螢幕的電腦也行
\ | /
└──────── 帳號伺服器(只負責把大家接起來)────────┘
|
大腦:Bot、聊天、記憶、例行任務在這裡
|
手腳:大腦叫它看畫面、點擊、讀檔、開瀏覽器
```
| 角色 | 你要做的 |
|---|---|
| 大腦 | 架一次伺服器,或先用一台常開的 Mac |
| 螢幕 | 裝桌面 App,登入同一個帳號 |
| 手腳 | 按「加一台電腦」,把那一行貼過去 |
| 手機 | 瀏覽器打開你的網址,加入主畫面 |
沒有伺服器也可以先拿一台 Mac 當大腦,見 [docs/multi-device.md](docs/multi-device.md) 的做法 B。
---
## 一句話進去之後
```mermaid
flowchart TD
you[你:桌面 App 或手機]
relay[帳號伺服器<br/>只轉送,不保存聊天]
brain[大腦上的 AnyBot]
model[你選的模型]
ask[要動電腦?先問你]
box[Bot 自己的電腦<br/>Docker 裡的小桌面]
hands[某一台手腳<br/>你的 Mac、Linux 或 Windows]
you --> relay --> brain
brain --> model
brain --> ask
ask --> box
ask --> hands
```
1. 你在桌面或手機送出訊息。手機不自己想,它看的是大腦上的同一份聊天。
2. 大腦把這句話、這個 Bot 的指示、它能用的工具,交給你選的模型。
3. 模型只要回答就直接寫回來;要讀檔、開網頁、點畫面,就提出一個動作。
4. 這個動作先過 AnyBot 自己的規則,不讓模型決定能不能做。
5. 你允許之後,動作在**你指定的那台電腦**上做:隔離桌面、你正在用的這台,或一台配對過的手腳。
6. 結果回到聊天。手機、筆電看到同一份,因為都在看大腦。
三支程式就夠了,沒有資料庫伺服器:`anybot`(桌面、背景 `anybot --serve`、終端機設定 `anybot setup` 都這一支)、`anybot-relay`(帳號伺服器,電腦主動連過去)、手機網頁(一個檔案,做在程式裡)。實作細節在 [docs/architecture.md](docs/architecture.md)。
---
## 文件
| 你想… | 看 |
|---|---|
| 手機、大腦、手腳、連不上 | [docs/multi-device.md](docs/multi-device.md) |
| 某個平台裝失敗、要自己編譯 | [docs/install.md](docs/install.md) |
| 程式怎麼分層 | [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
| Bot 記得什麼、帶多少給模型 | [docs/memory.md](docs/memory.md) |
| 帳號伺服器的介面 | [docs/protocol.md](docs/protocol.md) |
| 信任邊界、金鑰放哪 | [SECURITY.md](SECURITY.md) |
| 功能一條條清單 | [FEATURES.md](FEATURES.md) |
| 打包、自動建置 | [docs/release.md](docs/release.md) |
英文摘要在 `docs/en/`。
## 一起改
```sh
git clone https://code.30cm.net/daniel.w/AnyBot.git
cd AnyBot
make deps && make && make install
```
`make run` 直接打開,`make test` 跑測試,`make help` 看全部。
## 授權
Apache-2.0,見 [LICENSE](LICENSE)。