AnyBot/deploy/server/docker-compose.yml

138 lines
7.6 KiB
YAML
Raw Permalink Normal View History

# Everything on one small server: the account server (relay), HTTPS (Caddy), and AnyBot itself.
# Set up: make server (= ./setup.sh: asks for the address, account and keys, writes .env and
# Caddyfile, starts everything and checks it). Settings live only in .env; after changing it, or
# to update: make update-server. Logs: make server-logs.
# Don't start this with a bare `docker compose up`: on a host with both rootless and root Docker
# that can reach the daemon without this server's data and bring up a second, empty server; the
# make targets always use the one in .env (DOCKER_SOCKET) and the HTTPS port in its address.
# AI keys: set them in .env, or set ANYBOT_RESTORE_FROM_ACCOUNT=1 to start from the newest backup
# your Mac made (bots, chats, routines and the keys you set there).
#
# 大腦: this AnyBot is the brain of the account. It keeps the bots, chats, memory and routines,
# and works even while your computers sleep. On each of your computers: 設定 › 手機與帳號 ›
# 大腦 › 「改用它當大腦」. Those computers then show these bots, and the bots can use them as hands
# (screen, files, browser), asking you first as usual. A Linux computer without a screen can be
# hands too: run `anybot setup` there and pick this brain.
services:
relay:
build:
context: ../..
dockerfile: relay/Dockerfile
args: { JOBS: "${ANYBOT_BUILD_JOBS:-}" }
restart: unless-stopped
environment:
# Your public address (for the links of sites the bots publish), e.g. https://anybot.example.com
ANYBOT_RELAY_PUBLIC_URL: "${ANYBOT_RELAY_PUBLIC_URL:-}"
ANYBOT_RELAY_INVITE: "${ANYBOT_RELAY_INVITE:-}"
Bug sweep: gates, relay 2FA, Windows input, snapshots, encodings Permissions and reach - a file leaving a computer passes the same questions as reading it; "looking" shell commands that do more than look ask first - a symlink out of the work/sealed folder counts as outside it (real paths, not just lexical ones); the search walk skips links - web_fetch and skill_install read the public web only: localhost, the LAN and cloud metadata are refused, at every redirect - preview shows a file without running it; browser_upload may ask - vault: logins no longer match across shared suffixes (pages.dev, com.tw, ...); registrable_domain knows public suffixes - axwrite: found elements are retained (use-after-free) Relay - replacing or turning off 2FA needs the current code (rate-limited); new recovery codes only count once enrollment is verified - a removed computer loses its socket and its `call` access - a site name taken by another account answers 409 - RELAY_TRUST_PROXY: the login lock counts the caller's address, not the proxy's (compose files and README) - httpd: half a body is not a request Desktop - sign-in, join and restore work with 2FA on (code field; --serve reads ANYBOT_ACCOUNT_CODE; the setup wizard points to a pairing code) - Windows: text was typed twice; modifiers are held through click, drag and scroll; horizontal scroll; screen control is no longer refused - a recording that hits the limit is transcribed, not thrown away - bot's computer: a new home volume restores the snapshot; a snapshot is read through before the home is wiped; a failed volume removal stops reset/restore - events of a stopped turn no longer land in the next one; each channel message gets a turn of its own - saving a bot's settings keeps what it got meanwhile (three-way merge); a save file that cannot be read is kept - pages in Big5/GBK/Shift_JIS are read in their own encoding (encoding_rs); osascript output past 64 KB no longer stalls - pick_tab keeps a job's own non-http tab; pictures larger than the texture limit are fitted; the auto-update time field takes typing - skills live in <data>/skills; memories are unnumbered in the prompt; the phone may skillify and skill_install CI - the test step fails when the tests fail (it piped into tail) Tests: anybot 268 passed, 27 ignored; relay 16 passed; clippy unchanged. Not run: Windows on a real machine (win.rs type-checked alone), the Docker paths of the bot's computer, the live accessibility writes. Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-10 03:46:17 +00:00
# Caddy (or `tailscale serve`) is in front: the caller's address is the one it reports.
# Without this every login attempt counts as coming from the proxy, and a few wrong
# passwords from anyone lock that account for everyone.
RELAY_TRUST_PROXY: "1"
volumes:
- relay-data:/data
caddy:
image: caddy:2
restart: unless-stopped
ports: ["80:80", "443:443"]
volumes:
# Written by setup.sh (your domain); ../../relay/Caddyfile is the template.
- ./Caddyfile:/etc/caddy/Caddyfile:ro
- caddy-data:/data
depends_on: [relay]
anybot:
build:
context: ../..
dockerfile: deploy/server/Dockerfile
args: { JOBS: "${ANYBOT_BUILD_JOBS:-}" }
restart: unless-stopped
depends_on: [relay]
# A second wall for the bots' computer (optional, Linux): install gVisor on this host
# (see gvisor.dev/docs "Installation" for the apt repository + `apt-get install runsc`,
# then register it in /etc/docker/daemon.json: {"runtimes": {"runsc": {"path": "runsc"}}}
# and `systemctl restart docker`). In AnyBot: 設定 › 電腦 › 在哪裡執行 › 容器隔離 →
# 「強隔離(gVisor)」, then rebuild the computer (更新). The box gets a virtualized
# kernel and Chromium's own sandbox comes back on. On a host without runsc the box won't
# start — switch 容器隔離 back to 標準.
environment:
ANYBOT_ACCOUNT: "http://relay:8080|${ANYBOT_USER}"
ANYBOT_ACCOUNT_PASSWORD: "${ANYBOT_PASSWORD}"
ANYBOT_HOST_NAME: "${ANYBOT_HOST_NAME:-雲端 AnyBot}"
# First start on a new server: make the account (the first one needs no invite).
ANYBOT_ACCOUNT_CREATE: "1"
ANYBOT_RELAY_INVITE: "${ANYBOT_RELAY_INVITE:-}"
XAI_API_KEY: "${XAI_API_KEY:-}"
ANTHROPIC_API_KEY: "${ANTHROPIC_API_KEY:-}"
OPENAI_API_KEY: "${OPENAI_API_KEY:-}"
GEMINI_API_KEY: "${GEMINI_API_KEY:-}"
ANYBOT_RESTORE_FROM_ACCOUNT: "${ANYBOT_RESTORE_FROM_ACCOUNT:-}"
# The bots' computer goes by its own name: a desktop AnyBot on this same machine keeps
# "anybot-box" for itself (and used to pause the brain's one as idle).
ANYBOT_BOX_NAME: "anybot-brain-box"
# The Docker socket is not mounted here any more (a mounted socket is full control of this
# host). The bots' computer is driven through the filtered proxy below, which only answers
# the calls cloudbox.rs makes: containers (run/start/stop/rm/inspect/ps), exec, volumes,
# images and the box image build. DOCKER_HOST is the plain `docker` CLI default, which is
# what src/cloudbox.rs uses when its own docker_host setting is empty.
DOCKER_HOST: "tcp://docker-socket-proxy:2375"
# 語音 on this server (the voice service below, when it is on): 設定 › 語音 is filled in
# with it once; what you choose there afterwards stays.
ANYBOT_VOICE_URL: "${ANYBOT_VOICE_URL:-}"
ANYBOT_VOICE_LISTEN_MODEL: "${ANYBOT_VOICE_LISTEN_MODEL:-}"
ANYBOT_VOICE_SPEAK_MODEL: "${ANYBOT_VOICE_SPEAK_MODEL:-}"
ANYBOT_VOICE_VOICE: "${ANYBOT_VOICE_VOICE:-}"
記憶: 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
# 記憶的本機語意模型 is fetched from Hugging Face on the first start (530 MB, kept as
# 130 MB under /data/models); a mirror when that can't be reached, e.g. https://hf-mirror.com.
ANYBOT_HF_BASE: "${ANYBOT_HF_BASE:-}"
2026-11-11 08:19:06 +00:00
networks: [default, docker-api]
volumes:
- anybot-data:/data
# 語音 (optional: ./setup.sh asks; COMPOSE_PROFILES=voice in .env turns it on): speech to text
# (Whisper) on this server's CPU for every screen and phone, with no key. speaches (MIT) speaks
# OpenAI's audio API. No port is published: only the brain reaches it, at http://voice:8000/v1.
# The model is downloaded once, into voice-models. (It reads English aloud but not Chinese:
# reading aloud is set in 設定 › 語音, e.g. xAI.)
voice:
# The build checked with AnyBot (latest-cpu of 2025-09-19; the 0.8.2-cpu tag is older).
image: ghcr.io/speaches-ai/speaches@sha256:21e3df06d842fb7802ab470dd77c25f0e8c0d22950e8d8c6ae886e851af53ef8
profiles: ["voice"]
restart: unless-stopped
# The brain asks it for ANYBOT_VOICE_LISTEN_MODEL at each start (this build has no
# PRELOAD_MODELS): downloaded the first time, found at once after that.
environment:
WHISPER__COMPUTE_TYPE: "int8"
# Stay loaded: the first sentence after a quiet hour shouldn't wait for a model to load.
WHISPER__TTL: "-1"
volumes:
- voice-models:/home/ubuntu/.cache/huggingface/hub
docker-socket-proxy:
# https://github.com/Tecnativa/docker-socket-proxy: a small nginx in front of the Docker
# socket with an endpoint allowlist. Keep this list minimal: adding an API here widens what
# a compromised brain can do on this host (no AUTH, no SECRETS, no SWARM, no plugins).
image: tecnativa/docker-socket-proxy:0.3.0
restart: unless-stopped
environment:
CONTAINERS: "1" # run, start, stop, rm, inspect, ps (the box's lifecycle)
EXEC: "1" # docker exec: every screen step, box_exec, snapshots
IMAGES: "1" # inspect/create the box image (build uploads it)
BUILD: "1" # 更新/重建 builds the box image
VOLUMES: "1" # anybot-box-home: inspect, create, rm (Reset/Restore)
NETWORKS: "1" # inspect/attach (docker run needs the bridge network)
POST: "1"
GET: "1"
# DOCKER_SOCKET in .env: the Docker this server lives on (setup.sh writes it at the first setup,
# e.g. /run/user/<uid>/docker.sock for rootless Docker, and starts compose on that same one).
# The default /var/run/docker.sock is the root daemon; on a rootless host the proxy answers 503.
2026-11-11 08:19:06 +00:00
networks: [docker-api]
volumes:
- ${DOCKER_SOCKET:-/var/run/docker.sock}:/var/run/docker.sock:ro
2026-11-11 08:19:06 +00:00
networks:
# Only `anybot` shares this internal network with `docker-socket-proxy`; `relay`, `caddy` and
# `voice` cannot reach port 2375.
docker-api:
internal: true
volumes:
relay-data:
caddy-data:
anybot-data:
voice-models: