Commit Graph

9 Commits

Author SHA1 Message Date
王性驊 00e79d66eb feat: 螢幕電腦沒網路照樣能用——直接開副本、訊息和設定排著連上再送、離線只剩一個小標示
螢幕電腦經 Tailscale 香港中繼連大腦(來回 0.6–1 秒、常斷):以前打開一定先停在「正在連到…」
等大腦第一次回答,斷線就「現在只能看」、一大塊紅色提示佔掉聊天高度,訊息 100 秒送不到就退回輸入框。

- 有副本就直接進去:磁碟上有這個大腦的副本(brain-copy.at.json 是這個大腦、有 Bot)時,打開 App
  立刻顯示副本、不等網路,之後照舊只拿變了的;只有第一次(沒副本、或是另一個大腦的)才停在等待頁。
  副本的設定當「上次知道的大腦設定」(mir.base),離線時的改動照樣算成小改動。
- 沒網路照樣能送:訊息(連引用、附件、記憶)進排隊,馬上顯示在聊天最下面(等連上大腦後送出/
  傳送中…/排隊中…),還沒送出去過的可以「取消」放回輸入框。排隊存在 brain-queue-<大腦>.json
  (每個大腦一份、金鑰封存),關掉 App 再開還在;連上後依序送,斷線多久都等;附件傳上去的記下來,
  重試不再傳;大腦一直連得到、這則卻連續 20 次送不過去才放棄(說可能已經到了)。大腦拒收的才退回輸入框。
- 只做一次:每則照舊帶編號(大腦記 10 分鐘);離第一次送出超過 9 分鐘才再送的,先看大腦的聊天裡
  有沒有這句,有就不送。設定改動照舊用 (client, seq)。
- 沒網路照樣能改設定:改動同樣排著,連上後由現有的 pending/unsaved 機制疊在大腦的新設定上;
  秘密欄位、keep_run_times 的保證不變。離線時新增的 Bot、例行任務,編號從大腦上次的計數之後
  1000–9000(每台不同)起跳,不會跟大腦這段時間給出去的撞號;只讓出編號不算改動;計數器在
  apply_ops 也只往前。
- 停止、重新產生、還原、執行例行任務、新對話、清除、回答卡片、按鈕送的指令:照舊要連上才做
  (斷線不到約 100 秒照樣送),改走自己的一條路,不會卡在等連線的訊息後面(回答卡片不等;
  其他最多等剛排進去的改動 10 秒)。回答卡片的內容和 key 沒變。
- 不擋畫面:紅色大提示拿掉,聊天頂端「分享」旁邊一個小小的「離線」(有在等的寫「離線 · N 則
  等送出」,剛打開是「連線中…」),滑鼠移上去說原因、顯示的是幾點同步的、做的事連上後才送。
- 順便修好:大腦送出的設定裡,沒有觸發條件的例行任務被插了 "trigger": null,螢幕電腦每次存檔都
  把所有 Bot 的例行任務當改動送回去(the_brains_settings_read_back_the_same)。
- src/remote.rs 只加了 sync_try(一次嘗試、分得出網路還是大腦拒收),拿掉不再用的
  sync_upload_sure;first_delivery/DELIVERY_TTL 沒動。
- docs/feature-map/account.md 的 account-brain 和陷阱、FEATURES.md、docs/multi-device.md 同步。

已驗證: cargo test(主程式 763,含新測試:有副本就進去/沒副本才等、離線的訊息連上後只到一次、
重開後排隊還在、太久沒回答的先查聊天、試不過去會放棄、離線改的設定疊到大腦的新設定、離線新增
不撞號、送出的設定讀回來不多出改動、離線送出排隊與取消);featuremap::、layout_audit::、
approval_decisions_are_characterized、tool_specs_are_locked 綠;verify-anybot 帳號區走得到的步驟
(只聽一個位址、密碼錯/登入、重開不用重登、登出另一台、登出這支手機、錯 5 次要等)都過;
六輪乾淨脈絡審查,P0/P1 都修完,最後一輪沒有新的 P0/P1。
未驗證: 螢幕電腦連大腦的真實路徑(要帳號伺服器加第二台電腦,scratch 不准帶帳號);桌面視窗上
「離線」標示和排隊泡泡的樣子(ctl desktop-shot 要開視窗、須使用者同意,沒跑);大腦重開期間
回答掉了的訊息可能多收一次(大腦只在記憶體記編號)。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha5JgTkqJjkgMtrEXrn
2026-11-20 11:03:53 +08:00
王性驊 323c77f4f3 隧道長連線也走迴圈位址:自己連自己不再绕 tailnet(體感最後一段)
手機/審批/訊息都跑在這條 WebSocket 上。自己連自己的伺服器時它经
tailnet hairpin 绕远方中继:连线后每个来回也多 RTT,訊息、審批卡
「到得慢」和「容易斷線」感都出自这里。

- remote::self_tunnel:ts.net 名字解析到本機自己的 Tailscale 位址 →  recognizable
- tunnel::open:自己连自己时循环地址优先,其余地址照旧兜底;TLS 用
  URL 里的名字(SNI、ts.net 证书照验)
- docs/multi-device.md:加「聊天在主力機、Bot 控制另一台」的配法
  (B1:遠端電腦當大腦,主力機和手機當螢幕,零新 code)

已驗證: cargo test 723 全綠。
未驗證: 真機手机審批卡到得速度(tailnet 環境dependent,使用者自觀)。
2026-11-19 16:13:04 +08:00
王性驊 c6c9a1674a 傳送: a file or a few words from any device of the account to any other
Outside the chats and without a bot: computer → phone, phone → computer,
computer → computer.

- The brain is the post office (src/drops.rs). The sender hands the file
  over in 2 MB pieces; the brain keeps it in drops/ and pushes it piece by
  piece to the destination computer (device/run tool `drop_put`), going on
  from where a broken link stopped and waiting up to 7 days for a computer
  that is off. What is for the phone waits at the brain to be downloaded.
- Files land in Downloads/AnyBot with a notification; words go on the
  clipboard. A computer takes parcels only from its own brain.
- Window: an ↑ button at the bottom of the sidebar opens 傳送到其他裝置
  (pick a device, drop files or paste text, the last 7 days below).
- Phone: 傳送到其他裝置 in the account menu (send, download, copy).
- Bots: a `send_to_device` tool, gated like send_file.
- Owner only; the account server is unchanged. Without an account, this
  computer and a phone connected to it directly can exchange.
- Docs: FEATURES §36, protocol, architecture, multi-device (zh and en).

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3SYw9JJ9dXwaNvYh4
2026-11-11 10:04:13 +08:00
王性驊 28784232a5 記憶: 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-11 07:46:50 +08:00
王性驊 12c9944dee Server voice service: Whisper on the brain's own server, checked for real
`make server` now asks whether to run a voice service there (and the
kept-setup menu can add or remove it): speaches, Whisper
large-v3-turbo on the CPU, behind the brain only (no published port),
enabled with COMPOSE_PROFILES=voice so it composes with the Tailscale
and LAN files. The brain sees ANYBOT_VOICE_URL, fills 設定 › 語音 › 聽
with it once (what is changed later stays), and asks the service for
its model at each start: this build downloads only when asked (it has
no PRELOAD_MODELS, and the 0.8.2-cpu tag is older still, so the image
is pinned by the digest that was tested).

Tested end to end on 12 CPU cores with the compose file itself: first
start 404 s to download the model, later starts 1 s; 11 s of Mandarin
mixed with English (Chrome, Tesla FSD) in 3.4–3.6 s, every word right.
small is three times faster and slipped a character. Reading aloud
stays with another service: speaches can't say Chinese (its espeak has
no "zh"), English works.

From the same test: a service that answers 200 with no sound is now an
error said in words (it was played as silence), Whisper's ASCII
punctuation in Chinese becomes full-width (,?!), and speaches'
"not installed locally" says the model is still on its way.
2026-11-11 00:14:50 +08:00
王性驊 00f6723588 HTTPS on the local network's own IP, with a certificate the server signs itself
setup.sh offers 「區網 IP」 (alone, or next to Tailscale): Caddy serves https://<LAN IP> with its
own small certificate authority (tls internal, default_sni for clients that send no name) and
hands out the root at http://<LAN IP>/anybot-ca.crt for each device to trust once.
docker-compose.lan.yml binds Caddy to that address only, so it sits beside tailscale serve.

The app now accepts, for the account server, the certificates this computer trusts as well as
the built-in public ones (HTTP and the WebSocket alike), so it connects once the root is
trusted; before that it says what to install instead of "the certificate is wrong".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha2RVfSYmrhqNnqx9Z4
2026-11-07 21:27:07 +08:00
王性驊 c0dfef0995 Docs: 頁面, Tailscale servers, no-questions install, hands' virtual screen and updates
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-05 08:35:47 +08:00
王性驊 472a004f87 One-step install: install.sh, fixed Linux and server builds, clearer README
- install.sh (curl | sh): app, hands, server and deps modes; installs system packages
  (right names per release, e.g. libasound2t64 on Ubuntu 24.04), Rust via rustup (1.95+),
  Docker for the server; limits parallel compiles on small machines
- Server Docker image: add the ALSA build/runtime packages (the build failed), cache the
  cargo registry and target between rebuilds, JOBS build arg
- 加一台電腦 now gives a line that installs AnyBot on a blank computer before joining it
- Makefile: make deps installs Rust too, make doctor, clear message when Rust is missing/old
- README rewritten: one line per use, getting started, update/remove, troubleshooting,
  deployment options; docs/install.md and multi-device.md follow it
- Tested on fresh ubuntu:24.04 (app) and debian:12 (curl | sh hands) containers

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-05 00:52:10 +08:00
王性驊 867732bd73 make, README and docs: build and install from source
- Makefile: make / run / install / uninstall / deps / test / serve / setup /
  hands / relay-run / server / dist / clean (macOS and Linux).
- README.md and docs/: install (all platforms, data locations, troubleshooting),
  multi-device (brain, hands, screens, pairing, what the offline messages mean),
  architecture (layers, data, security, sync, keys, hands, picture helper),
  protocol (relay and AnyBot endpoints, WebSocket frames, sync ops), release
  (packaging, Gitea Actions, Linux and Mac runners).
- install.sh --deps-only, bundle.sh KEEP_APP=1 (used by make deps / install).
- FEATURES.md: the multi-device part is done.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 22:16:45 +08:00