AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
// 手機遙控: use AnyBot from a phone (or any browser).
|
|
|
|
|
|
//
|
|
|
|
|
|
// Two ways in, one API:
|
|
|
|
|
|
// • 區域網路/Tailscale: this AnyBot answers on port 8793 itself (password login).
|
|
|
|
|
|
// • 帳號(薄後端): this AnyBot keeps an outgoing connection to the relay (relay/ in this repo,
|
|
|
|
|
|
// run on a small server). The phone signs in to the relay with the account, and the relay hands
|
|
|
|
|
|
// each request to this AnyBot. No open port, works from anywhere, and the relay also keeps the
|
|
|
|
|
|
// account, the device list and an encrypted backup of AnyBot's data.
|
|
|
|
|
|
//
|
|
|
|
|
|
// The original keeps its brain in its cloud and reaches devices from there (its device tools wait
|
|
|
|
|
|
// 30 s for the device). Here the brain stays in AnyBot — on this Mac, or on an always-on server
|
|
|
|
|
|
// started with `anybot --serve` — and the relay only passes requests along.
|
|
|
|
|
|
|
|
|
|
|
|
use crate::httpd::{self, Req, Resp};
|
|
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
|
|
use serde_json::{json, Value};
|
|
|
|
|
|
use std::collections::HashMap;
|
|
|
|
|
|
use std::sync::atomic::{AtomicU64, Ordering};
|
|
|
|
|
|
use std::sync::{Arc, Condvar, Mutex, OnceLock};
|
|
|
|
|
|
use std::time::{Duration, Instant};
|
|
|
|
|
|
|
|
|
|
|
|
pub const LAN_PORT: u16 = 8793;
|
|
|
|
|
|
/// How long the phone's "anything new?" request waits.
|
|
|
|
|
|
pub const LONG_POLL_SECS: u64 = 20;
|
|
|
|
|
|
/// Wrong passwords allowed before logins slow down.
|
|
|
|
|
|
const MAX_FAILS: u32 = 5;
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Clone, Serialize, Deserialize, Debug, Default, PartialEq)]
|
|
|
|
|
|
pub struct Device {
|
|
|
|
|
|
pub name: String,
|
|
|
|
|
|
pub token_hash: String,
|
|
|
|
|
|
pub created: i64,
|
|
|
|
|
|
#[serde(default)]
|
|
|
|
|
|
pub last_seen: i64,
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Clone, Serialize, Deserialize, Debug, PartialEq)]
|
|
|
|
|
|
pub struct Settings {
|
|
|
|
|
|
/// Answer phones on the local network (and Tailscale) on LAN_PORT.
|
|
|
|
|
|
#[serde(default)]
|
|
|
|
|
|
pub lan: bool,
|
|
|
|
|
|
/// The phone password, stored as salt$hash.
|
|
|
|
|
|
#[serde(default)]
|
|
|
|
|
|
pub password: String,
|
|
|
|
|
|
/// Phones and browsers signed in directly.
|
|
|
|
|
|
#[serde(default)]
|
|
|
|
|
|
pub devices: Vec<Device>,
|
|
|
|
|
|
/// The phone may see and operate this Mac's own screen (not just the bot's computer).
|
|
|
|
|
|
#[serde(default)]
|
|
|
|
|
|
pub mac_from_phone: bool,
|
|
|
|
|
|
/// Other AnyBots in the same account may operate this Mac (裝置連結). Each action still follows
|
|
|
|
|
|
/// this Mac's rules and asks the person on the brain's side.
|
|
|
|
|
|
#[serde(default)]
|
|
|
|
|
|
pub device_link: bool,
|
|
|
|
|
|
/// The relay (thin backend), e.g. https://anybot.example.com
|
|
|
|
|
|
#[serde(default)]
|
|
|
|
|
|
pub relay_url: String,
|
|
|
|
|
|
#[serde(default)]
|
|
|
|
|
|
pub relay_user: String,
|
|
|
|
|
|
/// This AnyBot's own key at the relay (a "host").
|
|
|
|
|
|
#[serde(default)]
|
|
|
|
|
|
pub host_id: String,
|
|
|
|
|
|
#[serde(default)]
|
|
|
|
|
|
pub host_token: String,
|
|
|
|
|
|
/// What this AnyBot is called on the phone.
|
|
|
|
|
|
#[serde(default = "default_host_name")]
|
|
|
|
|
|
pub host_name: String,
|
|
|
|
|
|
/// Key for the encrypted backup (made from the account password; never sent).
|
|
|
|
|
|
#[serde(default)]
|
|
|
|
|
|
pub backup_key: String,
|
|
|
|
|
|
#[serde(default)]
|
|
|
|
|
|
pub auto_backup: bool,
|
|
|
|
|
|
#[serde(default)]
|
|
|
|
|
|
pub last_backup: i64,
|
2026-11-04 09:46:43 +00:00
|
|
|
|
/// 大腦: the AnyBot of this account whose bots, chats and settings this one shows (its relay
|
|
|
|
|
|
/// host id). Empty = this AnyBot is its own brain. When set, this one is a screen and hands.
|
|
|
|
|
|
#[serde(default, skip_serializing_if = "String::is_empty")]
|
|
|
|
|
|
pub brain_id: String,
|
|
|
|
|
|
#[serde(default, skip_serializing_if = "String::is_empty")]
|
|
|
|
|
|
pub brain_name: String,
|
2026-11-04 12:38:45 +00:00
|
|
|
|
/// 手腳: only this brain (host id) may use this computer (empty = any AnyBot of the account).
|
|
|
|
|
|
#[serde(default, skip_serializing_if = "String::is_empty")]
|
|
|
|
|
|
pub hands_for: String,
|
|
|
|
|
|
#[serde(default, skip_serializing_if = "String::is_empty")]
|
|
|
|
|
|
pub hands_for_name: String,
|
2026-11-13 16:40:16 +00:00
|
|
|
|
/// 手腳: the key its brain gave it with the 配對碼 (never sent to the account server). With
|
|
|
|
|
|
/// one, this computer only runs what is signed with it (see `signed_run`).
|
|
|
|
|
|
#[serde(default, skip_serializing_if = "String::is_empty")]
|
|
|
|
|
|
pub link_key: String,
|
|
|
|
|
|
/// 大腦: the keys it gave out with its 配對碼 (the newest MAX_LINK_KEYS).
|
|
|
|
|
|
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
|
|
|
|
|
pub link_keys: Vec<String>,
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Keys a brain keeps for its hands.
|
|
|
|
|
|
pub const MAX_LINK_KEYS: usize = 24;
|
|
|
|
|
|
/// Letters of a link key: no digits, so it rides behind the 6-digit 配對碼 (「135790-abc…」) and
|
|
|
|
|
|
/// an AnyBot from before this still reads the code.
|
|
|
|
|
|
const LINK_KEY_LEN: usize = 24;
|
|
|
|
|
|
/// How far apart two computers' clocks may be, and how long a signed command counts.
|
|
|
|
|
|
const SIGNED_FOR_SECS: u64 = 600;
|
|
|
|
|
|
|
|
|
|
|
|
/// A new key for one pairing.
|
|
|
|
|
|
pub fn new_link_key() -> String {
|
|
|
|
|
|
// (Bytes above 233 are thrown away so every letter is as likely as another.)
|
|
|
|
|
|
let mut out = String::new();
|
|
|
|
|
|
while out.len() < LINK_KEY_LEN {
|
|
|
|
|
|
out.extend(httpd::random_bytes(32).into_iter().filter(|b| *b < 234).map(|b| (b'a' + b % 26) as char).take(LINK_KEY_LEN - out.len()));
|
|
|
|
|
|
}
|
|
|
|
|
|
out
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// 「135790-abc…」 as typed or pasted → (the code for the account server, the key kept here).
|
|
|
|
|
|
pub fn split_pair_code(text: &str) -> (String, String) {
|
|
|
|
|
|
let code: String = text.chars().filter(|c| c.is_ascii_digit()).collect();
|
|
|
|
|
|
let key: String = text.chars().filter(|c| c.is_ascii_lowercase()).collect();
|
|
|
|
|
|
(code, if key.len() == LINK_KEY_LEN { key } else { String::new() })
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn run_mac(key: &str, to: &str, at: u64, nonce: &str, tool: &str, who: &str, args: &str) -> String {
|
|
|
|
|
|
let k = ring::hmac::Key::new(ring::hmac::HMAC_SHA256, key.as_bytes());
|
|
|
|
|
|
let msg = format!("anybot-device-run\n{to}\n{at}\n{nonce}\n{}\n{tool}\n{}\n{who}\n{args}", tool.len(), who.len());
|
|
|
|
|
|
ring::hmac::sign(&k, msg.as_bytes()).as_ref().iter().map(|b| format!("{b:02x}")).collect()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// A command for the computer `to`, signed with every key this brain gave out (it doesn't know
|
|
|
|
|
|
/// which pairing became which computer; the signature names the computer, so one is no use on
|
|
|
|
|
|
/// another). The account server carries it and can't make one.
|
|
|
|
|
|
fn signed_run(s: &Settings, to: &str, tool: &str, args: &str, who: &str) -> Value {
|
|
|
|
|
|
let mut v = json!({"tool": tool, "args": args, "who": who});
|
|
|
|
|
|
if !s.link_keys.is_empty() {
|
|
|
|
|
|
let at = std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).map(|d| d.as_secs()).unwrap_or(0);
|
|
|
|
|
|
let nonce = httpd::random_hex(12);
|
|
|
|
|
|
let macs: Vec<String> = s.link_keys.iter().map(|k| run_mac(k, to, at, &nonce, tool, who, args)).collect();
|
|
|
|
|
|
v["sig"] = json!({"t": at, "n": nonce, "macs": macs});
|
|
|
|
|
|
}
|
|
|
|
|
|
v
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Whether the command `v` was signed for this computer with its key, now, and not seen before.
|
|
|
|
|
|
fn run_is_signed(v: &Value, s: &Settings) -> Result<(), &'static str> {
|
|
|
|
|
|
static SEEN: Mutex<Vec<(String, u64)>> = Mutex::new(Vec::new());
|
|
|
|
|
|
let sig = &v["sig"];
|
|
|
|
|
|
let (Some(at), Some(nonce)) = (sig["t"].as_u64(), sig["n"].as_str()) else { return Err("這台電腦只接受它的大腦簽過的指令(大腦請更新到最新版,或重新配對)") };
|
|
|
|
|
|
let now = std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).map(|d| d.as_secs()).unwrap_or(0);
|
|
|
|
|
|
if now.abs_diff(at) > SIGNED_FOR_SECS {
|
|
|
|
|
|
return Err("指令的時間對不上:請確認兩台電腦的時鐘都是準的");
|
|
|
|
|
|
}
|
|
|
|
|
|
let want = run_mac(&s.link_key, &s.host_id, at, nonce, v["tool"].as_str().unwrap_or(""), v["who"].as_str().unwrap_or(""), v["args"].as_str().unwrap_or(""));
|
|
|
|
|
|
let ok = sig["macs"].as_array().is_some_and(|a| a.iter().take(MAX_LINK_KEYS * 2).filter_map(|m| m.as_str()).fold(false, |hit, m| hit | httpd::constant_time_eq(m, &want)));
|
|
|
|
|
|
if !ok {
|
|
|
|
|
|
return Err("指令的簽章不對:不是這台電腦的大腦發的");
|
|
|
|
|
|
}
|
|
|
|
|
|
// Once only: the same signed command sent again (by whoever carried it) is refused.
|
|
|
|
|
|
let mut seen = SEEN.lock().unwrap();
|
|
|
|
|
|
seen.retain(|(_, t)| now.abs_diff(*t) <= SIGNED_FOR_SECS * 2);
|
|
|
|
|
|
if seen.iter().any(|(n, _)| n == nonce) {
|
|
|
|
|
|
return Err("這個指令已經執行過了");
|
|
|
|
|
|
}
|
|
|
|
|
|
seen.push((nonce.to_string(), at));
|
|
|
|
|
|
Ok(())
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl Default for Settings {
|
|
|
|
|
|
fn default() -> Self {
|
2026-11-13 16:40:16 +00:00
|
|
|
|
Settings { lan: false, password: String::new(), devices: vec![], mac_from_phone: false, device_link: false, relay_url: String::new(), relay_user: String::new(), host_id: String::new(), host_token: String::new(), host_name: default_host_name(), backup_key: String::new(), auto_backup: true, last_backup: 0, brain_id: String::new(), brain_name: String::new(), hands_for: String::new(), hands_for_name: String::new(), link_key: String::new(), link_keys: vec![] }
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn default_host_name() -> String {
|
2026-11-05 08:47:28 +00:00
|
|
|
|
// Asked of the system once (it runs a program).
|
|
|
|
|
|
static N: OnceLock<String> = OnceLock::new();
|
|
|
|
|
|
N.get_or_init(system_host_name).clone()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn system_host_name() -> String {
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
if !cfg!(target_os = "macos") {
|
|
|
|
|
|
let pretty = std::process::Command::new("hostnamectl").arg("--pretty").output().ok().map(|o| String::from_utf8_lossy(&o.stdout).trim().to_string()).unwrap_or_default();
|
|
|
|
|
|
let name = if pretty.is_empty() { std::fs::read_to_string("/etc/hostname").unwrap_or_default().trim().to_string() } else { pretty };
|
|
|
|
|
|
if !name.is_empty() {
|
|
|
|
|
|
return name;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
let out = std::process::Command::new("scutil").args(["--get", "ComputerName"]).output().ok().map(|o| String::from_utf8_lossy(&o.stdout).trim().to_string()).unwrap_or_default();
|
|
|
|
|
|
if !out.is_empty() {
|
|
|
|
|
|
return out;
|
|
|
|
|
|
}
|
|
|
|
|
|
std::env::var("HOSTNAME").ok().filter(|h| !h.is_empty()).unwrap_or_else(|| "AnyBot".into())
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// What the phone asks AnyBot to do; the app carries these out on its own thread.
|
|
|
|
|
|
#[derive(Clone, Debug, PartialEq)]
|
|
|
|
|
|
pub enum Cmd {
|
2026-11-05 08:47:28 +00:00
|
|
|
|
/// `from`: the account computer the person typed it on (empty: the phone, or this one).
|
記憶: 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
|
|
|
|
/// `memories`: what the person picked under the composer (None: they didn't; the brain chooses).
|
安全、修正: harden sandboxes, approval gates, vault, relay roles, and fix protocol/UI bugs
- macOS 沙盒與工具 (tools.rs, policy.rs, docindex.rs): block AppleScript raw events and
concatenation outside the sandbox; stop exposing ~/.ssh or localhost sockets in Sealed
mode; deny writes to shell profiles, LaunchAgents and .git/hooks; expand secret-file
ignores and enforce symlink/policy checks across SSH, device and document search.
- 電腦操作與遮罩 (computer.rs, agent.rs, marks.rs, desktop.rs, cloudbox.rs, portal.rs):
forbid clicking or typing into AnyBot's own windows; extend the sensitive-action hard
gate to raw coordinates, Return/Delete submits and remote devices; stop batch steps if
the front app changes; black out secrets on zoom, show, >600-node trees, adjacent OTP
labels, box screenshots and control text lists; preserve non-text Wayland clipboards.
- 保險庫與瀏覽器 (vault.rs, vault_store.rs, browser.rs, botbrowser.rs, web.rs, box/browser):
verify tab host and HTTPS atomically at fill time; taint filled tabs against browser_eval
and PDF export while masking card/CVC values and screenshots; remember sites only on
always-allow; drop --remote-allow-origins=*; gate private URLs and block metadata/Docker
ports, OrbStack 198.18/15 and IPv6 transition ranges.
- 帳號伺服器、同步與傳送 (relay/, remote.rs, mirror_ui.rs, share.rs, drops.rs): isolate
paired hands hosts from brain sync, tickets, pairing and backup overwrites; redact
routine trigger secrets and clear REDACTED when endpoints change; isolate channel and
team-member turns from owner memories, appctl and grants; scrub shared bot exports and
reset grants/routines on import; validate drop IDs and serialize chunk writes.
- 網路與協定穩定性 (httpd.rs, tunnel.rs, vnc.rs, Caddyfile*): fix chunked integer overflow
and CRLF header injection; enforce Origin checks, connection/job caps, 200 MB backup
reads, unique atomic temp files and ASCII hex guards; bound deflate unzip and VNC sniff
buffers; move VNC stdin/text off the tunnel loop.
- 介面、排程、語言與其他修正 (app.rs, i18n.rs, providers.rs, skills.rs, routines.rs,
setup.rs, store.rs, preview.rs, attach.rs, speech.rs, teams.rs, mcp.rs, voice.rs):
wire up the delete-routine confirmation dialog and mirror run-now; preserve unsaved
mirror edits across brief disconnects; give Chinese skills distinct folders and approval
gates; convert parsed tool JSON fields without corrupting code fences, URLs or paths;
fix Hourly DST offsets and time out unattended routine approvals; lock --install-skill,
cap docx/xlsx unzip sizes, isolate test env keys, and tighten local file permissions.
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-12 06:34:10 +00:00
|
|
|
|
/// `member`: sent by a team `member` (not owner/admin).
|
|
|
|
|
|
Send { bot: u64, text: String, attachments: Vec<String>, from: String, memories: Option<Vec<String>>, member: bool },
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
Stop { bot: u64 },
|
問題卡、搜尋: the bot asks with a card; every chat is searched; a refusal holds for the turn
- 問題卡 (ask_person, src/ask.rs): up to 6 questions on a card above the input, one at a
time — a choice (one click moves on), several choices, or a field that arrives filled
for the person to correct; 「自己回答」 on every question, 上一題 and 略過. The turn waits;
a message typed instead leaves the card unanswered. Travels as an approval of kind
Question (questions as JSON) with a new answer Answered, so the window, a screen of
another brain and the phone draw the same card.
- 搜尋所有聊天 (src/find.rs): the sidebar's search also lists what the person and the bots
said in every chat, past conversations included, and attachment names; newest first,
40 at most. A click opens the bot (bringing a past conversation back first), scrolls to
the message and lights it for a moment.
- 拒絕後停下: a step the person refused is refused for them when it comes back unchanged
in the same turn — no second card, no second review — until they write again.
- The bot's instructions: stop after a refusal instead of trying another way; before
sending, posting, buying or deleting, check the person's own messages asked for exactly
that, and ask with the card when they didn't.
- 直接操作 no longer answers a hand-off (or a question) on the person's behalf.
- The repeated-step check leaves questions to the person alone.
- Screenshot views `ask` and `find`; FEATURES.md.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3QxSfoydRPM9mjj6d
2026-11-12 02:17:32 +00:00
|
|
|
|
/// (`text`: the answers of a 問題卡.)
|
|
|
|
|
|
Answer { bot: u64, answer: String, text: String },
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
Read { bot: u64 },
|
|
|
|
|
|
NewThread { bot: u64 },
|
2026-11-06 12:33:06 +00:00
|
|
|
|
/// The time zone of the phone the person uses (a brain on a server only knows UTC).
|
|
|
|
|
|
PersonTimezone(String),
|
Phone: a home with the computers, pages and routines; each bot's settings a tap away; long jobs fold up
The phone page was bare: one row per bot, a chat listing every step, a menu with four lines.
- Home: the main bot large at the top with its model and last words, the other bots with times,
then its computers (own box and the account's, online or not, 看畫面), the newest pages and the
routines with their next run.
- Chat: the bot's name opens its settings — model (chat models only), computer, past conversations
(restore), regenerate, new chat. A turn's steps fold into 「已完成 N 個步驟」 when done (the newest
three stay while it works); copy and regenerate under replies; four ready starts in a new chat;
a jump back to the newest message.
- Menu: 外觀 (follow the phone, light, dark).
- API: api/state carries pages and models; each bot its model, computers, routines, past
conversations; POST api/bots/{id}/set | regenerate | restore. The home's last line skips errors.
Checked on a local copy of the brain's data (cut off from the account and Docker) at iPhone size.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha2RVfSYmrhqNnqx9Z4
2026-11-06 12:28:08 +00:00
|
|
|
|
/// The phone changes a bot's model or its computer (empty = unchanged).
|
|
|
|
|
|
SetBot { bot: u64, provider: String, model: String, computer: String },
|
2026-11-04 09:46:43 +00:00
|
|
|
|
/// Answer the last message again (重新產生) / reply to what is there (重新傳送).
|
|
|
|
|
|
Regenerate { bot: u64 },
|
2026-11-13 13:34:03 +00:00
|
|
|
|
/// 還原上一個答案: put back what 重新產生 replaced.
|
|
|
|
|
|
RestoreAnswer { bot: u64 },
|
2026-11-04 09:46:43 +00:00
|
|
|
|
Reply { bot: u64 },
|
A turn cut off by a crash leaves a 「繼續」 card, and nothing it may have done runs twice
Each bot keeps a work log (oplog/bot-<id>.jsonl, after pi's durable-harness design, cut down):
before something happens a line says it is about to — the turn, each model call, each step once
its checks passed (with the arguments it runs with and whether it may run again), each message
typed mid-turn — synced to disk first. When the turn ends the file shrinks to the messages still
waiting, usually nothing.
On the next start after AnyBot was killed mid-turn, the log puts the chat right before anything
runs: the message the turn answered comes back if the chat lost it; a step that was running and
reaches outside (a text, a click, a file, a published site) shows as 「可能已經執行了」, both to the
person and in the result the bot reads — no longer as "not allowed"; a step that only looked shows
as cut off; messages typed mid-turn that never reached the bot go back into the chat. The chat is
saved, then the log closes the turn. A turn the person didn't stop ends with a 「繼續」 card (what
it was doing, what may have run, the messages put back); it goes on only when they press it — in
the window, on a screen of the brain, or on the phone — from where its steps stand, never running
a step that may have run again. Pressing stop is on disk at once, and a stopped turn stays
stopped.
Also in the turn loop:
- 自動審核 that doesn't answer (or answers something that isn't a verdict) asks the person; in
直接操作 mode it used to let the step through unchecked.
- "Too long for this model" folds older messages into a summary and asks the same step again,
once per thing the person said, instead of ending the turn.
- Folding keeps the person's chat whole: the summary goes in at the fold and the model reads from
the newest summary on (it used to delete what it folded).
- A step moved to the chosen computer runs there, but the chat keeps the call as the model wrote
it; the result says where it ran.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha5F5gJt93t3yEx3XcS
2026-11-08 16:49:12 +00:00
|
|
|
|
/// 「繼續」 on the card a crash left: the cut-off turn goes on.
|
|
|
|
|
|
Resume { bot: u64 },
|
2026-11-04 09:46:43 +00:00
|
|
|
|
/// Bring back an earlier conversation (過去的對話).
|
|
|
|
|
|
RestoreThread { bot: u64, index: usize },
|
2026-11-05 08:47:28 +00:00
|
|
|
|
/// 清除聊天記錄 from a screen of this brain (the chat lives here).
|
|
|
|
|
|
Clear { bot: u64 },
|
安全、修正: harden sandboxes, approval gates, vault, relay roles, and fix protocol/UI bugs
- macOS 沙盒與工具 (tools.rs, policy.rs, docindex.rs): block AppleScript raw events and
concatenation outside the sandbox; stop exposing ~/.ssh or localhost sockets in Sealed
mode; deny writes to shell profiles, LaunchAgents and .git/hooks; expand secret-file
ignores and enforce symlink/policy checks across SSH, device and document search.
- 電腦操作與遮罩 (computer.rs, agent.rs, marks.rs, desktop.rs, cloudbox.rs, portal.rs):
forbid clicking or typing into AnyBot's own windows; extend the sensitive-action hard
gate to raw coordinates, Return/Delete submits and remote devices; stop batch steps if
the front app changes; black out secrets on zoom, show, >600-node trees, adjacent OTP
labels, box screenshots and control text lists; preserve non-text Wayland clipboards.
- 保險庫與瀏覽器 (vault.rs, vault_store.rs, browser.rs, botbrowser.rs, web.rs, box/browser):
verify tab host and HTTPS atomically at fill time; taint filled tabs against browser_eval
and PDF export while masking card/CVC values and screenshots; remember sites only on
always-allow; drop --remote-allow-origins=*; gate private URLs and block metadata/Docker
ports, OrbStack 198.18/15 and IPv6 transition ranges.
- 帳號伺服器、同步與傳送 (relay/, remote.rs, mirror_ui.rs, share.rs, drops.rs): isolate
paired hands hosts from brain sync, tickets, pairing and backup overwrites; redact
routine trigger secrets and clear REDACTED when endpoints change; isolate channel and
team-member turns from owner memories, appctl and grants; scrub shared bot exports and
reset grants/routines on import; validate drop IDs and serialize chunk writes.
- 網路與協定穩定性 (httpd.rs, tunnel.rs, vnc.rs, Caddyfile*): fix chunked integer overflow
and CRLF header injection; enforce Origin checks, connection/job caps, 200 MB backup
reads, unique atomic temp files and ASCII hex guards; bound deflate unzip and VNC sniff
buffers; move VNC stdin/text off the tunnel loop.
- 介面、排程、語言與其他修正 (app.rs, i18n.rs, providers.rs, skills.rs, routines.rs,
setup.rs, store.rs, preview.rs, attach.rs, speech.rs, teams.rs, mcp.rs, voice.rs):
wire up the delete-routine confirmation dialog and mirror run-now; preserve unsaved
mirror edits across brief disconnects; give Chinese skills distinct folders and approval
gates; convert parsed tool JSON fields without corrupting code fences, URLs or paths;
fix Hourly DST offsets and time out unattended routine approvals; lock --install-skill,
cap docx/xlsx unzip sizes, isolate test env keys, and tighten local file permissions.
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-12 06:34:10 +00:00
|
|
|
|
/// 立即執行例行任務 from a screen of this brain.
|
|
|
|
|
|
RunRoutine { bot: u64, routine: u64 },
|
Voice: its own 設定 › 語音, run by the brain for every screen and the phone
Voice was three implementations that broke on their own: speech to text
borrowed the OpenAI key (so with only Grok set up the mic recorded,
then failed), OpenAI's models it hard-coded stop on 2027-02-26, read
aloud was macOS `say` or espeak-ng (silently nothing on Windows, where
espeak isn't installed), and the phone used the browser's own
recognition. Now:
- 設定 › 語音 has 聽 and 說, each a service: off, OpenAI-compatible
(OpenAI, Groq, a Whisper server of your own: the address decides),
xAI or ElevenLabs. An empty key borrows 設定 › 模型's for the same
service. Each side says 可以用 or what it lacks; 聽 has 試試看
(record a sentence, show what was heard), 說 has 試聽 and the voice
list. speech.rs does the calls; xAI's both ways were checked for real
(Mandarin read, then heard back, in Traditional characters).
- The brain does it all: the phone POSTs its recording (MediaRecorder)
to /api/voice/transcribe, screens to /api/sync/voice/transcribe;
answers come back as MP3 from …/voice/speech and are played on the
device (rodio; an <audio> on the phone, 「唸出來」 in a message's
menu). Keys stay on the brain (the voice keys are redacted for
screens like the others).
- No service, no voice anywhere: the mic, 語音聊天, 會議錄音 and 朗讀
only appear once 聽 (and 說) can be called; the phone's state says
which. Without voice the send arrow just rests where 語音聊天 was.
- 會議錄音 is uploaded to the brain, which turns it into text in the
background and hands it to the bot itself: a meeting is longer than
the 35 s the account lets a request wait, and a brain on a server has
no window (the jobs are polled in background()).
- Recognisers answer Mandarin in Simplified: in a Traditional Chinese
window or phone the text becomes Traditional with Taiwan wording.
- Older saves: whoever had an OpenAI key keeps voice input (聽 =
OpenAI); everyone else starts with it off. Bots' macOS voice names
are cleared. 對話詳細資訊's 加入會議 started plain voice input; it
starts a meeting now.
2026-11-10 14:58:18 +00:00
|
|
|
|
/// 會議錄音 from a screen (uploaded here first): turn it into text, then hand it to the bot.
|
|
|
|
|
|
Meeting { bot: u64, path: String, lang: String },
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
/// A new phone signed in (to remember), or one was signed out.
|
|
|
|
|
|
DeviceAdded(Device),
|
|
|
|
|
|
DeviceSeen(String),
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// What the phone can see, refreshed by the app when something changes.
|
|
|
|
|
|
#[derive(Default, Clone)]
|
|
|
|
|
|
pub struct View {
|
|
|
|
|
|
pub host: String,
|
2026-11-13 06:19:59 +00:00
|
|
|
|
pub person: String,
|
|
|
|
|
|
pub accent: String,
|
|
|
|
|
|
pub pin_order: Vec<u64>,
|
|
|
|
|
|
pub newer: bool,
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
pub bots: Vec<Value>,
|
|
|
|
|
|
pub approvals: Vec<Value>,
|
|
|
|
|
|
pub messages: HashMap<u64, Vec<Value>>,
|
頁面: pages a bot makes and keeps up to date (like the original's tracking pages)
- write_page / read_page / list_pages: Markdown pages with versions (last 10 kept), per bot;
the reply gets a card (title, fading preview, page icon, 頁面 · 更新時間, 最近更新), and
[標題](page:ID) links open the page
- The page opens large: summary, what changed, the version picker, 複製 / 存成檔案 / 刪除;
listed under 資料庫 in the right panel
- Page blocks for richer pages, in the chat's Markdown too: ```stats tiles, ```steps progress,
> [!NOTE]/[!TIP]/[!WARNING]/[!IMPORTANT] call-outs (with tables and Mermaid charts)
- Phone: the card in chats, page links, a page view with the same blocks; charts drawn by the
AnyBot as SVG (GET /api/pages/<id>[/chart/<n>]); members may read pages
- Bots are told to make a page for things to track and to update it from a routine only when
there is real news
- Screenshot views: ANYBOT_SHOT_VIEW=pagecard / page
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 17:41:41 +00:00
|
|
|
|
/// 頁面, for the phone's page view.
|
|
|
|
|
|
pub pages: Vec<crate::pages::Page>,
|
Phone: a home with the computers, pages and routines; each bot's settings a tap away; long jobs fold up
The phone page was bare: one row per bot, a chat listing every step, a menu with four lines.
- Home: the main bot large at the top with its model and last words, the other bots with times,
then its computers (own box and the account's, online or not, 看畫面), the newest pages and the
routines with their next run.
- Chat: the bot's name opens its settings — model (chat models only), computer, past conversations
(restore), regenerate, new chat. A turn's steps fold into 「已完成 N 個步驟」 when done (the newest
three stay while it works); copy and regenerate under replies; four ready starts in a new chat;
a jump back to the newest message.
- Menu: 外觀 (follow the phone, light, dark).
- API: api/state carries pages and models; each bot its model, computers, routines, past
conversations; POST api/bots/{id}/set | regenerate | restore. The home's last line skips errors.
Checked on a local copy of the brain's data (cut off from the account and Docker) at iPhone size.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha2RVfSYmrhqNnqx9Z4
2026-11-06 12:28:08 +00:00
|
|
|
|
/// The models the phone can switch a bot to: each ready provider with its known models.
|
|
|
|
|
|
pub models: Vec<Value>,
|
The phone page does what the desktop does, laid out like it
A new mobile/index.html in the desktop's (and Grok Bot's) shape: the sidebar
with its sections and folders, the chat with steps, thinking, reactions, quotes
and the approval card, 對話詳細資訊, Bot 設定, routines, pages, computers and
設定. Each action goes to the desktop's own code on the app's thread
(api/act/<what> -> App::phone_act): appctl, set_pinned, restart_bot,
toggle_reaction, box_task, channels_restart and the rest. No new rules.
Keys, channel tokens and the vault never reach the phone; a model key can only
be written. Admins keep what the phone always let them do; making, changing or
deleting bots, routines, memories, pages, folders and settings stays the
owner's. The state the phone polls now carries the sidebar's section order.
Checked by using it on a preview brain: routines, memories, templates, folders,
keys, signing another phone out, approvals and a chat with a fake model.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha2RVfSYmrhqNnqx9Z4
2026-11-06 19:05:12 +00:00
|
|
|
|
/// The sidebar's 分區 in order (None = 未分區), empty ones too, as the desktop shows them.
|
|
|
|
|
|
pub sections: Vec<Option<String>>,
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
pub version: u64,
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub struct Hub {
|
|
|
|
|
|
view: Mutex<View>,
|
|
|
|
|
|
changed: Condvar,
|
|
|
|
|
|
cmds: Mutex<Vec<Cmd>>,
|
|
|
|
|
|
repaint: Mutex<Option<Arc<dyn Fn() + Send + Sync>>>,
|
|
|
|
|
|
settings: Mutex<Settings>,
|
2026-11-05 07:48:20 +00:00
|
|
|
|
/// Wrong logins, counted per source (one noisy LAN device must not lock out the owner).
|
|
|
|
|
|
fails: Mutex<HashMap<String, (u32, Instant)>>,
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
relay_status: Mutex<String>,
|
2026-11-04 09:46:43 +00:00
|
|
|
|
sync: Mutex<Vec<SyncReq>>,
|
Voice: its own 設定 › 語音, run by the brain for every screen and the phone
Voice was three implementations that broke on their own: speech to text
borrowed the OpenAI key (so with only Grok set up the mic recorded,
then failed), OpenAI's models it hard-coded stop on 2027-02-26, read
aloud was macOS `say` or espeak-ng (silently nothing on Windows, where
espeak isn't installed), and the phone used the browser's own
recognition. Now:
- 設定 › 語音 has 聽 and 說, each a service: off, OpenAI-compatible
(OpenAI, Groq, a Whisper server of your own: the address decides),
xAI or ElevenLabs. An empty key borrows 設定 › 模型's for the same
service. Each side says 可以用 or what it lacks; 聽 has 試試看
(record a sentence, show what was heard), 說 has 試聽 and the voice
list. speech.rs does the calls; xAI's both ways were checked for real
(Mandarin read, then heard back, in Traditional characters).
- The brain does it all: the phone POSTs its recording (MediaRecorder)
to /api/voice/transcribe, screens to /api/sync/voice/transcribe;
answers come back as MP3 from …/voice/speech and are played on the
device (rodio; an <audio> on the phone, 「唸出來」 in a message's
menu). Keys stay on the brain (the voice keys are redacted for
screens like the others).
- No service, no voice anywhere: the mic, 語音聊天, 會議錄音 and 朗讀
only appear once 聽 (and 說) can be called; the phone's state says
which. Without voice the send arrow just rests where 語音聊天 was.
- 會議錄音 is uploaded to the brain, which turns it into text in the
background and hands it to the bot itself: a meeting is longer than
the 35 s the account lets a request wait, and a brain on a server has
no window (the jobs are polled in background()).
- Recognisers answer Mandarin in Simplified: in a Traditional Chinese
window or phone the text becomes Traditional with Taiwan wording.
- Older saves: whoever had an OpenAI key keeps voice input (聽 =
OpenAI); everyone else starts with it off. Bots' macOS voice names
are cleared. 對話詳細資訊's 加入會議 started plain voice input; it
starts a meeting now.
2026-11-10 14:58:18 +00:00
|
|
|
|
/// 設定 › 語音 with its keys: what the phone's and the screens' recordings go through.
|
|
|
|
|
|
voice: Mutex<crate::speech::Engines>,
|
2026-11-04 09:46:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// 大腦: another AnyBot of this account (a screen) asks for what changed, or sends its edits.
|
|
|
|
|
|
pub enum SyncKind {
|
The phone page does what the desktop does, laid out like it
A new mobile/index.html in the desktop's (and Grok Bot's) shape: the sidebar
with its sections and folders, the chat with steps, thinking, reactions, quotes
and the approval card, 對話詳細資訊, Bot 設定, routines, pages, computers and
設定. Each action goes to the desktop's own code on the app's thread
(api/act/<what> -> App::phone_act): appctl, set_pinned, restart_bot,
toggle_reaction, box_task, channels_restart and the rest. No new rules.
Keys, channel tokens and the vault never reach the phone; a model key can only
be written. Admins keep what the phone always let them do; making, changing or
deleting bots, routines, memories, pages, folders and settings stays the
owner's. The state the phone polls now carries the sidebar's section order.
Checked by using it on a preview brain: routines, memories, templates, folders,
keys, signing another phone out, approvals and a chat with a fake model.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha2RVfSYmrhqNnqx9Z4
2026-11-06 19:05:12 +00:00
|
|
|
|
/// 手機: something the desktop does with a bot, a page, a routine or a setting, or one of the
|
|
|
|
|
|
/// views it shows (a bot's details, 設定), done on the app's thread; `role` is who asks.
|
|
|
|
|
|
Phone { action: String, body: Value, role: String },
|
2026-11-04 09:46:43 +00:00
|
|
|
|
Pull { client: String, since: u64 },
|
|
|
|
|
|
Edit(Value),
|
2026-11-04 11:30:32 +00:00
|
|
|
|
/// A provider's model list, fetched with the brain's own key (screens don't have it).
|
|
|
|
|
|
Models(String),
|
2026-11-04 09:46:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub struct SyncReq {
|
|
|
|
|
|
pub kind: SyncKind,
|
|
|
|
|
|
pub reply: std::sync::mpsc::Sender<Value>,
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn hub() -> &'static Hub {
|
|
|
|
|
|
static H: OnceLock<Hub> = OnceLock::new();
|
Voice: its own 設定 › 語音, run by the brain for every screen and the phone
Voice was three implementations that broke on their own: speech to text
borrowed the OpenAI key (so with only Grok set up the mic recorded,
then failed), OpenAI's models it hard-coded stop on 2027-02-26, read
aloud was macOS `say` or espeak-ng (silently nothing on Windows, where
espeak isn't installed), and the phone used the browser's own
recognition. Now:
- 設定 › 語音 has 聽 and 說, each a service: off, OpenAI-compatible
(OpenAI, Groq, a Whisper server of your own: the address decides),
xAI or ElevenLabs. An empty key borrows 設定 › 模型's for the same
service. Each side says 可以用 or what it lacks; 聽 has 試試看
(record a sentence, show what was heard), 說 has 試聽 and the voice
list. speech.rs does the calls; xAI's both ways were checked for real
(Mandarin read, then heard back, in Traditional characters).
- The brain does it all: the phone POSTs its recording (MediaRecorder)
to /api/voice/transcribe, screens to /api/sync/voice/transcribe;
answers come back as MP3 from …/voice/speech and are played on the
device (rodio; an <audio> on the phone, 「唸出來」 in a message's
menu). Keys stay on the brain (the voice keys are redacted for
screens like the others).
- No service, no voice anywhere: the mic, 語音聊天, 會議錄音 and 朗讀
only appear once 聽 (and 說) can be called; the phone's state says
which. Without voice the send arrow just rests where 語音聊天 was.
- 會議錄音 is uploaded to the brain, which turns it into text in the
background and hands it to the bot itself: a meeting is longer than
the 35 s the account lets a request wait, and a brain on a server has
no window (the jobs are polled in background()).
- Recognisers answer Mandarin in Simplified: in a Traditional Chinese
window or phone the text becomes Traditional with Taiwan wording.
- Older saves: whoever had an OpenAI key keeps voice input (聽 =
OpenAI); everyone else starts with it off. Bots' macOS voice names
are cleared. 對話詳細資訊's 加入會議 started plain voice input; it
starts a meeting now.
2026-11-10 14:58:18 +00:00
|
|
|
|
H.get_or_init(|| Hub { view: Mutex::new(View::default()), changed: Condvar::new(), cmds: Mutex::new(vec![]), repaint: Mutex::new(None), settings: Mutex::new(Settings::default()), fails: Mutex::new(HashMap::new()), relay_status: Mutex::new(String::new()), sync: Mutex::new(vec![]), voice: Mutex::new(Default::default()) })
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static VERSION: AtomicU64 = AtomicU64::new(1);
|
|
|
|
|
|
|
|
|
|
|
|
impl Hub {
|
|
|
|
|
|
pub fn publish(&self, mut v: View) {
|
|
|
|
|
|
v.version = VERSION.fetch_add(1, Ordering::SeqCst) + 1;
|
|
|
|
|
|
*self.view.lock().unwrap() = v;
|
|
|
|
|
|
self.changed.notify_all();
|
|
|
|
|
|
}
|
2026-11-04 09:46:43 +00:00
|
|
|
|
pub fn take_sync(&self) -> Vec<SyncReq> {
|
|
|
|
|
|
std::mem::take(&mut *self.sync.lock().unwrap())
|
|
|
|
|
|
}
|
|
|
|
|
|
/// Hand a sync request to the app's thread and wait for its answer.
|
|
|
|
|
|
fn ask_sync(&self, kind: SyncKind) -> Result<Value, String> {
|
2026-11-04 11:30:32 +00:00
|
|
|
|
self.ask_sync_for(kind, 10)
|
|
|
|
|
|
}
|
|
|
|
|
|
fn ask_sync_for(&self, kind: SyncKind, secs: u64) -> Result<Value, String> {
|
2026-11-04 09:46:43 +00:00
|
|
|
|
let (tx, rx) = std::sync::mpsc::channel();
|
|
|
|
|
|
self.sync.lock().unwrap().push(SyncReq { kind, reply: tx });
|
|
|
|
|
|
if let Some(r) = self.repaint.lock().unwrap().as_ref() {
|
|
|
|
|
|
r();
|
|
|
|
|
|
}
|
2026-11-04 11:30:32 +00:00
|
|
|
|
rx.recv_timeout(Duration::from_secs(secs)).map_err(|_| "大腦太忙,沒有及時回應".to_string())
|
2026-11-04 09:46:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
pub fn version(&self) -> u64 {
|
|
|
|
|
|
self.view.lock().unwrap().version
|
|
|
|
|
|
}
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
pub fn take_cmds(&self) -> Vec<Cmd> {
|
|
|
|
|
|
std::mem::take(&mut *self.cmds.lock().unwrap())
|
|
|
|
|
|
}
|
|
|
|
|
|
fn push(&self, c: Cmd) {
|
|
|
|
|
|
self.cmds.lock().unwrap().push(c);
|
|
|
|
|
|
if let Some(r) = self.repaint.lock().unwrap().as_ref() {
|
|
|
|
|
|
r();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
傳送: 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 02:04:13 +00:00
|
|
|
|
/// Something changed that the window shows (a file arrived): draw again.
|
|
|
|
|
|
pub fn repaint_now(&self) {
|
|
|
|
|
|
if let Some(r) = self.repaint.lock().unwrap().as_ref() {
|
|
|
|
|
|
r();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
pub fn set_repaint(&self, f: Arc<dyn Fn() + Send + Sync>) {
|
|
|
|
|
|
*self.repaint.lock().unwrap() = Some(f);
|
|
|
|
|
|
}
|
|
|
|
|
|
pub fn set_settings(&self, s: &Settings) {
|
|
|
|
|
|
*self.settings.lock().unwrap() = s.clone();
|
|
|
|
|
|
}
|
|
|
|
|
|
pub fn settings(&self) -> Settings {
|
|
|
|
|
|
self.settings.lock().unwrap().clone()
|
|
|
|
|
|
}
|
Voice: its own 設定 › 語音, run by the brain for every screen and the phone
Voice was three implementations that broke on their own: speech to text
borrowed the OpenAI key (so with only Grok set up the mic recorded,
then failed), OpenAI's models it hard-coded stop on 2027-02-26, read
aloud was macOS `say` or espeak-ng (silently nothing on Windows, where
espeak isn't installed), and the phone used the browser's own
recognition. Now:
- 設定 › 語音 has 聽 and 說, each a service: off, OpenAI-compatible
(OpenAI, Groq, a Whisper server of your own: the address decides),
xAI or ElevenLabs. An empty key borrows 設定 › 模型's for the same
service. Each side says 可以用 or what it lacks; 聽 has 試試看
(record a sentence, show what was heard), 說 has 試聽 and the voice
list. speech.rs does the calls; xAI's both ways were checked for real
(Mandarin read, then heard back, in Traditional characters).
- The brain does it all: the phone POSTs its recording (MediaRecorder)
to /api/voice/transcribe, screens to /api/sync/voice/transcribe;
answers come back as MP3 from …/voice/speech and are played on the
device (rodio; an <audio> on the phone, 「唸出來」 in a message's
menu). Keys stay on the brain (the voice keys are redacted for
screens like the others).
- No service, no voice anywhere: the mic, 語音聊天, 會議錄音 and 朗讀
only appear once 聽 (and 說) can be called; the phone's state says
which. Without voice the send arrow just rests where 語音聊天 was.
- 會議錄音 is uploaded to the brain, which turns it into text in the
background and hands it to the bot itself: a meeting is longer than
the 35 s the account lets a request wait, and a brain on a server has
no window (the jobs are polled in background()).
- Recognisers answer Mandarin in Simplified: in a Traditional Chinese
window or phone the text becomes Traditional with Taiwan wording.
- Older saves: whoever had an OpenAI key keeps voice input (聽 =
OpenAI); everyone else starts with it off. Bots' macOS voice names
are cleared. 對話詳細資訊's 加入會議 started plain voice input; it
starts a meeting now.
2026-11-10 14:58:18 +00:00
|
|
|
|
pub fn set_voice(&self, v: crate::speech::Engines) {
|
|
|
|
|
|
*self.voice.lock().unwrap() = v;
|
|
|
|
|
|
}
|
|
|
|
|
|
pub fn voice(&self) -> crate::speech::Engines {
|
|
|
|
|
|
self.voice.lock().unwrap().clone()
|
|
|
|
|
|
}
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
pub fn relay_status(&self) -> String {
|
|
|
|
|
|
self.relay_status.lock().unwrap().clone()
|
|
|
|
|
|
}
|
|
|
|
|
|
fn set_relay_status(&self, s: &str) {
|
|
|
|
|
|
*self.relay_status.lock().unwrap() = s.to_string();
|
|
|
|
|
|
}
|
|
|
|
|
|
/// The view once it is newer than `since` (or after the wait).
|
|
|
|
|
|
fn wait_newer(&self, since: u64, secs: u64) -> View {
|
|
|
|
|
|
let g = self.view.lock().unwrap();
|
|
|
|
|
|
let (g, _) = self.changed.wait_timeout_while(g, Duration::from_secs(secs), |v| v.version <= since).unwrap();
|
|
|
|
|
|
g.clone()
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ---------- shaping the chat for the phone ----------
|
|
|
|
|
|
|
|
|
|
|
|
pub fn tool_label(name: &str) -> &'static str {
|
|
|
|
|
|
if crate::appctl::is_app_tool(name) {
|
|
|
|
|
|
crate::appctl::label(name)
|
|
|
|
|
|
} else if crate::macapps::is_mac_tool(name) {
|
|
|
|
|
|
crate::macapps::label(name)
|
|
|
|
|
|
} else if crate::computer::is_computer_tool(name) {
|
|
|
|
|
|
crate::computer::label(name)
|
|
|
|
|
|
} else if crate::web::is_web_tool(name) {
|
|
|
|
|
|
crate::web::label(name)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
crate::tools::label(name)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
A turn cut off by a crash leaves a 「繼續」 card, and nothing it may have done runs twice
Each bot keeps a work log (oplog/bot-<id>.jsonl, after pi's durable-harness design, cut down):
before something happens a line says it is about to — the turn, each model call, each step once
its checks passed (with the arguments it runs with and whether it may run again), each message
typed mid-turn — synced to disk first. When the turn ends the file shrinks to the messages still
waiting, usually nothing.
On the next start after AnyBot was killed mid-turn, the log puts the chat right before anything
runs: the message the turn answered comes back if the chat lost it; a step that was running and
reaches outside (a text, a click, a file, a published site) shows as 「可能已經執行了」, both to the
person and in the result the bot reads — no longer as "not allowed"; a step that only looked shows
as cut off; messages typed mid-turn that never reached the bot go back into the chat. The chat is
saved, then the log closes the turn. A turn the person didn't stop ends with a 「繼續」 card (what
it was doing, what may have run, the messages put back); it goes on only when they press it — in
the window, on a screen of the brain, or on the phone — from where its steps stand, never running
a step that may have run again. Pressing stop is on disk at once, and a stopped turn stays
stopped.
Also in the turn loop:
- 自動審核 that doesn't answer (or answers something that isn't a verdict) asks the person; in
直接操作 mode it used to let the step through unchecked.
- "Too long for this model" folds older messages into a summary and asks the same step again,
once per thing the person said, instead of ending the turn.
- Folding keeps the person's chat whole: the summary goes in at the fold and the model reads from
the newest summary on (it used to delete what it folded).
- A step moved to the chosen computer runs there, but the chat keeps the call as the model wrote
it; the result says where it ran.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha5F5gJt93t3yEx3XcS
2026-11-08 16:49:12 +00:00
|
|
|
|
pub(crate) fn tool_detail(name: &str, args: &str) -> String {
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
let d = if crate::appctl::is_app_tool(name) {
|
|
|
|
|
|
crate::appctl::describe(name, args)
|
|
|
|
|
|
} else if crate::computer::is_computer_tool(name) {
|
|
|
|
|
|
crate::computer::describe(name, args)
|
|
|
|
|
|
} else if crate::web::is_web_tool(name) {
|
|
|
|
|
|
crate::web::describe(name, args)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
crate::tools::describe(name, args)
|
|
|
|
|
|
};
|
|
|
|
|
|
d.chars().take(120).collect()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// One message as the phone shows it (tool results are folded away like in the window).
|
頁面: pages a bot makes and keeps up to date (like the original's tracking pages)
- write_page / read_page / list_pages: Markdown pages with versions (last 10 kept), per bot;
the reply gets a card (title, fading preview, page icon, 頁面 · 更新時間, 最近更新), and
[標題](page:ID) links open the page
- The page opens large: summary, what changed, the version picker, 複製 / 存成檔案 / 刪除;
listed under 資料庫 in the right panel
- Page blocks for richer pages, in the chat's Markdown too: ```stats tiles, ```steps progress,
> [!NOTE]/[!TIP]/[!WARNING]/[!IMPORTANT] call-outs (with tables and Mermaid charts)
- Phone: the card in chats, page links, a page view with the same blocks; charts drawn by the
AnyBot as SVG (GET /api/pages/<id>[/chart/<n>]); members may read pages
- Bots are told to make a page for things to track and to update it from a routine only when
there is real news
- Screenshot views: ANYBOT_SHOT_VIEW=pagecard / page
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 17:41:41 +00:00
|
|
|
|
pub fn message_json(m: &crate::model::Message, names: &HashMap<u64, String>, pages: &[crate::pages::Page]) -> Option<Value> {
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
use crate::model::{Role, ToolStatus};
|
|
|
|
|
|
if m.role == Role::Tool {
|
|
|
|
|
|
return None;
|
|
|
|
|
|
}
|
|
|
|
|
|
let calls: Vec<Value> = m
|
|
|
|
|
|
.tool_calls
|
|
|
|
|
|
.iter()
|
|
|
|
|
|
.map(|c| {
|
|
|
|
|
|
let st = match c.status {
|
|
|
|
|
|
ToolStatus::Waiting => "waiting",
|
|
|
|
|
|
ToolStatus::Running => "running",
|
|
|
|
|
|
ToolStatus::Done => "done",
|
|
|
|
|
|
ToolStatus::Denied => "denied",
|
|
|
|
|
|
ToolStatus::Failed => "failed",
|
|
|
|
|
|
};
|
頁面: pages a bot makes and keeps up to date (like the original's tracking pages)
- write_page / read_page / list_pages: Markdown pages with versions (last 10 kept), per bot;
the reply gets a card (title, fading preview, page icon, 頁面 · 更新時間, 最近更新), and
[標題](page:ID) links open the page
- The page opens large: summary, what changed, the version picker, 複製 / 存成檔案 / 刪除;
listed under 資料庫 in the right panel
- Page blocks for richer pages, in the chat's Markdown too: ```stats tiles, ```steps progress,
> [!NOTE]/[!TIP]/[!WARNING]/[!IMPORTANT] call-outs (with tables and Mermaid charts)
- Phone: the card in chats, page links, a page view with the same blocks; charts drawn by the
AnyBot as SVG (GET /api/pages/<id>[/chart/<n>]); members may read pages
- Bots are told to make a page for things to track and to update it from a routine only when
there is real news
- Screenshot views: ANYBOT_SHOT_VIEW=pagecard / page
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 17:41:41 +00:00
|
|
|
|
let page = (c.name == "write_page").then(|| serde_json::from_str::<Value>(&c.args).ok().and_then(|a| a["id"].as_u64())).flatten().and_then(|id| pages.iter().find(|p| p.id == id));
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
if c.name == "show_card" {
|
|
|
|
|
|
json!({"card": serde_json::from_str::<Value>(&c.args).unwrap_or(Value::Null), "status": st})
|
2026-11-13 14:03:26 +00:00
|
|
|
|
} else if matches!(c.name.as_str(), "ask_bot" | "message_bot") {
|
|
|
|
|
|
// 同事之間: a conversation card (the answer joins it with the step's result).
|
|
|
|
|
|
let a = crate::tools::args_of(&c.args);
|
|
|
|
|
|
let asked = c.name == "ask_bot";
|
|
|
|
|
|
json!({"talk": {"ask": asked, "to": a["bot"].as_str().unwrap_or(""), "text": a[if asked { "question" } else { "text" }].as_str().unwrap_or("")}, "status": st})
|
頁面: pages a bot makes and keeps up to date (like the original's tracking pages)
- write_page / read_page / list_pages: Markdown pages with versions (last 10 kept), per bot;
the reply gets a card (title, fading preview, page icon, 頁面 · 更新時間, 最近更新), and
[標題](page:ID) links open the page
- The page opens large: summary, what changed, the version picker, 複製 / 存成檔案 / 刪除;
listed under 資料庫 in the right panel
- Page blocks for richer pages, in the chat's Markdown too: ```stats tiles, ```steps progress,
> [!NOTE]/[!TIP]/[!WARNING]/[!IMPORTANT] call-outs (with tables and Mermaid charts)
- Phone: the card in chats, page links, a page view with the same blocks; charts drawn by the
AnyBot as SVG (GET /api/pages/<id>[/chart/<n>]); members may read pages
- Bots are told to make a page for things to track and to update it from a routine only when
there is real news
- Screenshot views: ANYBOT_SHOT_VIEW=pagecard / page
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 17:41:41 +00:00
|
|
|
|
} else if let Some(p) = page {
|
|
|
|
|
|
json!({"page": crate::pages::card_json(p, crate::model::now_ms()), "status": st})
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
} else {
|
|
|
|
|
|
json!({"label": tool_label(&c.name), "detail": tool_detail(&c.name, &c.args), "status": st})
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
.collect();
|
|
|
|
|
|
Some(json!({
|
|
|
|
|
|
"role": match m.role { Role::User => "user", _ => "assistant" },
|
|
|
|
|
|
"text": m.text,
|
|
|
|
|
|
"via": m.via,
|
|
|
|
|
|
"error": m.error,
|
|
|
|
|
|
"summary": m.summary,
|
A turn cut off by a crash leaves a 「繼續」 card, and nothing it may have done runs twice
Each bot keeps a work log (oplog/bot-<id>.jsonl, after pi's durable-harness design, cut down):
before something happens a line says it is about to — the turn, each model call, each step once
its checks passed (with the arguments it runs with and whether it may run again), each message
typed mid-turn — synced to disk first. When the turn ends the file shrinks to the messages still
waiting, usually nothing.
On the next start after AnyBot was killed mid-turn, the log puts the chat right before anything
runs: the message the turn answered comes back if the chat lost it; a step that was running and
reaches outside (a text, a click, a file, a published site) shows as 「可能已經執行了」, both to the
person and in the result the bot reads — no longer as "not allowed"; a step that only looked shows
as cut off; messages typed mid-turn that never reached the bot go back into the chat. The chat is
saved, then the log closes the turn. A turn the person didn't stop ends with a 「繼續」 card (what
it was doing, what may have run, the messages put back); it goes on only when they press it — in
the window, on a screen of the brain, or on the phone — from where its steps stand, never running
a step that may have run again. Pressing stop is on disk at once, and a stopped turn stays
stopped.
Also in the turn loop:
- 自動審核 that doesn't answer (or answers something that isn't a verdict) asks the person; in
直接操作 mode it used to let the step through unchecked.
- "Too long for this model" folds older messages into a summary and asks the same step again,
once per thing the person said, instead of ending the turn.
- Folding keeps the person's chat whole: the summary goes in at the fold and the model reads from
the newest summary on (it used to delete what it folded).
- A step moved to the chosen computer runs there, but the chat keeps the call as the model wrote
it; the result says where it ran.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha5F5gJt93t3yEx3XcS
2026-11-08 16:49:12 +00:00
|
|
|
|
"interrupted": m.interrupted,
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
"wake": m.wake,
|
目標: /goal keeps a bot working turn after turn until a second model, reading the chat, says the goal holds
- goal.rs: the command (/goal, /goal clear, /goal <condition>), the judge's brief and how its
answer is read (met / not_met / waiting / impossible), and the brakes: 20 turns, 3 idle turns,
a question for the person, a failed turn, a stop, a silent judge or a restart pause it; the
person's next message takes it up again
- app/goal_ui.rs: on the brain, each finished turn of a goal is checked on a thread with the bot's
quick model; not yet met wakes it with 「[目標]還沒達成:…」, the rest leave a note in the chat
(never sent to the model) and tell the person when away; the line above the input with 清除目標
- typed on the computer, a screen or the phone, the brain acts on it; /goal leads the / list on
both; the phone shows the bar, the notes and the 目標 tag
- anybot --ask "/goal …" runs to the end, like claude -p "/goal …"
- tests for the command, the verdicts, the brakes, the brief and the slash list; FEATURES.md
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3QxSfoydRPM9mjj6d
2026-11-11 12:24:27 +00:00
|
|
|
|
"note": m.note,
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
"author": if m.author == 0 { String::new() } else { names.get(&m.author).cloned().unwrap_or_default() },
|
|
|
|
|
|
"reactions": m.reactions,
|
2026-11-13 06:19:59 +00:00
|
|
|
|
"attachments": m.attachments.iter().map(|a| json!({"name": a.name, "image": a.image, "path": a.path, "bytes": a.bytes, "kind": crate::preview::kind_label(&a.name)})).collect::<Vec<_>>(),
|
Phone: a home with the computers, pages and routines; each bot's settings a tap away; long jobs fold up
The phone page was bare: one row per bot, a chat listing every step, a menu with four lines.
- Home: the main bot large at the top with its model and last words, the other bots with times,
then its computers (own box and the account's, online or not, 看畫面), the newest pages and the
routines with their next run.
- Chat: the bot's name opens its settings — model (chat models only), computer, past conversations
(restore), regenerate, new chat. A turn's steps fold into 「已完成 N 個步驟」 when done (the newest
three stay while it works); copy and regenerate under replies; four ready starts in a new chat;
a jump back to the newest message.
- Menu: 外觀 (follow the phone, light, dark).
- API: api/state carries pages and models; each bot its model, computers, routines, past
conversations; POST api/bots/{id}/set | regenerate | restore. The home's last line skips errors.
Checked on a local copy of the brain's data (cut off from the account and Docker) at iPhone size.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha2RVfSYmrhqNnqx9Z4
2026-11-06 12:28:08 +00:00
|
|
|
|
"at": m.at,
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
"tools": calls,
|
記憶: 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
|
|
|
|
"memories": m.memories,
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
}))
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Newest messages kept in the phone's view of each chat.
|
|
|
|
|
|
pub const PHONE_TAIL: usize = 120;
|
|
|
|
|
|
|
|
|
|
|
|
// ---------- the API (both the local server and the relay call this) ----------
|
|
|
|
|
|
|
2026-11-13 15:36:34 +00:00
|
|
|
|
/// A phone's 區網 login lasts this long without being used.
|
|
|
|
|
|
const DEVICE_IDLE_DAYS: i64 = 30;
|
|
|
|
|
|
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
fn devices_ok(token: &str) -> Option<String> {
|
|
|
|
|
|
if token.is_empty() {
|
|
|
|
|
|
return None;
|
|
|
|
|
|
}
|
|
|
|
|
|
let h = httpd::sha256_hex(token);
|
2026-11-13 15:36:34 +00:00
|
|
|
|
// (A phone not seen for DEVICE_IDLE_DAYS signs in again: a login copied once isn't for ever.)
|
|
|
|
|
|
let cutoff = chrono::Utc::now().timestamp() - DEVICE_IDLE_DAYS * 86_400;
|
|
|
|
|
|
hub().settings.lock().unwrap().devices.iter().find(|d| httpd::constant_time_eq(&d.token_hash, &h) && d.last_seen.max(d.created) > cutoff).map(|d| d.token_hash.clone())
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
安全、修正: harden sandboxes, approval gates, vault, relay roles, and fix protocol/UI bugs
- macOS 沙盒與工具 (tools.rs, policy.rs, docindex.rs): block AppleScript raw events and
concatenation outside the sandbox; stop exposing ~/.ssh or localhost sockets in Sealed
mode; deny writes to shell profiles, LaunchAgents and .git/hooks; expand secret-file
ignores and enforce symlink/policy checks across SSH, device and document search.
- 電腦操作與遮罩 (computer.rs, agent.rs, marks.rs, desktop.rs, cloudbox.rs, portal.rs):
forbid clicking or typing into AnyBot's own windows; extend the sensitive-action hard
gate to raw coordinates, Return/Delete submits and remote devices; stop batch steps if
the front app changes; black out secrets on zoom, show, >600-node trees, adjacent OTP
labels, box screenshots and control text lists; preserve non-text Wayland clipboards.
- 保險庫與瀏覽器 (vault.rs, vault_store.rs, browser.rs, botbrowser.rs, web.rs, box/browser):
verify tab host and HTTPS atomically at fill time; taint filled tabs against browser_eval
and PDF export while masking card/CVC values and screenshots; remember sites only on
always-allow; drop --remote-allow-origins=*; gate private URLs and block metadata/Docker
ports, OrbStack 198.18/15 and IPv6 transition ranges.
- 帳號伺服器、同步與傳送 (relay/, remote.rs, mirror_ui.rs, share.rs, drops.rs): isolate
paired hands hosts from brain sync, tickets, pairing and backup overwrites; redact
routine trigger secrets and clear REDACTED when endpoints change; isolate channel and
team-member turns from owner memories, appctl and grants; scrub shared bot exports and
reset grants/routines on import; validate drop IDs and serialize chunk writes.
- 網路與協定穩定性 (httpd.rs, tunnel.rs, vnc.rs, Caddyfile*): fix chunked integer overflow
and CRLF header injection; enforce Origin checks, connection/job caps, 200 MB backup
reads, unique atomic temp files and ASCII hex guards; bound deflate unzip and VNC sniff
buffers; move VNC stdin/text off the tunnel loop.
- 介面、排程、語言與其他修正 (app.rs, i18n.rs, providers.rs, skills.rs, routines.rs,
setup.rs, store.rs, preview.rs, attach.rs, speech.rs, teams.rs, mcp.rs, voice.rs):
wire up the delete-routine confirmation dialog and mirror run-now; preserve unsaved
mirror edits across brief disconnects; give Chinese skills distinct folders and approval
gates; convert parsed tool JSON fields without corrupting code fences, URLs or paths;
fix Hourly DST offsets and time out unattended routine approvals; lock --install-skill,
cap docx/xlsx unzip sizes, isolate test env keys, and tighten local file permissions.
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-12 06:34:10 +00:00
|
|
|
|
/// Prevent DNS rebinding against the local LAN HTTP server (`0.0.0.0:8793`): `Host` must be empty
|
|
|
|
|
|
/// (non-browser tests), `localhost`, `.local`, `.ts.net`, or an IP literal.
|
|
|
|
|
|
fn valid_lan_host(req: &Req) -> bool {
|
|
|
|
|
|
let h = req.header("host");
|
|
|
|
|
|
if h.is_empty() {
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
let host = if let Some(v6) = h.strip_prefix('[') {
|
|
|
|
|
|
v6.split_once(']').map(|(a, _)| a).unwrap_or(h)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
h.split(':').next().unwrap_or(h)
|
|
|
|
|
|
};
|
|
|
|
|
|
let low = host.trim_end_matches('.').to_ascii_lowercase();
|
|
|
|
|
|
low == "localhost" || low.ends_with(".local") || low.ends_with(".ts.net") || low.parse::<std::net::IpAddr>().is_ok()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
/// `via_relay`: the relay already checked the account, so no phone password is needed.
|
|
|
|
|
|
pub fn handle(req: Req, via_relay: bool) -> Resp {
|
安全、修正: harden sandboxes, approval gates, vault, relay roles, and fix protocol/UI bugs
- macOS 沙盒與工具 (tools.rs, policy.rs, docindex.rs): block AppleScript raw events and
concatenation outside the sandbox; stop exposing ~/.ssh or localhost sockets in Sealed
mode; deny writes to shell profiles, LaunchAgents and .git/hooks; expand secret-file
ignores and enforce symlink/policy checks across SSH, device and document search.
- 電腦操作與遮罩 (computer.rs, agent.rs, marks.rs, desktop.rs, cloudbox.rs, portal.rs):
forbid clicking or typing into AnyBot's own windows; extend the sensitive-action hard
gate to raw coordinates, Return/Delete submits and remote devices; stop batch steps if
the front app changes; black out secrets on zoom, show, >600-node trees, adjacent OTP
labels, box screenshots and control text lists; preserve non-text Wayland clipboards.
- 保險庫與瀏覽器 (vault.rs, vault_store.rs, browser.rs, botbrowser.rs, web.rs, box/browser):
verify tab host and HTTPS atomically at fill time; taint filled tabs against browser_eval
and PDF export while masking card/CVC values and screenshots; remember sites only on
always-allow; drop --remote-allow-origins=*; gate private URLs and block metadata/Docker
ports, OrbStack 198.18/15 and IPv6 transition ranges.
- 帳號伺服器、同步與傳送 (relay/, remote.rs, mirror_ui.rs, share.rs, drops.rs): isolate
paired hands hosts from brain sync, tickets, pairing and backup overwrites; redact
routine trigger secrets and clear REDACTED when endpoints change; isolate channel and
team-member turns from owner memories, appctl and grants; scrub shared bot exports and
reset grants/routines on import; validate drop IDs and serialize chunk writes.
- 網路與協定穩定性 (httpd.rs, tunnel.rs, vnc.rs, Caddyfile*): fix chunked integer overflow
and CRLF header injection; enforce Origin checks, connection/job caps, 200 MB backup
reads, unique atomic temp files and ASCII hex guards; bound deflate unzip and VNC sniff
buffers; move VNC stdin/text off the tunnel loop.
- 介面、排程、語言與其他修正 (app.rs, i18n.rs, providers.rs, skills.rs, routines.rs,
setup.rs, store.rs, preview.rs, attach.rs, speech.rs, teams.rs, mcp.rs, voice.rs):
wire up the delete-routine confirmation dialog and mirror run-now; preserve unsaved
mirror edits across brief disconnects; give Chinese skills distinct folders and approval
gates; convert parsed tool JSON fields without corrupting code fences, URLs or paths;
fix Hourly DST offsets and time out unattended routine approvals; lock --install-skill,
cap docx/xlsx unzip sizes, isolate test env keys, and tighten local file permissions.
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-12 06:34:10 +00:00
|
|
|
|
if !via_relay && !valid_lan_host(&req) {
|
|
|
|
|
|
return Resp::error(403, "forbidden host");
|
|
|
|
|
|
}
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
let parts = req.parts();
|
Clippy is clean on macOS and Linux, for the app and the relay
Every warning `cargo clippy --all-targets` gave (50 on macOS, 8 more only on
Linux, 1 in the relay), fixed without changing what anything does:
- long types get a name (Peer, Members, Imported, Joining, Mention, Stream…);
- the two big enum variants are boxed (the vault's login plan, joining an
account);
- a test now waits for the copy it relaunched (it left a zombie behind);
- a hint's format had a dead `if` whose two branches were both "";
- the rest is what clippy suggests: sort_by_key, as_chunks, is_none_or,
is_multiple_of, while let, from_ref, next_back, struct init, no casts to
the same type.
Checked: cargo test (177 macOS, 181 Linux), relay tests (11), remote_e2e
28/28, and the live Linux test (X11; Wayland clicks, keys, Chinese typing,
scroll and screenshots).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha2RVfSYmrhqNnqx9Z4
2026-11-07 02:10:28 +00:00
|
|
|
|
let path: Vec<&str> = parts.to_vec();
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
match (req.method.as_str(), path.as_slice()) {
|
|
|
|
|
|
("GET", []) | ("GET", ["index.html"]) => return page(),
|
2026-11-13 16:40:16 +00:00
|
|
|
|
("GET", ["screen"]) => return Resp::bytes("text/html; charset=utf-8", SCREEN_PAGE.as_bytes().to_vec()).with_header("Content-Security-Policy", &format!("default-src 'self'; img-src 'self' blob: data:; style-src 'self' 'unsafe-inline'; {}; connect-src 'self' ws: wss:; base-uri 'none'; object-src 'none'; frame-ancestors 'self'", httpd::script_src(SCREEN_PAGE))),
|
People watch and help on the bots' computer through VNC (noVNC), carried by the account server
The core: the bot works the computer; a person watches it like a colleague, and takes over
when it needs them. VNC is made for that (only what changed, every mouse move and key, touch on
phones), so the pictures sent one by one go, and with them their own input path.
- vnc.rs: a VNC proxy to the box's x11vnc through one docker exec (a Python bridge that ends
with either side). It signs in to the box with the box's own password (its VNC_PASSWORD) and
offers the viewer no password, so the password never leaves the brain. The person's clicks
and keys make the bot's steps wait until 8 s after they stop; text typed in the viewer's box
(any language) is pasted in the box.
- Account server: /screen (the viewer page) and /novnc.js (noVNC 1.6.0, MPL-2.0, bundled);
/relay/vnc/<host> takes the browser's WebSocket (account session, or a 10-minute ticket the
app asks for with POST /relay/screen-ticket; owners and admins) and carries it over that
AnyBot's lasting connection (vopen / vdata / vtext / vclose). Both ends of that connection
wait 2 ms instead of 40 ms to read while things move: a request and its answer took up to
160 ms more than needed.
- Phone page: 看 Bot 的電腦 and 接管 open the viewer page (also on the local network: /api/vnc on
the AnyBot's own phone server). This Mac's own screen moved to the ⋯ menu.
- Mac app: 看畫面 opens the viewer in the browser (a screen of a brain: the brain's computer by
ticket; else this computer's box, noVNC straight from it). The in-app picture viewer, the
live JPEG stream, the person's click/move/scroll/key endpoints and the input shell are gone.
- Opening a Mac app uses LaunchServices (`open -a`): agent-desktop's launch waited on the window
through accessibility and failed without 輔助使用 now and then.
Measured on this Mac (made-up account, local relay + headless brain + the real box): viewer
signed in in 0.4–0.7 s, a request and its answer through relay + brain + box 25–58 ms median;
headless Chrome shows the desktop live in /screen. remote_e2e 28/28 ×2, 149 unit tests, relay 11.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-05 15:05:44 +00:00
|
|
|
|
("GET", ["novnc.js"]) => return Resp::bytes("text/javascript; charset=utf-8", NOVNC.as_bytes().to_vec()).with_header("Cache-Control", "public, max-age=86400"),
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
("GET", ["manifest.webmanifest"]) => return Resp::bytes("application/manifest+json", MANIFEST.as_bytes().to_vec()),
|
|
|
|
|
|
("GET", ["icon.svg"]) => return Resp::bytes("image/svg+xml", ICON.as_bytes().to_vec()),
|
2026-11-05 11:20:29 +00:00
|
|
|
|
("GET", [name]) if ICON_PNGS.iter().any(|(n, _)| n == name) => return Resp::bytes("image/png", ICON_PNGS.iter().find(|(n, _)| n == name).map(|(_, b)| b.to_vec()).unwrap_or_default()),
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
("GET", ["api", "hello"]) => {
|
|
|
|
|
|
let s = hub().settings();
|
|
|
|
|
|
return Resp::json(&json!({"app": "anybot", "host": s.host_name, "relay": via_relay, "needs_password": !via_relay}));
|
|
|
|
|
|
}
|
|
|
|
|
|
("POST", ["api", "login"]) if !via_relay => return login(&req),
|
|
|
|
|
|
_ => {}
|
|
|
|
|
|
}
|
|
|
|
|
|
if !via_relay {
|
|
|
|
|
|
match devices_ok(&req.bearer()) {
|
|
|
|
|
|
Some(h) => hub().push(Cmd::DeviceSeen(h)),
|
|
|
|
|
|
None => return Resp::error(401, "請先登入"),
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
let s = hub().settings();
|
|
|
|
|
|
// Direct phones are the owner's. Through the relay, the relay says who is asking.
|
2026-11-13 15:36:34 +00:00
|
|
|
|
// (A request from the relay that names no role is nobody's — it used to be the owner's.)
|
|
|
|
|
|
let role = if via_relay { Some(req.header("x-anybot-role")).filter(|r| !r.is_empty()).unwrap_or("none").to_string() } else { "owner".to_string() };
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
if !role_allows(&role, &req.method, &path) {
|
|
|
|
|
|
return Resp::error(403, "你在這台 AnyBot 的角色不能做這件事(請擁有者處理)");
|
|
|
|
|
|
}
|
2026-11-13 15:36:34 +00:00
|
|
|
|
// 團隊: a teammate sees only the bots shared with the team — their chats, pages and files.
|
|
|
|
|
|
if role == "member" {
|
|
|
|
|
|
let v = hub().view.lock().unwrap();
|
|
|
|
|
|
let shared: Vec<u64> = v.bots.iter().filter(|b| b["team"] == true).filter_map(|b| b["id"].as_u64()).collect();
|
|
|
|
|
|
let ok = match path.as_slice() {
|
|
|
|
|
|
["api", "bots", id, ..] => id.parse::<u64>().is_ok_and(|i| shared.contains(&i)),
|
|
|
|
|
|
["api", "pages", id, ..] => id.parse::<u64>().ok().and_then(|i| v.pages.iter().find(|p| p.id == i)).is_some_and(|p| shared.contains(&p.bot)),
|
|
|
|
|
|
["api", "file"] | ["api", "preview", ..] => member_file_ok(req.query.get("path").map(String::as_str).unwrap_or(""), &shared),
|
|
|
|
|
|
_ => true,
|
|
|
|
|
|
};
|
|
|
|
|
|
if !ok {
|
|
|
|
|
|
return Resp::error(404, "找不到(或這個 Bot 沒有分享給團隊)");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
match (req.method.as_str(), path.as_slice()) {
|
|
|
|
|
|
("GET", ["api", "state"]) => {
|
|
|
|
|
|
let since: u64 = req.query.get("since").and_then(|v| v.parse().ok()).unwrap_or(0);
|
2026-11-06 12:33:06 +00:00
|
|
|
|
// The phone says where the person is (once per change, not every poll).
|
|
|
|
|
|
if let Some(tz) = req.query.get("tz").filter(|t| t.parse::<chrono_tz::Tz>().is_ok()) {
|
|
|
|
|
|
static TOLD: Mutex<String> = Mutex::new(String::new());
|
|
|
|
|
|
let mut told = TOLD.lock().unwrap_or_else(|e| e.into_inner());
|
|
|
|
|
|
if *told != *tz {
|
|
|
|
|
|
*told = tz.clone();
|
|
|
|
|
|
hub().push(Cmd::PersonTimezone(tz.clone()));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
let v = hub().wait_newer(since, if since == 0 { 0 } else { LONG_POLL_SECS });
|
Phone: a home with the computers, pages and routines; each bot's settings a tap away; long jobs fold up
The phone page was bare: one row per bot, a chat listing every step, a menu with four lines.
- Home: the main bot large at the top with its model and last words, the other bots with times,
then its computers (own box and the account's, online or not, 看畫面), the newest pages and the
routines with their next run.
- Chat: the bot's name opens its settings — model (chat models only), computer, past conversations
(restore), regenerate, new chat. A turn's steps fold into 「已完成 N 個步驟」 when done (the newest
three stay while it works); copy and regenerate under replies; four ready starts in a new chat;
a jump back to the newest message.
- Menu: 外觀 (follow the phone, light, dark).
- API: api/state carries pages and models; each bot its model, computers, routines, past
conversations; POST api/bots/{id}/set | regenerate | restore. The home's last line skips errors.
Checked on a local copy of the brain's data (cut off from the account and Docker) at iPhone size.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha2RVfSYmrhqNnqx9Z4
2026-11-06 12:28:08 +00:00
|
|
|
|
// 頁面 for the phone's home: the newest first, each with its bot.
|
|
|
|
|
|
let now = crate::model::now_ms();
|
2026-11-13 15:36:34 +00:00
|
|
|
|
let shared = |id: u64| role != "member" || v.bots.iter().any(|b| b["id"].as_u64() == Some(id) && b["team"] == true);
|
|
|
|
|
|
let mut pages: Vec<&crate::pages::Page> = v.pages.iter().filter(|p| shared(p.bot)).collect();
|
Phone: a home with the computers, pages and routines; each bot's settings a tap away; long jobs fold up
The phone page was bare: one row per bot, a chat listing every step, a menu with four lines.
- Home: the main bot large at the top with its model and last words, the other bots with times,
then its computers (own box and the account's, online or not, 看畫面), the newest pages and the
routines with their next run.
- Chat: the bot's name opens its settings — model (chat models only), computer, past conversations
(restore), regenerate, new chat. A turn's steps fold into 「已完成 N 個步驟」 when done (the newest
three stay while it works); copy and regenerate under replies; four ready starts in a new chat;
a jump back to the newest message.
- Menu: 外觀 (follow the phone, light, dark).
- API: api/state carries pages and models; each bot its model, computers, routines, past
conversations; POST api/bots/{id}/set | regenerate | restore. The home's last line skips errors.
Checked on a local copy of the brain's data (cut off from the account and Docker) at iPhone size.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha2RVfSYmrhqNnqx9Z4
2026-11-06 12:28:08 +00:00
|
|
|
|
pages.sort_by_key(|p| std::cmp::Reverse(p.updated));
|
|
|
|
|
|
let bot_name = |id: u64| v.bots.iter().find(|b| b["id"].as_u64() == Some(id)).and_then(|b| b["name"].as_str()).unwrap_or("").to_string();
|
|
|
|
|
|
let pages: Vec<Value> = pages.into_iter().take(12).map(|p| {
|
|
|
|
|
|
let mut c = crate::pages::card_json(p, now);
|
|
|
|
|
|
c["bot"] = json!(bot_name(p.bot));
|
|
|
|
|
|
c
|
|
|
|
|
|
}).collect();
|
安全、修正: harden sandboxes, approval gates, vault, relay roles, and fix protocol/UI bugs
- macOS 沙盒與工具 (tools.rs, policy.rs, docindex.rs): block AppleScript raw events and
concatenation outside the sandbox; stop exposing ~/.ssh or localhost sockets in Sealed
mode; deny writes to shell profiles, LaunchAgents and .git/hooks; expand secret-file
ignores and enforce symlink/policy checks across SSH, device and document search.
- 電腦操作與遮罩 (computer.rs, agent.rs, marks.rs, desktop.rs, cloudbox.rs, portal.rs):
forbid clicking or typing into AnyBot's own windows; extend the sensitive-action hard
gate to raw coordinates, Return/Delete submits and remote devices; stop batch steps if
the front app changes; black out secrets on zoom, show, >600-node trees, adjacent OTP
labels, box screenshots and control text lists; preserve non-text Wayland clipboards.
- 保險庫與瀏覽器 (vault.rs, vault_store.rs, browser.rs, botbrowser.rs, web.rs, box/browser):
verify tab host and HTTPS atomically at fill time; taint filled tabs against browser_eval
and PDF export while masking card/CVC values and screenshots; remember sites only on
always-allow; drop --remote-allow-origins=*; gate private URLs and block metadata/Docker
ports, OrbStack 198.18/15 and IPv6 transition ranges.
- 帳號伺服器、同步與傳送 (relay/, remote.rs, mirror_ui.rs, share.rs, drops.rs): isolate
paired hands hosts from brain sync, tickets, pairing and backup overwrites; redact
routine trigger secrets and clear REDACTED when endpoints change; isolate channel and
team-member turns from owner memories, appctl and grants; scrub shared bot exports and
reset grants/routines on import; validate drop IDs and serialize chunk writes.
- 網路與協定穩定性 (httpd.rs, tunnel.rs, vnc.rs, Caddyfile*): fix chunked integer overflow
and CRLF header injection; enforce Origin checks, connection/job caps, 200 MB backup
reads, unique atomic temp files and ASCII hex guards; bound deflate unzip and VNC sniff
buffers; move VNC stdin/text off the tunnel loop.
- 介面、排程、語言與其他修正 (app.rs, i18n.rs, providers.rs, skills.rs, routines.rs,
setup.rs, store.rs, preview.rs, attach.rs, speech.rs, teams.rs, mcp.rs, voice.rs):
wire up the delete-routine confirmation dialog and mirror run-now; preserve unsaved
mirror edits across brief disconnects; give Chinese skills distinct folders and approval
gates; convert parsed tool JSON fields without corrupting code fences, URLs or paths;
fix Hourly DST offsets and time out unattended routine approvals; lock --install-skill,
cap docx/xlsx unzip sizes, isolate test env keys, and tighten local file permissions.
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-12 06:34:10 +00:00
|
|
|
|
let bots: Vec<Value> = if role == "member" {
|
|
|
|
|
|
v.bots
|
|
|
|
|
|
.iter()
|
2026-11-13 15:36:34 +00:00
|
|
|
|
.filter(|b| b["team"] == true)
|
安全、修正: harden sandboxes, approval gates, vault, relay roles, and fix protocol/UI bugs
- macOS 沙盒與工具 (tools.rs, policy.rs, docindex.rs): block AppleScript raw events and
concatenation outside the sandbox; stop exposing ~/.ssh or localhost sockets in Sealed
mode; deny writes to shell profiles, LaunchAgents and .git/hooks; expand secret-file
ignores and enforce symlink/policy checks across SSH, device and document search.
- 電腦操作與遮罩 (computer.rs, agent.rs, marks.rs, desktop.rs, cloudbox.rs, portal.rs):
forbid clicking or typing into AnyBot's own windows; extend the sensitive-action hard
gate to raw coordinates, Return/Delete submits and remote devices; stop batch steps if
the front app changes; black out secrets on zoom, show, >600-node trees, adjacent OTP
labels, box screenshots and control text lists; preserve non-text Wayland clipboards.
- 保險庫與瀏覽器 (vault.rs, vault_store.rs, browser.rs, botbrowser.rs, web.rs, box/browser):
verify tab host and HTTPS atomically at fill time; taint filled tabs against browser_eval
and PDF export while masking card/CVC values and screenshots; remember sites only on
always-allow; drop --remote-allow-origins=*; gate private URLs and block metadata/Docker
ports, OrbStack 198.18/15 and IPv6 transition ranges.
- 帳號伺服器、同步與傳送 (relay/, remote.rs, mirror_ui.rs, share.rs, drops.rs): isolate
paired hands hosts from brain sync, tickets, pairing and backup overwrites; redact
routine trigger secrets and clear REDACTED when endpoints change; isolate channel and
team-member turns from owner memories, appctl and grants; scrub shared bot exports and
reset grants/routines on import; validate drop IDs and serialize chunk writes.
- 網路與協定穩定性 (httpd.rs, tunnel.rs, vnc.rs, Caddyfile*): fix chunked integer overflow
and CRLF header injection; enforce Origin checks, connection/job caps, 200 MB backup
reads, unique atomic temp files and ASCII hex guards; bound deflate unzip and VNC sniff
buffers; move VNC stdin/text off the tunnel loop.
- 介面、排程、語言與其他修正 (app.rs, i18n.rs, providers.rs, skills.rs, routines.rs,
setup.rs, store.rs, preview.rs, attach.rs, speech.rs, teams.rs, mcp.rs, voice.rs):
wire up the delete-routine confirmation dialog and mirror run-now; preserve unsaved
mirror edits across brief disconnects; give Chinese skills distinct folders and approval
gates; convert parsed tool JSON fields without corrupting code fences, URLs or paths;
fix Hourly DST offsets and time out unattended routine approvals; lock --install-skill,
cap docx/xlsx unzip sizes, isolate test env keys, and tighten local file permissions.
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-12 06:34:10 +00:00
|
|
|
|
.map(|b| {
|
|
|
|
|
|
let mut c = b.clone();
|
|
|
|
|
|
if let Some(o) = c.as_object_mut() {
|
|
|
|
|
|
o.insert("routines".into(), json!([]));
|
|
|
|
|
|
o.insert("threads".into(), json!([]));
|
|
|
|
|
|
o.insert("queued".into(), json!([]));
|
|
|
|
|
|
o.remove("goal");
|
|
|
|
|
|
}
|
|
|
|
|
|
c
|
|
|
|
|
|
})
|
|
|
|
|
|
.collect()
|
|
|
|
|
|
} else {
|
|
|
|
|
|
v.bots.clone()
|
|
|
|
|
|
};
|
2026-11-13 06:19:59 +00:00
|
|
|
|
let mut out = json!({
|
|
|
|
|
|
"version": v.version, "host": v.host, "person": v.person, "accent": v.accent,
|
|
|
|
|
|
"pin_order": v.pin_order, "newer": v.newer, "bots": bots,
|
安全、修正: harden sandboxes, approval gates, vault, relay roles, and fix protocol/UI bugs
- macOS 沙盒與工具 (tools.rs, policy.rs, docindex.rs): block AppleScript raw events and
concatenation outside the sandbox; stop exposing ~/.ssh or localhost sockets in Sealed
mode; deny writes to shell profiles, LaunchAgents and .git/hooks; expand secret-file
ignores and enforce symlink/policy checks across SSH, device and document search.
- 電腦操作與遮罩 (computer.rs, agent.rs, marks.rs, desktop.rs, cloudbox.rs, portal.rs):
forbid clicking or typing into AnyBot's own windows; extend the sensitive-action hard
gate to raw coordinates, Return/Delete submits and remote devices; stop batch steps if
the front app changes; black out secrets on zoom, show, >600-node trees, adjacent OTP
labels, box screenshots and control text lists; preserve non-text Wayland clipboards.
- 保險庫與瀏覽器 (vault.rs, vault_store.rs, browser.rs, botbrowser.rs, web.rs, box/browser):
verify tab host and HTTPS atomically at fill time; taint filled tabs against browser_eval
and PDF export while masking card/CVC values and screenshots; remember sites only on
always-allow; drop --remote-allow-origins=*; gate private URLs and block metadata/Docker
ports, OrbStack 198.18/15 and IPv6 transition ranges.
- 帳號伺服器、同步與傳送 (relay/, remote.rs, mirror_ui.rs, share.rs, drops.rs): isolate
paired hands hosts from brain sync, tickets, pairing and backup overwrites; redact
routine trigger secrets and clear REDACTED when endpoints change; isolate channel and
team-member turns from owner memories, appctl and grants; scrub shared bot exports and
reset grants/routines on import; validate drop IDs and serialize chunk writes.
- 網路與協定穩定性 (httpd.rs, tunnel.rs, vnc.rs, Caddyfile*): fix chunked integer overflow
and CRLF header injection; enforce Origin checks, connection/job caps, 200 MB backup
reads, unique atomic temp files and ASCII hex guards; bound deflate unzip and VNC sniff
buffers; move VNC stdin/text off the tunnel loop.
- 介面、排程、語言與其他修正 (app.rs, i18n.rs, providers.rs, skills.rs, routines.rs,
setup.rs, store.rs, preview.rs, attach.rs, speech.rs, teams.rs, mcp.rs, voice.rs):
wire up the delete-routine confirmation dialog and mirror run-now; preserve unsaved
mirror edits across brief disconnects; give Chinese skills distinct folders and approval
gates; convert parsed tool JSON fields without corrupting code fences, URLs or paths;
fix Hourly DST offsets and time out unattended routine approvals; lock --install-skill,
cap docx/xlsx unzip sizes, isolate test env keys, and tighten local file permissions.
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-12 06:34:10 +00:00
|
|
|
|
"approvals": if role == "member" { vec![] } else { v.approvals.clone() },
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
"box": crate::cloudbox::run_state().label(),
|
|
|
|
|
|
"box_available": crate::cloudbox::available(),
|
|
|
|
|
|
"mac": s.mac_from_phone && cfg!(target_os = "macos") && role != "member",
|
|
|
|
|
|
"role": role,
|
Phone: a home with the computers, pages and routines; each bot's settings a tap away; long jobs fold up
The phone page was bare: one row per bot, a chat listing every step, a menu with four lines.
- Home: the main bot large at the top with its model and last words, the other bots with times,
then its computers (own box and the account's, online or not, 看畫面), the newest pages and the
routines with their next run.
- Chat: the bot's name opens its settings — model (chat models only), computer, past conversations
(restore), regenerate, new chat. A turn's steps fold into 「已完成 N 個步驟」 when done (the newest
three stay while it works); copy and regenerate under replies; four ready starts in a new chat;
a jump back to the newest message.
- Menu: 外觀 (follow the phone, light, dark).
- API: api/state carries pages and models; each bot its model, computers, routines, past
conversations; POST api/bots/{id}/set | regenerate | restore. The home's last line skips errors.
Checked on a local copy of the brain's data (cut off from the account and Docker) at iPhone size.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha2RVfSYmrhqNnqx9Z4
2026-11-06 12:28:08 +00:00
|
|
|
|
"pages": pages,
|
|
|
|
|
|
"models": if role == "member" { vec![] } else { v.models.clone() },
|
The phone page does what the desktop does, laid out like it
A new mobile/index.html in the desktop's (and Grok Bot's) shape: the sidebar
with its sections and folders, the chat with steps, thinking, reactions, quotes
and the approval card, 對話詳細資訊, Bot 設定, routines, pages, computers and
設定. Each action goes to the desktop's own code on the app's thread
(api/act/<what> -> App::phone_act): appctl, set_pinned, restart_bot,
toggle_reaction, box_task, channels_restart and the rest. No new rules.
Keys, channel tokens and the vault never reach the phone; a model key can only
be written. Admins keep what the phone always let them do; making, changing or
deleting bots, routines, memories, pages, folders and settings stays the
owner's. The state the phone polls now carries the sidebar's section order.
Checked by using it on a preview brain: routines, memories, templates, folders,
keys, signing another phone out, approvals and a chat with a fake model.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha2RVfSYmrhqNnqx9Z4
2026-11-06 19:05:12 +00:00
|
|
|
|
"sections": v.sections,
|
Voice: its own 設定 › 語音, run by the brain for every screen and the phone
Voice was three implementations that broke on their own: speech to text
borrowed the OpenAI key (so with only Grok set up the mic recorded,
then failed), OpenAI's models it hard-coded stop on 2027-02-26, read
aloud was macOS `say` or espeak-ng (silently nothing on Windows, where
espeak isn't installed), and the phone used the browser's own
recognition. Now:
- 設定 › 語音 has 聽 and 說, each a service: off, OpenAI-compatible
(OpenAI, Groq, a Whisper server of your own: the address decides),
xAI or ElevenLabs. An empty key borrows 設定 › 模型's for the same
service. Each side says 可以用 or what it lacks; 聽 has 試試看
(record a sentence, show what was heard), 說 has 試聽 and the voice
list. speech.rs does the calls; xAI's both ways were checked for real
(Mandarin read, then heard back, in Traditional characters).
- The brain does it all: the phone POSTs its recording (MediaRecorder)
to /api/voice/transcribe, screens to /api/sync/voice/transcribe;
answers come back as MP3 from …/voice/speech and are played on the
device (rodio; an <audio> on the phone, 「唸出來」 in a message's
menu). Keys stay on the brain (the voice keys are redacted for
screens like the others).
- No service, no voice anywhere: the mic, 語音聊天, 會議錄音 and 朗讀
only appear once 聽 (and 說) can be called; the phone's state says
which. Without voice the send arrow just rests where 語音聊天 was.
- 會議錄音 is uploaded to the brain, which turns it into text in the
background and hands it to the bot itself: a meeting is longer than
the 35 s the account lets a request wait, and a brain on a server has
no window (the jobs are polled in background()).
- Recognisers answer Mandarin in Simplified: in a Traditional Chinese
window or phone the text becomes Traditional with Taiwan wording.
- Older saves: whoever had an OpenAI key keeps voice input (聽 =
OpenAI); everyone else starts with it off. Bots' macOS voice names
are cleared. 對話詳細資訊's 加入會議 started plain voice input; it
starts a meeting now.
2026-11-10 14:58:18 +00:00
|
|
|
|
// 語音: the mic shows only when this brain can hear (and read aloud).
|
|
|
|
|
|
"voice": {"listen": hub().voice().listen.is_some(), "speak": hub().voice().speak.is_some()},
|
2026-11-13 06:19:59 +00:00
|
|
|
|
});
|
|
|
|
|
|
// Single-trip active chat sync: when the browser names its open bot (`&bot=ID`),
|
|
|
|
|
|
// include that chat's messages whenever their signature changed (`&chat_sig=…`).
|
|
|
|
|
|
if let Some(open_id) = req.query.get("bot").and_then(|b| b.parse::<u64>().ok()).filter(|&id| id > 0) {
|
|
|
|
|
|
if let Some(raw) = v.messages.get(&open_id) {
|
|
|
|
|
|
let msgs = messages_for_role(raw, &role);
|
|
|
|
|
|
let sig = chat_sig(&msgs);
|
|
|
|
|
|
let client_sig = req.query.get("chat_sig").map(String::as_str).unwrap_or("");
|
|
|
|
|
|
out["chat"] = if client_sig == sig {
|
|
|
|
|
|
json!({"bot": open_id, "sig": sig, "unchanged": true})
|
|
|
|
|
|
} else {
|
|
|
|
|
|
json!({"bot": open_id, "sig": sig, "messages": msgs})
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
Resp::json(&out)
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
}
|
頁面: pages a bot makes and keeps up to date (like the original's tracking pages)
- write_page / read_page / list_pages: Markdown pages with versions (last 10 kept), per bot;
the reply gets a card (title, fading preview, page icon, 頁面 · 更新時間, 最近更新), and
[標題](page:ID) links open the page
- The page opens large: summary, what changed, the version picker, 複製 / 存成檔案 / 刪除;
listed under 資料庫 in the right panel
- Page blocks for richer pages, in the chat's Markdown too: ```stats tiles, ```steps progress,
> [!NOTE]/[!TIP]/[!WARNING]/[!IMPORTANT] call-outs (with tables and Mermaid charts)
- Phone: the card in chats, page links, a page view with the same blocks; charts drawn by the
AnyBot as SVG (GET /api/pages/<id>[/chart/<n>]); members may read pages
- Bots are told to make a page for things to track and to update it from a routine only when
there is real news
- Screenshot views: ANYBOT_SHOT_VIEW=pagecard / page
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 17:41:41 +00:00
|
|
|
|
// 頁面: the whole page (or an older version with ?rev=N), and its charts drawn as SVG.
|
|
|
|
|
|
("GET", ["api", "pages", id]) => {
|
|
|
|
|
|
let id: u64 = id.parse().unwrap_or(0);
|
|
|
|
|
|
let v = hub().view.lock().unwrap();
|
|
|
|
|
|
let Some(cur) = v.pages.iter().find(|p| p.id == id) else { return Resp::error(404, "這個頁面已經刪除了") };
|
|
|
|
|
|
let shown = req.query.get("rev").and_then(|r| r.parse().ok()).and_then(|r| crate::pages::version_of(cur, r)).unwrap_or_else(|| cur.clone());
|
|
|
|
|
|
let bot = v.bots.iter().find(|b| b["id"].as_u64() == Some(cur.bot)).and_then(|b| b["name"].as_str()).unwrap_or("").to_string();
|
|
|
|
|
|
let mut out = crate::pages::page_json(&shown, &bot, crate::model::now_ms());
|
|
|
|
|
|
out["versions"] = crate::pages::page_json(cur, &bot, 0)["versions"].clone();
|
|
|
|
|
|
out["latest"] = json!(cur.revision);
|
|
|
|
|
|
Resp::json(&out)
|
|
|
|
|
|
}
|
|
|
|
|
|
("GET", ["api", "pages", id, "chart", n]) => {
|
|
|
|
|
|
let id: u64 = id.parse().unwrap_or(0);
|
|
|
|
|
|
let n: usize = n.parse().unwrap_or(0);
|
|
|
|
|
|
let body = {
|
|
|
|
|
|
let v = hub().view.lock().unwrap();
|
|
|
|
|
|
let Some(cur) = v.pages.iter().find(|p| p.id == id) else { return Resp::error(404, "這個頁面已經刪除了") };
|
|
|
|
|
|
req.query.get("rev").and_then(|r| r.parse().ok()).and_then(|r| crate::pages::version_of(cur, r)).unwrap_or_else(|| cur.clone()).body
|
|
|
|
|
|
};
|
|
|
|
|
|
let Some(src) = crate::pages::mermaid_blocks(&body).into_iter().nth(n) else { return Resp::error(404, "找不到這張圖") };
|
|
|
|
|
|
match crate::diagram::svg(&src, req.query.get("dark").map(|d| d == "1").unwrap_or(false)) {
|
|
|
|
|
|
Ok(svg) => Resp::bytes("image/svg+xml", svg.into_bytes()),
|
|
|
|
|
|
Err(e) => Resp::error(422, &e),
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
("GET", ["api", "bots", id]) => {
|
|
|
|
|
|
let id: u64 = id.parse().unwrap_or(0);
|
|
|
|
|
|
let v = hub().view.lock().unwrap();
|
|
|
|
|
|
match v.messages.get(&id) {
|
2026-11-13 06:19:59 +00:00
|
|
|
|
Some(m) => {
|
|
|
|
|
|
let msgs = messages_for_role(m, &role);
|
|
|
|
|
|
let sig = chat_sig(&msgs);
|
|
|
|
|
|
Resp::json(&json!({"version": v.version, "sig": sig, "messages": msgs}))
|
2026-11-11 01:35:59 +00:00
|
|
|
|
}
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
None => Resp::error(404, "找不到這個 Bot"),
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
The phone page does what the desktop does, laid out like it
A new mobile/index.html in the desktop's (and Grok Bot's) shape: the sidebar
with its sections and folders, the chat with steps, thinking, reactions, quotes
and the approval card, 對話詳細資訊, Bot 設定, routines, pages, computers and
設定. Each action goes to the desktop's own code on the app's thread
(api/act/<what> -> App::phone_act): appctl, set_pinned, restart_bot,
toggle_reaction, box_task, channels_restart and the rest. No new rules.
Keys, channel tokens and the vault never reach the phone; a model key can only
be written. Admins keep what the phone always let them do; making, changing or
deleting bots, routines, memories, pages, folders and settings stays the
owner's. The state the phone polls now carries the sidebar's section order.
Checked by using it on a preview brain: routines, memories, templates, folders,
keys, signing another phone out, approvals and a chat with a fake model.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha2RVfSYmrhqNnqx9Z4
2026-11-06 19:05:12 +00:00
|
|
|
|
// What the desktop shows beside the chat and in 設定, made when asked (never keys, tokens
|
|
|
|
|
|
// or the vault's secrets), and everything else it can do (api/act/<what>).
|
|
|
|
|
|
("GET", ["api", "bots", id, "detail"]) => phone_act("detail", json!({"bot": id.parse::<u64>().unwrap_or(0)}), &role),
|
安全、修正: harden sandboxes, approval gates, vault, relay roles, and fix protocol/UI bugs
- macOS 沙盒與工具 (tools.rs, policy.rs, docindex.rs): block AppleScript raw events and
concatenation outside the sandbox; stop exposing ~/.ssh or localhost sockets in Sealed
mode; deny writes to shell profiles, LaunchAgents and .git/hooks; expand secret-file
ignores and enforce symlink/policy checks across SSH, device and document search.
- 電腦操作與遮罩 (computer.rs, agent.rs, marks.rs, desktop.rs, cloudbox.rs, portal.rs):
forbid clicking or typing into AnyBot's own windows; extend the sensitive-action hard
gate to raw coordinates, Return/Delete submits and remote devices; stop batch steps if
the front app changes; black out secrets on zoom, show, >600-node trees, adjacent OTP
labels, box screenshots and control text lists; preserve non-text Wayland clipboards.
- 保險庫與瀏覽器 (vault.rs, vault_store.rs, browser.rs, botbrowser.rs, web.rs, box/browser):
verify tab host and HTTPS atomically at fill time; taint filled tabs against browser_eval
and PDF export while masking card/CVC values and screenshots; remember sites only on
always-allow; drop --remote-allow-origins=*; gate private URLs and block metadata/Docker
ports, OrbStack 198.18/15 and IPv6 transition ranges.
- 帳號伺服器、同步與傳送 (relay/, remote.rs, mirror_ui.rs, share.rs, drops.rs): isolate
paired hands hosts from brain sync, tickets, pairing and backup overwrites; redact
routine trigger secrets and clear REDACTED when endpoints change; isolate channel and
team-member turns from owner memories, appctl and grants; scrub shared bot exports and
reset grants/routines on import; validate drop IDs and serialize chunk writes.
- 網路與協定穩定性 (httpd.rs, tunnel.rs, vnc.rs, Caddyfile*): fix chunked integer overflow
and CRLF header injection; enforce Origin checks, connection/job caps, 200 MB backup
reads, unique atomic temp files and ASCII hex guards; bound deflate unzip and VNC sniff
buffers; move VNC stdin/text off the tunnel loop.
- 介面、排程、語言與其他修正 (app.rs, i18n.rs, providers.rs, skills.rs, routines.rs,
setup.rs, store.rs, preview.rs, attach.rs, speech.rs, teams.rs, mcp.rs, voice.rs):
wire up the delete-routine confirmation dialog and mirror run-now; preserve unsaved
mirror edits across brief disconnects; give Chinese skills distinct folders and approval
gates; convert parsed tool JSON fields without corrupting code fences, URLs or paths;
fix Hourly DST offsets and time out unattended routine approvals; lock --install-skill,
cap docx/xlsx unzip sizes, isolate test env keys, and tighten local file permissions.
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-12 06:34:10 +00:00
|
|
|
|
// The audit timeline of this bot's work log (owner/admin; the phone's 稽核時間軸),
|
|
|
|
|
|
// read from the 30-day SQLite audit trail (since the JSONL log shrinks at turn end).
|
Audit timeline: what this turn did, on the phone (S5)
- oplog gets wall-clock times on tool records (serde-default: old logs read
fine), and OpLog::timeline turns the machine log into a story: per turn —
the prompt, model calls (retries counted into one line), every tool with
the arguments it ran with and its status (等核准/進行中/完成/被拒絕/失敗),
messages typed mid-turn, stop, outcome
- GET /api/bots/<id>/audit (owner/admin; members' allow-list untouched)
- 對話詳細資訊 gains a 稽核 tab: newest turn first, running tool shows
進行中…, an approval gate shows as 等核准 — the phone can answer the question
'what is my bot doing right now, exactly', step by step
- the log stays the machine format recovery reads; the timeline is derived
2026-11-09 09:58:56 +00:00
|
|
|
|
("GET", ["api", "bots", id, "audit"]) => {
|
安全、修正: harden sandboxes, approval gates, vault, relay roles, and fix protocol/UI bugs
- macOS 沙盒與工具 (tools.rs, policy.rs, docindex.rs): block AppleScript raw events and
concatenation outside the sandbox; stop exposing ~/.ssh or localhost sockets in Sealed
mode; deny writes to shell profiles, LaunchAgents and .git/hooks; expand secret-file
ignores and enforce symlink/policy checks across SSH, device and document search.
- 電腦操作與遮罩 (computer.rs, agent.rs, marks.rs, desktop.rs, cloudbox.rs, portal.rs):
forbid clicking or typing into AnyBot's own windows; extend the sensitive-action hard
gate to raw coordinates, Return/Delete submits and remote devices; stop batch steps if
the front app changes; black out secrets on zoom, show, >600-node trees, adjacent OTP
labels, box screenshots and control text lists; preserve non-text Wayland clipboards.
- 保險庫與瀏覽器 (vault.rs, vault_store.rs, browser.rs, botbrowser.rs, web.rs, box/browser):
verify tab host and HTTPS atomically at fill time; taint filled tabs against browser_eval
and PDF export while masking card/CVC values and screenshots; remember sites only on
always-allow; drop --remote-allow-origins=*; gate private URLs and block metadata/Docker
ports, OrbStack 198.18/15 and IPv6 transition ranges.
- 帳號伺服器、同步與傳送 (relay/, remote.rs, mirror_ui.rs, share.rs, drops.rs): isolate
paired hands hosts from brain sync, tickets, pairing and backup overwrites; redact
routine trigger secrets and clear REDACTED when endpoints change; isolate channel and
team-member turns from owner memories, appctl and grants; scrub shared bot exports and
reset grants/routines on import; validate drop IDs and serialize chunk writes.
- 網路與協定穩定性 (httpd.rs, tunnel.rs, vnc.rs, Caddyfile*): fix chunked integer overflow
and CRLF header injection; enforce Origin checks, connection/job caps, 200 MB backup
reads, unique atomic temp files and ASCII hex guards; bound deflate unzip and VNC sniff
buffers; move VNC stdin/text off the tunnel loop.
- 介面、排程、語言與其他修正 (app.rs, i18n.rs, providers.rs, skills.rs, routines.rs,
setup.rs, store.rs, preview.rs, attach.rs, speech.rs, teams.rs, mcp.rs, voice.rs):
wire up the delete-routine confirmation dialog and mirror run-now; preserve unsaved
mirror edits across brief disconnects; give Chinese skills distinct folders and approval
gates; convert parsed tool JSON fields without corrupting code fences, URLs or paths;
fix Hourly DST offsets and time out unattended routine approvals; lock --install-skill,
cap docx/xlsx unzip sizes, isolate test env keys, and tighten local file permissions.
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-12 06:34:10 +00:00
|
|
|
|
let bid = id.parse().unwrap_or(0);
|
|
|
|
|
|
let trail = crate::store::turns(bid);
|
|
|
|
|
|
if trail["turns"].as_array().is_some_and(|a| !a.is_empty()) {
|
|
|
|
|
|
Resp::json(&trail)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
let recs = crate::oplog::OpLog::for_bot(bid).read();
|
|
|
|
|
|
Resp::json(&crate::oplog::OpLog::timeline(&recs))
|
|
|
|
|
|
}
|
Audit timeline: what this turn did, on the phone (S5)
- oplog gets wall-clock times on tool records (serde-default: old logs read
fine), and OpLog::timeline turns the machine log into a story: per turn —
the prompt, model calls (retries counted into one line), every tool with
the arguments it ran with and its status (等核准/進行中/完成/被拒絕/失敗),
messages typed mid-turn, stop, outcome
- GET /api/bots/<id>/audit (owner/admin; members' allow-list untouched)
- 對話詳細資訊 gains a 稽核 tab: newest turn first, running tool shows
進行中…, an approval gate shows as 等核准 — the phone can answer the question
'what is my bot doing right now, exactly', step by step
- the log stays the machine format recovery reads; the timeline is derived
2026-11-09 09:58:56 +00:00
|
|
|
|
}
|
The phone page does what the desktop does, laid out like it
A new mobile/index.html in the desktop's (and Grok Bot's) shape: the sidebar
with its sections and folders, the chat with steps, thinking, reactions, quotes
and the approval card, 對話詳細資訊, Bot 設定, routines, pages, computers and
設定. Each action goes to the desktop's own code on the app's thread
(api/act/<what> -> App::phone_act): appctl, set_pinned, restart_bot,
toggle_reaction, box_task, channels_restart and the rest. No new rules.
Keys, channel tokens and the vault never reach the phone; a model key can only
be written. Admins keep what the phone always let them do; making, changing or
deleting bots, routines, memories, pages, folders and settings stays the
owner's. The state the phone polls now carries the sidebar's section order.
Checked by using it on a preview brain: routines, memories, templates, folders,
keys, signing another phone out, approvals and a chat with a fake model.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha2RVfSYmrhqNnqx9Z4
2026-11-06 19:05:12 +00:00
|
|
|
|
("GET", ["api", "settings"]) => phone_act("settings", json!({}), &role),
|
|
|
|
|
|
("GET", ["api", "box", "thumb"]) => box_thumb(),
|
2026-11-13 16:40:16 +00:00
|
|
|
|
// 看畫面 on 區網: a ticket for the screen's connection, so the login isn't in its address.
|
|
|
|
|
|
("POST", ["api", "vnc", "ticket"]) if !via_relay => {
|
|
|
|
|
|
let t = httpd::random_hex(24);
|
|
|
|
|
|
let mut all = lan_tickets().lock().unwrap();
|
|
|
|
|
|
all.retain(|_, (_, made)| made.elapsed() < Duration::from_secs(60));
|
|
|
|
|
|
if all.len() >= 64 {
|
|
|
|
|
|
return Resp::error(429, "要求太頻繁了,請稍後再試");
|
|
|
|
|
|
}
|
|
|
|
|
|
all.insert(t.clone(), (req.bearer(), Instant::now()));
|
|
|
|
|
|
Resp::json(&json!({"ticket": t}))
|
|
|
|
|
|
}
|
2026-11-13 15:36:34 +00:00
|
|
|
|
("POST", ["api", "act", action]) => {
|
|
|
|
|
|
let body = req.json();
|
|
|
|
|
|
// 區網 is plain http: whoever shares the Wi-Fi can read one request and use its
|
|
|
|
|
|
// login. So what would let a bot act without asking — 直接操作, an 「一律允許」
|
|
|
|
|
|
// rule, a new connector — can't be switched on over it; on the computer itself, or
|
|
|
|
|
|
// through the account (https), it can.
|
|
|
|
|
|
if !via_relay && loosens_guard(action, &body) {
|
|
|
|
|
|
return Resp::error(403, "這項設定會讓 Bot 不用問就動手,不能從區網連線(沒有加密)打開:請在電腦上的 AnyBot 改,或用帳號連線。");
|
|
|
|
|
|
}
|
|
|
|
|
|
phone_act(action, body, &role)
|
|
|
|
|
|
}
|
記憶: 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
|
|
|
|
// 記憶: the memory page and the composer's suggestions — the owner's (a screen of the
|
|
|
|
|
|
// owner's counts as the owner). Reads answer here at once; changes go through the app's
|
|
|
|
|
|
// thread, because a fact also lives in the bot's list.
|
|
|
|
|
|
("POST", ["api", "memory"] | ["api", "sync", "memory"]) => {
|
|
|
|
|
|
if role != "owner" && role != "mirror" {
|
|
|
|
|
|
return Resp::error(403, "記憶只有擁有者能看和改");
|
|
|
|
|
|
}
|
|
|
|
|
|
let b = req.json();
|
|
|
|
|
|
match crate::memory::api_read(&b) {
|
|
|
|
|
|
Some(v) => Resp::json(&v),
|
|
|
|
|
|
None => phone_act("memory", b, "owner"),
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
傳送: 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 02:04:13 +00:00
|
|
|
|
// 傳送: a file or words from this device to another of the account (drops.rs). The
|
|
|
|
|
|
// owner's phone, or one of the owner's computers showing this brain.
|
|
|
|
|
|
(m, ["api", "drop", what] | ["api", "sync", "drop", what]) => {
|
|
|
|
|
|
if role != "owner" && role != "mirror" {
|
|
|
|
|
|
return Resp::error(403, "只有擁有者能在裝置之間傳送");
|
|
|
|
|
|
}
|
|
|
|
|
|
let (from, from_id) = if role == "mirror" {
|
|
|
|
|
|
let id = req.header("x-anybot-from").to_string();
|
|
|
|
|
|
let name = peer_name(&id);
|
|
|
|
|
|
(if name.is_empty() { "另一台電腦".to_string() } else { name }, id)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
("手機".to_string(), crate::drops::PHONE.to_string())
|
|
|
|
|
|
};
|
|
|
|
|
|
if (m, *what) == ("GET", "file") {
|
|
|
|
|
|
let n = |k: &str| req.query.get(k).and_then(|v| v.parse::<u64>().ok()).unwrap_or(0);
|
|
|
|
|
|
return match crate::drops::office().read(req.query.get("id").map(String::as_str).unwrap_or(""), n("at"), n("len")) {
|
|
|
|
|
|
Ok(b) => Resp::bytes("application/octet-stream", b),
|
|
|
|
|
|
Err(e) => Resp::error(404, &e),
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
match crate::drops::api(what, m, &req.query, &req.body, &from, &from_id) {
|
|
|
|
|
|
Ok(v) => Resp::json(&v),
|
|
|
|
|
|
Err(e) => Resp::error(400, &e),
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
("POST", ["api", "bots", id, action]) => {
|
|
|
|
|
|
let bot: u64 = id.parse().unwrap_or(0);
|
|
|
|
|
|
let b = req.json();
|
|
|
|
|
|
let cmd = match *action {
|
|
|
|
|
|
"send" => {
|
|
|
|
|
|
let text = b["text"].as_str().unwrap_or("").trim().to_string();
|
|
|
|
|
|
let attachments: Vec<String> = b["attachments"].as_array().map(|a| a.iter().filter_map(|x| x.as_str().map(String::from)).collect()).unwrap_or_default();
|
|
|
|
|
|
if text.is_empty() && attachments.is_empty() {
|
|
|
|
|
|
return Resp::error(400, "訊息是空的");
|
|
|
|
|
|
}
|
安全、修正: harden sandboxes, approval gates, vault, relay roles, and fix protocol/UI bugs
- macOS 沙盒與工具 (tools.rs, policy.rs, docindex.rs): block AppleScript raw events and
concatenation outside the sandbox; stop exposing ~/.ssh or localhost sockets in Sealed
mode; deny writes to shell profiles, LaunchAgents and .git/hooks; expand secret-file
ignores and enforce symlink/policy checks across SSH, device and document search.
- 電腦操作與遮罩 (computer.rs, agent.rs, marks.rs, desktop.rs, cloudbox.rs, portal.rs):
forbid clicking or typing into AnyBot's own windows; extend the sensitive-action hard
gate to raw coordinates, Return/Delete submits and remote devices; stop batch steps if
the front app changes; black out secrets on zoom, show, >600-node trees, adjacent OTP
labels, box screenshots and control text lists; preserve non-text Wayland clipboards.
- 保險庫與瀏覽器 (vault.rs, vault_store.rs, browser.rs, botbrowser.rs, web.rs, box/browser):
verify tab host and HTTPS atomically at fill time; taint filled tabs against browser_eval
and PDF export while masking card/CVC values and screenshots; remember sites only on
always-allow; drop --remote-allow-origins=*; gate private URLs and block metadata/Docker
ports, OrbStack 198.18/15 and IPv6 transition ranges.
- 帳號伺服器、同步與傳送 (relay/, remote.rs, mirror_ui.rs, share.rs, drops.rs): isolate
paired hands hosts from brain sync, tickets, pairing and backup overwrites; redact
routine trigger secrets and clear REDACTED when endpoints change; isolate channel and
team-member turns from owner memories, appctl and grants; scrub shared bot exports and
reset grants/routines on import; validate drop IDs and serialize chunk writes.
- 網路與協定穩定性 (httpd.rs, tunnel.rs, vnc.rs, Caddyfile*): fix chunked integer overflow
and CRLF header injection; enforce Origin checks, connection/job caps, 200 MB backup
reads, unique atomic temp files and ASCII hex guards; bound deflate unzip and VNC sniff
buffers; move VNC stdin/text off the tunnel loop.
- 介面、排程、語言與其他修正 (app.rs, i18n.rs, providers.rs, skills.rs, routines.rs,
setup.rs, store.rs, preview.rs, attach.rs, speech.rs, teams.rs, mcp.rs, voice.rs):
wire up the delete-routine confirmation dialog and mirror run-now; preserve unsaved
mirror edits across brief disconnects; give Chinese skills distinct folders and approval
gates; convert parsed tool JSON fields without corrupting code fences, URLs or paths;
fix Hourly DST offsets and time out unattended routine approvals; lock --install-skill,
cap docx/xlsx unzip sizes, isolate test env keys, and tighten local file permissions.
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-12 06:34:10 +00:00
|
|
|
|
// 團隊: the bot knows who is talking when it isn't the owner (except `/goal`
|
|
|
|
|
|
// commands from an admin, which AnyBot handles before the bot).
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
let who = req.header("x-anybot-user");
|
安全、修正: harden sandboxes, approval gates, vault, relay roles, and fix protocol/UI bugs
- macOS 沙盒與工具 (tools.rs, policy.rs, docindex.rs): block AppleScript raw events and
concatenation outside the sandbox; stop exposing ~/.ssh or localhost sockets in Sealed
mode; deny writes to shell profiles, LaunchAgents and .git/hooks; expand secret-file
ignores and enforce symlink/policy checks across SSH, device and document search.
- 電腦操作與遮罩 (computer.rs, agent.rs, marks.rs, desktop.rs, cloudbox.rs, portal.rs):
forbid clicking or typing into AnyBot's own windows; extend the sensitive-action hard
gate to raw coordinates, Return/Delete submits and remote devices; stop batch steps if
the front app changes; black out secrets on zoom, show, >600-node trees, adjacent OTP
labels, box screenshots and control text lists; preserve non-text Wayland clipboards.
- 保險庫與瀏覽器 (vault.rs, vault_store.rs, browser.rs, botbrowser.rs, web.rs, box/browser):
verify tab host and HTTPS atomically at fill time; taint filled tabs against browser_eval
and PDF export while masking card/CVC values and screenshots; remember sites only on
always-allow; drop --remote-allow-origins=*; gate private URLs and block metadata/Docker
ports, OrbStack 198.18/15 and IPv6 transition ranges.
- 帳號伺服器、同步與傳送 (relay/, remote.rs, mirror_ui.rs, share.rs, drops.rs): isolate
paired hands hosts from brain sync, tickets, pairing and backup overwrites; redact
routine trigger secrets and clear REDACTED when endpoints change; isolate channel and
team-member turns from owner memories, appctl and grants; scrub shared bot exports and
reset grants/routines on import; validate drop IDs and serialize chunk writes.
- 網路與協定穩定性 (httpd.rs, tunnel.rs, vnc.rs, Caddyfile*): fix chunked integer overflow
and CRLF header injection; enforce Origin checks, connection/job caps, 200 MB backup
reads, unique atomic temp files and ASCII hex guards; bound deflate unzip and VNC sniff
buffers; move VNC stdin/text off the tunnel loop.
- 介面、排程、語言與其他修正 (app.rs, i18n.rs, providers.rs, skills.rs, routines.rs,
setup.rs, store.rs, preview.rs, attach.rs, speech.rs, teams.rs, mcp.rs, voice.rs):
wire up the delete-routine confirmation dialog and mirror run-now; preserve unsaved
mirror edits across brief disconnects; give Chinese skills distinct folders and approval
gates; convert parsed tool JSON fields without corrupting code fences, URLs or paths;
fix Hourly DST offsets and time out unattended routine approvals; lock --install-skill,
cap docx/xlsx unzip sizes, isolate test env keys, and tighten local file permissions.
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-12 06:34:10 +00:00
|
|
|
|
let is_admin_goal = role == "admin" && crate::goal::command(&text).is_some();
|
|
|
|
|
|
let text = if role != "owner" && !who.is_empty() && !is_admin_goal { format!("【{who}】{text}") } else { text };
|
|
|
|
|
|
let member = role == "member";
|
|
|
|
|
|
Cmd::Send { bot, text, attachments, from: String::new(), memories: if role == "owner" { picks_of(&b) } else { Some(vec![]) }, member }
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
"stop" => Cmd::Stop { bot },
|
問題卡、搜尋: the bot asks with a card; every chat is searched; a refusal holds for the turn
- 問題卡 (ask_person, src/ask.rs): up to 6 questions on a card above the input, one at a
time — a choice (one click moves on), several choices, or a field that arrives filled
for the person to correct; 「自己回答」 on every question, 上一題 and 略過. The turn waits;
a message typed instead leaves the card unanswered. Travels as an approval of kind
Question (questions as JSON) with a new answer Answered, so the window, a screen of
another brain and the phone draw the same card.
- 搜尋所有聊天 (src/find.rs): the sidebar's search also lists what the person and the bots
said in every chat, past conversations included, and attachment names; newest first,
40 at most. A click opens the bot (bringing a past conversation back first), scrolls to
the message and lights it for a moment.
- 拒絕後停下: a step the person refused is refused for them when it comes back unchanged
in the same turn — no second card, no second review — until they write again.
- The bot's instructions: stop after a refusal instead of trying another way; before
sending, posting, buying or deleting, check the person's own messages asked for exactly
that, and ask with the card when they didn't.
- 直接操作 no longer answers a hand-off (or a question) on the person's behalf.
- The repeated-step check leaves questions to the person alone.
- Screenshot views `ask` and `find`; FEATURES.md.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3QxSfoydRPM9mjj6d
2026-11-12 02:17:32 +00:00
|
|
|
|
"answer" => Cmd::Answer { bot, answer: b["answer"].as_str().unwrap_or("reject").to_string(), text: b["text"].as_str().unwrap_or("").to_string() },
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
"read" => Cmd::Read { bot },
|
|
|
|
|
|
"new" => Cmd::NewThread { bot },
|
Phone: a home with the computers, pages and routines; each bot's settings a tap away; long jobs fold up
The phone page was bare: one row per bot, a chat listing every step, a menu with four lines.
- Home: the main bot large at the top with its model and last words, the other bots with times,
then its computers (own box and the account's, online or not, 看畫面), the newest pages and the
routines with their next run.
- Chat: the bot's name opens its settings — model (chat models only), computer, past conversations
(restore), regenerate, new chat. A turn's steps fold into 「已完成 N 個步驟」 when done (the newest
three stay while it works); copy and regenerate under replies; four ready starts in a new chat;
a jump back to the newest message.
- Menu: 外觀 (follow the phone, light, dark).
- API: api/state carries pages and models; each bot its model, computers, routines, past
conversations; POST api/bots/{id}/set | regenerate | restore. The home's last line skips errors.
Checked on a local copy of the brain's data (cut off from the account and Docker) at iPhone size.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha2RVfSYmrhqNnqx9Z4
2026-11-06 12:28:08 +00:00
|
|
|
|
"regenerate" => Cmd::Regenerate { bot },
|
2026-11-13 13:34:03 +00:00
|
|
|
|
"restore_answer" => Cmd::RestoreAnswer { bot },
|
Phone: a home with the computers, pages and routines; each bot's settings a tap away; long jobs fold up
The phone page was bare: one row per bot, a chat listing every step, a menu with four lines.
- Home: the main bot large at the top with its model and last words, the other bots with times,
then its computers (own box and the account's, online or not, 看畫面), the newest pages and the
routines with their next run.
- Chat: the bot's name opens its settings — model (chat models only), computer, past conversations
(restore), regenerate, new chat. A turn's steps fold into 「已完成 N 個步驟」 when done (the newest
three stay while it works); copy and regenerate under replies; four ready starts in a new chat;
a jump back to the newest message.
- Menu: 外觀 (follow the phone, light, dark).
- API: api/state carries pages and models; each bot its model, computers, routines, past
conversations; POST api/bots/{id}/set | regenerate | restore. The home's last line skips errors.
Checked on a local copy of the brain's data (cut off from the account and Docker) at iPhone size.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha2RVfSYmrhqNnqx9Z4
2026-11-06 12:28:08 +00:00
|
|
|
|
"restore" => Cmd::RestoreThread { bot, index: b["index"].as_u64().unwrap_or(0) as usize },
|
|
|
|
|
|
"set" => Cmd::SetBot {
|
|
|
|
|
|
bot,
|
|
|
|
|
|
provider: b["provider"].as_str().unwrap_or("").to_string(),
|
|
|
|
|
|
model: b["model"].as_str().unwrap_or("").trim().to_string(),
|
|
|
|
|
|
computer: b["computer"].as_str().unwrap_or("").trim().to_string(),
|
|
|
|
|
|
},
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
"upload" => return upload(bot, &req),
|
|
|
|
|
|
_ => return Resp::error(404, "沒有這個動作"),
|
|
|
|
|
|
};
|
|
|
|
|
|
hub().push(cmd);
|
|
|
|
|
|
Resp::json(&json!({"ok": true}))
|
|
|
|
|
|
}
|
Voice: its own 設定 › 語音, run by the brain for every screen and the phone
Voice was three implementations that broke on their own: speech to text
borrowed the OpenAI key (so with only Grok set up the mic recorded,
then failed), OpenAI's models it hard-coded stop on 2027-02-26, read
aloud was macOS `say` or espeak-ng (silently nothing on Windows, where
espeak isn't installed), and the phone used the browser's own
recognition. Now:
- 設定 › 語音 has 聽 and 說, each a service: off, OpenAI-compatible
(OpenAI, Groq, a Whisper server of your own: the address decides),
xAI or ElevenLabs. An empty key borrows 設定 › 模型's for the same
service. Each side says 可以用 or what it lacks; 聽 has 試試看
(record a sentence, show what was heard), 說 has 試聽 and the voice
list. speech.rs does the calls; xAI's both ways were checked for real
(Mandarin read, then heard back, in Traditional characters).
- The brain does it all: the phone POSTs its recording (MediaRecorder)
to /api/voice/transcribe, screens to /api/sync/voice/transcribe;
answers come back as MP3 from …/voice/speech and are played on the
device (rodio; an <audio> on the phone, 「唸出來」 in a message's
menu). Keys stay on the brain (the voice keys are redacted for
screens like the others).
- No service, no voice anywhere: the mic, 語音聊天, 會議錄音 and 朗讀
only appear once 聽 (and 說) can be called; the phone's state says
which. Without voice the send arrow just rests where 語音聊天 was.
- 會議錄音 is uploaded to the brain, which turns it into text in the
background and hands it to the bot itself: a meeting is longer than
the 35 s the account lets a request wait, and a brain on a server has
no window (the jobs are polled in background()).
- Recognisers answer Mandarin in Simplified: in a Traditional Chinese
window or phone the text becomes Traditional with Taiwan wording.
- Older saves: whoever had an OpenAI key keeps voice input (聽 =
OpenAI); everyone else starts with it off. Bots' macOS voice names
are cleared. 對話詳細資訊's 加入會議 started plain voice input; it
starts a meeting now.
2026-11-10 14:58:18 +00:00
|
|
|
|
// 語音: the phone's and the screens' recordings become text here, and answers sound.
|
連接器: a 公用市集 of remote servers from the official MCP Registry, on the computer and the phone
- 連接器市集 gets a search box over registry.modelcontextprotocol.io (public, with an API):
servers reached by address only (a package would have to run on the brain, which may have no
Node or uv); old SSE ones are marked as not yet supported, taken-down ones left out. A name
that only says "mcp" (com.notion/mcp) reads as whose it is (notion).
- 加入 on the computer fills 新增連接器 and scrolls to it: a free name, the address, and the
header with the registry's placeholder ("Authorization: Bearer {smithery_api_key}"), shown
unmasked with what to put there (the key's description, an address variable's choices). 新增
stays off while a 「{…}」 is left.
- The phone: 設定 › 整合 › 從公用市集加入. The brain searches (the phone's page may only talk to
its own server; GET /api/mcp/registry, owner only, on the HTTP thread); a pick asks for the key
or the address part and the brain adds it (the 「mcp」 action's new `add`).
- A server that answers 401 (or a 403 asking for a login) with no key given now says it signs
people in with OAuth, which AnyBot can't do yet; with a key, that the key is wrong or old.
- mcpservers.org and the like are pages for people behind a browser check, with no list a program
may read, so the market uses the registry.
- Checked live: 「notion」 finds 6; AWS Knowledge (no key) connects with 5 tools; Notion's own
server (OAuth) gives the OAuth sentence. `cargo test -- --ignored registry_search_live`.
- Screenshot mode: ANYBOT_SHOT_MCP=<search> shows the 公用市集 after that search.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 09:12:12 +00:00
|
|
|
|
// 公用市集 for the phone: the official MCP Registry, searched here (the phone's page may
|
|
|
|
|
|
// only talk to its own server). Answered on this thread, not the app's.
|
|
|
|
|
|
("GET", ["api", "mcp", "registry"]) => {
|
|
|
|
|
|
if role != "owner" {
|
|
|
|
|
|
return Resp::error(403, "連接器只有擁有者能加");
|
|
|
|
|
|
}
|
|
|
|
|
|
match crate::mcp::registry_search(req.query.get("q").map(String::as_str).unwrap_or("")) {
|
|
|
|
|
|
Ok(list) => Resp::json(&json!({"ok": true, "servers": list})),
|
|
|
|
|
|
Err(e) => Resp::error(502, &e),
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
Voice: its own 設定 › 語音, run by the brain for every screen and the phone
Voice was three implementations that broke on their own: speech to text
borrowed the OpenAI key (so with only Grok set up the mic recorded,
then failed), OpenAI's models it hard-coded stop on 2027-02-26, read
aloud was macOS `say` or espeak-ng (silently nothing on Windows, where
espeak isn't installed), and the phone used the browser's own
recognition. Now:
- 設定 › 語音 has 聽 and 說, each a service: off, OpenAI-compatible
(OpenAI, Groq, a Whisper server of your own: the address decides),
xAI or ElevenLabs. An empty key borrows 設定 › 模型's for the same
service. Each side says 可以用 or what it lacks; 聽 has 試試看
(record a sentence, show what was heard), 說 has 試聽 and the voice
list. speech.rs does the calls; xAI's both ways were checked for real
(Mandarin read, then heard back, in Traditional characters).
- The brain does it all: the phone POSTs its recording (MediaRecorder)
to /api/voice/transcribe, screens to /api/sync/voice/transcribe;
answers come back as MP3 from …/voice/speech and are played on the
device (rodio; an <audio> on the phone, 「唸出來」 in a message's
menu). Keys stay on the brain (the voice keys are redacted for
screens like the others).
- No service, no voice anywhere: the mic, 語音聊天, 會議錄音 and 朗讀
only appear once 聽 (and 說) can be called; the phone's state says
which. Without voice the send arrow just rests where 語音聊天 was.
- 會議錄音 is uploaded to the brain, which turns it into text in the
background and hands it to the bot itself: a meeting is longer than
the 35 s the account lets a request wait, and a brain on a server has
no window (the jobs are polled in background()).
- Recognisers answer Mandarin in Simplified: in a Traditional Chinese
window or phone the text becomes Traditional with Taiwan wording.
- Older saves: whoever had an OpenAI key keeps voice input (聽 =
OpenAI); everyone else starts with it off. Bots' macOS voice names
are cleared. 對話詳細資訊's 加入會議 started plain voice input; it
starts a meeting now.
2026-11-10 14:58:18 +00:00
|
|
|
|
("POST", ["api", "voice", "transcribe"] | ["api", "sync", "voice", "transcribe"]) => voice_transcribe(&req),
|
|
|
|
|
|
("POST", ["api", "voice", "speech"] | ["api", "sync", "voice", "speech"]) => voice_speech(&req),
|
|
|
|
|
|
("POST", ["api", "sync", "voice", "voices"]) => match hub().voice().speak.map(|e| crate::speech::voices(&e)) {
|
|
|
|
|
|
Some(Ok(v)) => Resp::json(&json!({"voices": v})),
|
|
|
|
|
|
Some(Err(err)) => Resp::error(502, &err),
|
|
|
|
|
|
None => Resp::error(409, crate::speech::NOT_SET),
|
|
|
|
|
|
},
|
People watch and help on the bots' computer through VNC (noVNC), carried by the account server
The core: the bot works the computer; a person watches it like a colleague, and takes over
when it needs them. VNC is made for that (only what changed, every mouse move and key, touch on
phones), so the pictures sent one by one go, and with them their own input path.
- vnc.rs: a VNC proxy to the box's x11vnc through one docker exec (a Python bridge that ends
with either side). It signs in to the box with the box's own password (its VNC_PASSWORD) and
offers the viewer no password, so the password never leaves the brain. The person's clicks
and keys make the bot's steps wait until 8 s after they stop; text typed in the viewer's box
(any language) is pasted in the box.
- Account server: /screen (the viewer page) and /novnc.js (noVNC 1.6.0, MPL-2.0, bundled);
/relay/vnc/<host> takes the browser's WebSocket (account session, or a 10-minute ticket the
app asks for with POST /relay/screen-ticket; owners and admins) and carries it over that
AnyBot's lasting connection (vopen / vdata / vtext / vclose). Both ends of that connection
wait 2 ms instead of 40 ms to read while things move: a request and its answer took up to
160 ms more than needed.
- Phone page: 看 Bot 的電腦 and 接管 open the viewer page (also on the local network: /api/vnc on
the AnyBot's own phone server). This Mac's own screen moved to the ⋯ menu.
- Mac app: 看畫面 opens the viewer in the browser (a screen of a brain: the brain's computer by
ticket; else this computer's box, noVNC straight from it). The in-app picture viewer, the
live JPEG stream, the person's click/move/scroll/key endpoints and the input shell are gone.
- Opening a Mac app uses LaunchServices (`open -a`): agent-desktop's launch waited on the window
through accessibility and failed without 輔助使用 now and then.
Measured on this Mac (made-up account, local relay + headless brain + the real box): viewer
signed in in 0.4–0.7 s, a request and its answer through relay + brain + box 25–58 ms median;
headless Chrome shows the desktop live in /screen. remote_e2e 28/28 ×2, 149 unit tests, relay 11.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-05 15:05:44 +00:00
|
|
|
|
("GET", ["api", "screen", which]) => screen(which, &s),
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
("POST", ["api", "screen", which]) => screen_input(which, &req.json(), &s),
|
2026-11-04 12:38:45 +00:00
|
|
|
|
("POST", ["api", "device", "run"]) => device_run(&req.json(), &s, via_relay, req.header("x-anybot-from")),
|
2026-11-04 09:46:43 +00:00
|
|
|
|
("GET", ["api", "sync"]) => {
|
|
|
|
|
|
let since: u64 = req.query.get("since").and_then(|v| v.parse().ok()).unwrap_or(0);
|
|
|
|
|
|
let client = req.query.get("client").cloned().unwrap_or_default();
|
|
|
|
|
|
if since > 0 {
|
|
|
|
|
|
let _ = hub().wait_newer(since, LONG_POLL_SECS);
|
|
|
|
|
|
}
|
|
|
|
|
|
match hub().ask_sync(SyncKind::Pull { client, since }) {
|
|
|
|
|
|
Ok(v) => Resp::json(&v),
|
|
|
|
|
|
Err(e) => Resp::error(503, &e),
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
("POST", ["api", "sync", "edit"]) => match hub().ask_sync(SyncKind::Edit(req.json())) {
|
|
|
|
|
|
Ok(v) if v["error"].is_string() => Resp::error(400, v["error"].as_str().unwrap_or("")),
|
|
|
|
|
|
Ok(v) => Resp::json(&v),
|
|
|
|
|
|
Err(e) => Resp::error(503, &e),
|
|
|
|
|
|
},
|
|
|
|
|
|
("POST", ["api", "sync", "upload", id]) => upload(id.parse().unwrap_or(0), &req),
|
People watch and help on the bots' computer through VNC (noVNC), carried by the account server
The core: the bot works the computer; a person watches it like a colleague, and takes over
when it needs them. VNC is made for that (only what changed, every mouse move and key, touch on
phones), so the pictures sent one by one go, and with them their own input path.
- vnc.rs: a VNC proxy to the box's x11vnc through one docker exec (a Python bridge that ends
with either side). It signs in to the box with the box's own password (its VNC_PASSWORD) and
offers the viewer no password, so the password never leaves the brain. The person's clicks
and keys make the bot's steps wait until 8 s after they stop; text typed in the viewer's box
(any language) is pasted in the box.
- Account server: /screen (the viewer page) and /novnc.js (noVNC 1.6.0, MPL-2.0, bundled);
/relay/vnc/<host> takes the browser's WebSocket (account session, or a 10-minute ticket the
app asks for with POST /relay/screen-ticket; owners and admins) and carries it over that
AnyBot's lasting connection (vopen / vdata / vtext / vclose). Both ends of that connection
wait 2 ms instead of 40 ms to read while things move: a request and its answer took up to
160 ms more than needed.
- Phone page: 看 Bot 的電腦 and 接管 open the viewer page (also on the local network: /api/vnc on
the AnyBot's own phone server). This Mac's own screen moved to the ⋯ menu.
- Mac app: 看畫面 opens the viewer in the browser (a screen of a brain: the brain's computer by
ticket; else this computer's box, noVNC straight from it). The in-app picture viewer, the
live JPEG stream, the person's click/move/scroll/key endpoints and the input shell are gone.
- Opening a Mac app uses LaunchServices (`open -a`): agent-desktop's launch waited on the window
through accessibility and failed without 輔助使用 now and then.
Measured on this Mac (made-up account, local relay + headless brain + the real box): viewer
signed in in 0.4–0.7 s, a request and its answer through relay + brain + box 25–58 ms median;
headless Chrome shows the desktop live in /screen. remote_e2e 28/28 ×2, 149 unit tests, relay 11.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-05 15:05:44 +00:00
|
|
|
|
// A screen of this brain shows the bots' own computer, which lives here: a small picture
|
|
|
|
|
|
// (people watch it live through VNC, see vnc.rs).
|
|
|
|
|
|
("GET", ["api", "sync", "screen"]) => match crate::cloudbox::thumbnail(320) {
|
|
|
|
|
|
Some(img) => match crate::computer::encode_jpeg(&image::DynamicImage::ImageRgba8(img).to_rgb8()) {
|
|
|
|
|
|
Some(j) => Resp::bytes("image/jpeg", j),
|
|
|
|
|
|
None => Resp::error(500, "畫面編碼失敗"),
|
|
|
|
|
|
},
|
|
|
|
|
|
None => Resp::error(404, "還沒有畫面"),
|
|
|
|
|
|
},
|
|
|
|
|
|
// 接管 / 我完成了 from a screen: the bot's steps wait (or not) for the person.
|
2026-11-05 08:47:28 +00:00
|
|
|
|
("POST", ["api", "sync", "screen"]) => {
|
|
|
|
|
|
let v = req.json();
|
|
|
|
|
|
match v["kind"].as_str().unwrap_or("") {
|
|
|
|
|
|
"hold" => {
|
|
|
|
|
|
crate::cloudbox::HELD_BY_PERSON.store(v["on"].as_bool().unwrap_or(false), Ordering::SeqCst);
|
|
|
|
|
|
Resp::json(&json!({"ok": true}))
|
|
|
|
|
|
}
|
People watch and help on the bots' computer through VNC (noVNC), carried by the account server
The core: the bot works the computer; a person watches it like a colleague, and takes over
when it needs them. VNC is made for that (only what changed, every mouse move and key, touch on
phones), so the pictures sent one by one go, and with them their own input path.
- vnc.rs: a VNC proxy to the box's x11vnc through one docker exec (a Python bridge that ends
with either side). It signs in to the box with the box's own password (its VNC_PASSWORD) and
offers the viewer no password, so the password never leaves the brain. The person's clicks
and keys make the bot's steps wait until 8 s after they stop; text typed in the viewer's box
(any language) is pasted in the box.
- Account server: /screen (the viewer page) and /novnc.js (noVNC 1.6.0, MPL-2.0, bundled);
/relay/vnc/<host> takes the browser's WebSocket (account session, or a 10-minute ticket the
app asks for with POST /relay/screen-ticket; owners and admins) and carries it over that
AnyBot's lasting connection (vopen / vdata / vtext / vclose). Both ends of that connection
wait 2 ms instead of 40 ms to read while things move: a request and its answer took up to
160 ms more than needed.
- Phone page: 看 Bot 的電腦 and 接管 open the viewer page (also on the local network: /api/vnc on
the AnyBot's own phone server). This Mac's own screen moved to the ⋯ menu.
- Mac app: 看畫面 opens the viewer in the browser (a screen of a brain: the brain's computer by
ticket; else this computer's box, noVNC straight from it). The in-app picture viewer, the
live JPEG stream, the person's click/move/scroll/key endpoints and the input shell are gone.
- Opening a Mac app uses LaunchServices (`open -a`): agent-desktop's launch waited on the window
through accessibility and failed without 輔助使用 now and then.
Measured on this Mac (made-up account, local relay + headless brain + the real box): viewer
signed in in 0.4–0.7 s, a request and its answer through relay + brain + box 25–58 ms median;
headless Chrome shows the desktop live in /screen. remote_e2e 28/28 ×2, 149 unit tests, relay 11.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-05 15:05:44 +00:00
|
|
|
|
"wake" => match crate::cloudbox::ensure_running() {
|
|
|
|
|
|
Ok(()) => Resp::json(&json!({"ok": true})),
|
|
|
|
|
|
Err(e) => Resp::error(500, &e),
|
|
|
|
|
|
},
|
|
|
|
|
|
_ => Resp::error(400, "不認得的操作"),
|
2026-11-05 08:47:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-11-04 11:30:32 +00:00
|
|
|
|
("POST", ["api", "sync", "models"]) => match hub().ask_sync_for(SyncKind::Models(req.json()["provider"].as_str().unwrap_or("").to_string()), 45) {
|
|
|
|
|
|
Ok(v) => Resp::json(&v),
|
|
|
|
|
|
Err(e) => Resp::error(503, &e),
|
|
|
|
|
|
},
|
|
|
|
|
|
// A file shown in a chat (only what AnyBot keeps as attachments).
|
Real-use fixes: the person sees the screens the bot shows, files reach the phone, no blank-tab loops
From real runs on the cloud brain with the person's Mac (Threads patrol, a post draft, "show me my
screen"):
- computer_use_show: a plain picture of any computer's screen goes into the chat (the bot sees it
too). The bot used to describe a screenshot in words and fail to send it.
- The phone shows the bot's attachments: pictures in place, other files download on a tap (api/file,
only from the chats' file folder). It showed nothing for the bot and names only for the person.
- send_file works from the person's other computers (fetch_file over the relay, 20 MB, secrets stay).
- The same call with the same answer again and again is warned the 3rd time and stopped from the
4th (a blank tab was read 11 times, then the bot said Threads was logged out without opening it);
a blank tab says so; checking a login means opening the site.
- Screenshot lists: a nameless row around a named button isn't numbered, a nameless row takes the
words inside it, empty spacer rows aren't numbered (System Settings: 63 numbers -> 33, all named).
- Writing "in my voice" reads the person's own recent posts first.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha2RVfSYmrhqNnqx9Z4
2026-11-06 11:37:45 +00:00
|
|
|
|
// A file in a chat (a picture the bot showed, a file it sent, one the person attached),
|
|
|
|
|
|
// for the phone to show or download. Only from the chats' own file folder.
|
|
|
|
|
|
("GET", ["api", "file"]) => match chat_file(&req.query.get("path").cloned().unwrap_or_default()) {
|
2026-11-13 06:19:59 +00:00
|
|
|
|
Some((f, b)) => Resp::bytes(content_type(&f), b).with_header("Content-Security-Policy", "default-src 'none'; style-src 'unsafe-inline'; sandbox"),
|
Real-use fixes: the person sees the screens the bot shows, files reach the phone, no blank-tab loops
From real runs on the cloud brain with the person's Mac (Threads patrol, a post draft, "show me my
screen"):
- computer_use_show: a plain picture of any computer's screen goes into the chat (the bot sees it
too). The bot used to describe a screenshot in words and fail to send it.
- The phone shows the bot's attachments: pictures in place, other files download on a tap (api/file,
only from the chats' file folder). It showed nothing for the bot and names only for the person.
- send_file works from the person's other computers (fetch_file over the relay, 20 MB, secrets stay).
- The same call with the same answer again and again is warned the 3rd time and stopped from the
4th (a blank tab was read 11 times, then the bot said Threads was logged out without opening it);
a blank tab says so; checking a login means opening the site.
- Screenshot lists: a nameless row around a named button isn't numbered, a nameless row takes the
words inside it, empty spacer rows aren't numbered (System Settings: 63 numbers -> 33, all named).
- Writing "in my voice" reads the person's own recent posts first.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha2RVfSYmrhqNnqx9Z4
2026-11-06 11:37:45 +00:00
|
|
|
|
None => Resp::error(404, "找不到這個檔案"),
|
|
|
|
|
|
},
|
2026-11-13 06:19:59 +00:00
|
|
|
|
("GET", ["api", "preview"]) => file_preview(&req.query.get("path").cloned().unwrap_or_default()),
|
|
|
|
|
|
("GET", ["api", "preview", "pdf"]) => {
|
|
|
|
|
|
let page = req.query.get("page").and_then(|p| p.parse::<usize>().ok()).unwrap_or(0);
|
|
|
|
|
|
file_preview_pdf(&req.query.get("path").cloned().unwrap_or_default(), page)
|
|
|
|
|
|
}
|
|
|
|
|
|
("GET", ["api", "preview", "image"]) => file_preview_image(&req.query.get("path").cloned().unwrap_or_default()),
|
2026-11-04 11:30:32 +00:00
|
|
|
|
("GET", ["api", "sync", "file"]) => {
|
|
|
|
|
|
let want = std::path::PathBuf::from(req.query.get("path").cloned().unwrap_or_default());
|
|
|
|
|
|
let root = crate::model::State::path().parent().map(|p| p.join("attachments")).and_then(|p| p.canonicalize().ok());
|
|
|
|
|
|
match (want.canonicalize().ok(), root) {
|
|
|
|
|
|
(Some(f), Some(root)) if f.starts_with(&root) && f.is_file() => match std::fs::read(&f) {
|
|
|
|
|
|
Ok(b) => Resp::bytes("application/octet-stream", b),
|
|
|
|
|
|
Err(_) => Resp::error(404, "大腦上找不到這個檔案"),
|
|
|
|
|
|
},
|
|
|
|
|
|
_ => Resp::error(404, "大腦上找不到這個檔案"),
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
技能: / in the input picks one; on a brain's screen the brain adds, installs and deletes them; 設定 › 整合's lists keep their buttons clear
- Typing / at the start of the input (computer and phone) lists the skills that are on: names that
start with what is typed first, then names containing it, then descriptions (「/簡報」 finds
pptx). A click, or ↑↓ and Enter/Tab, puts 「/name 」 in the input; Esc closes the list. Sent, the
brain recognises 「/name」 and adds a line after the message telling the model to read that skill
with use_skill first, so a phone or a message channel gets it too; a / that names no skill (a
path) gets nothing. The phone asks the brain for the list again at each new /, so a skill added
since is there.
- On a screen, 加入 / 安裝 / 刪除 ran on the screen's own disk and only the list entry reached the
brain: a GitHub skill's scripts stayed on the screen's computer, an install also pushed every
skill in that computer's folder into the brain's list, and a deleted skill's folder stayed on the
brain and came back at its next start. These now go to the brain (/api/sync/skill, the phone's
own 「skill」 action): it fetches an address itself, a folder or .md file on the screen's
computer goes up whole with its files, and a delete takes the folder too. 「把這台的 Bot 搬到大腦」
hands over skills the same way. A refused package leaves no folder behind.
- 技能, 技能市集 and 連接器市集 rows: a long description took the whole row and 開啟 / 檢視 / 刪除
/ 已加入 / 安裝 were drawn over it. The buttons are laid out first and the description ends in …
before them (the whole of it on hover).
- Screenshot mode: ANYBOT_SHOT_KEYS="ArrowDown@60;Enter@64" presses keys at given frames.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 08:54:58 +00:00
|
|
|
|
// 技能 from a screen: add, install, hand over a folder, delete — done here, where the
|
|
|
|
|
|
// bots read them (the files land on this disk, and a deleted one's folder goes too).
|
|
|
|
|
|
("POST", ["api", "sync", "skill"]) => phone_act_for("skill", req.json(), "owner", 55),
|
連接器: the brain's connectors work — a screen shows the brain's state, 重新連線, many tools are found instead of sent
- 設定 › 連接器 on a screen showed the screen's own (empty) MCP state: every brain connector read
「未連線」 and its error never reached the person. The brain now sends its connectors' state with
each sync; errors from the brain say 「在大腦上:」.
- 重新連線 on each connector (computer, screen → brain, phone); one that is on but not connected is
tried again each minute; a link that died (process ended, HTTP session expired) is dropped and
connected again instead of failing every call.
- More than 20 connector tools: none ride along. The model gets find_connector_tool (the list of
connectors, search by words) and use_connector_tool (runs the found tool, asked like the tool
itself). A brain with scc (82) + the market's sent ~170 tools / ~120 KB a turn, over the
128-tool limit of many services.
- A server that doesn't start says why: no Node.js / uv, a folder not on this computer, and the
last lines it wrote to stderr; it is ended instead of left running.
- The brain image has nodejs/npm, python3 and uv (uvx), caches on /data.
- Moving to a brain leaves connectors that name this computer's folders here.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha5Mk1tvt3gyzfzhDgb
2026-11-12 07:53:09 +00:00
|
|
|
|
// 連接器 › 重新連線 from a screen (the list itself changes through edits).
|
|
|
|
|
|
("POST", ["api", "sync", "mcp"]) => phone_act_for("mcp", json!({"name": req.json()["name"], "reconnect": true}), "owner", 10),
|
2026-11-04 09:46:43 +00:00
|
|
|
|
("POST", ["api", "sync", "act"]) => {
|
|
|
|
|
|
let b = req.json();
|
|
|
|
|
|
let bot = b["bot"].as_u64().unwrap_or(0);
|
|
|
|
|
|
let cmd = match b["action"].as_str().unwrap_or("") {
|
|
|
|
|
|
"send" => Cmd::Send {
|
|
|
|
|
|
bot,
|
|
|
|
|
|
text: b["text"].as_str().unwrap_or("").trim().to_string(),
|
|
|
|
|
|
attachments: b["attachments"].as_array().map(|a| a.iter().filter_map(|x| x.as_str().map(String::from)).collect()).unwrap_or_default(),
|
2026-11-05 08:47:28 +00:00
|
|
|
|
// The relay names the computer that asked: the one the person is using.
|
|
|
|
|
|
from: req.header("x-anybot-from").to_string(),
|
記憶: 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
|
|
|
|
memories: picks_of(&b),
|
安全、修正: harden sandboxes, approval gates, vault, relay roles, and fix protocol/UI bugs
- macOS 沙盒與工具 (tools.rs, policy.rs, docindex.rs): block AppleScript raw events and
concatenation outside the sandbox; stop exposing ~/.ssh or localhost sockets in Sealed
mode; deny writes to shell profiles, LaunchAgents and .git/hooks; expand secret-file
ignores and enforce symlink/policy checks across SSH, device and document search.
- 電腦操作與遮罩 (computer.rs, agent.rs, marks.rs, desktop.rs, cloudbox.rs, portal.rs):
forbid clicking or typing into AnyBot's own windows; extend the sensitive-action hard
gate to raw coordinates, Return/Delete submits and remote devices; stop batch steps if
the front app changes; black out secrets on zoom, show, >600-node trees, adjacent OTP
labels, box screenshots and control text lists; preserve non-text Wayland clipboards.
- 保險庫與瀏覽器 (vault.rs, vault_store.rs, browser.rs, botbrowser.rs, web.rs, box/browser):
verify tab host and HTTPS atomically at fill time; taint filled tabs against browser_eval
and PDF export while masking card/CVC values and screenshots; remember sites only on
always-allow; drop --remote-allow-origins=*; gate private URLs and block metadata/Docker
ports, OrbStack 198.18/15 and IPv6 transition ranges.
- 帳號伺服器、同步與傳送 (relay/, remote.rs, mirror_ui.rs, share.rs, drops.rs): isolate
paired hands hosts from brain sync, tickets, pairing and backup overwrites; redact
routine trigger secrets and clear REDACTED when endpoints change; isolate channel and
team-member turns from owner memories, appctl and grants; scrub shared bot exports and
reset grants/routines on import; validate drop IDs and serialize chunk writes.
- 網路與協定穩定性 (httpd.rs, tunnel.rs, vnc.rs, Caddyfile*): fix chunked integer overflow
and CRLF header injection; enforce Origin checks, connection/job caps, 200 MB backup
reads, unique atomic temp files and ASCII hex guards; bound deflate unzip and VNC sniff
buffers; move VNC stdin/text off the tunnel loop.
- 介面、排程、語言與其他修正 (app.rs, i18n.rs, providers.rs, skills.rs, routines.rs,
setup.rs, store.rs, preview.rs, attach.rs, speech.rs, teams.rs, mcp.rs, voice.rs):
wire up the delete-routine confirmation dialog and mirror run-now; preserve unsaved
mirror edits across brief disconnects; give Chinese skills distinct folders and approval
gates; convert parsed tool JSON fields without corrupting code fences, URLs or paths;
fix Hourly DST offsets and time out unattended routine approvals; lock --install-skill,
cap docx/xlsx unzip sizes, isolate test env keys, and tighten local file permissions.
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-12 06:34:10 +00:00
|
|
|
|
member: false,
|
2026-11-04 09:46:43 +00:00
|
|
|
|
},
|
|
|
|
|
|
"stop" => Cmd::Stop { bot },
|
問題卡、搜尋: the bot asks with a card; every chat is searched; a refusal holds for the turn
- 問題卡 (ask_person, src/ask.rs): up to 6 questions on a card above the input, one at a
time — a choice (one click moves on), several choices, or a field that arrives filled
for the person to correct; 「自己回答」 on every question, 上一題 and 略過. The turn waits;
a message typed instead leaves the card unanswered. Travels as an approval of kind
Question (questions as JSON) with a new answer Answered, so the window, a screen of
another brain and the phone draw the same card.
- 搜尋所有聊天 (src/find.rs): the sidebar's search also lists what the person and the bots
said in every chat, past conversations included, and attachment names; newest first,
40 at most. A click opens the bot (bringing a past conversation back first), scrolls to
the message and lights it for a moment.
- 拒絕後停下: a step the person refused is refused for them when it comes back unchanged
in the same turn — no second card, no second review — until they write again.
- The bot's instructions: stop after a refusal instead of trying another way; before
sending, posting, buying or deleting, check the person's own messages asked for exactly
that, and ask with the card when they didn't.
- 直接操作 no longer answers a hand-off (or a question) on the person's behalf.
- The repeated-step check leaves questions to the person alone.
- Screenshot views `ask` and `find`; FEATURES.md.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3QxSfoydRPM9mjj6d
2026-11-12 02:17:32 +00:00
|
|
|
|
"answer" => Cmd::Answer { bot, answer: b["answer"].as_str().unwrap_or("reject").to_string(), text: b["text"].as_str().unwrap_or("").to_string() },
|
2026-11-04 09:46:43 +00:00
|
|
|
|
"read" => Cmd::Read { bot },
|
|
|
|
|
|
"new" => Cmd::NewThread { bot },
|
|
|
|
|
|
"regenerate" => Cmd::Regenerate { bot },
|
2026-11-13 13:34:03 +00:00
|
|
|
|
"restore_answer" => Cmd::RestoreAnswer { bot },
|
2026-11-04 09:46:43 +00:00
|
|
|
|
"reply" => Cmd::Reply { bot },
|
A turn cut off by a crash leaves a 「繼續」 card, and nothing it may have done runs twice
Each bot keeps a work log (oplog/bot-<id>.jsonl, after pi's durable-harness design, cut down):
before something happens a line says it is about to — the turn, each model call, each step once
its checks passed (with the arguments it runs with and whether it may run again), each message
typed mid-turn — synced to disk first. When the turn ends the file shrinks to the messages still
waiting, usually nothing.
On the next start after AnyBot was killed mid-turn, the log puts the chat right before anything
runs: the message the turn answered comes back if the chat lost it; a step that was running and
reaches outside (a text, a click, a file, a published site) shows as 「可能已經執行了」, both to the
person and in the result the bot reads — no longer as "not allowed"; a step that only looked shows
as cut off; messages typed mid-turn that never reached the bot go back into the chat. The chat is
saved, then the log closes the turn. A turn the person didn't stop ends with a 「繼續」 card (what
it was doing, what may have run, the messages put back); it goes on only when they press it — in
the window, on a screen of the brain, or on the phone — from where its steps stand, never running
a step that may have run again. Pressing stop is on disk at once, and a stopped turn stays
stopped.
Also in the turn loop:
- 自動審核 that doesn't answer (or answers something that isn't a verdict) asks the person; in
直接操作 mode it used to let the step through unchecked.
- "Too long for this model" folds older messages into a summary and asks the same step again,
once per thing the person said, instead of ending the turn.
- Folding keeps the person's chat whole: the summary goes in at the fold and the model reads from
the newest summary on (it used to delete what it folded).
- A step moved to the chosen computer runs there, but the chat keeps the call as the model wrote
it; the result says where it ran.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha5F5gJt93t3yEx3XcS
2026-11-08 16:49:12 +00:00
|
|
|
|
"resume" => Cmd::Resume { bot },
|
2026-11-04 09:46:43 +00:00
|
|
|
|
"restore" => Cmd::RestoreThread { bot, index: b["index"].as_u64().unwrap_or(0) as usize },
|
2026-11-05 08:47:28 +00:00
|
|
|
|
"clear" => Cmd::Clear { bot },
|
安全、修正: harden sandboxes, approval gates, vault, relay roles, and fix protocol/UI bugs
- macOS 沙盒與工具 (tools.rs, policy.rs, docindex.rs): block AppleScript raw events and
concatenation outside the sandbox; stop exposing ~/.ssh or localhost sockets in Sealed
mode; deny writes to shell profiles, LaunchAgents and .git/hooks; expand secret-file
ignores and enforce symlink/policy checks across SSH, device and document search.
- 電腦操作與遮罩 (computer.rs, agent.rs, marks.rs, desktop.rs, cloudbox.rs, portal.rs):
forbid clicking or typing into AnyBot's own windows; extend the sensitive-action hard
gate to raw coordinates, Return/Delete submits and remote devices; stop batch steps if
the front app changes; black out secrets on zoom, show, >600-node trees, adjacent OTP
labels, box screenshots and control text lists; preserve non-text Wayland clipboards.
- 保險庫與瀏覽器 (vault.rs, vault_store.rs, browser.rs, botbrowser.rs, web.rs, box/browser):
verify tab host and HTTPS atomically at fill time; taint filled tabs against browser_eval
and PDF export while masking card/CVC values and screenshots; remember sites only on
always-allow; drop --remote-allow-origins=*; gate private URLs and block metadata/Docker
ports, OrbStack 198.18/15 and IPv6 transition ranges.
- 帳號伺服器、同步與傳送 (relay/, remote.rs, mirror_ui.rs, share.rs, drops.rs): isolate
paired hands hosts from brain sync, tickets, pairing and backup overwrites; redact
routine trigger secrets and clear REDACTED when endpoints change; isolate channel and
team-member turns from owner memories, appctl and grants; scrub shared bot exports and
reset grants/routines on import; validate drop IDs and serialize chunk writes.
- 網路與協定穩定性 (httpd.rs, tunnel.rs, vnc.rs, Caddyfile*): fix chunked integer overflow
and CRLF header injection; enforce Origin checks, connection/job caps, 200 MB backup
reads, unique atomic temp files and ASCII hex guards; bound deflate unzip and VNC sniff
buffers; move VNC stdin/text off the tunnel loop.
- 介面、排程、語言與其他修正 (app.rs, i18n.rs, providers.rs, skills.rs, routines.rs,
setup.rs, store.rs, preview.rs, attach.rs, speech.rs, teams.rs, mcp.rs, voice.rs):
wire up the delete-routine confirmation dialog and mirror run-now; preserve unsaved
mirror edits across brief disconnects; give Chinese skills distinct folders and approval
gates; convert parsed tool JSON fields without corrupting code fences, URLs or paths;
fix Hourly DST offsets and time out unattended routine approvals; lock --install-skill,
cap docx/xlsx unzip sizes, isolate test env keys, and tighten local file permissions.
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-12 06:34:10 +00:00
|
|
|
|
"run_routine" => Cmd::RunRoutine { bot, routine: b["routine"].as_u64().unwrap_or(0) },
|
Voice: its own 設定 › 語音, run by the brain for every screen and the phone
Voice was three implementations that broke on their own: speech to text
borrowed the OpenAI key (so with only Grok set up the mic recorded,
then failed), OpenAI's models it hard-coded stop on 2027-02-26, read
aloud was macOS `say` or espeak-ng (silently nothing on Windows, where
espeak isn't installed), and the phone used the browser's own
recognition. Now:
- 設定 › 語音 has 聽 and 說, each a service: off, OpenAI-compatible
(OpenAI, Groq, a Whisper server of your own: the address decides),
xAI or ElevenLabs. An empty key borrows 設定 › 模型's for the same
service. Each side says 可以用 or what it lacks; 聽 has 試試看
(record a sentence, show what was heard), 說 has 試聽 and the voice
list. speech.rs does the calls; xAI's both ways were checked for real
(Mandarin read, then heard back, in Traditional characters).
- The brain does it all: the phone POSTs its recording (MediaRecorder)
to /api/voice/transcribe, screens to /api/sync/voice/transcribe;
answers come back as MP3 from …/voice/speech and are played on the
device (rodio; an <audio> on the phone, 「唸出來」 in a message's
menu). Keys stay on the brain (the voice keys are redacted for
screens like the others).
- No service, no voice anywhere: the mic, 語音聊天, 會議錄音 and 朗讀
only appear once 聽 (and 說) can be called; the phone's state says
which. Without voice the send arrow just rests where 語音聊天 was.
- 會議錄音 is uploaded to the brain, which turns it into text in the
background and hands it to the bot itself: a meeting is longer than
the 35 s the account lets a request wait, and a brain on a server has
no window (the jobs are polled in background()).
- Recognisers answer Mandarin in Simplified: in a Traditional Chinese
window or phone the text becomes Traditional with Taiwan wording.
- Older saves: whoever had an OpenAI key keeps voice input (聽 =
OpenAI); everyone else starts with it off. Bots' macOS voice names
are cleared. 對話詳細資訊's 加入會議 started plain voice input; it
starts a meeting now.
2026-11-10 14:58:18 +00:00
|
|
|
|
"meeting" => Cmd::Meeting { bot, path: b["path"].as_str().unwrap_or("").to_string(), lang: b["lang"].as_str().unwrap_or("").to_string() },
|
2026-11-04 09:46:43 +00:00
|
|
|
|
_ => return Resp::error(404, "沒有這個動作"),
|
|
|
|
|
|
};
|
|
|
|
|
|
hub().push(cmd);
|
|
|
|
|
|
Resp::json(&json!({"ok": true}))
|
|
|
|
|
|
}
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
("POST", ["api", "logout"]) if !via_relay => {
|
|
|
|
|
|
let h = httpd::sha256_hex(&req.bearer());
|
|
|
|
|
|
hub().push(Cmd::DeviceSeen(format!("-{h}")));
|
|
|
|
|
|
Resp::json(&json!({"ok": true}))
|
|
|
|
|
|
}
|
2026-11-11 03:07:55 +00:00
|
|
|
|
_ => Resp::error(404, NO_SUCH_PATH),
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
記憶: 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
|
|
|
|
/// The memories picked under a composer: `"memories": [...]` (even empty: the person chose none),
|
|
|
|
|
|
/// or nothing (they didn't look).
|
|
|
|
|
|
fn picks_of(b: &Value) -> Option<Vec<String>> {
|
|
|
|
|
|
b["memories"].as_array().map(|a| a.iter().filter_map(|x| x.as_str().map(|s| s.trim().to_string())).filter(|s| !s.is_empty()).take(20).collect())
|
|
|
|
|
|
}
|
|
|
|
|
|
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
/// 團隊角色: what each role may do. "member" chats and attaches files; "admin" also approves,
|
|
|
|
|
|
/// stops, starts new chats and uses the screens; only "device" (another AnyBot of the owner's
|
|
|
|
|
|
/// account) may run tools here.
|
The phone page does what the desktop does, laid out like it
A new mobile/index.html in the desktop's (and Grok Bot's) shape: the sidebar
with its sections and folders, the chat with steps, thinking, reactions, quotes
and the approval card, 對話詳細資訊, Bot 設定, routines, pages, computers and
設定. Each action goes to the desktop's own code on the app's thread
(api/act/<what> -> App::phone_act): appctl, set_pinned, restart_bot,
toggle_reaction, box_task, channels_restart and the rest. No new rules.
Keys, channel tokens and the vault never reach the phone; a model key can only
be written. Admins keep what the phone always let them do; making, changing or
deleting bots, routines, memories, pages, folders and settings stays the
owner's. The state the phone polls now carries the sidebar's section order.
Checked by using it on a preview brain: routines, memories, templates, folders,
keys, signing another phone out, approvals and a chat with a fake model.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha2RVfSYmrhqNnqx9Z4
2026-11-06 19:05:12 +00:00
|
|
|
|
/// A phone action carried out on the app's thread (where the state is), with its answer.
|
2026-11-13 15:36:34 +00:00
|
|
|
|
/// Whether a phone action takes a guard away: turning 直接操作 on, adding an allow rule, adding
|
|
|
|
|
|
/// a connector (a new tool the bots may call).
|
|
|
|
|
|
fn loosens_guard(action: &str, body: &Value) -> bool {
|
|
|
|
|
|
match action {
|
|
|
|
|
|
"setting" => match body["key"].as_str().unwrap_or("") {
|
|
|
|
|
|
"direct_mode" => body["value"].as_bool().unwrap_or(false),
|
|
|
|
|
|
"rule_add" => body["list"].as_str() != Some("ask"),
|
|
|
|
|
|
_ => false,
|
|
|
|
|
|
},
|
|
|
|
|
|
"mcp" => body["add"].is_object(),
|
2026-11-13 16:40:16 +00:00
|
|
|
|
// What a bot may do, and where (the phone sends the whole ticked list).
|
|
|
|
|
|
"bot" => matches!(body["key"].as_str().unwrap_or(""), "abilities" | "may_use"),
|
2026-11-13 15:36:34 +00:00
|
|
|
|
_ => false,
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
The phone page does what the desktop does, laid out like it
A new mobile/index.html in the desktop's (and Grok Bot's) shape: the sidebar
with its sections and folders, the chat with steps, thinking, reactions, quotes
and the approval card, 對話詳細資訊, Bot 設定, routines, pages, computers and
設定. Each action goes to the desktop's own code on the app's thread
(api/act/<what> -> App::phone_act): appctl, set_pinned, restart_bot,
toggle_reaction, box_task, channels_restart and the rest. No new rules.
Keys, channel tokens and the vault never reach the phone; a model key can only
be written. Admins keep what the phone always let them do; making, changing or
deleting bots, routines, memories, pages, folders and settings stays the
owner's. The state the phone polls now carries the sidebar's section order.
Checked by using it on a preview brain: routines, memories, templates, folders,
keys, signing another phone out, approvals and a chat with a fake model.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha2RVfSYmrhqNnqx9Z4
2026-11-06 19:05:12 +00:00
|
|
|
|
fn phone_act(action: &str, body: Value, role: &str) -> Resp {
|
技能: / in the input picks one; on a brain's screen the brain adds, installs and deletes them; 設定 › 整合's lists keep their buttons clear
- Typing / at the start of the input (computer and phone) lists the skills that are on: names that
start with what is typed first, then names containing it, then descriptions (「/簡報」 finds
pptx). A click, or ↑↓ and Enter/Tab, puts 「/name 」 in the input; Esc closes the list. Sent, the
brain recognises 「/name」 and adds a line after the message telling the model to read that skill
with use_skill first, so a phone or a message channel gets it too; a / that names no skill (a
path) gets nothing. The phone asks the brain for the list again at each new /, so a skill added
since is there.
- On a screen, 加入 / 安裝 / 刪除 ran on the screen's own disk and only the list entry reached the
brain: a GitHub skill's scripts stayed on the screen's computer, an install also pushed every
skill in that computer's folder into the brain's list, and a deleted skill's folder stayed on the
brain and came back at its next start. These now go to the brain (/api/sync/skill, the phone's
own 「skill」 action): it fetches an address itself, a folder or .md file on the screen's
computer goes up whole with its files, and a delete takes the folder too. 「把這台的 Bot 搬到大腦」
hands over skills the same way. A refused package leaves no folder behind.
- 技能, 技能市集 and 連接器市集 rows: a long description took the whole row and 開啟 / 檢視 / 刪除
/ 已加入 / 安裝 were drawn over it. The buttons are laid out first and the description ends in …
before them (the whole of it on hover).
- Screenshot mode: ANYBOT_SHOT_KEYS="ArrowDown@60;Enter@64" presses keys at given frames.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 08:54:58 +00:00
|
|
|
|
phone_act_for(action, body, role, 20)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// [`phone_act`], waiting up to `secs` (installing a skill from GitHub takes a while).
|
|
|
|
|
|
fn phone_act_for(action: &str, body: Value, role: &str, secs: u64) -> Resp {
|
|
|
|
|
|
match hub().ask_sync_for(SyncKind::Phone { action: action.to_string(), body, role: role.to_string() }, secs) {
|
The phone page does what the desktop does, laid out like it
A new mobile/index.html in the desktop's (and Grok Bot's) shape: the sidebar
with its sections and folders, the chat with steps, thinking, reactions, quotes
and the approval card, 對話詳細資訊, Bot 設定, routines, pages, computers and
設定. Each action goes to the desktop's own code on the app's thread
(api/act/<what> -> App::phone_act): appctl, set_pinned, restart_bot,
toggle_reaction, box_task, channels_restart and the rest. No new rules.
Keys, channel tokens and the vault never reach the phone; a model key can only
be written. Admins keep what the phone always let them do; making, changing or
deleting bots, routines, memories, pages, folders and settings stays the
owner's. The state the phone polls now carries the sidebar's section order.
Checked by using it on a preview brain: routines, memories, templates, folders,
keys, signing another phone out, approvals and a chat with a fake model.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha2RVfSYmrhqNnqx9Z4
2026-11-06 19:05:12 +00:00
|
|
|
|
Ok(v) if v.get("error").is_some() => Resp::error(400, v["error"].as_str().unwrap_or("做不到")),
|
|
|
|
|
|
Ok(v) => Resp::json(&v),
|
|
|
|
|
|
Err(e) => Resp::error(503, &e),
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
Voice: its own 設定 › 語音, run by the brain for every screen and the phone
Voice was three implementations that broke on their own: speech to text
borrowed the OpenAI key (so with only Grok set up the mic recorded,
then failed), OpenAI's models it hard-coded stop on 2027-02-26, read
aloud was macOS `say` or espeak-ng (silently nothing on Windows, where
espeak isn't installed), and the phone used the browser's own
recognition. Now:
- 設定 › 語音 has 聽 and 說, each a service: off, OpenAI-compatible
(OpenAI, Groq, a Whisper server of your own: the address decides),
xAI or ElevenLabs. An empty key borrows 設定 › 模型's for the same
service. Each side says 可以用 or what it lacks; 聽 has 試試看
(record a sentence, show what was heard), 說 has 試聽 and the voice
list. speech.rs does the calls; xAI's both ways were checked for real
(Mandarin read, then heard back, in Traditional characters).
- The brain does it all: the phone POSTs its recording (MediaRecorder)
to /api/voice/transcribe, screens to /api/sync/voice/transcribe;
answers come back as MP3 from …/voice/speech and are played on the
device (rodio; an <audio> on the phone, 「唸出來」 in a message's
menu). Keys stay on the brain (the voice keys are redacted for
screens like the others).
- No service, no voice anywhere: the mic, 語音聊天, 會議錄音 and 朗讀
only appear once 聽 (and 說) can be called; the phone's state says
which. Without voice the send arrow just rests where 語音聊天 was.
- 會議錄音 is uploaded to the brain, which turns it into text in the
background and hands it to the bot itself: a meeting is longer than
the 35 s the account lets a request wait, and a brain on a server has
no window (the jobs are polled in background()).
- Recognisers answer Mandarin in Simplified: in a Traditional Chinese
window or phone the text becomes Traditional with Taiwan wording.
- Older saves: whoever had an OpenAI key keeps voice input (聽 =
OpenAI); everyone else starts with it off. Bots' macOS voice names
are cleared. 對話詳細資訊's 加入會議 started plain voice input; it
starts a meeting now.
2026-11-10 14:58:18 +00:00
|
|
|
|
/// A recording (the body; ?name=voice.webm says its format, ?lang= the spoken language, ?ui=
|
|
|
|
|
|
/// the asker's window language) → {text}, through 設定 › 語音's 聽.
|
|
|
|
|
|
fn voice_transcribe(req: &Req) -> Resp {
|
|
|
|
|
|
let Some(e) = hub().voice().listen else { return Resp::error(409, crate::speech::NOT_SET) };
|
|
|
|
|
|
// Only the format from the name the asker gave.
|
|
|
|
|
|
let ext = req.query.get("name").and_then(|n| n.rsplit('.').next()).filter(|x| ["m4a", "mp4", "webm", "wav", "ogg", "opus", "mp3", "flac"].contains(&x.to_ascii_lowercase().as_str())).unwrap_or("m4a").to_ascii_lowercase();
|
|
|
|
|
|
let lang = req.query.get("lang").cloned().unwrap_or_default();
|
|
|
|
|
|
let ui = req.query.get("ui").cloned().unwrap_or_else(crate::i18n::lang);
|
|
|
|
|
|
match crate::speech::transcribe(&e, &req.body, &format!("voice.{ext}"), &lang, &ui) {
|
|
|
|
|
|
Ok(text) => Resp::json(&json!({"text": text})),
|
|
|
|
|
|
Err(err) => Resp::error(502, &err),
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// {text, voice, lang, speed} → MP3, through 設定 › 語音's 說.
|
|
|
|
|
|
fn voice_speech(req: &Req) -> Resp {
|
|
|
|
|
|
let Some(e) = hub().voice().speak else { return Resp::error(409, crate::speech::NOT_SET) };
|
|
|
|
|
|
let b = req.json();
|
|
|
|
|
|
let text = b["text"].as_str().unwrap_or("");
|
|
|
|
|
|
match crate::speech::speak(&e, text, b["voice"].as_str().unwrap_or(""), b["lang"].as_str().unwrap_or(""), b["speed"].as_f64().unwrap_or(1.0) as f32) {
|
|
|
|
|
|
Ok(mp3) => Resp::bytes("audio/mpeg", mp3),
|
|
|
|
|
|
Err(err) => Resp::error(502, &err),
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
The phone page does what the desktop does, laid out like it
A new mobile/index.html in the desktop's (and Grok Bot's) shape: the sidebar
with its sections and folders, the chat with steps, thinking, reactions, quotes
and the approval card, 對話詳細資訊, Bot 設定, routines, pages, computers and
設定. Each action goes to the desktop's own code on the app's thread
(api/act/<what> -> App::phone_act): appctl, set_pinned, restart_bot,
toggle_reaction, box_task, channels_restart and the rest. No new rules.
Keys, channel tokens and the vault never reach the phone; a model key can only
be written. Admins keep what the phone always let them do; making, changing or
deleting bots, routines, memories, pages, folders and settings stays the
owner's. The state the phone polls now carries the sidebar's section order.
Checked by using it on a preview brain: routines, memories, templates, folders,
keys, signing another phone out, approvals and a chat with a fake model.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha2RVfSYmrhqNnqx9Z4
2026-11-06 19:05:12 +00:00
|
|
|
|
/// The bots' computer's screen, small (the phone's 電腦 card and a hand-off), as JPEG.
|
|
|
|
|
|
fn box_thumb() -> Resp {
|
|
|
|
|
|
let Some(img) = crate::cloudbox::thumbnail(480) else { return Resp::error(404, "Bot 的電腦沒有開著") };
|
|
|
|
|
|
let mut out = std::io::Cursor::new(vec![]);
|
|
|
|
|
|
match image::codecs::jpeg::JpegEncoder::new_with_quality(&mut out, 72).encode_image(&image::DynamicImage::ImageRgba8(img).to_rgb8()) {
|
|
|
|
|
|
Ok(()) => Resp::bytes("image/jpeg", out.into_inner()),
|
|
|
|
|
|
Err(e) => Resp::error(500, &e.to_string()),
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
pub fn role_allows(role: &str, method: &str, path: &[&str]) -> bool {
|
|
|
|
|
|
let device = matches!(path, ["api", "device", "run"]);
|
2026-11-04 09:46:43 +00:00
|
|
|
|
let sync = matches!(path, ["api", "sync", ..]);
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
match role {
|
|
|
|
|
|
"device" => device,
|
2026-11-04 09:46:43 +00:00
|
|
|
|
// 大腦: the owner's other AnyBots showing this one's bots.
|
|
|
|
|
|
"mirror" => sync,
|
|
|
|
|
|
"owner" | "admin" => !device && !sync,
|
2026-11-13 06:19:59 +00:00
|
|
|
|
"member" => matches!((method, path), ("GET", ["api", "state"]) | ("GET", ["api", "bots", _]) | ("GET", ["api", "pages", ..]) | ("GET", ["api", "file"]) | ("GET", ["api", "preview", ..]) | ("POST", ["api", "bots", _, "send" | "read" | "upload"]) | ("POST", ["api", "voice", "transcribe" | "speech"])),
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
_ => false,
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-11-13 06:19:59 +00:00
|
|
|
|
fn messages_for_role(m: &[Value], role: &str) -> Value {
|
|
|
|
|
|
if role == "owner" {
|
|
|
|
|
|
return Value::Array(m.to_vec());
|
|
|
|
|
|
}
|
|
|
|
|
|
let mut out = Value::Array(m.to_vec());
|
|
|
|
|
|
for x in out.as_array_mut().into_iter().flatten() {
|
|
|
|
|
|
if let Some(o) = x.as_object_mut() {
|
|
|
|
|
|
o.remove("memories");
|
|
|
|
|
|
if role == "member" {
|
|
|
|
|
|
o.remove("thinking");
|
|
|
|
|
|
for t in o.get_mut("tools").and_then(Value::as_array_mut).into_iter().flatten() {
|
|
|
|
|
|
if let Some(to) = t.as_object_mut() {
|
|
|
|
|
|
to.remove("result");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
out
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn chat_sig(msgs: &Value) -> String {
|
|
|
|
|
|
use std::hash::{Hash, Hasher};
|
|
|
|
|
|
let mut h = std::collections::hash_map::DefaultHasher::new();
|
|
|
|
|
|
msgs.to_string().hash(&mut h);
|
|
|
|
|
|
format!("{:016x}", h.finish())
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-11-13 15:36:34 +00:00
|
|
|
|
/// A teammate's file request: only inside the file folder of a bot shared with the team.
|
|
|
|
|
|
fn member_file_ok(want: &str, shared: &[u64]) -> bool {
|
|
|
|
|
|
let Some(f) = safe_chat_path(want) else { return false };
|
|
|
|
|
|
let Some(root) = crate::model::State::path().parent().and_then(|p| p.join("attachments").canonicalize().ok()) else { return false };
|
|
|
|
|
|
shared.iter().any(|id| f.starts_with(root.join(format!("bot-{id}"))))
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-11-13 06:19:59 +00:00
|
|
|
|
fn safe_chat_path(want: &str) -> Option<std::path::PathBuf> {
|
Real-use fixes: the person sees the screens the bot shows, files reach the phone, no blank-tab loops
From real runs on the cloud brain with the person's Mac (Threads patrol, a post draft, "show me my
screen"):
- computer_use_show: a plain picture of any computer's screen goes into the chat (the bot sees it
too). The bot used to describe a screenshot in words and fail to send it.
- The phone shows the bot's attachments: pictures in place, other files download on a tap (api/file,
only from the chats' file folder). It showed nothing for the bot and names only for the person.
- send_file works from the person's other computers (fetch_file over the relay, 20 MB, secrets stay).
- The same call with the same answer again and again is warned the 3rd time and stopped from the
4th (a blank tab was read 11 times, then the bot said Threads was logged out without opening it);
a blank tab says so; checking a login means opening the site.
- Screenshot lists: a nameless row around a named button isn't numbered, a nameless row takes the
words inside it, empty spacer rows aren't numbered (System Settings: 63 numbers -> 33, all named).
- Writing "in my voice" reads the person's own recent posts first.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha2RVfSYmrhqNnqx9Z4
2026-11-06 11:37:45 +00:00
|
|
|
|
let root = crate::model::State::path().parent()?.join("attachments").canonicalize().ok()?;
|
|
|
|
|
|
let f = std::path::PathBuf::from(want).canonicalize().ok()?;
|
2026-11-13 06:19:59 +00:00
|
|
|
|
(f.starts_with(&root) && f.is_file()).then_some(f)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// A chat file by its path, only when it really is inside the chats' file folder.
|
|
|
|
|
|
fn chat_file(want: &str) -> Option<(std::path::PathBuf, Vec<u8>)> {
|
|
|
|
|
|
let f = safe_chat_path(want)?;
|
Real-use fixes: the person sees the screens the bot shows, files reach the phone, no blank-tab loops
From real runs on the cloud brain with the person's Mac (Threads patrol, a post draft, "show me my
screen"):
- computer_use_show: a plain picture of any computer's screen goes into the chat (the bot sees it
too). The bot used to describe a screenshot in words and fail to send it.
- The phone shows the bot's attachments: pictures in place, other files download on a tap (api/file,
only from the chats' file folder). It showed nothing for the bot and names only for the person.
- send_file works from the person's other computers (fetch_file over the relay, 20 MB, secrets stay).
- The same call with the same answer again and again is warned the 3rd time and stopped from the
4th (a blank tab was read 11 times, then the bot said Threads was logged out without opening it);
a blank tab says so; checking a login means opening the site.
- Screenshot lists: a nameless row around a named button isn't numbered, a nameless row takes the
words inside it, empty spacer rows aren't numbered (System Settings: 63 numbers -> 33, all named).
- Writing "in my voice" reads the person's own recent posts first.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha2RVfSYmrhqNnqx9Z4
2026-11-06 11:37:45 +00:00
|
|
|
|
let b = std::fs::read(&f).ok()?;
|
|
|
|
|
|
Some((f, b))
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-11-13 06:19:59 +00:00
|
|
|
|
fn file_preview(want: &str) -> Resp {
|
|
|
|
|
|
let Some(f) = safe_chat_path(want) else { return Resp::error(404, "找不到這個檔案") };
|
|
|
|
|
|
let raw_name = f.file_name().map(|n| n.to_string_lossy().to_string()).unwrap_or_default();
|
|
|
|
|
|
let name = raw_name.split_once('-').map(|x| x.1.to_string()).unwrap_or(raw_name);
|
|
|
|
|
|
let bytes = std::fs::metadata(&f).map(|m| m.len()).unwrap_or(0);
|
|
|
|
|
|
let label = crate::preview::kind_label(&name);
|
|
|
|
|
|
let ext = name.rsplit('.').next().unwrap_or("").to_lowercase();
|
|
|
|
|
|
use crate::preview::Preview;
|
|
|
|
|
|
match crate::preview::load(&f, &name) {
|
|
|
|
|
|
Preview::Table(sheets) => Resp::json(&json!({
|
|
|
|
|
|
"kind": "sheet", "name": name, "label": label, "bytes": bytes,
|
|
|
|
|
|
"sheets": sheets.into_iter().map(|(sn, rows)| json!({"name": sn, "rows": rows})).collect::<Vec<_>>(),
|
|
|
|
|
|
})),
|
|
|
|
|
|
Preview::Markdown(md) => Resp::json(&json!({"kind": "markdown", "name": name, "label": label, "bytes": bytes, "text": md})),
|
|
|
|
|
|
Preview::Html(md) => Resp::json(&json!({"kind": "html", "name": name, "label": label, "bytes": bytes, "text": md})),
|
|
|
|
|
|
Preview::Text(txt) => Resp::json(&json!({"kind": "text", "name": name, "label": label, "bytes": bytes, "ext": ext, "text": txt})),
|
|
|
|
|
|
Preview::Pdf => match crate::preview::pdf_page_count(&f) {
|
|
|
|
|
|
Ok(pages) => Resp::json(&json!({"kind": "pdf", "name": name, "label": label, "bytes": bytes, "pages": pages})),
|
|
|
|
|
|
Err(e) => Resp::json(&json!({"kind": "other", "name": name, "label": label, "bytes": bytes, "message": e})),
|
|
|
|
|
|
},
|
|
|
|
|
|
Preview::Image => Resp::json(&json!({"kind": "image", "name": name, "label": label, "bytes": bytes, "ext": ext})),
|
|
|
|
|
|
Preview::Audio => Resp::json(&json!({"kind": "audio", "name": name, "label": label, "bytes": bytes, "ext": ext})),
|
|
|
|
|
|
Preview::Video => Resp::json(&json!({"kind": "video", "name": name, "label": label, "bytes": bytes, "ext": ext})),
|
|
|
|
|
|
Preview::Other(msg) => Resp::json(&json!({"kind": "other", "name": name, "label": label, "bytes": bytes, "message": msg})),
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn file_preview_pdf(want: &str, page: usize) -> Resp {
|
|
|
|
|
|
let Some(f) = safe_chat_path(want) else { return Resp::error(404, "找不到這個檔案") };
|
|
|
|
|
|
match crate::preview::pdf_single_page(&f, page, 1400.0) {
|
|
|
|
|
|
Ok((total, rgba)) => {
|
|
|
|
|
|
let mut out = std::io::Cursor::new(vec![]);
|
|
|
|
|
|
match image::codecs::jpeg::JpegEncoder::new_with_quality(&mut out, 86).encode_image(&image::DynamicImage::ImageRgba8(rgba).to_rgb8()) {
|
|
|
|
|
|
Ok(()) => Resp::bytes("image/jpeg", out.into_inner()).with_header("X-Pages", &total.to_string()),
|
|
|
|
|
|
Err(e) => Resp::error(500, &e.to_string()),
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
Err(e) => Resp::error(422, &e),
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn file_preview_image(want: &str) -> Resp {
|
|
|
|
|
|
let Some(f) = safe_chat_path(want) else { return Resp::error(404, "找不到這個檔案") };
|
|
|
|
|
|
let ext = f.extension().and_then(|e| e.to_str()).unwrap_or("").to_ascii_lowercase();
|
|
|
|
|
|
if matches!(ext.as_str(), "png" | "jpg" | "jpeg" | "gif" | "webp") {
|
|
|
|
|
|
if let Ok(b) = std::fs::read(&f) {
|
|
|
|
|
|
return Resp::bytes(content_type(&f), b);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
let Some(rgba) = crate::preview::decode_image(&f) else { return Resp::error(422, "這張圖片解碼失敗") };
|
|
|
|
|
|
let mut out = std::io::Cursor::new(vec![]);
|
|
|
|
|
|
match image::DynamicImage::ImageRgba8(rgba).write_to(&mut out, image::ImageFormat::Png) {
|
|
|
|
|
|
Ok(()) => Resp::bytes("image/png", out.into_inner()),
|
|
|
|
|
|
Err(e) => Resp::error(500, &e.to_string()),
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
Real-use fixes: the person sees the screens the bot shows, files reach the phone, no blank-tab loops
From real runs on the cloud brain with the person's Mac (Threads patrol, a post draft, "show me my
screen"):
- computer_use_show: a plain picture of any computer's screen goes into the chat (the bot sees it
too). The bot used to describe a screenshot in words and fail to send it.
- The phone shows the bot's attachments: pictures in place, other files download on a tap (api/file,
only from the chats' file folder). It showed nothing for the bot and names only for the person.
- send_file works from the person's other computers (fetch_file over the relay, 20 MB, secrets stay).
- The same call with the same answer again and again is warned the 3rd time and stopped from the
4th (a blank tab was read 11 times, then the bot said Threads was logged out without opening it);
a blank tab says so; checking a login means opening the site.
- Screenshot lists: a nameless row around a named button isn't numbered, a nameless row takes the
words inside it, empty spacer rows aren't numbered (System Settings: 63 numbers -> 33, all named).
- Writing "in my voice" reads the person's own recent posts first.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha2RVfSYmrhqNnqx9Z4
2026-11-06 11:37:45 +00:00
|
|
|
|
fn content_type(f: &std::path::Path) -> &'static str {
|
|
|
|
|
|
match f.extension().and_then(|e| e.to_str()).map(|e| e.to_ascii_lowercase()).as_deref() {
|
|
|
|
|
|
Some("jpg" | "jpeg") => "image/jpeg",
|
|
|
|
|
|
Some("png") => "image/png",
|
|
|
|
|
|
Some("gif") => "image/gif",
|
|
|
|
|
|
Some("webp") => "image/webp",
|
2026-11-13 06:19:59 +00:00
|
|
|
|
Some("svg") => "image/svg+xml",
|
Real-use fixes: the person sees the screens the bot shows, files reach the phone, no blank-tab loops
From real runs on the cloud brain with the person's Mac (Threads patrol, a post draft, "show me my
screen"):
- computer_use_show: a plain picture of any computer's screen goes into the chat (the bot sees it
too). The bot used to describe a screenshot in words and fail to send it.
- The phone shows the bot's attachments: pictures in place, other files download on a tap (api/file,
only from the chats' file folder). It showed nothing for the bot and names only for the person.
- send_file works from the person's other computers (fetch_file over the relay, 20 MB, secrets stay).
- The same call with the same answer again and again is warned the 3rd time and stopped from the
4th (a blank tab was read 11 times, then the bot said Threads was logged out without opening it);
a blank tab says so; checking a login means opening the site.
- Screenshot lists: a nameless row around a named button isn't numbered, a nameless row takes the
words inside it, empty spacer rows aren't numbered (System Settings: 63 numbers -> 33, all named).
- Writing "in my voice" reads the person's own recent posts first.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha2RVfSYmrhqNnqx9Z4
2026-11-06 11:37:45 +00:00
|
|
|
|
Some("pdf") => "application/pdf",
|
2026-11-13 06:19:59 +00:00
|
|
|
|
Some("mp3") => "audio/mpeg",
|
|
|
|
|
|
Some("m4a") => "audio/mp4",
|
|
|
|
|
|
Some("wav") => "audio/wav",
|
|
|
|
|
|
Some("ogg" | "oga" | "opus") => "audio/ogg",
|
|
|
|
|
|
Some("flac") => "audio/flac",
|
|
|
|
|
|
Some("mp4" | "m4v") => "video/mp4",
|
|
|
|
|
|
Some("webm") => "video/webm",
|
|
|
|
|
|
Some("mov") => "video/quicktime",
|
|
|
|
|
|
Some("txt" | "md" | "csv" | "json" | "log") => "text/plain; charset=utf-8",
|
Real-use fixes: the person sees the screens the bot shows, files reach the phone, no blank-tab loops
From real runs on the cloud brain with the person's Mac (Threads patrol, a post draft, "show me my
screen"):
- computer_use_show: a plain picture of any computer's screen goes into the chat (the bot sees it
too). The bot used to describe a screenshot in words and fail to send it.
- The phone shows the bot's attachments: pictures in place, other files download on a tap (api/file,
only from the chats' file folder). It showed nothing for the bot and names only for the person.
- send_file works from the person's other computers (fetch_file over the relay, 20 MB, secrets stay).
- The same call with the same answer again and again is warned the 3rd time and stopped from the
4th (a blank tab was read 11 times, then the bot said Threads was logged out without opening it);
a blank tab says so; checking a login means opening the site.
- Screenshot lists: a nameless row around a named button isn't numbered, a nameless row takes the
words inside it, empty spacer rows aren't numbered (System Settings: 63 numbers -> 33, all named).
- Writing "in my voice" reads the person's own recent posts first.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha2RVfSYmrhqNnqx9Z4
2026-11-06 11:37:45 +00:00
|
|
|
|
_ => "application/octet-stream",
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
fn login(req: &Req) -> Resp {
|
2026-11-05 07:48:20 +00:00
|
|
|
|
// One counter per source address, cleaned as it is touched.
|
|
|
|
|
|
let ip = req.peer.split(':').next().unwrap_or(&req.peer).to_string();
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
{
|
|
|
|
|
|
let mut f = hub().fails.lock().unwrap();
|
2026-11-05 07:48:20 +00:00
|
|
|
|
f.retain(|_, (_, t)| t.elapsed() < Duration::from_secs(60));
|
2026-11-13 15:36:34 +00:00
|
|
|
|
// (From everywhere together too: there is one password, whatever the address.)
|
|
|
|
|
|
let all = f.get("*").map(|(n, _)| *n).unwrap_or(0);
|
|
|
|
|
|
if f.get(&ip).is_some_and(|(n, _)| *n >= MAX_FAILS) || all >= MAX_FAILS * 6 {
|
|
|
|
|
|
return Resp::error(429, "密碼錯太多次,請一分鐘後再試");
|
|
|
|
|
|
}
|
|
|
|
|
|
// Counted before the check (taken back on a right password): tries sent all at once
|
|
|
|
|
|
// can't all pass the count before any of them fails.
|
|
|
|
|
|
for k in [ip.as_str(), "*"] {
|
|
|
|
|
|
let e = f.entry(k.to_string()).or_insert((0, Instant::now()));
|
|
|
|
|
|
e.0 += 1;
|
|
|
|
|
|
e.1 = Instant::now();
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
let b = req.json();
|
|
|
|
|
|
let pw = b["password"].as_str().unwrap_or("");
|
|
|
|
|
|
let stored = hub().settings().password;
|
安全、修正: harden sandboxes, approval gates, vault, relay roles, and fix protocol/UI bugs
- macOS 沙盒與工具 (tools.rs, policy.rs, docindex.rs): block AppleScript raw events and
concatenation outside the sandbox; stop exposing ~/.ssh or localhost sockets in Sealed
mode; deny writes to shell profiles, LaunchAgents and .git/hooks; expand secret-file
ignores and enforce symlink/policy checks across SSH, device and document search.
- 電腦操作與遮罩 (computer.rs, agent.rs, marks.rs, desktop.rs, cloudbox.rs, portal.rs):
forbid clicking or typing into AnyBot's own windows; extend the sensitive-action hard
gate to raw coordinates, Return/Delete submits and remote devices; stop batch steps if
the front app changes; black out secrets on zoom, show, >600-node trees, adjacent OTP
labels, box screenshots and control text lists; preserve non-text Wayland clipboards.
- 保險庫與瀏覽器 (vault.rs, vault_store.rs, browser.rs, botbrowser.rs, web.rs, box/browser):
verify tab host and HTTPS atomically at fill time; taint filled tabs against browser_eval
and PDF export while masking card/CVC values and screenshots; remember sites only on
always-allow; drop --remote-allow-origins=*; gate private URLs and block metadata/Docker
ports, OrbStack 198.18/15 and IPv6 transition ranges.
- 帳號伺服器、同步與傳送 (relay/, remote.rs, mirror_ui.rs, share.rs, drops.rs): isolate
paired hands hosts from brain sync, tickets, pairing and backup overwrites; redact
routine trigger secrets and clear REDACTED when endpoints change; isolate channel and
team-member turns from owner memories, appctl and grants; scrub shared bot exports and
reset grants/routines on import; validate drop IDs and serialize chunk writes.
- 網路與協定穩定性 (httpd.rs, tunnel.rs, vnc.rs, Caddyfile*): fix chunked integer overflow
and CRLF header injection; enforce Origin checks, connection/job caps, 200 MB backup
reads, unique atomic temp files and ASCII hex guards; bound deflate unzip and VNC sniff
buffers; move VNC stdin/text off the tunnel loop.
- 介面、排程、語言與其他修正 (app.rs, i18n.rs, providers.rs, skills.rs, routines.rs,
setup.rs, store.rs, preview.rs, attach.rs, speech.rs, teams.rs, mcp.rs, voice.rs):
wire up the delete-routine confirmation dialog and mirror run-now; preserve unsaved
mirror edits across brief disconnects; give Chinese skills distinct folders and approval
gates; convert parsed tool JSON fields without corrupting code fences, URLs or paths;
fix Hourly DST offsets and time out unattended routine approvals; lock --install-skill,
cap docx/xlsx unzip sizes, isolate test env keys, and tighten local file permissions.
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-12 06:34:10 +00:00
|
|
|
|
let dummy = "argon2id$000102030405060708090a0b0c0d0e0f$0000000000000000000000000000000000000000000000000000000000000000";
|
|
|
|
|
|
let ok = if stored.is_empty() {
|
|
|
|
|
|
let _ = httpd::check_password(pw, dummy);
|
|
|
|
|
|
false
|
|
|
|
|
|
} else {
|
|
|
|
|
|
httpd::check_password(pw, &stored)
|
|
|
|
|
|
};
|
2026-11-13 15:36:34 +00:00
|
|
|
|
if ok {
|
|
|
|
|
|
let mut f = hub().fails.lock().unwrap();
|
|
|
|
|
|
f.remove(&ip);
|
|
|
|
|
|
if let Some(e) = f.get_mut("*") {
|
|
|
|
|
|
e.0 = e.0.saturating_sub(1);
|
2026-11-05 07:48:20 +00:00
|
|
|
|
}
|
2026-11-13 15:36:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
if !ok {
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
// Slow guessing down a little more.
|
|
|
|
|
|
std::thread::sleep(Duration::from_millis(600));
|
|
|
|
|
|
return Resp::error(401, if stored.is_empty() { "這台 AnyBot 還沒設定手機密碼" } else { "密碼不對" });
|
|
|
|
|
|
}
|
2026-11-05 07:48:20 +00:00
|
|
|
|
hub().fails.lock().unwrap().remove(&ip);
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
let token = httpd::random_hex(32);
|
|
|
|
|
|
let name = b["device"].as_str().filter(|d| !d.trim().is_empty()).unwrap_or("手機").chars().take(40).collect::<String>();
|
|
|
|
|
|
let d = Device { name, token_hash: httpd::sha256_hex(&token), created: chrono::Utc::now().timestamp(), last_seen: chrono::Utc::now().timestamp() };
|
|
|
|
|
|
// Known at once (the app saves it a moment later).
|
|
|
|
|
|
hub().settings.lock().unwrap().devices.push(d.clone());
|
|
|
|
|
|
hub().push(Cmd::DeviceAdded(d));
|
|
|
|
|
|
Resp::json(&json!({"token": token}))
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn upload(bot: u64, req: &Req) -> Resp {
|
安全、修正: harden sandboxes, approval gates, vault, relay roles, and fix protocol/UI bugs
- macOS 沙盒與工具 (tools.rs, policy.rs, docindex.rs): block AppleScript raw events and
concatenation outside the sandbox; stop exposing ~/.ssh or localhost sockets in Sealed
mode; deny writes to shell profiles, LaunchAgents and .git/hooks; expand secret-file
ignores and enforce symlink/policy checks across SSH, device and document search.
- 電腦操作與遮罩 (computer.rs, agent.rs, marks.rs, desktop.rs, cloudbox.rs, portal.rs):
forbid clicking or typing into AnyBot's own windows; extend the sensitive-action hard
gate to raw coordinates, Return/Delete submits and remote devices; stop batch steps if
the front app changes; black out secrets on zoom, show, >600-node trees, adjacent OTP
labels, box screenshots and control text lists; preserve non-text Wayland clipboards.
- 保險庫與瀏覽器 (vault.rs, vault_store.rs, browser.rs, botbrowser.rs, web.rs, box/browser):
verify tab host and HTTPS atomically at fill time; taint filled tabs against browser_eval
and PDF export while masking card/CVC values and screenshots; remember sites only on
always-allow; drop --remote-allow-origins=*; gate private URLs and block metadata/Docker
ports, OrbStack 198.18/15 and IPv6 transition ranges.
- 帳號伺服器、同步與傳送 (relay/, remote.rs, mirror_ui.rs, share.rs, drops.rs): isolate
paired hands hosts from brain sync, tickets, pairing and backup overwrites; redact
routine trigger secrets and clear REDACTED when endpoints change; isolate channel and
team-member turns from owner memories, appctl and grants; scrub shared bot exports and
reset grants/routines on import; validate drop IDs and serialize chunk writes.
- 網路與協定穩定性 (httpd.rs, tunnel.rs, vnc.rs, Caddyfile*): fix chunked integer overflow
and CRLF header injection; enforce Origin checks, connection/job caps, 200 MB backup
reads, unique atomic temp files and ASCII hex guards; bound deflate unzip and VNC sniff
buffers; move VNC stdin/text off the tunnel loop.
- 介面、排程、語言與其他修正 (app.rs, i18n.rs, providers.rs, skills.rs, routines.rs,
setup.rs, store.rs, preview.rs, attach.rs, speech.rs, teams.rs, mcp.rs, voice.rs):
wire up the delete-routine confirmation dialog and mirror run-now; preserve unsaved
mirror edits across brief disconnects; give Chinese skills distinct folders and approval
gates; convert parsed tool JSON fields without corrupting code fences, URLs or paths;
fix Hourly DST offsets and time out unattended routine approvals; lock --install-skill,
cap docx/xlsx unzip sizes, isolate test env keys, and tighten local file permissions.
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-12 06:34:10 +00:00
|
|
|
|
if bot == 0 || (req.header("x-anybot-role") == "member" && !hub().view.lock().unwrap().bots.iter().any(|b| b["id"].as_u64() == Some(bot))) {
|
|
|
|
|
|
return Resp::error(404, "找不到這個 Bot");
|
|
|
|
|
|
}
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
let name = req.query.get("name").cloned().unwrap_or_else(|| "手機上傳".into());
|
|
|
|
|
|
let name: String = name.chars().filter(|c| !matches!(c, '/' | '\\' | '\0')).take(80).collect();
|
|
|
|
|
|
if req.body.is_empty() {
|
|
|
|
|
|
return Resp::error(400, "檔案是空的");
|
|
|
|
|
|
}
|
|
|
|
|
|
let dir = std::env::temp_dir().join(format!("anybot-phone-{}", httpd::random_hex(6)));
|
|
|
|
|
|
let _ = std::fs::create_dir_all(&dir);
|
|
|
|
|
|
let tmp = dir.join(if name.is_empty() { "upload".to_string() } else { name });
|
|
|
|
|
|
if let Err(e) = std::fs::write(&tmp, &req.body) {
|
|
|
|
|
|
return Resp::error(500, &e.to_string());
|
|
|
|
|
|
}
|
|
|
|
|
|
let r = crate::attach::store(bot, &tmp);
|
|
|
|
|
|
let _ = std::fs::remove_dir_all(&dir);
|
|
|
|
|
|
match r {
|
|
|
|
|
|
Ok(a) => Resp::json(&json!({"path": a.path, "name": a.name, "image": a.image})),
|
|
|
|
|
|
Err(e) => Resp::error(400, &e),
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// A frame of the bot's computer ("box") or this Mac ("mac") as JPEG.
|
People watch and help on the bots' computer through VNC (noVNC), carried by the account server
The core: the bot works the computer; a person watches it like a colleague, and takes over
when it needs them. VNC is made for that (only what changed, every mouse move and key, touch on
phones), so the pictures sent one by one go, and with them their own input path.
- vnc.rs: a VNC proxy to the box's x11vnc through one docker exec (a Python bridge that ends
with either side). It signs in to the box with the box's own password (its VNC_PASSWORD) and
offers the viewer no password, so the password never leaves the brain. The person's clicks
and keys make the bot's steps wait until 8 s after they stop; text typed in the viewer's box
(any language) is pasted in the box.
- Account server: /screen (the viewer page) and /novnc.js (noVNC 1.6.0, MPL-2.0, bundled);
/relay/vnc/<host> takes the browser's WebSocket (account session, or a 10-minute ticket the
app asks for with POST /relay/screen-ticket; owners and admins) and carries it over that
AnyBot's lasting connection (vopen / vdata / vtext / vclose). Both ends of that connection
wait 2 ms instead of 40 ms to read while things move: a request and its answer took up to
160 ms more than needed.
- Phone page: 看 Bot 的電腦 and 接管 open the viewer page (also on the local network: /api/vnc on
the AnyBot's own phone server). This Mac's own screen moved to the ⋯ menu.
- Mac app: 看畫面 opens the viewer in the browser (a screen of a brain: the brain's computer by
ticket; else this computer's box, noVNC straight from it). The in-app picture viewer, the
live JPEG stream, the person's click/move/scroll/key endpoints and the input shell are gone.
- Opening a Mac app uses LaunchServices (`open -a`): agent-desktop's launch waited on the window
through accessibility and failed without 輔助使用 now and then.
Measured on this Mac (made-up account, local relay + headless brain + the real box): viewer
signed in in 0.4–0.7 s, a request and its answer through relay + brain + box 25–58 ms median;
headless Chrome shows the desktop live in /screen. remote_e2e 28/28 ×2, 149 unit tests, relay 11.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-05 15:05:44 +00:00
|
|
|
|
/// This Mac's screen for the phone (when allowed). The bots' computer is watched through VNC
|
|
|
|
|
|
/// (the page /screen, vnc.rs).
|
|
|
|
|
|
fn screen(which: &str, s: &Settings) -> Resp {
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
match which {
|
|
|
|
|
|
"mac" if s.mac_from_phone => {
|
Bots click by number: every control on the screen is boxed and numbered, on every computer
A bot asked to open a Threads profile clicked an empty strip ten times: it guessed coordinates
from a picture, and the web tools' description told it they didn't work on its own computer.
- marks.rs: the picture a bot gets has every button, link, field and menu item boxed and
numbered (a tiny built-in digit font, pure Rust), with the same numbers in a list. click /
typing / scroll / mouse_move take the number (ref) and land on the control's centre.
- Where the controls come from: macOS AX and Linux AT-SPI through agent-desktop on a person's
computer (desktop::elements); AT-SPI in the bots' own computer (box/a11y, after XBot's
box-a11y), web pages included. On a Mac a control whose spot another app's window covers gets
no number (topmost window at its centre must be the app's; the Dock's invisible full-screen
window doesn't count). open_app waits until the app is really in front.
- No going round in circles: a step that changed nothing says so; the same step (clicks within
16 px) a third time in a turn comes with a warning, from the fourth time it isn't run.
- The box (version 4): one TigerVNC server instead of Xvfb + x11vnc, the AT-SPI bus and registry
at boot, one browser launcher (box/browser, after XBot's box-chrome: same profile and CDP,
renderer accessibility, a launch lock, stale profile locks cleared). One docker exec per look
(list + picture, ~0.4 s). A brain updates an older box by itself when it has been idle a
minute (files and logins stay); a new box is never made from an older image.
- Gone: computer_use_read_app (the list is in every picture), computer_use_mouse_button, the
per-call picture for the phone (it gets a plain one), the stale browser_read note; the prompt
says web work goes through browser_* by number, and never to read browser cookie or history
files.
Tests: marks (numbering, drawing, fingerprints), box_numbers_are_exact on a box from the new
image (a Threads-like page: the icon links get numbers, Profile clicked by number, Chinese typed
into the numbered field, a click on nothing called out), box_screen_is_exact, VNC e2e 11/11 on
TigerVNC, Calculator 7×8=56 by numbers through the signed app on this Mac, remote_e2e 28/28,
153 unit tests; Linux build + 157 tests + x11_live.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-05 16:47:01 +00:00
|
|
|
|
match crate::computer::plain_picture() {
|
|
|
|
|
|
Ok((w, h, jpeg)) => Resp::bytes("image/jpeg", jpeg).with_header("X-Size", &format!("{w}x{h}")),
|
|
|
|
|
|
Err(e) => Resp::error(503, &e),
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
"mac" => Resp::error(403, "這台 Mac 沒有開放從手機操作(AnyBot 設定 › 手機與帳號)"),
|
|
|
|
|
|
_ => Resp::error(404, "沒有這個畫面"),
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
People watch and help on the bots' computer through VNC (noVNC), carried by the account server
The core: the bot works the computer; a person watches it like a colleague, and takes over
when it needs them. VNC is made for that (only what changed, every mouse move and key, touch on
phones), so the pictures sent one by one go, and with them their own input path.
- vnc.rs: a VNC proxy to the box's x11vnc through one docker exec (a Python bridge that ends
with either side). It signs in to the box with the box's own password (its VNC_PASSWORD) and
offers the viewer no password, so the password never leaves the brain. The person's clicks
and keys make the bot's steps wait until 8 s after they stop; text typed in the viewer's box
(any language) is pasted in the box.
- Account server: /screen (the viewer page) and /novnc.js (noVNC 1.6.0, MPL-2.0, bundled);
/relay/vnc/<host> takes the browser's WebSocket (account session, or a 10-minute ticket the
app asks for with POST /relay/screen-ticket; owners and admins) and carries it over that
AnyBot's lasting connection (vopen / vdata / vtext / vclose). Both ends of that connection
wait 2 ms instead of 40 ms to read while things move: a request and its answer took up to
160 ms more than needed.
- Phone page: 看 Bot 的電腦 and 接管 open the viewer page (also on the local network: /api/vnc on
the AnyBot's own phone server). This Mac's own screen moved to the ⋯ menu.
- Mac app: 看畫面 opens the viewer in the browser (a screen of a brain: the brain's computer by
ticket; else this computer's box, noVNC straight from it). The in-app picture viewer, the
live JPEG stream, the person's click/move/scroll/key endpoints and the input shell are gone.
- Opening a Mac app uses LaunchServices (`open -a`): agent-desktop's launch waited on the window
through accessibility and failed without 輔助使用 now and then.
Measured on this Mac (made-up account, local relay + headless brain + the real box): viewer
signed in in 0.4–0.7 s, a request and its answer through relay + brain + box 25–58 ms median;
headless Chrome shows the desktop live in /screen. remote_e2e 28/28 ×2, 149 unit tests, relay 11.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-05 15:05:44 +00:00
|
|
|
|
/// The phone taps, types or scrolls on this Mac's screen, as the person, in the pixels of the
|
|
|
|
|
|
/// picture it was sent (shot_size). The bots' computer takes the person's input through VNC.
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
fn screen_input(which: &str, v: &Value, s: &Settings) -> Resp {
|
One way to act on a screen: a real click or keystroke, wherever the bot looked
- Acting by an app's number (read_app's e7) is now a real click at that control's spot, the
same path as screenshot coordinates. agent-desktop only reads; its own actions (a second set
with its own key names and failures: no typing in terminals, "/" and "`" failing off the main
thread) are gone, with computer_use_select, background clicks and press_key's app.
- Every action comes back with the screen after it (or, with no picture allowed, the front
app's numbered controls), so the bot no longer spends a step on a screenshot to check.
- Coordinates map without remembering a screenshot: the picture's size depends only on the
screen. The phone's taps go straight to the screen as the person's, in the pixels of the
picture it was sent; they used to borrow the bot's last screenshot scale and landed 1.25x off
on the bots' computer, or failed with "screenshot first".
- Mac typing pastes (⌘V, clipboard put back): with 注音 on, text sent as key events vanished
while return arrived, so commands typed into a terminal ran empty. Bare printing keys
("slash", "r") are typed the same way; keys like "slash" and "grave" have names.
- The bots' Docker computer: one docker exec per step (action, settle, picture), never
`mousemove --sync` (it waits forever when the pointer is already there: a second click on
the same spot hung two minutes), open_app (chromium = the browser browser_* drive, xterm).
Tests: box_screen_is_exact (real Docker: bot and phone coordinates exact, same spot twice in
under 2 s, ASCII + Chinese + named key typed), Calculator by numbers and Terminal typing under
注音 through the signed app, remote_e2e 28/28, Linux build + 151 tests + x11_live.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-05 13:51:19 +00:00
|
|
|
|
let (x, y) = (v["x"].as_f64().unwrap_or(0.0), v["y"].as_f64().unwrap_or(0.0));
|
|
|
|
|
|
let down = v["direction"].as_str().unwrap_or("down") != "up";
|
|
|
|
|
|
let amount = v["amount"].as_i64().unwrap_or(3).clamp(1, 20);
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
match which {
|
|
|
|
|
|
"mac" if s.mac_from_phone => {
|
People watch and help on the bots' computer through VNC (noVNC), carried by the account server
The core: the bot works the computer; a person watches it like a colleague, and takes over
when it needs them. VNC is made for that (only what changed, every mouse move and key, touch on
phones), so the pictures sent one by one go, and with them their own input path.
- vnc.rs: a VNC proxy to the box's x11vnc through one docker exec (a Python bridge that ends
with either side). It signs in to the box with the box's own password (its VNC_PASSWORD) and
offers the viewer no password, so the password never leaves the brain. The person's clicks
and keys make the bot's steps wait until 8 s after they stop; text typed in the viewer's box
(any language) is pasted in the box.
- Account server: /screen (the viewer page) and /novnc.js (noVNC 1.6.0, MPL-2.0, bundled);
/relay/vnc/<host> takes the browser's WebSocket (account session, or a 10-minute ticket the
app asks for with POST /relay/screen-ticket; owners and admins) and carries it over that
AnyBot's lasting connection (vopen / vdata / vtext / vclose). Both ends of that connection
wait 2 ms instead of 40 ms to read while things move: a request and its answer took up to
160 ms more than needed.
- Phone page: 看 Bot 的電腦 and 接管 open the viewer page (also on the local network: /api/vnc on
the AnyBot's own phone server). This Mac's own screen moved to the ⋯ menu.
- Mac app: 看畫面 opens the viewer in the browser (a screen of a brain: the brain's computer by
ticket; else this computer's box, noVNC straight from it). The in-app picture viewer, the
live JPEG stream, the person's click/move/scroll/key endpoints and the input shell are gone.
- Opening a Mac app uses LaunchServices (`open -a`): agent-desktop's launch waited on the window
through accessibility and failed without 輔助使用 now and then.
Measured on this Mac (made-up account, local relay + headless brain + the real box): viewer
signed in in 0.4–0.7 s, a request and its answer through relay + brain + box 25–58 ms median;
headless Chrome shows the desktop live in /screen. remote_e2e 28/28 ×2, 149 unit tests, relay 11.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-05 15:05:44 +00:00
|
|
|
|
let (name, args) = match v["kind"].as_str().unwrap_or("") {
|
One way to act on a screen: a real click or keystroke, wherever the bot looked
- Acting by an app's number (read_app's e7) is now a real click at that control's spot, the
same path as screenshot coordinates. agent-desktop only reads; its own actions (a second set
with its own key names and failures: no typing in terminals, "/" and "`" failing off the main
thread) are gone, with computer_use_select, background clicks and press_key's app.
- Every action comes back with the screen after it (or, with no picture allowed, the front
app's numbered controls), so the bot no longer spends a step on a screenshot to check.
- Coordinates map without remembering a screenshot: the picture's size depends only on the
screen. The phone's taps go straight to the screen as the person's, in the pixels of the
picture it was sent; they used to borrow the bot's last screenshot scale and landed 1.25x off
on the bots' computer, or failed with "screenshot first".
- Mac typing pastes (⌘V, clipboard put back): with 注音 on, text sent as key events vanished
while return arrived, so commands typed into a terminal ran empty. Bare printing keys
("slash", "r") are typed the same way; keys like "slash" and "grave" have names.
- The bots' Docker computer: one docker exec per step (action, settle, picture), never
`mousemove --sync` (it waits forever when the pointer is already there: a second click on
the same spot hung two minutes), open_app (chromium = the browser browser_* drive, xterm).
Tests: box_screen_is_exact (real Docker: bot and phone coordinates exact, same spot twice in
under 2 s, ASCII + Chinese + named key typed), Calculator by numbers and Terminal typing under
注音 through the signed app, remote_e2e 28/28, Linux build + 151 tests + x11_live.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-05 13:51:19 +00:00
|
|
|
|
"click" => ("computer_use_click", json!({"x": x, "y": y, "button": v["button"].as_str().unwrap_or("left"), "count": v["count"].as_u64().unwrap_or(1)})),
|
|
|
|
|
|
"type" => ("computer_use_typing", json!({"value": v["text"]})),
|
|
|
|
|
|
"key" => ("computer_use_press_key", json!({"key": v["key"]})),
|
|
|
|
|
|
"scroll" => ("computer_use_scroll", json!({"x": x, "y": y, "direction": if down { "down" } else { "up" }, "amount": amount})),
|
|
|
|
|
|
_ => return Resp::error(400, "不認得的操作"),
|
|
|
|
|
|
};
|
|
|
|
|
|
match crate::computer::person_act(name, &args) {
|
|
|
|
|
|
Ok(()) => Resp::json(&json!({"ok": true})),
|
|
|
|
|
|
Err(e) => Resp::error(500, &e),
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
People watch and help on the bots' computer through VNC (noVNC), carried by the account server
The core: the bot works the computer; a person watches it like a colleague, and takes over
when it needs them. VNC is made for that (only what changed, every mouse move and key, touch on
phones), so the pictures sent one by one go, and with them their own input path.
- vnc.rs: a VNC proxy to the box's x11vnc through one docker exec (a Python bridge that ends
with either side). It signs in to the box with the box's own password (its VNC_PASSWORD) and
offers the viewer no password, so the password never leaves the brain. The person's clicks
and keys make the bot's steps wait until 8 s after they stop; text typed in the viewer's box
(any language) is pasted in the box.
- Account server: /screen (the viewer page) and /novnc.js (noVNC 1.6.0, MPL-2.0, bundled);
/relay/vnc/<host> takes the browser's WebSocket (account session, or a 10-minute ticket the
app asks for with POST /relay/screen-ticket; owners and admins) and carries it over that
AnyBot's lasting connection (vopen / vdata / vtext / vclose). Both ends of that connection
wait 2 ms instead of 40 ms to read while things move: a request and its answer took up to
160 ms more than needed.
- Phone page: 看 Bot 的電腦 and 接管 open the viewer page (also on the local network: /api/vnc on
the AnyBot's own phone server). This Mac's own screen moved to the ⋯ menu.
- Mac app: 看畫面 opens the viewer in the browser (a screen of a brain: the brain's computer by
ticket; else this computer's box, noVNC straight from it). The in-app picture viewer, the
live JPEG stream, the person's click/move/scroll/key endpoints and the input shell are gone.
- Opening a Mac app uses LaunchServices (`open -a`): agent-desktop's launch waited on the window
through accessibility and failed without 輔助使用 now and then.
Measured on this Mac (made-up account, local relay + headless brain + the real box): viewer
signed in in 0.4–0.7 s, a request and its answer through relay + brain + box 25–58 ms median;
headless Chrome shows the desktop live in /screen. remote_e2e 28/28 ×2, 149 unit tests, relay 11.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-05 15:05:44 +00:00
|
|
|
|
"mac" => Resp::error(403, "這台 Mac 沒有開放從手機操作"),
|
|
|
|
|
|
_ => Resp::error(404, "沒有這個畫面"),
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// 裝置連結: another AnyBot in this account (e.g. the one on the server) runs a screen tool on
|
|
|
|
|
|
/// this Mac. Only through the relay, and only when this Mac allows it.
|
2026-11-04 12:38:45 +00:00
|
|
|
|
fn device_run(v: &Value, s: &Settings, via_relay: bool, from: &str) -> Resp {
|
2026-11-13 16:40:16 +00:00
|
|
|
|
// Paired with a key: only what its brain signed. The account server in between (or whoever
|
|
|
|
|
|
// got into it) can then neither make a command nor send one twice.
|
|
|
|
|
|
if !s.link_key.is_empty() {
|
|
|
|
|
|
if let Err(why) = run_is_signed(v, s) {
|
|
|
|
|
|
return Resp::error(403, why);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
傳送: 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 02:04:13 +00:00
|
|
|
|
// 傳送: a file or words the person sent to this computer, pushed by its brain. Not an
|
|
|
|
|
|
// operation on this computer (it only lands in 下載/AnyBot), so it doesn't need 裝置連結 —
|
|
|
|
|
|
// but it is taken only from this computer's own brain.
|
|
|
|
|
|
if v["tool"] == crate::drops::PUT {
|
|
|
|
|
|
let brain = if s.brain_id.is_empty() { &s.hands_for } else { &s.brain_id };
|
|
|
|
|
|
let known = if brain.is_empty() { s.device_link } else { from == brain };
|
|
|
|
|
|
if !via_relay || !known {
|
|
|
|
|
|
return Resp::error(403, "這台電腦只收它自己的大腦傳來的東西");
|
|
|
|
|
|
}
|
|
|
|
|
|
return Resp::json(&crate::drops::take_here(v["args"].as_str().unwrap_or("{}")));
|
|
|
|
|
|
}
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
if !via_relay || !s.device_link {
|
|
|
|
|
|
return Resp::error(403, "這台電腦沒有開放給帳號裡的其他 AnyBot 操作");
|
|
|
|
|
|
}
|
2026-11-04 12:38:45 +00:00
|
|
|
|
if !s.hands_for.is_empty() && from != s.hands_for {
|
|
|
|
|
|
return Resp::error(403, &format!("這台電腦只讓大腦「{}」使用", s.hands_for_name));
|
|
|
|
|
|
}
|
2026-11-09 12:37:27 +00:00
|
|
|
|
// Pictures this computer sends now cross a network: WebP, smaller by a quarter (C5).
|
|
|
|
|
|
crate::computer::REMOTE_LANE.with(|c| c.set(true));
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
let tool = v["tool"].as_str().unwrap_or("");
|
|
|
|
|
|
let args = v["args"].as_str().unwrap_or("{}");
|
|
|
|
|
|
let who = v["who"].as_str().unwrap_or("遠端 AnyBot");
|
2026-11-05 07:00:31 +00:00
|
|
|
|
// The brain's model request to a model only this computer's network reaches.
|
|
|
|
|
|
if tool == MODEL_FETCH {
|
|
|
|
|
|
return model_fetch_here(args);
|
|
|
|
|
|
}
|
安全、修正: harden sandboxes, approval gates, vault, relay roles, and fix protocol/UI bugs
- macOS 沙盒與工具 (tools.rs, policy.rs, docindex.rs): block AppleScript raw events and
concatenation outside the sandbox; stop exposing ~/.ssh or localhost sockets in Sealed
mode; deny writes to shell profiles, LaunchAgents and .git/hooks; expand secret-file
ignores and enforce symlink/policy checks across SSH, device and document search.
- 電腦操作與遮罩 (computer.rs, agent.rs, marks.rs, desktop.rs, cloudbox.rs, portal.rs):
forbid clicking or typing into AnyBot's own windows; extend the sensitive-action hard
gate to raw coordinates, Return/Delete submits and remote devices; stop batch steps if
the front app changes; black out secrets on zoom, show, >600-node trees, adjacent OTP
labels, box screenshots and control text lists; preserve non-text Wayland clipboards.
- 保險庫與瀏覽器 (vault.rs, vault_store.rs, browser.rs, botbrowser.rs, web.rs, box/browser):
verify tab host and HTTPS atomically at fill time; taint filled tabs against browser_eval
and PDF export while masking card/CVC values and screenshots; remember sites only on
always-allow; drop --remote-allow-origins=*; gate private URLs and block metadata/Docker
ports, OrbStack 198.18/15 and IPv6 transition ranges.
- 帳號伺服器、同步與傳送 (relay/, remote.rs, mirror_ui.rs, share.rs, drops.rs): isolate
paired hands hosts from brain sync, tickets, pairing and backup overwrites; redact
routine trigger secrets and clear REDACTED when endpoints change; isolate channel and
team-member turns from owner memories, appctl and grants; scrub shared bot exports and
reset grants/routines on import; validate drop IDs and serialize chunk writes.
- 網路與協定穩定性 (httpd.rs, tunnel.rs, vnc.rs, Caddyfile*): fix chunked integer overflow
and CRLF header injection; enforce Origin checks, connection/job caps, 200 MB backup
reads, unique atomic temp files and ASCII hex guards; bound deflate unzip and VNC sniff
buffers; move VNC stdin/text off the tunnel loop.
- 介面、排程、語言與其他修正 (app.rs, i18n.rs, providers.rs, skills.rs, routines.rs,
setup.rs, store.rs, preview.rs, attach.rs, speech.rs, teams.rs, mcp.rs, voice.rs):
wire up the delete-routine confirmation dialog and mirror run-now; preserve unsaved
mirror edits across brief disconnects; give Chinese skills distinct folders and approval
gates; convert parsed tool JSON fields without corrupting code fences, URLs or paths;
fix Hourly DST offsets and time out unattended routine approvals; lock --install-skill,
cap docx/xlsx unzip sizes, isolate test env keys, and tighten local file permissions.
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-12 06:34:10 +00:00
|
|
|
|
if !crate::policy::read().local.allows() {
|
|
|
|
|
|
return Resp::json(&json!({"text": "這台電腦已被系統管理員政策鎖定,不允許本機操作。", "ok": false}));
|
|
|
|
|
|
}
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
if crate::computer::is_computer_tool(tool) {
|
|
|
|
|
|
let (text, ok, img) = crate::computer::run_by(tool, args, who);
|
|
|
|
|
|
return Resp::json(&json!({"text": text, "ok": ok, "image": img}));
|
|
|
|
|
|
}
|
2026-11-04 09:46:43 +00:00
|
|
|
|
// The AnyBot browser here (its logins are this computer's).
|
|
|
|
|
|
if crate::web::is_web_tool(tool) && tool != "web_fetch" {
|
|
|
|
|
|
let mut v: Value = serde_json::from_str(args).unwrap_or(json!({}));
|
|
|
|
|
|
if let Some(o) = v.as_object_mut() {
|
|
|
|
|
|
o.remove("computer");
|
|
|
|
|
|
}
|
2026-11-11 08:19:06 +00:00
|
|
|
|
if tool == "browser_upload" {
|
|
|
|
|
|
let p = crate::tools::expand_home(v["path"].as_str().unwrap_or(""));
|
|
|
|
|
|
let real = std::fs::canonicalize(&p).unwrap_or_else(|_| p.clone());
|
|
|
|
|
|
if crate::tools::is_ignored(&p) || crate::tools::is_ignored(&real) {
|
|
|
|
|
|
return Resp::json(&json!({"text": "這個檔案是機密的,不能上傳到網頁。", "ok": false}));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-11-04 09:46:43 +00:00
|
|
|
|
let (text, ok, img) = crate::web::run_full(tool, &v.to_string(), &std::sync::atomic::AtomicBool::new(false));
|
|
|
|
|
|
return Resp::json(&json!({"text": text, "ok": ok, "image": img}));
|
|
|
|
|
|
}
|
2026-11-12 14:53:30 +00:00
|
|
|
|
// 保險庫填入 on this computer's browser: the brain planned it, the person approved it; this
|
|
|
|
|
|
// one command carries that entry's secret (vault::REMOTE_TOOL); the page's host guard holds.
|
|
|
|
|
|
if tool == crate::vault::REMOTE_TOOL {
|
|
|
|
|
|
return Resp::json(&crate::vault::run_remote(args));
|
|
|
|
|
|
}
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
if crate::macapps::is_mac_tool(tool) && cfg!(target_os = "macos") {
|
|
|
|
|
|
let (text, ok) = crate::macapps::run(tool, args);
|
|
|
|
|
|
return Resp::json(&json!({"text": text, "ok": ok}));
|
|
|
|
|
|
}
|
Real-use fixes: the person sees the screens the bot shows, files reach the phone, no blank-tab loops
From real runs on the cloud brain with the person's Mac (Threads patrol, a post draft, "show me my
screen"):
- computer_use_show: a plain picture of any computer's screen goes into the chat (the bot sees it
too). The bot used to describe a screenshot in words and fail to send it.
- The phone shows the bot's attachments: pictures in place, other files download on a tap (api/file,
only from the chats' file folder). It showed nothing for the bot and names only for the person.
- send_file works from the person's other computers (fetch_file over the relay, 20 MB, secrets stay).
- The same call with the same answer again and again is warned the 3rd time and stopped from the
4th (a blank tab was read 11 times, then the bot said Threads was logged out without opening it);
a blank tab says so; checking a login means opening the site.
- Screenshot lists: a nameless row around a named button isn't numbered, a nameless row takes the
words inside it, empty spacer rows aren't numbered (System Settings: 63 numbers -> 33, all named).
- Writing "in my voice" reads the person's own recent posts first.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha2RVfSYmrhqNnqx9Z4
2026-11-06 11:37:45 +00:00
|
|
|
|
// send_file from this computer: the file itself goes to the brain, which puts it in the chat.
|
|
|
|
|
|
if tool == FETCH_FILE {
|
|
|
|
|
|
return fetch_file_here(args);
|
|
|
|
|
|
}
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
if matches!(tool, "shell" | "read_file" | "edit_file" | "list_dir" | "search" | "read_terminal" | "write_terminal") {
|
2026-11-05 13:28:32 +00:00
|
|
|
|
// The brain passes the bot's work folder inside the tool's args (empty = this home).
|
繁體中文、換電腦: what a model writes is put into Traditional Chinese whatever the setting's system; a work folder from another computer lands under this home
- 繁體中文: converted at the one place every model call comes back (providers::run_step),
decided from the request itself: the setting is 繁體中文, or it follows the system and
the person writes Traditional. It used to be on only for the explicit setting, so a
brain on an English server with 跟著系統 never converted, whatever the instructions said.
Not when another language is chosen, nor when the latest message asks for Simplified.
- Converted: the reply, the thinking, and steps whose words are for the person (question
card, card, page, memory, routine). Left as written: code blocks and `inline code`, a
line of Japanese, file names, commands, searches, recipients.
- Taiwan wording after the characters: about 55 one-meaning computer terms (網絡→網路,
文件夾→資料夾, 默認→預設…), and zhconv's OpenCC tables on (设置里的 → 設定裡的).
- The reply instruction says it too: no Simplified characters, no mainland wording.
- 換電腦: a bot's work folder chosen on one computer (/Users/daniel on a Mac) no longer
breaks every file and command step on another (Linux, another user). It is sent as ~/…
with the folder as chosen alongside; the receiving computer uses the folder if it is
there, else the same place under its own home, else its home.
- FEATURES.md.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3QxSfoydRPM9mjj6d
2026-11-12 02:29:02 +00:00
|
|
|
|
// (A folder chosen on another computer may not be here: then its like under this
|
|
|
|
|
|
// home, or this home. The tools never fail for the folder alone.)
|
|
|
|
|
|
let workdir = crate::tools::workdir_of_args(&crate::tools::args_of(args));
|
2026-11-13 16:40:16 +00:00
|
|
|
|
// What is refused everywhere is refused here too, whoever asks: the always-denied
|
|
|
|
|
|
// commands and this computer's private files (keys, AnyBot's own data). The brain
|
|
|
|
|
|
// decides what needs the person's yes; this is the floor under it, should a request
|
|
|
|
|
|
// ever come from somewhere that isn't the brain.
|
|
|
|
|
|
if let crate::tools::Decision::Deny(why) = crate::tools::decide(tool, args, &workdir, &[]) {
|
|
|
|
|
|
return Resp::json(&json!({"text": format!("被安全規則擋下:{why}"), "ok": false}));
|
|
|
|
|
|
}
|
2026-11-05 13:28:32 +00:00
|
|
|
|
let t = crate::tools::Target { name: crate::model::THIS_COMPUTER_NAME.into(), place: crate::tools::Place::Local { workdir } };
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
let ids = crate::tools::RunIds { conversation: "device".into(), request: httpd::random_hex(6) };
|
|
|
|
|
|
let (text, ok) = crate::tools::run_on(tool, args, &t, &std::sync::atomic::AtomicBool::new(false), &ids);
|
|
|
|
|
|
return Resp::json(&json!({"text": text, "ok": ok}));
|
|
|
|
|
|
}
|
|
|
|
|
|
Resp::error(400, "這個工具不能遠端使用")
|
|
|
|
|
|
}
|
|
|
|
|
|
|
Real-use fixes: the person sees the screens the bot shows, files reach the phone, no blank-tab loops
From real runs on the cloud brain with the person's Mac (Threads patrol, a post draft, "show me my
screen"):
- computer_use_show: a plain picture of any computer's screen goes into the chat (the bot sees it
too). The bot used to describe a screenshot in words and fail to send it.
- The phone shows the bot's attachments: pictures in place, other files download on a tap (api/file,
only from the chats' file folder). It showed nothing for the bot and names only for the person.
- send_file works from the person's other computers (fetch_file over the relay, 20 MB, secrets stay).
- The same call with the same answer again and again is warned the 3rd time and stopped from the
4th (a blank tab was read 11 times, then the bot said Threads was logged out without opening it);
a blank tab says so; checking a login means opening the site.
- Screenshot lists: a nameless row around a named button isn't numbered, a nameless row takes the
words inside it, empty spacer rows aren't numbered (System Settings: 63 numbers -> 33, all named).
- Writing "in my voice" reads the person's own recent posts first.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha2RVfSYmrhqNnqx9Z4
2026-11-06 11:37:45 +00:00
|
|
|
|
/// A file on this computer, for the brain's send_file (the brain has no other way to it).
|
|
|
|
|
|
pub const FETCH_FILE: &str = "fetch_file";
|
|
|
|
|
|
/// Largest file sent that way: the relay carries 30 MB, and base64 adds a third.
|
|
|
|
|
|
const FETCH_FILE_MAX: u64 = 20 * 1024 * 1024;
|
|
|
|
|
|
|
|
|
|
|
|
fn fetch_file_here(args: &str) -> Resp {
|
|
|
|
|
|
let v = crate::tools::args_of(args);
|
|
|
|
|
|
let path = v["path"].as_str().unwrap_or("").trim().to_string();
|
繁體中文、換電腦: what a model writes is put into Traditional Chinese whatever the setting's system; a work folder from another computer lands under this home
- 繁體中文: converted at the one place every model call comes back (providers::run_step),
decided from the request itself: the setting is 繁體中文, or it follows the system and
the person writes Traditional. It used to be on only for the explicit setting, so a
brain on an English server with 跟著系統 never converted, whatever the instructions said.
Not when another language is chosen, nor when the latest message asks for Simplified.
- Converted: the reply, the thinking, and steps whose words are for the person (question
card, card, page, memory, routine). Left as written: code blocks and `inline code`, a
line of Japanese, file names, commands, searches, recipients.
- Taiwan wording after the characters: about 55 one-meaning computer terms (網絡→網路,
文件夾→資料夾, 默認→預設…), and zhconv's OpenCC tables on (设置里的 → 設定裡的).
- The reply instruction says it too: no Simplified characters, no mainland wording.
- 換電腦: a bot's work folder chosen on one computer (/Users/daniel on a Mac) no longer
breaks every file and command step on another (Linux, another user). It is sent as ~/…
with the folder as chosen alongside; the receiving computer uses the folder if it is
there, else the same place under its own home, else its home.
- FEATURES.md.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3QxSfoydRPM9mjj6d
2026-11-12 02:29:02 +00:00
|
|
|
|
let base = crate::tools::workdir_of_args(&v);
|
Real-use fixes: the person sees the screens the bot shows, files reach the phone, no blank-tab loops
From real runs on the cloud brain with the person's Mac (Threads patrol, a post draft, "show me my
screen"):
- computer_use_show: a plain picture of any computer's screen goes into the chat (the bot sees it
too). The bot used to describe a screenshot in words and fail to send it.
- The phone shows the bot's attachments: pictures in place, other files download on a tap (api/file,
only from the chats' file folder). It showed nothing for the bot and names only for the person.
- send_file works from the person's other computers (fetch_file over the relay, 20 MB, secrets stay).
- The same call with the same answer again and again is warned the 3rd time and stopped from the
4th (a blank tab was read 11 times, then the bot said Threads was logged out without opening it);
a blank tab says so; checking a login means opening the site.
- Screenshot lists: a nameless row around a named button isn't numbered, a nameless row takes the
words inside it, empty spacer rows aren't numbered (System Settings: 63 numbers -> 33, all named).
- Writing "in my voice" reads the person's own recent posts first.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha2RVfSYmrhqNnqx9Z4
2026-11-06 11:37:45 +00:00
|
|
|
|
let full = crate::tools::resolve(&base, &path);
|
安全、修正: harden sandboxes, approval gates, vault, relay roles, and fix protocol/UI bugs
- macOS 沙盒與工具 (tools.rs, policy.rs, docindex.rs): block AppleScript raw events and
concatenation outside the sandbox; stop exposing ~/.ssh or localhost sockets in Sealed
mode; deny writes to shell profiles, LaunchAgents and .git/hooks; expand secret-file
ignores and enforce symlink/policy checks across SSH, device and document search.
- 電腦操作與遮罩 (computer.rs, agent.rs, marks.rs, desktop.rs, cloudbox.rs, portal.rs):
forbid clicking or typing into AnyBot's own windows; extend the sensitive-action hard
gate to raw coordinates, Return/Delete submits and remote devices; stop batch steps if
the front app changes; black out secrets on zoom, show, >600-node trees, adjacent OTP
labels, box screenshots and control text lists; preserve non-text Wayland clipboards.
- 保險庫與瀏覽器 (vault.rs, vault_store.rs, browser.rs, botbrowser.rs, web.rs, box/browser):
verify tab host and HTTPS atomically at fill time; taint filled tabs against browser_eval
and PDF export while masking card/CVC values and screenshots; remember sites only on
always-allow; drop --remote-allow-origins=*; gate private URLs and block metadata/Docker
ports, OrbStack 198.18/15 and IPv6 transition ranges.
- 帳號伺服器、同步與傳送 (relay/, remote.rs, mirror_ui.rs, share.rs, drops.rs): isolate
paired hands hosts from brain sync, tickets, pairing and backup overwrites; redact
routine trigger secrets and clear REDACTED when endpoints change; isolate channel and
team-member turns from owner memories, appctl and grants; scrub shared bot exports and
reset grants/routines on import; validate drop IDs and serialize chunk writes.
- 網路與協定穩定性 (httpd.rs, tunnel.rs, vnc.rs, Caddyfile*): fix chunked integer overflow
and CRLF header injection; enforce Origin checks, connection/job caps, 200 MB backup
reads, unique atomic temp files and ASCII hex guards; bound deflate unzip and VNC sniff
buffers; move VNC stdin/text off the tunnel loop.
- 介面、排程、語言與其他修正 (app.rs, i18n.rs, providers.rs, skills.rs, routines.rs,
setup.rs, store.rs, preview.rs, attach.rs, speech.rs, teams.rs, mcp.rs, voice.rs):
wire up the delete-routine confirmation dialog and mirror run-now; preserve unsaved
mirror edits across brief disconnects; give Chinese skills distinct folders and approval
gates; convert parsed tool JSON fields without corrupting code fences, URLs or paths;
fix Hourly DST offsets and time out unattended routine approvals; lock --install-skill,
cap docx/xlsx unzip sizes, isolate test env keys, and tighten local file permissions.
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-12 06:34:10 +00:00
|
|
|
|
let real = std::fs::canonicalize(&full).unwrap_or_else(|_| full.clone());
|
|
|
|
|
|
// Same rule as reading a file (including symlink targets): keys, the app's own data and other secrets never leave.
|
|
|
|
|
|
if crate::tools::is_ignored(&full) || crate::tools::is_ignored(&real) || crate::tools::is_ignored(std::path::Path::new(&path)) {
|
Real-use fixes: the person sees the screens the bot shows, files reach the phone, no blank-tab loops
From real runs on the cloud brain with the person's Mac (Threads patrol, a post draft, "show me my
screen"):
- computer_use_show: a plain picture of any computer's screen goes into the chat (the bot sees it
too). The bot used to describe a screenshot in words and fail to send it.
- The phone shows the bot's attachments: pictures in place, other files download on a tap (api/file,
only from the chats' file folder). It showed nothing for the bot and names only for the person.
- send_file works from the person's other computers (fetch_file over the relay, 20 MB, secrets stay).
- The same call with the same answer again and again is warned the 3rd time and stopped from the
4th (a blank tab was read 11 times, then the bot said Threads was logged out without opening it);
a blank tab says so; checking a login means opening the site.
- Screenshot lists: a nameless row around a named button isn't numbered, a nameless row takes the
words inside it, empty spacer rows aren't numbered (System Settings: 63 numbers -> 33, all named).
- Writing "in my voice" reads the person's own recent posts first.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha2RVfSYmrhqNnqx9Z4
2026-11-06 11:37:45 +00:00
|
|
|
|
return Resp::json(&json!({"text": "這個檔案是機密的,不能傳到聊天。", "ok": false}));
|
|
|
|
|
|
}
|
|
|
|
|
|
match std::fs::metadata(&full) {
|
|
|
|
|
|
Ok(m) if m.is_dir() => Resp::json(&json!({"text": format!("「{path}」是資料夾,請先壓縮成一個檔案。"), "ok": false})),
|
|
|
|
|
|
Ok(m) if m.len() > FETCH_FILE_MAX => Resp::json(&json!({"text": format!("「{path}」太大了(最多 20 MB)。"), "ok": false})),
|
|
|
|
|
|
Ok(_) => match std::fs::read(&full) {
|
|
|
|
|
|
Ok(b) => {
|
|
|
|
|
|
use base64::Engine;
|
|
|
|
|
|
let name = full.file_name().map(|n| n.to_string_lossy().to_string()).unwrap_or_else(|| "檔案".into());
|
|
|
|
|
|
Resp::json(&json!({"ok": true, "text": "", "name": name, "data": base64::engine::general_purpose::STANDARD.encode(&b)}))
|
|
|
|
|
|
}
|
|
|
|
|
|
Err(e) => Resp::json(&json!({"text": format!("讀不到「{path}」:{e}"), "ok": false})),
|
|
|
|
|
|
},
|
|
|
|
|
|
Err(_) => Resp::json(&json!({"text": format!("這台電腦上找不到「{path}」。"), "ok": false})),
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-11-05 07:00:31 +00:00
|
|
|
|
// ---------- a model on the person's network, for a brain on a server ----------
|
|
|
|
|
|
// A brain in the cloud can't reach a model at a private address (a Qwen server at work, Ollama at
|
|
|
|
|
|
// home). Its hands can: the brain hands them the request and gets the whole answer back.
|
|
|
|
|
|
|
|
|
|
|
|
const MODEL_FETCH: &str = "model_fetch";
|
|
|
|
|
|
|
|
|
|
|
|
/// Private, link-local or loopback address (by name: localhost and *.local).
|
|
|
|
|
|
fn private_host(host: &str) -> bool {
|
|
|
|
|
|
let h = host.trim_matches(['[', ']']);
|
|
|
|
|
|
if h == "localhost" || h.ends_with(".local") {
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
match h.parse::<std::net::IpAddr>() {
|
2026-11-05 07:48:20 +00:00
|
|
|
|
// Not link-local: a cloud VM's metadata service (169.254.169.254) must never be
|
|
|
|
|
|
// reachable through the hands, only real model servers on the person's network.
|
|
|
|
|
|
Ok(std::net::IpAddr::V4(a)) => (a.is_private() || a.is_loopback()) && !a.is_link_local(),
|
|
|
|
|
|
Ok(std::net::IpAddr::V6(a)) => (a.is_loopback() || (a.segments()[0] & 0xfe00) == 0xfc00) && !a.is_unicast_link_local(),
|
2026-11-05 07:00:31 +00:00
|
|
|
|
Err(_) => false,
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn host_port(url: &str) -> Option<(String, u16)> {
|
|
|
|
|
|
let (scheme, rest) = url.split_once("://")?;
|
|
|
|
|
|
let auth = rest.split('/').next()?;
|
|
|
|
|
|
let auth = auth.rsplit('@').next()?;
|
|
|
|
|
|
let (h, p) = match auth.rsplit_once(':') {
|
|
|
|
|
|
Some((h, p)) if !h.ends_with(']') || auth.starts_with('[') => (h.to_string(), p.parse().ok()?),
|
|
|
|
|
|
_ => (auth.to_string(), if scheme == "https" { 443 } else { 80 }),
|
|
|
|
|
|
};
|
|
|
|
|
|
Some((h, p))
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// The hands to send a model request through: the model is at a private address this brain
|
|
|
|
|
|
/// can't open a connection to, and the person's computer lends this brain its hands.
|
|
|
|
|
|
pub fn model_hands_for(url: &str) -> Option<String> {
|
|
|
|
|
|
let s = hub().settings();
|
2026-11-05 08:47:28 +00:00
|
|
|
|
// The person's own computer (the one they type on) is the one on their network; the first
|
|
|
|
|
|
// hands by id was a desktop in the server room that can't reach a model at their office.
|
|
|
|
|
|
let hands = my_hands(&s.host_id);
|
|
|
|
|
|
let person = person_host();
|
|
|
|
|
|
let hand = hands.iter().find(|h| **h == person).or_else(|| hands.first()).cloned()?;
|
2026-11-05 07:00:31 +00:00
|
|
|
|
let (h, p) = host_port(url)?;
|
|
|
|
|
|
if !private_host(&h) || h == "localhost" || h.starts_with("127.") {
|
|
|
|
|
|
return None;
|
|
|
|
|
|
}
|
|
|
|
|
|
static SEEN: Mutex<Option<HashMap<String, (bool, std::time::Instant)>>> = Mutex::new(None);
|
|
|
|
|
|
let key = format!("{h}:{p}");
|
|
|
|
|
|
if let Some((reach, at)) = SEEN.lock().unwrap().get_or_insert_with(HashMap::new).get(&key) {
|
|
|
|
|
|
if at.elapsed().as_secs() < 300 {
|
|
|
|
|
|
return if *reach { None } else { Some(hand) };
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
use std::net::ToSocketAddrs;
|
|
|
|
|
|
let reach = (h.as_str(), p).to_socket_addrs().ok().and_then(|mut a| a.next()).map(|a| std::net::TcpStream::connect_timeout(&a, std::time::Duration::from_millis(1500)).is_ok()).unwrap_or(false);
|
|
|
|
|
|
SEEN.lock().unwrap().get_or_insert_with(HashMap::new).insert(key, (reach, std::time::Instant::now()));
|
|
|
|
|
|
if reach { None } else { Some(hand) }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Send a model request (POST, JSON) through the hands; gives back its status and whole body.
|
|
|
|
|
|
pub fn model_via_hands(hand: &str, url: &str, headers: &[(String, String)], body: &str) -> Result<(u16, Vec<u8>), String> {
|
|
|
|
|
|
let args = json!({"url": url, "headers": headers, "body": body}).to_string();
|
2026-11-13 16:40:16 +00:00
|
|
|
|
let req = signed_run(&hub().settings(), hand, MODEL_FETCH, &args, "大腦").to_string();
|
2026-11-05 07:00:31 +00:00
|
|
|
|
let name = peer_name(hand);
|
2026-11-05 08:47:28 +00:00
|
|
|
|
let whom = if name.is_empty() { "使用者的電腦".to_string() } else { format!("「{name}」") };
|
2026-11-05 07:00:31 +00:00
|
|
|
|
let r = crate::tunnel::call(hand, "POST", "/api/device/run", &[], req.as_bytes(), 600).ok_or_else(|| format!("模型在只有{whom}連得到的網路上,但大腦現在和帳號伺服器沒有連線"))?;
|
|
|
|
|
|
let a = r.map_err(|e| format!("透過{whom}連模型失敗:{e}"))?;
|
|
|
|
|
|
let v = answer_value(a.status, &a.body, &whom)?;
|
|
|
|
|
|
if let Some(e) = v["error"].as_str() {
|
|
|
|
|
|
return Err(format!("{whom}也連不到模型:{e}"));
|
|
|
|
|
|
}
|
|
|
|
|
|
Ok((v["status"].as_u64().unwrap_or(502) as u16, v["text"].as_str().unwrap_or("").as_bytes().to_vec()))
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-11-11 08:19:06 +00:00
|
|
|
|
fn lan_only_addr(ip: std::net::IpAddr) -> bool {
|
|
|
|
|
|
match ip {
|
|
|
|
|
|
std::net::IpAddr::V4(a) => a.is_private() && !a.is_loopback() && !a.is_link_local(),
|
|
|
|
|
|
std::net::IpAddr::V6(a) => match a.to_ipv4_mapped() {
|
|
|
|
|
|
Some(v4) => lan_only_addr(std::net::IpAddr::V4(v4)),
|
|
|
|
|
|
None => (a.segments()[0] & 0xfe00) == 0xfc00 && !a.is_loopback() && !a.is_unicast_link_local(),
|
|
|
|
|
|
},
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// On the hands: make the brain's model request, only to a LAN address on this computer's network
|
|
|
|
|
|
/// (never this computer's own loopback or a cloud VM's link-local metadata).
|
2026-11-05 07:00:31 +00:00
|
|
|
|
fn model_fetch_here(args: &str) -> Resp {
|
2026-11-11 08:19:06 +00:00
|
|
|
|
use std::net::ToSocketAddrs;
|
2026-11-05 07:00:31 +00:00
|
|
|
|
let v: Value = serde_json::from_str(args).unwrap_or(Value::Null);
|
|
|
|
|
|
let url = v["url"].as_str().unwrap_or("");
|
2026-11-11 08:19:06 +00:00
|
|
|
|
if !(url.starts_with("http://") || url.starts_with("https://")) {
|
|
|
|
|
|
return Resp::error(403, "只支援 http:// 或 https://");
|
|
|
|
|
|
}
|
|
|
|
|
|
let Some((h, p)) = host_port(url) else {
|
|
|
|
|
|
return Resp::error(403, "只幫大腦連這台電腦網路裡的模型");
|
|
|
|
|
|
};
|
|
|
|
|
|
let h_clean = h.trim_matches(['[', ']']).trim_end_matches('.').to_ascii_lowercase();
|
|
|
|
|
|
if !private_host(&h) || h_clean == "localhost" || h_clean.ends_with(".localhost") || h_clean.starts_with("127.") || h_clean == "::1" {
|
2026-11-05 07:00:31 +00:00
|
|
|
|
return Resp::error(403, "只幫大腦連這台電腦網路裡的模型");
|
|
|
|
|
|
}
|
2026-11-11 08:19:06 +00:00
|
|
|
|
if let Ok(addrs) = (h.trim_matches(['[', ']']), p).to_socket_addrs() {
|
|
|
|
|
|
let list: Vec<_> = addrs.collect();
|
|
|
|
|
|
if list.is_empty() || list.iter().any(|a| !lan_only_addr(a.ip())) {
|
|
|
|
|
|
return Resp::error(403, "只幫大腦連這台電腦網路裡的模型");
|
|
|
|
|
|
}
|
|
|
|
|
|
} else if h.trim_matches(['[', ']']).parse::<std::net::IpAddr>().map(|ip| !lan_only_addr(ip)).unwrap_or(false) {
|
|
|
|
|
|
return Resp::error(403, "只幫大腦連這台電腦網路裡的模型");
|
|
|
|
|
|
}
|
|
|
|
|
|
const ALLOWED_HEADERS: [&str; 7] = ["authorization", "x-api-key", "anthropic-version", "anthropic-beta", "x-title", "x-opencode-session", "accept"];
|
2026-11-05 07:00:31 +00:00
|
|
|
|
let mut r = agent(600).post(url).header("Content-Type", "application/json");
|
|
|
|
|
|
for h in v["headers"].as_array().into_iter().flatten() {
|
|
|
|
|
|
if let (Some(k), Some(val)) = (h[0].as_str(), h[1].as_str()) {
|
2026-11-11 08:19:06 +00:00
|
|
|
|
let kl = k.trim().to_ascii_lowercase();
|
|
|
|
|
|
if ALLOWED_HEADERS.contains(&kl.as_str()) && !val.chars().any(|c| c == '\r' || c == '\n' || c == '\0') {
|
|
|
|
|
|
r = r.header(k.trim(), val);
|
|
|
|
|
|
}
|
2026-11-05 07:00:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
match r.config().http_status_as_error(false).build().send(v["body"].as_str().unwrap_or("").as_bytes()) {
|
|
|
|
|
|
Ok(mut resp) => {
|
|
|
|
|
|
let status = resp.status().as_u16();
|
|
|
|
|
|
let text = resp.body_mut().with_config().limit(50 * 1024 * 1024).read_to_string().unwrap_or_default();
|
|
|
|
|
|
Resp::json(&json!({"status": status, "text": text}))
|
|
|
|
|
|
}
|
|
|
|
|
|
Err(e) => Resp::json(&json!({"error": why_unreachable(&e)})),
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
// ---------- the local server ----------
|
|
|
|
|
|
|
|
|
|
|
|
static LAN_GEN: AtomicU64 = AtomicU64::new(0);
|
|
|
|
|
|
static LAN_BOUND: Mutex<Option<u16>> = Mutex::new(None);
|
|
|
|
|
|
|
|
|
|
|
|
pub fn lan_port() -> Option<u16> {
|
|
|
|
|
|
*LAN_BOUND.lock().unwrap()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Start (or stop) answering phones on the local network.
|
|
|
|
|
|
pub fn set_lan(on: bool) -> Result<u16, String> {
|
|
|
|
|
|
let gen = LAN_GEN.fetch_add(1, Ordering::SeqCst) + 1;
|
|
|
|
|
|
*LAN_BOUND.lock().unwrap() = None;
|
|
|
|
|
|
if !on {
|
|
|
|
|
|
return Ok(0);
|
|
|
|
|
|
}
|
|
|
|
|
|
let port_env: Option<u16> = std::env::var("ANYBOT_PHONE_PORT").ok().and_then(|p| p.parse().ok());
|
|
|
|
|
|
let start = port_env.unwrap_or(LAN_PORT);
|
|
|
|
|
|
// The old listener notices the new generation within 50 ms; give it the port back.
|
|
|
|
|
|
let listener = (0..40)
|
|
|
|
|
|
.find_map(|_| {
|
|
|
|
|
|
let l = (start..start + 10).find_map(|p| std::net::TcpListener::bind(("0.0.0.0", p)).ok());
|
|
|
|
|
|
if l.is_none() {
|
|
|
|
|
|
std::thread::sleep(Duration::from_millis(60));
|
|
|
|
|
|
}
|
|
|
|
|
|
l
|
|
|
|
|
|
})
|
|
|
|
|
|
.ok_or("找不到可用的連接埠")?;
|
|
|
|
|
|
let port = listener.local_addr().map_err(|e| e.to_string())?.port();
|
|
|
|
|
|
*LAN_BOUND.lock().unwrap() = Some(port);
|
2026-11-13 16:40:16 +00:00
|
|
|
|
let alive: Arc<dyn Fn() -> bool + Send + Sync> = Arc::new(move || LAN_GEN.load(Ordering::SeqCst) == gen);
|
|
|
|
|
|
// HTTPS on that port (lantls), with the plain server behind it on this machine only. If the
|
|
|
|
|
|
// certificate can't be made, it is the plain server as before — and 設定 says so.
|
|
|
|
|
|
*LAN_CERT.lock().unwrap() = None;
|
|
|
|
|
|
let mut served = Some(listener);
|
|
|
|
|
|
if let Some((behind, cfg, print)) = lan_tls(port) {
|
|
|
|
|
|
if let (Some(l), Ok(to)) = (served.take(), behind.local_addr()) {
|
|
|
|
|
|
*LAN_CERT.lock().unwrap() = Some(print);
|
|
|
|
|
|
let alive2 = alive.clone();
|
|
|
|
|
|
std::thread::spawn(move || crate::lantls::front(l, to, cfg, alive2));
|
|
|
|
|
|
served = Some(behind);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if let Some(l) = served {
|
|
|
|
|
|
std::thread::spawn(move || httpd::serve_upgrade(l, Arc::new(|r| handle(r, false)), Some(Arc::new(move |r, c| lan_vnc(r, c, gen))), alive));
|
|
|
|
|
|
}
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
Ok(port)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-11-13 16:40:16 +00:00
|
|
|
|
static LAN_CERT: Mutex<Option<String>> = Mutex::new(None);
|
|
|
|
|
|
|
|
|
|
|
|
/// The fingerprint of the certificate 區網 HTTPS answers with (None: it is plain HTTP).
|
|
|
|
|
|
pub fn lan_fingerprint() -> Option<String> {
|
|
|
|
|
|
LAN_CERT.lock().unwrap().clone()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// What 區網 HTTPS needs: the listener behind, the TLS setup and the certificate's fingerprint.
|
|
|
|
|
|
#[cfg(not(test))]
|
|
|
|
|
|
fn lan_tls(port: u16) -> Option<(std::net::TcpListener, Arc<rustls::ServerConfig>, String)> {
|
|
|
|
|
|
let dir = crate::model::State::path().parent()?.to_path_buf();
|
|
|
|
|
|
let hosts: Vec<String> = addresses(port).iter().filter_map(|a| host_port(a).map(|(h, _)| h)).collect();
|
|
|
|
|
|
let (cert, key) = crate::lantls::identity(&dir, &hosts).map_err(|e| eprintln!("區網 HTTPS 的憑證做不出來:{e}")).ok()?;
|
|
|
|
|
|
let print = crate::lantls::fingerprint(&cert);
|
|
|
|
|
|
let cfg = crate::lantls::config(cert, key).ok()?;
|
|
|
|
|
|
let behind = std::net::TcpListener::bind("127.0.0.1:0").ok()?;
|
|
|
|
|
|
Some((behind, cfg, print))
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// (Tests never write the data folder.)
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
|
|
fn lan_tls(_: u16) -> Option<(std::net::TcpListener, Arc<rustls::ServerConfig>, String)> {
|
|
|
|
|
|
None
|
|
|
|
|
|
}
|
|
|
|
|
|
|
People watch and help on the bots' computer through VNC (noVNC), carried by the account server
The core: the bot works the computer; a person watches it like a colleague, and takes over
when it needs them. VNC is made for that (only what changed, every mouse move and key, touch on
phones), so the pictures sent one by one go, and with them their own input path.
- vnc.rs: a VNC proxy to the box's x11vnc through one docker exec (a Python bridge that ends
with either side). It signs in to the box with the box's own password (its VNC_PASSWORD) and
offers the viewer no password, so the password never leaves the brain. The person's clicks
and keys make the bot's steps wait until 8 s after they stop; text typed in the viewer's box
(any language) is pasted in the box.
- Account server: /screen (the viewer page) and /novnc.js (noVNC 1.6.0, MPL-2.0, bundled);
/relay/vnc/<host> takes the browser's WebSocket (account session, or a 10-minute ticket the
app asks for with POST /relay/screen-ticket; owners and admins) and carries it over that
AnyBot's lasting connection (vopen / vdata / vtext / vclose). Both ends of that connection
wait 2 ms instead of 40 ms to read while things move: a request and its answer took up to
160 ms more than needed.
- Phone page: 看 Bot 的電腦 and 接管 open the viewer page (also on the local network: /api/vnc on
the AnyBot's own phone server). This Mac's own screen moved to the ⋯ menu.
- Mac app: 看畫面 opens the viewer in the browser (a screen of a brain: the brain's computer by
ticket; else this computer's box, noVNC straight from it). The in-app picture viewer, the
live JPEG stream, the person's click/move/scroll/key endpoints and the input shell are gone.
- Opening a Mac app uses LaunchServices (`open -a`): agent-desktop's launch waited on the window
through accessibility and failed without 輔助使用 now and then.
Measured on this Mac (made-up account, local relay + headless brain + the real box): viewer
signed in in 0.4–0.7 s, a request and its answer through relay + brain + box 25–58 ms median;
headless Chrome shows the desktop live in /screen. remote_e2e 28/28 ×2, 149 unit tests, relay 11.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-05 15:05:44 +00:00
|
|
|
|
/// The phone page on the local network watching the bots' computer: /api/vnc, signed in with
|
|
|
|
|
|
/// the phone's password like every other request here; the VNC stream goes straight to the box.
|
2026-11-13 16:40:16 +00:00
|
|
|
|
/// Tickets for the screen's connection on 區網: (the login that asked, when).
|
|
|
|
|
|
fn lan_tickets() -> &'static Mutex<HashMap<String, (String, Instant)>> {
|
|
|
|
|
|
static T: std::sync::OnceLock<Mutex<HashMap<String, (String, Instant)>>> = std::sync::OnceLock::new();
|
|
|
|
|
|
T.get_or_init(Default::default)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
安全、修正: harden sandboxes, approval gates, vault, relay roles, and fix protocol/UI bugs
- macOS 沙盒與工具 (tools.rs, policy.rs, docindex.rs): block AppleScript raw events and
concatenation outside the sandbox; stop exposing ~/.ssh or localhost sockets in Sealed
mode; deny writes to shell profiles, LaunchAgents and .git/hooks; expand secret-file
ignores and enforce symlink/policy checks across SSH, device and document search.
- 電腦操作與遮罩 (computer.rs, agent.rs, marks.rs, desktop.rs, cloudbox.rs, portal.rs):
forbid clicking or typing into AnyBot's own windows; extend the sensitive-action hard
gate to raw coordinates, Return/Delete submits and remote devices; stop batch steps if
the front app changes; black out secrets on zoom, show, >600-node trees, adjacent OTP
labels, box screenshots and control text lists; preserve non-text Wayland clipboards.
- 保險庫與瀏覽器 (vault.rs, vault_store.rs, browser.rs, botbrowser.rs, web.rs, box/browser):
verify tab host and HTTPS atomically at fill time; taint filled tabs against browser_eval
and PDF export while masking card/CVC values and screenshots; remember sites only on
always-allow; drop --remote-allow-origins=*; gate private URLs and block metadata/Docker
ports, OrbStack 198.18/15 and IPv6 transition ranges.
- 帳號伺服器、同步與傳送 (relay/, remote.rs, mirror_ui.rs, share.rs, drops.rs): isolate
paired hands hosts from brain sync, tickets, pairing and backup overwrites; redact
routine trigger secrets and clear REDACTED when endpoints change; isolate channel and
team-member turns from owner memories, appctl and grants; scrub shared bot exports and
reset grants/routines on import; validate drop IDs and serialize chunk writes.
- 網路與協定穩定性 (httpd.rs, tunnel.rs, vnc.rs, Caddyfile*): fix chunked integer overflow
and CRLF header injection; enforce Origin checks, connection/job caps, 200 MB backup
reads, unique atomic temp files and ASCII hex guards; bound deflate unzip and VNC sniff
buffers; move VNC stdin/text off the tunnel loop.
- 介面、排程、語言與其他修正 (app.rs, i18n.rs, providers.rs, skills.rs, routines.rs,
setup.rs, store.rs, preview.rs, attach.rs, speech.rs, teams.rs, mcp.rs, voice.rs):
wire up the delete-routine confirmation dialog and mirror run-now; preserve unsaved
mirror edits across brief disconnects; give Chinese skills distinct folders and approval
gates; convert parsed tool JSON fields without corrupting code fences, URLs or paths;
fix Hourly DST offsets and time out unattended routine approvals; lock --install-skill,
cap docx/xlsx unzip sizes, isolate test env keys, and tighten local file permissions.
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-12 06:34:10 +00:00
|
|
|
|
fn lan_vnc(req: Req, mut c: std::net::TcpStream, gen: u64) {
|
People watch and help on the bots' computer through VNC (noVNC), carried by the account server
The core: the bot works the computer; a person watches it like a colleague, and takes over
when it needs them. VNC is made for that (only what changed, every mouse move and key, touch on
phones), so the pictures sent one by one go, and with them their own input path.
- vnc.rs: a VNC proxy to the box's x11vnc through one docker exec (a Python bridge that ends
with either side). It signs in to the box with the box's own password (its VNC_PASSWORD) and
offers the viewer no password, so the password never leaves the brain. The person's clicks
and keys make the bot's steps wait until 8 s after they stop; text typed in the viewer's box
(any language) is pasted in the box.
- Account server: /screen (the viewer page) and /novnc.js (noVNC 1.6.0, MPL-2.0, bundled);
/relay/vnc/<host> takes the browser's WebSocket (account session, or a 10-minute ticket the
app asks for with POST /relay/screen-ticket; owners and admins) and carries it over that
AnyBot's lasting connection (vopen / vdata / vtext / vclose). Both ends of that connection
wait 2 ms instead of 40 ms to read while things move: a request and its answer took up to
160 ms more than needed.
- Phone page: 看 Bot 的電腦 and 接管 open the viewer page (also on the local network: /api/vnc on
the AnyBot's own phone server). This Mac's own screen moved to the ⋯ menu.
- Mac app: 看畫面 opens the viewer in the browser (a screen of a brain: the brain's computer by
ticket; else this computer's box, noVNC straight from it). The in-app picture viewer, the
live JPEG stream, the person's click/move/scroll/key endpoints and the input shell are gone.
- Opening a Mac app uses LaunchServices (`open -a`): agent-desktop's launch waited on the window
through accessibility and failed without 輔助使用 now and then.
Measured on this Mac (made-up account, local relay + headless brain + the real box): viewer
signed in in 0.4–0.7 s, a request and its answer through relay + brain + box 25–58 ms median;
headless Chrome shows the desktop live in /screen. remote_e2e 28/28 ×2, 149 unit tests, relay 11.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-05 15:05:44 +00:00
|
|
|
|
use tungstenite::{protocol::Role, Message, WebSocket};
|
|
|
|
|
|
if req.path != "/api/vnc" {
|
|
|
|
|
|
return httpd::write_response(&mut c, &Resp::error(404, "沒有這個網址"));
|
|
|
|
|
|
}
|
2026-11-13 16:40:16 +00:00
|
|
|
|
// A ticket (asked for a moment ago with the login, used once) or, from an older page, the
|
|
|
|
|
|
// login itself.
|
|
|
|
|
|
let bearer = match req.query.get("ticket").filter(|t| !t.is_empty()) {
|
|
|
|
|
|
Some(t) => lan_tickets().lock().unwrap().remove(t).filter(|(_, made)| made.elapsed() < Duration::from_secs(60)).map(|(token, _)| token).unwrap_or_default(),
|
|
|
|
|
|
None => req.bearer(),
|
|
|
|
|
|
};
|
安全、修正: harden sandboxes, approval gates, vault, relay roles, and fix protocol/UI bugs
- macOS 沙盒與工具 (tools.rs, policy.rs, docindex.rs): block AppleScript raw events and
concatenation outside the sandbox; stop exposing ~/.ssh or localhost sockets in Sealed
mode; deny writes to shell profiles, LaunchAgents and .git/hooks; expand secret-file
ignores and enforce symlink/policy checks across SSH, device and document search.
- 電腦操作與遮罩 (computer.rs, agent.rs, marks.rs, desktop.rs, cloudbox.rs, portal.rs):
forbid clicking or typing into AnyBot's own windows; extend the sensitive-action hard
gate to raw coordinates, Return/Delete submits and remote devices; stop batch steps if
the front app changes; black out secrets on zoom, show, >600-node trees, adjacent OTP
labels, box screenshots and control text lists; preserve non-text Wayland clipboards.
- 保險庫與瀏覽器 (vault.rs, vault_store.rs, browser.rs, botbrowser.rs, web.rs, box/browser):
verify tab host and HTTPS atomically at fill time; taint filled tabs against browser_eval
and PDF export while masking card/CVC values and screenshots; remember sites only on
always-allow; drop --remote-allow-origins=*; gate private URLs and block metadata/Docker
ports, OrbStack 198.18/15 and IPv6 transition ranges.
- 帳號伺服器、同步與傳送 (relay/, remote.rs, mirror_ui.rs, share.rs, drops.rs): isolate
paired hands hosts from brain sync, tickets, pairing and backup overwrites; redact
routine trigger secrets and clear REDACTED when endpoints change; isolate channel and
team-member turns from owner memories, appctl and grants; scrub shared bot exports and
reset grants/routines on import; validate drop IDs and serialize chunk writes.
- 網路與協定穩定性 (httpd.rs, tunnel.rs, vnc.rs, Caddyfile*): fix chunked integer overflow
and CRLF header injection; enforce Origin checks, connection/job caps, 200 MB backup
reads, unique atomic temp files and ASCII hex guards; bound deflate unzip and VNC sniff
buffers; move VNC stdin/text off the tunnel loop.
- 介面、排程、語言與其他修正 (app.rs, i18n.rs, providers.rs, skills.rs, routines.rs,
setup.rs, store.rs, preview.rs, attach.rs, speech.rs, teams.rs, mcp.rs, voice.rs):
wire up the delete-routine confirmation dialog and mirror run-now; preserve unsaved
mirror edits across brief disconnects; give Chinese skills distinct folders and approval
gates; convert parsed tool JSON fields without corrupting code fences, URLs or paths;
fix Hourly DST offsets and time out unattended routine approvals; lock --install-skill,
cap docx/xlsx unzip sizes, isolate test env keys, and tighten local file permissions.
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-12 06:34:10 +00:00
|
|
|
|
if devices_ok(&bearer).is_none() {
|
People watch and help on the bots' computer through VNC (noVNC), carried by the account server
The core: the bot works the computer; a person watches it like a colleague, and takes over
when it needs them. VNC is made for that (only what changed, every mouse move and key, touch on
phones), so the pictures sent one by one go, and with them their own input path.
- vnc.rs: a VNC proxy to the box's x11vnc through one docker exec (a Python bridge that ends
with either side). It signs in to the box with the box's own password (its VNC_PASSWORD) and
offers the viewer no password, so the password never leaves the brain. The person's clicks
and keys make the bot's steps wait until 8 s after they stop; text typed in the viewer's box
(any language) is pasted in the box.
- Account server: /screen (the viewer page) and /novnc.js (noVNC 1.6.0, MPL-2.0, bundled);
/relay/vnc/<host> takes the browser's WebSocket (account session, or a 10-minute ticket the
app asks for with POST /relay/screen-ticket; owners and admins) and carries it over that
AnyBot's lasting connection (vopen / vdata / vtext / vclose). Both ends of that connection
wait 2 ms instead of 40 ms to read while things move: a request and its answer took up to
160 ms more than needed.
- Phone page: 看 Bot 的電腦 and 接管 open the viewer page (also on the local network: /api/vnc on
the AnyBot's own phone server). This Mac's own screen moved to the ⋯ menu.
- Mac app: 看畫面 opens the viewer in the browser (a screen of a brain: the brain's computer by
ticket; else this computer's box, noVNC straight from it). The in-app picture viewer, the
live JPEG stream, the person's click/move/scroll/key endpoints and the input shell are gone.
- Opening a Mac app uses LaunchServices (`open -a`): agent-desktop's launch waited on the window
through accessibility and failed without 輔助使用 now and then.
Measured on this Mac (made-up account, local relay + headless brain + the real box): viewer
signed in in 0.4–0.7 s, a request and its answer through relay + brain + box 25–58 ms median;
headless Chrome shows the desktop live in /screen. remote_e2e 28/28 ×2, 149 unit tests, relay 11.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-05 15:05:44 +00:00
|
|
|
|
return httpd::write_response(&mut c, &Resp::error(401, "請先登入"));
|
|
|
|
|
|
}
|
Remove what nothing uses and keep one copy of what was written several times
Unused (found by taking away the dead-code allowances; nothing else used them, tests aside):
computer::specs, quiet_button, the never-made Poke::Spin, ten icons and their SVGs, the
theme's chrome/bubble_agent colours, ImportRow.line, voice's multipart/transcribe/speak
wrappers, and the old keychain writers vault::save/remove/index_add with their live test
(the vault store replaced them; reading old keychain entries for the import stays).
One copy each: percent-encoding (httpd::url_encode, was four), tool arguments (tools::args_of,
was three), the WebSocket handshake (httpd::accept_websocket, was three), the read pacing
(wire::Pace, was two: relay and app), docker with input and a time limit (dk_with_input, was
two). Docs: FEATURES §看畫面 (VNC), protocol (v* frames, /screen, tickets), architecture.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-05 15:21:47 +00:00
|
|
|
|
if !httpd::accept_websocket(&req, &mut c) {
|
People watch and help on the bots' computer through VNC (noVNC), carried by the account server
The core: the bot works the computer; a person watches it like a colleague, and takes over
when it needs them. VNC is made for that (only what changed, every mouse move and key, touch on
phones), so the pictures sent one by one go, and with them their own input path.
- vnc.rs: a VNC proxy to the box's x11vnc through one docker exec (a Python bridge that ends
with either side). It signs in to the box with the box's own password (its VNC_PASSWORD) and
offers the viewer no password, so the password never leaves the brain. The person's clicks
and keys make the bot's steps wait until 8 s after they stop; text typed in the viewer's box
(any language) is pasted in the box.
- Account server: /screen (the viewer page) and /novnc.js (noVNC 1.6.0, MPL-2.0, bundled);
/relay/vnc/<host> takes the browser's WebSocket (account session, or a 10-minute ticket the
app asks for with POST /relay/screen-ticket; owners and admins) and carries it over that
AnyBot's lasting connection (vopen / vdata / vtext / vclose). Both ends of that connection
wait 2 ms instead of 40 ms to read while things move: a request and its answer took up to
160 ms more than needed.
- Phone page: 看 Bot 的電腦 and 接管 open the viewer page (also on the local network: /api/vnc on
the AnyBot's own phone server). This Mac's own screen moved to the ⋯ menu.
- Mac app: 看畫面 opens the viewer in the browser (a screen of a brain: the brain's computer by
ticket; else this computer's box, noVNC straight from it). The in-app picture viewer, the
live JPEG stream, the person's click/move/scroll/key endpoints and the input shell are gone.
- Opening a Mac app uses LaunchServices (`open -a`): agent-desktop's launch waited on the window
through accessibility and failed without 輔助使用 now and then.
Measured on this Mac (made-up account, local relay + headless brain + the real box): viewer
signed in in 0.4–0.7 s, a request and its answer through relay + brain + box 25–58 ms median;
headless Chrome shows the desktop live in /screen. remote_e2e 28/28 ×2, 149 unit tests, relay 11.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-05 15:05:44 +00:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
let _ = c.set_read_timeout(Some(Duration::from_millis(2)));
|
安全、修正: harden sandboxes, approval gates, vault, relay roles, and fix protocol/UI bugs
- macOS 沙盒與工具 (tools.rs, policy.rs, docindex.rs): block AppleScript raw events and
concatenation outside the sandbox; stop exposing ~/.ssh or localhost sockets in Sealed
mode; deny writes to shell profiles, LaunchAgents and .git/hooks; expand secret-file
ignores and enforce symlink/policy checks across SSH, device and document search.
- 電腦操作與遮罩 (computer.rs, agent.rs, marks.rs, desktop.rs, cloudbox.rs, portal.rs):
forbid clicking or typing into AnyBot's own windows; extend the sensitive-action hard
gate to raw coordinates, Return/Delete submits and remote devices; stop batch steps if
the front app changes; black out secrets on zoom, show, >600-node trees, adjacent OTP
labels, box screenshots and control text lists; preserve non-text Wayland clipboards.
- 保險庫與瀏覽器 (vault.rs, vault_store.rs, browser.rs, botbrowser.rs, web.rs, box/browser):
verify tab host and HTTPS atomically at fill time; taint filled tabs against browser_eval
and PDF export while masking card/CVC values and screenshots; remember sites only on
always-allow; drop --remote-allow-origins=*; gate private URLs and block metadata/Docker
ports, OrbStack 198.18/15 and IPv6 transition ranges.
- 帳號伺服器、同步與傳送 (relay/, remote.rs, mirror_ui.rs, share.rs, drops.rs): isolate
paired hands hosts from brain sync, tickets, pairing and backup overwrites; redact
routine trigger secrets and clear REDACTED when endpoints change; isolate channel and
team-member turns from owner memories, appctl and grants; scrub shared bot exports and
reset grants/routines on import; validate drop IDs and serialize chunk writes.
- 網路與協定穩定性 (httpd.rs, tunnel.rs, vnc.rs, Caddyfile*): fix chunked integer overflow
and CRLF header injection; enforce Origin checks, connection/job caps, 200 MB backup
reads, unique atomic temp files and ASCII hex guards; bound deflate unzip and VNC sniff
buffers; move VNC stdin/text off the tunnel loop.
- 介面、排程、語言與其他修正 (app.rs, i18n.rs, providers.rs, skills.rs, routines.rs,
setup.rs, store.rs, preview.rs, attach.rs, speech.rs, teams.rs, mcp.rs, voice.rs):
wire up the delete-routine confirmation dialog and mirror run-now; preserve unsaved
mirror edits across brief disconnects; give Chinese skills distinct folders and approval
gates; convert parsed tool JSON fields without corrupting code fences, URLs or paths;
fix Hourly DST offsets and time out unattended routine approvals; lock --install-skill,
cap docx/xlsx unzip sizes, isolate test env keys, and tighten local file permissions.
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-12 06:34:10 +00:00
|
|
|
|
let _ = c.set_write_timeout(Some(Duration::from_secs(30)));
|
|
|
|
|
|
let cfg = tungstenite::protocol::WebSocketConfig::default().max_message_size(Some(16 << 20)).max_frame_size(Some(16 << 20));
|
|
|
|
|
|
let mut ws = WebSocket::from_raw_socket(c, Role::Server, Some(cfg));
|
People watch and help on the bots' computer through VNC (noVNC), carried by the account server
The core: the bot works the computer; a person watches it like a colleague, and takes over
when it needs them. VNC is made for that (only what changed, every mouse move and key, touch on
phones), so the pictures sent one by one go, and with them their own input path.
- vnc.rs: a VNC proxy to the box's x11vnc through one docker exec (a Python bridge that ends
with either side). It signs in to the box with the box's own password (its VNC_PASSWORD) and
offers the viewer no password, so the password never leaves the brain. The person's clicks
and keys make the bot's steps wait until 8 s after they stop; text typed in the viewer's box
(any language) is pasted in the box.
- Account server: /screen (the viewer page) and /novnc.js (noVNC 1.6.0, MPL-2.0, bundled);
/relay/vnc/<host> takes the browser's WebSocket (account session, or a 10-minute ticket the
app asks for with POST /relay/screen-ticket; owners and admins) and carries it over that
AnyBot's lasting connection (vopen / vdata / vtext / vclose). Both ends of that connection
wait 2 ms instead of 40 ms to read while things move: a request and its answer took up to
160 ms more than needed.
- Phone page: 看 Bot 的電腦 and 接管 open the viewer page (also on the local network: /api/vnc on
the AnyBot's own phone server). This Mac's own screen moved to the ⋯ menu.
- Mac app: 看畫面 opens the viewer in the browser (a screen of a brain: the brain's computer by
ticket; else this computer's box, noVNC straight from it). The in-app picture viewer, the
live JPEG stream, the person's click/move/scroll/key endpoints and the input shell are gone.
- Opening a Mac app uses LaunchServices (`open -a`): agent-desktop's launch waited on the window
through accessibility and failed without 輔助使用 now and then.
Measured on this Mac (made-up account, local relay + headless brain + the real box): viewer
signed in in 0.4–0.7 s, a request and its answer through relay + brain + box 25–58 ms median;
headless Chrome shows the desktop live in /screen. remote_e2e 28/28 ×2, 149 unit tests, relay 11.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-05 15:05:44 +00:00
|
|
|
|
let (tx, rx) = std::sync::mpsc::channel::<Vec<u8>>();
|
|
|
|
|
|
let send = move |b: &[u8]| tx.send(b.to_vec()).is_ok();
|
|
|
|
|
|
let Ok(mut session) = crate::vnc::open(send.clone()) else { return };
|
|
|
|
|
|
if !send(crate::vnc::GREETING) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
安全、修正: harden sandboxes, approval gates, vault, relay roles, and fix protocol/UI bugs
- macOS 沙盒與工具 (tools.rs, policy.rs, docindex.rs): block AppleScript raw events and
concatenation outside the sandbox; stop exposing ~/.ssh or localhost sockets in Sealed
mode; deny writes to shell profiles, LaunchAgents and .git/hooks; expand secret-file
ignores and enforce symlink/policy checks across SSH, device and document search.
- 電腦操作與遮罩 (computer.rs, agent.rs, marks.rs, desktop.rs, cloudbox.rs, portal.rs):
forbid clicking or typing into AnyBot's own windows; extend the sensitive-action hard
gate to raw coordinates, Return/Delete submits and remote devices; stop batch steps if
the front app changes; black out secrets on zoom, show, >600-node trees, adjacent OTP
labels, box screenshots and control text lists; preserve non-text Wayland clipboards.
- 保險庫與瀏覽器 (vault.rs, vault_store.rs, browser.rs, botbrowser.rs, web.rs, box/browser):
verify tab host and HTTPS atomically at fill time; taint filled tabs against browser_eval
and PDF export while masking card/CVC values and screenshots; remember sites only on
always-allow; drop --remote-allow-origins=*; gate private URLs and block metadata/Docker
ports, OrbStack 198.18/15 and IPv6 transition ranges.
- 帳號伺服器、同步與傳送 (relay/, remote.rs, mirror_ui.rs, share.rs, drops.rs): isolate
paired hands hosts from brain sync, tickets, pairing and backup overwrites; redact
routine trigger secrets and clear REDACTED when endpoints change; isolate channel and
team-member turns from owner memories, appctl and grants; scrub shared bot exports and
reset grants/routines on import; validate drop IDs and serialize chunk writes.
- 網路與協定穩定性 (httpd.rs, tunnel.rs, vnc.rs, Caddyfile*): fix chunked integer overflow
and CRLF header injection; enforce Origin checks, connection/job caps, 200 MB backup
reads, unique atomic temp files and ASCII hex guards; bound deflate unzip and VNC sniff
buffers; move VNC stdin/text off the tunnel loop.
- 介面、排程、語言與其他修正 (app.rs, i18n.rs, providers.rs, skills.rs, routines.rs,
setup.rs, store.rs, preview.rs, attach.rs, speech.rs, teams.rs, mcp.rs, voice.rs):
wire up the delete-routine confirmation dialog and mirror run-now; preserve unsaved
mirror edits across brief disconnects; give Chinese skills distinct folders and approval
gates; convert parsed tool JSON fields without corrupting code fences, URLs or paths;
fix Hourly DST offsets and time out unattended routine approvals; lock --install-skill,
cap docx/xlsx unzip sizes, isolate test env keys, and tighten local file permissions.
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-12 06:34:10 +00:00
|
|
|
|
let mut checked = Instant::now();
|
2026-11-13 15:36:34 +00:00
|
|
|
|
// A phone that is gone without saying so (out of range, asleep) is noticed: a ping every
|
|
|
|
|
|
// 20 s, and the end after 60 s of hearing nothing. (The thread, the screen session and its
|
|
|
|
|
|
// fast polling used to stay for ever.)
|
|
|
|
|
|
let (mut heard, mut pinged) = (Instant::now(), Instant::now());
|
People watch and help on the bots' computer through VNC (noVNC), carried by the account server
The core: the bot works the computer; a person watches it like a colleague, and takes over
when it needs them. VNC is made for that (only what changed, every mouse move and key, touch on
phones), so the pictures sent one by one go, and with them their own input path.
- vnc.rs: a VNC proxy to the box's x11vnc through one docker exec (a Python bridge that ends
with either side). It signs in to the box with the box's own password (its VNC_PASSWORD) and
offers the viewer no password, so the password never leaves the brain. The person's clicks
and keys make the bot's steps wait until 8 s after they stop; text typed in the viewer's box
(any language) is pasted in the box.
- Account server: /screen (the viewer page) and /novnc.js (noVNC 1.6.0, MPL-2.0, bundled);
/relay/vnc/<host> takes the browser's WebSocket (account session, or a 10-minute ticket the
app asks for with POST /relay/screen-ticket; owners and admins) and carries it over that
AnyBot's lasting connection (vopen / vdata / vtext / vclose). Both ends of that connection
wait 2 ms instead of 40 ms to read while things move: a request and its answer took up to
160 ms more than needed.
- Phone page: 看 Bot 的電腦 and 接管 open the viewer page (also on the local network: /api/vnc on
the AnyBot's own phone server). This Mac's own screen moved to the ⋯ menu.
- Mac app: 看畫面 opens the viewer in the browser (a screen of a brain: the brain's computer by
ticket; else this computer's box, noVNC straight from it). The in-app picture viewer, the
live JPEG stream, the person's click/move/scroll/key endpoints and the input shell are gone.
- Opening a Mac app uses LaunchServices (`open -a`): agent-desktop's launch waited on the window
through accessibility and failed without 輔助使用 now and then.
Measured on this Mac (made-up account, local relay + headless brain + the real box): viewer
signed in in 0.4–0.7 s, a request and its answer through relay + brain + box 25–58 ms median;
headless Chrome shows the desktop live in /screen. remote_e2e 28/28 ×2, 149 unit tests, relay 11.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-05 15:05:44 +00:00
|
|
|
|
'live: loop {
|
安全、修正: harden sandboxes, approval gates, vault, relay roles, and fix protocol/UI bugs
- macOS 沙盒與工具 (tools.rs, policy.rs, docindex.rs): block AppleScript raw events and
concatenation outside the sandbox; stop exposing ~/.ssh or localhost sockets in Sealed
mode; deny writes to shell profiles, LaunchAgents and .git/hooks; expand secret-file
ignores and enforce symlink/policy checks across SSH, device and document search.
- 電腦操作與遮罩 (computer.rs, agent.rs, marks.rs, desktop.rs, cloudbox.rs, portal.rs):
forbid clicking or typing into AnyBot's own windows; extend the sensitive-action hard
gate to raw coordinates, Return/Delete submits and remote devices; stop batch steps if
the front app changes; black out secrets on zoom, show, >600-node trees, adjacent OTP
labels, box screenshots and control text lists; preserve non-text Wayland clipboards.
- 保險庫與瀏覽器 (vault.rs, vault_store.rs, browser.rs, botbrowser.rs, web.rs, box/browser):
verify tab host and HTTPS atomically at fill time; taint filled tabs against browser_eval
and PDF export while masking card/CVC values and screenshots; remember sites only on
always-allow; drop --remote-allow-origins=*; gate private URLs and block metadata/Docker
ports, OrbStack 198.18/15 and IPv6 transition ranges.
- 帳號伺服器、同步與傳送 (relay/, remote.rs, mirror_ui.rs, share.rs, drops.rs): isolate
paired hands hosts from brain sync, tickets, pairing and backup overwrites; redact
routine trigger secrets and clear REDACTED when endpoints change; isolate channel and
team-member turns from owner memories, appctl and grants; scrub shared bot exports and
reset grants/routines on import; validate drop IDs and serialize chunk writes.
- 網路與協定穩定性 (httpd.rs, tunnel.rs, vnc.rs, Caddyfile*): fix chunked integer overflow
and CRLF header injection; enforce Origin checks, connection/job caps, 200 MB backup
reads, unique atomic temp files and ASCII hex guards; bound deflate unzip and VNC sniff
buffers; move VNC stdin/text off the tunnel loop.
- 介面、排程、語言與其他修正 (app.rs, i18n.rs, providers.rs, skills.rs, routines.rs,
setup.rs, store.rs, preview.rs, attach.rs, speech.rs, teams.rs, mcp.rs, voice.rs):
wire up the delete-routine confirmation dialog and mirror run-now; preserve unsaved
mirror edits across brief disconnects; give Chinese skills distinct folders and approval
gates; convert parsed tool JSON fields without corrupting code fences, URLs or paths;
fix Hourly DST offsets and time out unattended routine approvals; lock --install-skill,
cap docx/xlsx unzip sizes, isolate test env keys, and tighten local file permissions.
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-12 06:34:10 +00:00
|
|
|
|
if checked.elapsed().as_secs() >= 3 {
|
|
|
|
|
|
checked = Instant::now();
|
|
|
|
|
|
if LAN_GEN.load(Ordering::SeqCst) != gen || devices_ok(&bearer).is_none() {
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
2026-11-13 15:36:34 +00:00
|
|
|
|
if heard.elapsed().as_secs() >= 60 {
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
if pinged.elapsed().as_secs() >= 20 {
|
|
|
|
|
|
pinged = Instant::now();
|
|
|
|
|
|
if ws.write(Message::Ping(Vec::new().into())).is_err() {
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
let _ = ws.flush();
|
|
|
|
|
|
}
|
安全、修正: harden sandboxes, approval gates, vault, relay roles, and fix protocol/UI bugs
- macOS 沙盒與工具 (tools.rs, policy.rs, docindex.rs): block AppleScript raw events and
concatenation outside the sandbox; stop exposing ~/.ssh or localhost sockets in Sealed
mode; deny writes to shell profiles, LaunchAgents and .git/hooks; expand secret-file
ignores and enforce symlink/policy checks across SSH, device and document search.
- 電腦操作與遮罩 (computer.rs, agent.rs, marks.rs, desktop.rs, cloudbox.rs, portal.rs):
forbid clicking or typing into AnyBot's own windows; extend the sensitive-action hard
gate to raw coordinates, Return/Delete submits and remote devices; stop batch steps if
the front app changes; black out secrets on zoom, show, >600-node trees, adjacent OTP
labels, box screenshots and control text lists; preserve non-text Wayland clipboards.
- 保險庫與瀏覽器 (vault.rs, vault_store.rs, browser.rs, botbrowser.rs, web.rs, box/browser):
verify tab host and HTTPS atomically at fill time; taint filled tabs against browser_eval
and PDF export while masking card/CVC values and screenshots; remember sites only on
always-allow; drop --remote-allow-origins=*; gate private URLs and block metadata/Docker
ports, OrbStack 198.18/15 and IPv6 transition ranges.
- 帳號伺服器、同步與傳送 (relay/, remote.rs, mirror_ui.rs, share.rs, drops.rs): isolate
paired hands hosts from brain sync, tickets, pairing and backup overwrites; redact
routine trigger secrets and clear REDACTED when endpoints change; isolate channel and
team-member turns from owner memories, appctl and grants; scrub shared bot exports and
reset grants/routines on import; validate drop IDs and serialize chunk writes.
- 網路與協定穩定性 (httpd.rs, tunnel.rs, vnc.rs, Caddyfile*): fix chunked integer overflow
and CRLF header injection; enforce Origin checks, connection/job caps, 200 MB backup
reads, unique atomic temp files and ASCII hex guards; bound deflate unzip and VNC sniff
buffers; move VNC stdin/text off the tunnel loop.
- 介面、排程、語言與其他修正 (app.rs, i18n.rs, providers.rs, skills.rs, routines.rs,
setup.rs, store.rs, preview.rs, attach.rs, speech.rs, teams.rs, mcp.rs, voice.rs):
wire up the delete-routine confirmation dialog and mirror run-now; preserve unsaved
mirror edits across brief disconnects; give Chinese skills distinct folders and approval
gates; convert parsed tool JSON fields without corrupting code fences, URLs or paths;
fix Hourly DST offsets and time out unattended routine approvals; lock --install-skill,
cap docx/xlsx unzip sizes, isolate test env keys, and tighten local file permissions.
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-12 06:34:10 +00:00
|
|
|
|
}
|
People watch and help on the bots' computer through VNC (noVNC), carried by the account server
The core: the bot works the computer; a person watches it like a colleague, and takes over
when it needs them. VNC is made for that (only what changed, every mouse move and key, touch on
phones), so the pictures sent one by one go, and with them their own input path.
- vnc.rs: a VNC proxy to the box's x11vnc through one docker exec (a Python bridge that ends
with either side). It signs in to the box with the box's own password (its VNC_PASSWORD) and
offers the viewer no password, so the password never leaves the brain. The person's clicks
and keys make the bot's steps wait until 8 s after they stop; text typed in the viewer's box
(any language) is pasted in the box.
- Account server: /screen (the viewer page) and /novnc.js (noVNC 1.6.0, MPL-2.0, bundled);
/relay/vnc/<host> takes the browser's WebSocket (account session, or a 10-minute ticket the
app asks for with POST /relay/screen-ticket; owners and admins) and carries it over that
AnyBot's lasting connection (vopen / vdata / vtext / vclose). Both ends of that connection
wait 2 ms instead of 40 ms to read while things move: a request and its answer took up to
160 ms more than needed.
- Phone page: 看 Bot 的電腦 and 接管 open the viewer page (also on the local network: /api/vnc on
the AnyBot's own phone server). This Mac's own screen moved to the ⋯ menu.
- Mac app: 看畫面 opens the viewer in the browser (a screen of a brain: the brain's computer by
ticket; else this computer's box, noVNC straight from it). The in-app picture viewer, the
live JPEG stream, the person's click/move/scroll/key endpoints and the input shell are gone.
- Opening a Mac app uses LaunchServices (`open -a`): agent-desktop's launch waited on the window
through accessibility and failed without 輔助使用 now and then.
Measured on this Mac (made-up account, local relay + headless brain + the real box): viewer
signed in in 0.4–0.7 s, a request and its answer through relay + brain + box 25–58 ms median;
headless Chrome shows the desktop live in /screen. remote_e2e 28/28 ×2, 149 unit tests, relay 11.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-05 15:05:44 +00:00
|
|
|
|
match ws.read() {
|
|
|
|
|
|
Ok(Message::Binary(b)) => {
|
2026-11-13 15:36:34 +00:00
|
|
|
|
heard = Instant::now();
|
People watch and help on the bots' computer through VNC (noVNC), carried by the account server
The core: the bot works the computer; a person watches it like a colleague, and takes over
when it needs them. VNC is made for that (only what changed, every mouse move and key, touch on
phones), so the pictures sent one by one go, and with them their own input path.
- vnc.rs: a VNC proxy to the box's x11vnc through one docker exec (a Python bridge that ends
with either side). It signs in to the box with the box's own password (its VNC_PASSWORD) and
offers the viewer no password, so the password never leaves the brain. The person's clicks
and keys make the bot's steps wait until 8 s after they stop; text typed in the viewer's box
(any language) is pasted in the box.
- Account server: /screen (the viewer page) and /novnc.js (noVNC 1.6.0, MPL-2.0, bundled);
/relay/vnc/<host> takes the browser's WebSocket (account session, or a 10-minute ticket the
app asks for with POST /relay/screen-ticket; owners and admins) and carries it over that
AnyBot's lasting connection (vopen / vdata / vtext / vclose). Both ends of that connection
wait 2 ms instead of 40 ms to read while things move: a request and its answer took up to
160 ms more than needed.
- Phone page: 看 Bot 的電腦 and 接管 open the viewer page (also on the local network: /api/vnc on
the AnyBot's own phone server). This Mac's own screen moved to the ⋯ menu.
- Mac app: 看畫面 opens the viewer in the browser (a screen of a brain: the brain's computer by
ticket; else this computer's box, noVNC straight from it). The in-app picture viewer, the
live JPEG stream, the person's click/move/scroll/key endpoints and the input shell are gone.
- Opening a Mac app uses LaunchServices (`open -a`): agent-desktop's launch waited on the window
through accessibility and failed without 輔助使用 now and then.
Measured on this Mac (made-up account, local relay + headless brain + the real box): viewer
signed in in 0.4–0.7 s, a request and its answer through relay + brain + box 25–58 ms median;
headless Chrome shows the desktop live in /screen. remote_e2e 28/28 ×2, 149 unit tests, relay 11.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-05 15:05:44 +00:00
|
|
|
|
if !session.feed(&b, &send) {
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-11-13 15:36:34 +00:00
|
|
|
|
Ok(Message::Text(t)) => {
|
|
|
|
|
|
heard = Instant::now();
|
|
|
|
|
|
crate::vnc::person_typed(&t)
|
|
|
|
|
|
}
|
People watch and help on the bots' computer through VNC (noVNC), carried by the account server
The core: the bot works the computer; a person watches it like a colleague, and takes over
when it needs them. VNC is made for that (only what changed, every mouse move and key, touch on
phones), so the pictures sent one by one go, and with them their own input path.
- vnc.rs: a VNC proxy to the box's x11vnc through one docker exec (a Python bridge that ends
with either side). It signs in to the box with the box's own password (its VNC_PASSWORD) and
offers the viewer no password, so the password never leaves the brain. The person's clicks
and keys make the bot's steps wait until 8 s after they stop; text typed in the viewer's box
(any language) is pasted in the box.
- Account server: /screen (the viewer page) and /novnc.js (noVNC 1.6.0, MPL-2.0, bundled);
/relay/vnc/<host> takes the browser's WebSocket (account session, or a 10-minute ticket the
app asks for with POST /relay/screen-ticket; owners and admins) and carries it over that
AnyBot's lasting connection (vopen / vdata / vtext / vclose). Both ends of that connection
wait 2 ms instead of 40 ms to read while things move: a request and its answer took up to
160 ms more than needed.
- Phone page: 看 Bot 的電腦 and 接管 open the viewer page (also on the local network: /api/vnc on
the AnyBot's own phone server). This Mac's own screen moved to the ⋯ menu.
- Mac app: 看畫面 opens the viewer in the browser (a screen of a brain: the brain's computer by
ticket; else this computer's box, noVNC straight from it). The in-app picture viewer, the
live JPEG stream, the person's click/move/scroll/key endpoints and the input shell are gone.
- Opening a Mac app uses LaunchServices (`open -a`): agent-desktop's launch waited on the window
through accessibility and failed without 輔助使用 now and then.
Measured on this Mac (made-up account, local relay + headless brain + the real box): viewer
signed in in 0.4–0.7 s, a request and its answer through relay + brain + box 25–58 ms median;
headless Chrome shows the desktop live in /screen. remote_e2e 28/28 ×2, 149 unit tests, relay 11.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-05 15:05:44 +00:00
|
|
|
|
Ok(Message::Close(_)) => break,
|
2026-11-13 15:36:34 +00:00
|
|
|
|
Ok(_) => heard = Instant::now(),
|
People watch and help on the bots' computer through VNC (noVNC), carried by the account server
The core: the bot works the computer; a person watches it like a colleague, and takes over
when it needs them. VNC is made for that (only what changed, every mouse move and key, touch on
phones), so the pictures sent one by one go, and with them their own input path.
- vnc.rs: a VNC proxy to the box's x11vnc through one docker exec (a Python bridge that ends
with either side). It signs in to the box with the box's own password (its VNC_PASSWORD) and
offers the viewer no password, so the password never leaves the brain. The person's clicks
and keys make the bot's steps wait until 8 s after they stop; text typed in the viewer's box
(any language) is pasted in the box.
- Account server: /screen (the viewer page) and /novnc.js (noVNC 1.6.0, MPL-2.0, bundled);
/relay/vnc/<host> takes the browser's WebSocket (account session, or a 10-minute ticket the
app asks for with POST /relay/screen-ticket; owners and admins) and carries it over that
AnyBot's lasting connection (vopen / vdata / vtext / vclose). Both ends of that connection
wait 2 ms instead of 40 ms to read while things move: a request and its answer took up to
160 ms more than needed.
- Phone page: 看 Bot 的電腦 and 接管 open the viewer page (also on the local network: /api/vnc on
the AnyBot's own phone server). This Mac's own screen moved to the ⋯ menu.
- Mac app: 看畫面 opens the viewer in the browser (a screen of a brain: the brain's computer by
ticket; else this computer's box, noVNC straight from it). The in-app picture viewer, the
live JPEG stream, the person's click/move/scroll/key endpoints and the input shell are gone.
- Opening a Mac app uses LaunchServices (`open -a`): agent-desktop's launch waited on the window
through accessibility and failed without 輔助使用 now and then.
Measured on this Mac (made-up account, local relay + headless brain + the real box): viewer
signed in in 0.4–0.7 s, a request and its answer through relay + brain + box 25–58 ms median;
headless Chrome shows the desktop live in /screen. remote_e2e 28/28 ×2, 149 unit tests, relay 11.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-05 15:05:44 +00:00
|
|
|
|
Err(tungstenite::Error::Io(e)) if matches!(e.kind(), std::io::ErrorKind::WouldBlock | std::io::ErrorKind::TimedOut) => {}
|
|
|
|
|
|
Err(_) => break,
|
|
|
|
|
|
}
|
|
|
|
|
|
loop {
|
|
|
|
|
|
match rx.try_recv() {
|
|
|
|
|
|
// An empty send: the box's side ended.
|
|
|
|
|
|
Ok(b) if b.is_empty() => break 'live,
|
|
|
|
|
|
Ok(b) => {
|
|
|
|
|
|
if ws.write(Message::Binary(b.into())).is_err() {
|
|
|
|
|
|
break 'live;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
Err(_) => break,
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
match ws.flush() {
|
|
|
|
|
|
Err(tungstenite::Error::Io(e)) if matches!(e.kind(), std::io::ErrorKind::WouldBlock | std::io::ErrorKind::TimedOut) => {}
|
|
|
|
|
|
Err(_) => break,
|
|
|
|
|
|
Ok(()) => {}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
let _ = ws.close(None);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
/// Addresses a phone can open (local network and Tailscale).
|
|
|
|
|
|
pub fn addresses(port: u16) -> Vec<String> {
|
|
|
|
|
|
// macOS: ifconfig ("inet 192.168.1.5 netmask…"); Linux: `ip -4 -o addr` ("… inet 192.168.1.5/24 …").
|
|
|
|
|
|
let mut out = std::process::Command::new("ifconfig").output().map(|o| String::from_utf8_lossy(&o.stdout).to_string()).unwrap_or_default();
|
|
|
|
|
|
if out.trim().is_empty() {
|
|
|
|
|
|
out = std::process::Command::new("ip").args(["-4", "-o", "addr"]).output().map(|o| String::from_utf8_lossy(&o.stdout).to_string()).unwrap_or_default();
|
|
|
|
|
|
}
|
|
|
|
|
|
let mut v: Vec<String> = out
|
|
|
|
|
|
.lines()
|
|
|
|
|
|
.filter_map(|l| l.split("inet ").nth(1))
|
|
|
|
|
|
.filter_map(|l| l.split_whitespace().next())
|
|
|
|
|
|
.map(|ip| ip.split('/').next().unwrap_or(ip))
|
|
|
|
|
|
.filter(|ip| !ip.starts_with("127.") && !ip.starts_with("169.254."))
|
2026-11-13 16:40:16 +00:00
|
|
|
|
// (Tailscale's 100.x is already encrypted and has no warning to click through.)
|
|
|
|
|
|
.map(|ip| if lan_fingerprint().is_some() && !ip.starts_with("100.") { format!("https://{ip}:{port}") } else { format!("http://{ip}:{port}") })
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
.collect();
|
|
|
|
|
|
v.dedup();
|
|
|
|
|
|
v
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ---------- the relay connection (this AnyBot as a "host") ----------
|
|
|
|
|
|
|
|
|
|
|
|
static RELAY_GEN: AtomicU64 = AtomicU64::new(0);
|
|
|
|
|
|
|
2026-11-04 11:30:32 +00:00
|
|
|
|
/// One agent per timeout, kept: its connections stay open between requests (no new TCP and TLS
|
2026-11-07 13:27:07 +00:00
|
|
|
|
/// handshake each time). It accepts the same certificates as the long connection
|
|
|
|
|
|
/// (`tunnel::trusted_roots`: the public ones and the ones this computer trusts).
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
fn agent(secs: u64) -> ureq::Agent {
|
2026-11-04 11:30:32 +00:00
|
|
|
|
static AGENTS: OnceLock<Mutex<HashMap<u64, ureq::Agent>>> = OnceLock::new();
|
|
|
|
|
|
AGENTS
|
|
|
|
|
|
.get_or_init(Mutex::default)
|
|
|
|
|
|
.lock()
|
|
|
|
|
|
.unwrap()
|
|
|
|
|
|
.entry(secs)
|
2026-11-07 13:27:07 +00:00
|
|
|
|
.or_insert_with(|| {
|
|
|
|
|
|
let roots: Vec<_> = crate::tunnel::trusted_roots().iter().map(|c| ureq::tls::Certificate::from_der(c.as_ref()).to_owned()).collect();
|
|
|
|
|
|
let tls = ureq::tls::TlsConfig::builder().root_certs(ureq::tls::RootCerts::new_with_certs(&roots)).build();
|
|
|
|
|
|
ureq::Agent::config_builder().timeout_global(Some(Duration::from_secs(secs))).http_status_as_error(false).tls_config(tls).build().into()
|
|
|
|
|
|
})
|
2026-11-04 11:30:32 +00:00
|
|
|
|
.clone()
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-11-04 11:07:55 +00:00
|
|
|
|
/// Why a request never got an answer, in plain words (never an error code).
|
|
|
|
|
|
pub fn why_unreachable(e: &ureq::Error) -> String {
|
|
|
|
|
|
use std::io::ErrorKind as K;
|
|
|
|
|
|
use ureq::Error as E;
|
|
|
|
|
|
let text = e.to_string().to_lowercase();
|
2026-11-04 23:56:19 +00:00
|
|
|
|
// A TLS failure often comes wrapped as an I/O error: look at the words first.
|
2026-11-07 13:27:07 +00:00
|
|
|
|
// A certificate no one this computer trusts has signed: usually a server that signs its own.
|
|
|
|
|
|
if text.contains("unknownissuer") || text.contains("unknown issuer") {
|
|
|
|
|
|
return "這台電腦還不信任伺服器的憑證(伺服器自己簽的):先在這台電腦安裝並信任它的憑證(區網伺服器:用瀏覽器打開 http://伺服器位址/anybot-ca.crt),再試一次".to_string();
|
|
|
|
|
|
}
|
2026-11-04 23:56:19 +00:00
|
|
|
|
if text.contains("certificate") || text.contains("tls") || text.contains("handshake") {
|
|
|
|
|
|
return "和伺服器的安全連線失敗:對方的憑證不對(網址可能連到了別的服務,或憑證過期)".to_string();
|
|
|
|
|
|
}
|
2026-11-04 11:07:55 +00:00
|
|
|
|
let w = match e {
|
|
|
|
|
|
E::HostNotFound => "找不到伺服器:這台電腦可能沒連上網路,或伺服器網址打錯了",
|
|
|
|
|
|
E::ConnectionFailed => "伺服器沒有回應:可能沒開機,或網路把連線擋住了",
|
|
|
|
|
|
E::Timeout(_) => "等太久沒有回應:網路很慢或斷斷續續",
|
|
|
|
|
|
E::Io(io) => match io.kind() {
|
|
|
|
|
|
K::ConnectionRefused => "伺服器沒有開(連線被拒絕)",
|
|
|
|
|
|
K::ConnectionReset | K::ConnectionAborted | K::BrokenPipe | K::UnexpectedEof => "連線到一半斷掉了",
|
|
|
|
|
|
K::TimedOut => "等太久沒有回應:網路很慢或斷斷續續",
|
|
|
|
|
|
K::NetworkUnreachable | K::HostUnreachable | K::NetworkDown | K::AddrNotAvailable => "這台電腦沒有連上網路",
|
|
|
|
|
|
_ => "網路連線出了問題",
|
|
|
|
|
|
},
|
|
|
|
|
|
_ if text.contains("dns") || text.contains("resolve") => "找不到伺服器:這台電腦可能沒連上網路,或伺服器網址打錯了",
|
|
|
|
|
|
_ => "網路連線出了問題",
|
|
|
|
|
|
};
|
|
|
|
|
|
w.to_string()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// An answer that wasn't a yes, in plain words. `whom` names the other side (大腦, 那台電腦…).
|
|
|
|
|
|
pub fn why_refused(st: u16, v: &Value, whom: &str) -> String {
|
|
|
|
|
|
if let Some(e) = v["error"].as_str().filter(|e| !e.is_empty()) {
|
|
|
|
|
|
return e.replace("那台 AnyBot ", whom).replace("那台 AnyBot", whom);
|
|
|
|
|
|
}
|
|
|
|
|
|
match st {
|
|
|
|
|
|
401 | 403 => "這台電腦的帳號登入失效了,請到「設定 › 手機與帳號」重新登入".into(),
|
|
|
|
|
|
404 => format!("{whom}不在這個帳號裡了(可能被移除,或兩邊 AnyBot 版本不同)"),
|
|
|
|
|
|
413 => "檔案太大,帳號伺服器不收".into(),
|
|
|
|
|
|
502 | 503 => "帳號伺服器暫時無法使用(可能正在重新啟動),稍後會自動再試".into(),
|
|
|
|
|
|
504 => format!("{whom}沒有及時回應(可能太忙或網路很慢)"),
|
|
|
|
|
|
500..=599 => "帳號伺服器出了問題,稍後會自動再試".into(),
|
|
|
|
|
|
_ => format!("{whom}的回應看不懂,請把兩邊的 AnyBot 都更新到最新版"),
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
pub fn relay_post(url: &str, bearer: &str, body: &Value) -> Result<Value, String> {
|
|
|
|
|
|
let mut r = agent(30).post(url).header("Content-Type", "application/json");
|
|
|
|
|
|
if !bearer.is_empty() {
|
|
|
|
|
|
r = r.header("Authorization", &format!("Bearer {bearer}"));
|
|
|
|
|
|
}
|
2026-11-04 11:07:55 +00:00
|
|
|
|
let mut resp = r.send(body.to_string().as_bytes()).map_err(|e| format!("連不到帳號伺服器:{}", why_unreachable(&e)))?;
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
let st = resp.status().as_u16();
|
|
|
|
|
|
let text = resp.body_mut().read_to_string().unwrap_or_default();
|
|
|
|
|
|
let v: Value = serde_json::from_str(&text).unwrap_or(Value::Null);
|
|
|
|
|
|
if !(200..300).contains(&st) {
|
2026-11-04 11:07:55 +00:00
|
|
|
|
return Err(why_refused(st, &v, "帳號伺服器"));
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
Ok(v)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn base(url: &str) -> String {
|
|
|
|
|
|
url.trim().trim_end_matches('/').to_string()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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
|
|
|
|
/// How the refusal starts when the account has 兩步驗證 on and no code came with the password
|
|
|
|
|
|
/// (the forms look for it to show their 驗證碼 field).
|
|
|
|
|
|
pub const NEED_CODE: &str = "這個帳號開了兩步驗證";
|
|
|
|
|
|
|
|
|
|
|
|
/// Sign in as the person: the password, then — when the account has 兩步驗證 on — the code of
|
|
|
|
|
|
/// their authenticator app (or one of the recovery codes). Gives the session.
|
|
|
|
|
|
/// (The answer to a right password is then a challenge, not a session: read as a session, it
|
|
|
|
|
|
/// was 「帳號伺服器沒有給登入憑證」, and an account with 兩步驗證 could not sign a computer in
|
|
|
|
|
|
/// or fetch its backup at all.)
|
|
|
|
|
|
fn relay_login(url: &str, user: &str, password: &str, device: &str, code: &str) -> Result<String, String> {
|
|
|
|
|
|
let v = relay_post(&format!("{url}/relay/login"), "", &json!({"user": user, "password": password, "device": device}))?;
|
|
|
|
|
|
if let Some(t) = v["token"].as_str().filter(|t| !t.is_empty()) {
|
|
|
|
|
|
return Ok(t.to_string());
|
|
|
|
|
|
}
|
|
|
|
|
|
if v["need_2fa"].as_bool() != Some(true) {
|
|
|
|
|
|
return Err("帳號伺服器沒有給登入憑證".into());
|
|
|
|
|
|
}
|
|
|
|
|
|
let code = code.trim();
|
|
|
|
|
|
if code.is_empty() {
|
|
|
|
|
|
return Err(format!("{NEED_CODE}:還要驗證器 App 現在的六位碼(或一組恢復碼)。"));
|
|
|
|
|
|
}
|
|
|
|
|
|
let v = relay_post(&format!("{url}/relay/2fa/verify"), "", &json!({"challenge": v["challenge"], "code": code}))?;
|
|
|
|
|
|
v["token"].as_str().filter(|t| !t.is_empty()).map(String::from).ok_or_else(|| "帳號伺服器沒有給登入憑證".to_string())
|
|
|
|
|
|
}
|
|
|
|
|
|
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
/// Sign in (or create the account) at the relay and register this AnyBot as one of its hosts.
|
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
|
|
|
|
/// Returns the settings to keep. `code`: the 兩步驗證 code, for an account that has it on.
|
|
|
|
|
|
pub fn relay_join(base_settings: &Settings, url: &str, user: &str, password: &str, create: bool, invite: &str, code: &str) -> Result<Settings, String> {
|
2026-11-05 07:48:20 +00:00
|
|
|
|
// The relay signs people in by the trimmed, lowered name; the backup key must be derived
|
|
|
|
|
|
// from exactly the same string, or two computers signing in as "Dan" and "dan" get keys
|
|
|
|
|
|
// that cannot open each other's backups.
|
|
|
|
|
|
let user = user.trim().to_lowercase();
|
|
|
|
|
|
let user = user.as_str();
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
let host_name = base_settings.host_name.as_str();
|
|
|
|
|
|
let url = base(url);
|
|
|
|
|
|
// Plain http only inside one machine or one Docker network (e.g. http://relay:8080).
|
|
|
|
|
|
let host = url.strip_prefix("http://").map(|r| r.split(['/', ':']).next().unwrap_or("")).unwrap_or("");
|
|
|
|
|
|
// Tailscale (100.64.0.0/10 and *.ts.net) is already encrypted end to end.
|
|
|
|
|
|
let tailscale = host.ends_with(".ts.net") || host.split('.').collect::<Vec<_>>().as_slice().first().map(|a| *a == "100").unwrap_or(false) && host.split('.').nth(1).and_then(|b| b.parse::<u8>().ok()).map(|b| (64..128).contains(&b)).unwrap_or(false);
|
|
|
|
|
|
let internal = host == "127.0.0.1" || host == "localhost" || tailscale || (!host.is_empty() && !host.contains('.'));
|
|
|
|
|
|
if !url.starts_with("https://") && !internal {
|
|
|
|
|
|
return Err("帳號伺服器要用 https:// 開頭的網址(這台電腦或 Tailscale 位址可以用 http://)".into());
|
|
|
|
|
|
}
|
|
|
|
|
|
if create {
|
2026-11-04 13:34:15 +00:00
|
|
|
|
if let Err(e) = relay_post(&format!("{url}/relay/signup"), "", &json!({"user": user, "password": password, "invite": invite})) {
|
|
|
|
|
|
// The account may be there already (made earlier, or on the phone): just sign in with it.
|
|
|
|
|
|
if relay_post(&format!("{url}/relay/login"), "", &json!({"user": user, "password": password, "device": host_name})).is_err() {
|
|
|
|
|
|
return Err(if e.contains("不開放註冊") || e.contains("邀請碼") {
|
|
|
|
|
|
"這台帳號伺服器已經有帳號了,不能再註冊新的。請取消勾選「建立新帳號」,用已經有的帳號登入。忘記密碼的話,在帳號伺服器那台電腦執行:anybot-relay --data 資料夾 --reset-password 帳號".into()
|
|
|
|
|
|
} else {
|
|
|
|
|
|
e
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
}
|
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
|
|
|
|
let session = relay_login(&url, user, password, host_name, code)?;
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
let h = relay_post(&format!("{url}/relay/hosts"), &session, &json!({"name": host_name}))?;
|
|
|
|
|
|
// The desktop doesn't need to stay signed in as a person; only the host key is kept.
|
|
|
|
|
|
let _ = relay_post(&format!("{url}/relay/logout"), &session, &json!({}));
|
|
|
|
|
|
let mut s = base_settings.clone();
|
|
|
|
|
|
s.relay_url = url;
|
|
|
|
|
|
s.relay_user = user.to_string();
|
|
|
|
|
|
s.host_id = h["id"].as_str().unwrap_or("").to_string();
|
|
|
|
|
|
s.host_token = h["token"].as_str().unwrap_or("").to_string();
|
|
|
|
|
|
s.backup_key = httpd::derive_key(password, user).iter().map(|b| format!("{b:02x}")).collect();
|
|
|
|
|
|
if s.host_id.is_empty() || s.host_token.is_empty() {
|
|
|
|
|
|
return Err("帳號伺服器沒有給這台電腦的金鑰".into());
|
|
|
|
|
|
}
|
|
|
|
|
|
Ok(s)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Keep the outgoing connection to the relay: wait for the phone's requests and answer them.
|
|
|
|
|
|
pub fn relay_restart(s: &Settings) {
|
|
|
|
|
|
let gen = RELAY_GEN.fetch_add(1, Ordering::SeqCst) + 1;
|
|
|
|
|
|
if s.relay_url.is_empty() || s.host_token.is_empty() {
|
|
|
|
|
|
hub().set_relay_status("");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
let (url, token) = (s.relay_url.clone(), s.host_token.clone());
|
|
|
|
|
|
hub().set_relay_status("連線中…");
|
2026-11-04 11:30:32 +00:00
|
|
|
|
std::thread::spawn(move || {
|
|
|
|
|
|
// 長連線 first; an older account server without it gets asked over and over instead.
|
|
|
|
|
|
if crate::tunnel::run(&url, &token, &|| alive(gen), &|m| hub().set_relay_status(m)) || !alive(gen) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
// A few workers, so a slow request (a long-poll) doesn't block the others.
|
|
|
|
|
|
for _ in 0..4 {
|
|
|
|
|
|
let (url, token) = (url.clone(), token.clone());
|
|
|
|
|
|
std::thread::spawn(move || relay_worker(&url, &token, gen));
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn alive(gen: u64) -> bool {
|
|
|
|
|
|
RELAY_GEN.load(Ordering::SeqCst) == gen
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn relay_worker(url: &str, token: &str, gen: u64) {
|
|
|
|
|
|
let mut backoff = 1u64;
|
|
|
|
|
|
while alive(gen) {
|
|
|
|
|
|
let r = agent(40).get(&format!("{url}/relay/host/next")).header("Authorization", &format!("Bearer {token}")).call();
|
|
|
|
|
|
let mut resp = match r {
|
|
|
|
|
|
Ok(r) => r,
|
|
|
|
|
|
Err(e) => {
|
2026-11-04 11:07:55 +00:00
|
|
|
|
hub().set_relay_status(&format!("連不上帳號伺服器:{}", why_unreachable(&e)));
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
std::thread::sleep(Duration::from_secs(backoff));
|
|
|
|
|
|
backoff = (backoff * 2).min(30);
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
let st = resp.status().as_u16();
|
|
|
|
|
|
if st == 401 {
|
|
|
|
|
|
hub().set_relay_status("這台電腦的金鑰失效了,請重新登入帳號");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
if st == 204 {
|
|
|
|
|
|
hub().set_relay_status("已連線");
|
|
|
|
|
|
backoff = 1;
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
let text = resp.body_mut().read_to_string().unwrap_or_default();
|
2026-11-13 15:36:34 +00:00
|
|
|
|
// An error from the server (busy, too many requests) is not a job: wait, longer each
|
|
|
|
|
|
// time. (Its JSON body was read as a job and answered at once — a tight loop of
|
|
|
|
|
|
// requests and threads exactly when the server was overloaded.)
|
|
|
|
|
|
if st != 200 {
|
|
|
|
|
|
hub().set_relay_status(&format!("連不上帳號伺服器:{}", why_refused(st, &serde_json::from_str(&text).unwrap_or(Value::Null), "帳號伺服器")));
|
|
|
|
|
|
std::thread::sleep(Duration::from_secs(backoff));
|
|
|
|
|
|
backoff = (backoff * 2).min(30);
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
let Ok(job) = serde_json::from_str::<Value>(&text) else {
|
2026-11-04 11:07:55 +00:00
|
|
|
|
hub().set_relay_status(&format!("連不上帳號伺服器:{}", why_refused(st, &Value::Null, "帳號伺服器")));
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
std::thread::sleep(Duration::from_secs(backoff));
|
2026-11-04 11:07:55 +00:00
|
|
|
|
backoff = (backoff * 2).min(30);
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
continue;
|
|
|
|
|
|
};
|
|
|
|
|
|
hub().set_relay_status("已連線");
|
|
|
|
|
|
backoff = 1;
|
|
|
|
|
|
let id = job["id"].as_str().unwrap_or("").to_string();
|
|
|
|
|
|
let req = req_from_json(&job);
|
|
|
|
|
|
// Answer on a separate thread so this worker can pick up the next request at once.
|
|
|
|
|
|
let (url, token) = (url.to_string(), token.to_string());
|
|
|
|
|
|
std::thread::spawn(move || {
|
|
|
|
|
|
let resp = handle(req, true);
|
|
|
|
|
|
let _ = agent(60).post(&format!("{url}/relay/host/reply/{id}")).header("Authorization", &format!("Bearer {token}")).header("Content-Type", "application/json").send(resp_to_json(&resp).to_string().as_bytes());
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn req_from_json(job: &Value) -> Req {
|
|
|
|
|
|
use base64::Engine;
|
|
|
|
|
|
Req {
|
|
|
|
|
|
method: job["method"].as_str().unwrap_or("GET").to_string(),
|
|
|
|
|
|
path: job["path"].as_str().unwrap_or("/").to_string(),
|
|
|
|
|
|
query: job["query"].as_object().map(|o| o.iter().map(|(k, v)| (k.clone(), v.as_str().unwrap_or("").to_string())).collect()).unwrap_or_default(),
|
|
|
|
|
|
// Who asked, as the relay vouches for it (團隊: owner / admin / member; "device" for 裝置連結).
|
2026-11-13 15:36:34 +00:00
|
|
|
|
headers: [("x-anybot-user", job["user"].as_str().unwrap_or("")), ("x-anybot-role", job["role"].as_str().unwrap_or("none")), ("x-anybot-from", job["from"].as_str().unwrap_or(""))].iter().map(|(k, v)| (k.to_string(), v.to_string())).collect(),
|
2026-11-04 11:30:32 +00:00
|
|
|
|
body: {
|
|
|
|
|
|
let b = base64::engine::general_purpose::STANDARD.decode(job["body"].as_str().unwrap_or("")).unwrap_or_default();
|
|
|
|
|
|
if job["z"].as_bool().unwrap_or(false) {
|
|
|
|
|
|
crate::tunnel::unzip(&b).unwrap_or_default()
|
|
|
|
|
|
} else {
|
|
|
|
|
|
b
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
peer: "relay".into(),
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn resp_to_json(r: &Resp) -> Value {
|
|
|
|
|
|
use base64::Engine;
|
|
|
|
|
|
json!({"status": r.status, "ctype": r.ctype, "body": base64::engine::general_purpose::STANDARD.encode(&r.body), "headers": r.headers})
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Upload an encrypted copy of AnyBot's data to the relay.
|
|
|
|
|
|
pub fn backup_now(s: &Settings, state_json: &[u8]) -> Result<usize, String> {
|
|
|
|
|
|
let key = key_of(&s.backup_key).ok_or("還沒登入帳號")?;
|
|
|
|
|
|
let sealed = httpd::seal(&key, state_json);
|
|
|
|
|
|
let mut resp = agent(120)
|
|
|
|
|
|
.put(&format!("{}/relay/backup", s.relay_url))
|
|
|
|
|
|
.header("Authorization", &format!("Bearer {}", s.host_token))
|
|
|
|
|
|
.header("Content-Type", "application/octet-stream")
|
|
|
|
|
|
.send(&sealed[..])
|
|
|
|
|
|
.map_err(|e| format!("備份上傳失敗:{e}"))?;
|
|
|
|
|
|
let st = resp.status().as_u16();
|
|
|
|
|
|
if !(200..300).contains(&st) {
|
|
|
|
|
|
return Err(format!("備份上傳失敗:{}", resp.body_mut().read_to_string().unwrap_or_default()));
|
|
|
|
|
|
}
|
|
|
|
|
|
Ok(sealed.len())
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Download and open the newest backup of this account (for a new computer).
|
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
|
|
|
|
pub fn restore(url: &str, user: &str, password: &str, code: &str) -> Result<Vec<u8>, String> {
|
2026-11-05 07:48:20 +00:00
|
|
|
|
// Same name shape the relay (and relay_join) use for the backup key.
|
|
|
|
|
|
let user = user.trim().to_lowercase();
|
|
|
|
|
|
let user = user.as_str();
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
let url = base(url);
|
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
|
|
|
|
let session = relay_login(&url, user, password, "還原備份", code)?;
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
let mut resp = agent(120).get(&format!("{url}/relay/backup")).header("Authorization", &format!("Bearer {session}")).call().map_err(|e| e.to_string())?;
|
|
|
|
|
|
let _ = relay_post(&format!("{url}/relay/logout"), &session, &json!({}));
|
|
|
|
|
|
if resp.status().as_u16() == 404 {
|
|
|
|
|
|
return Err("這個帳號還沒有備份".into());
|
|
|
|
|
|
}
|
|
|
|
|
|
let sealed = resp.body_mut().with_config().limit(200 * 1024 * 1024).read_to_vec().map_err(|e| e.to_string())?;
|
2026-11-13 16:40:16 +00:00
|
|
|
|
// (A backup made before the key got dearer to guess opens with the key as it was.)
|
|
|
|
|
|
httpd::open(&httpd::derive_key(password, user), &sealed).or_else(|| httpd::open(&httpd::derive_key_before(password, user), &sealed)).ok_or_else(|| "備份打不開(密碼不對,或備份壞了)".to_string())
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn key_of(hex: &str) -> Option<[u8; 32]> {
|
安全、修正: harden sandboxes, approval gates, vault, relay roles, and fix protocol/UI bugs
- macOS 沙盒與工具 (tools.rs, policy.rs, docindex.rs): block AppleScript raw events and
concatenation outside the sandbox; stop exposing ~/.ssh or localhost sockets in Sealed
mode; deny writes to shell profiles, LaunchAgents and .git/hooks; expand secret-file
ignores and enforce symlink/policy checks across SSH, device and document search.
- 電腦操作與遮罩 (computer.rs, agent.rs, marks.rs, desktop.rs, cloudbox.rs, portal.rs):
forbid clicking or typing into AnyBot's own windows; extend the sensitive-action hard
gate to raw coordinates, Return/Delete submits and remote devices; stop batch steps if
the front app changes; black out secrets on zoom, show, >600-node trees, adjacent OTP
labels, box screenshots and control text lists; preserve non-text Wayland clipboards.
- 保險庫與瀏覽器 (vault.rs, vault_store.rs, browser.rs, botbrowser.rs, web.rs, box/browser):
verify tab host and HTTPS atomically at fill time; taint filled tabs against browser_eval
and PDF export while masking card/CVC values and screenshots; remember sites only on
always-allow; drop --remote-allow-origins=*; gate private URLs and block metadata/Docker
ports, OrbStack 198.18/15 and IPv6 transition ranges.
- 帳號伺服器、同步與傳送 (relay/, remote.rs, mirror_ui.rs, share.rs, drops.rs): isolate
paired hands hosts from brain sync, tickets, pairing and backup overwrites; redact
routine trigger secrets and clear REDACTED when endpoints change; isolate channel and
team-member turns from owner memories, appctl and grants; scrub shared bot exports and
reset grants/routines on import; validate drop IDs and serialize chunk writes.
- 網路與協定穩定性 (httpd.rs, tunnel.rs, vnc.rs, Caddyfile*): fix chunked integer overflow
and CRLF header injection; enforce Origin checks, connection/job caps, 200 MB backup
reads, unique atomic temp files and ASCII hex guards; bound deflate unzip and VNC sniff
buffers; move VNC stdin/text off the tunnel loop.
- 介面、排程、語言與其他修正 (app.rs, i18n.rs, providers.rs, skills.rs, routines.rs,
setup.rs, store.rs, preview.rs, attach.rs, speech.rs, teams.rs, mcp.rs, voice.rs):
wire up the delete-routine confirmation dialog and mirror run-now; preserve unsaved
mirror edits across brief disconnects; give Chinese skills distinct folders and approval
gates; convert parsed tool JSON fields without corrupting code fences, URLs or paths;
fix Hourly DST offsets and time out unattended routine approvals; lock --install-skill,
cap docx/xlsx unzip sizes, isolate test env keys, and tighten local file permissions.
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-12 06:34:10 +00:00
|
|
|
|
if hex.len() != 64 || !hex.is_ascii() {
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
return None;
|
|
|
|
|
|
}
|
|
|
|
|
|
let mut k = [0u8; 32];
|
|
|
|
|
|
for i in 0..32 {
|
|
|
|
|
|
k[i] = u8::from_str_radix(&hex[i * 2..i * 2 + 2], 16).ok()?;
|
|
|
|
|
|
}
|
|
|
|
|
|
Some(k)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// 裝置連結: run a tool on another AnyBot of this account (through the relay).
|
|
|
|
|
|
pub fn run_on_device(host_id: &str, tool: &str, args: &str, who: &str) -> Result<Value, String> {
|
|
|
|
|
|
let s = hub().settings();
|
|
|
|
|
|
if s.relay_url.is_empty() {
|
|
|
|
|
|
return Err("沒有登入帳號,連不到其他裝置".into());
|
|
|
|
|
|
}
|
2026-11-13 16:40:16 +00:00
|
|
|
|
let body = signed_run(&s, host_id, tool, args, who).to_string();
|
2026-11-04 11:30:32 +00:00
|
|
|
|
if let Some(r) = crate::tunnel::call(host_id, "POST", "/api/device/run", &[], body.as_bytes(), 50) {
|
|
|
|
|
|
return r.map_err(|e| format!("連不到那台電腦:{e}")).and_then(|a| answer_value(a.status, &a.body, "那台電腦"));
|
|
|
|
|
|
}
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
let url = format!("{}/relay/hosts/{host_id}/api/device/run", s.relay_url);
|
|
|
|
|
|
let mut resp = agent(45)
|
|
|
|
|
|
.post(&url)
|
|
|
|
|
|
.header("Authorization", &format!("Bearer {}", s.host_token))
|
|
|
|
|
|
.header("Content-Type", "application/json")
|
2026-11-13 16:40:16 +00:00
|
|
|
|
// (Signed anew: a signature is good once.)
|
|
|
|
|
|
.send(signed_run(&s, host_id, tool, args, who).to_string().as_bytes())
|
2026-11-04 11:07:55 +00:00
|
|
|
|
.map_err(|e| format!("連不到帳號伺服器,所以也連不到那台電腦:{}", why_unreachable(&e)))?;
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
let st = resp.status().as_u16();
|
|
|
|
|
|
let text = resp.body_mut().with_config().limit(40 * 1024 * 1024).read_to_string().unwrap_or_default();
|
|
|
|
|
|
let v: Value = serde_json::from_str(&text).unwrap_or(Value::Null);
|
|
|
|
|
|
if !(200..300).contains(&st) {
|
2026-11-04 11:07:55 +00:00
|
|
|
|
return Err(why_refused(st, &v, "那台電腦"));
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
Ok(v)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-11-04 09:46:43 +00:00
|
|
|
|
// ---------- 大腦: this AnyBot as a screen of another ----------
|
|
|
|
|
|
|
|
|
|
|
|
fn brain_url(s: &Settings, rest: &str) -> Result<String, String> {
|
|
|
|
|
|
if s.relay_url.is_empty() || s.host_token.is_empty() {
|
|
|
|
|
|
return Err("沒有登入帳號".into());
|
|
|
|
|
|
}
|
|
|
|
|
|
if s.brain_id.is_empty() {
|
|
|
|
|
|
return Err("沒有選大腦".into());
|
|
|
|
|
|
}
|
|
|
|
|
|
Ok(format!("{}/relay/hosts/{}/api/sync{rest}", s.relay_url, s.brain_id))
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-11-04 11:30:32 +00:00
|
|
|
|
/// A JSON answer, or what went wrong in words.
|
|
|
|
|
|
fn answer_value(st: u16, bytes: &[u8], whom: &str) -> Result<Value, String> {
|
|
|
|
|
|
let v: Value = serde_json::from_slice(bytes).unwrap_or(Value::Null);
|
2026-11-04 09:46:43 +00:00
|
|
|
|
if !(200..300).contains(&st) {
|
2026-11-04 11:30:32 +00:00
|
|
|
|
return Err(why_refused(st, &v, whom));
|
2026-11-04 11:07:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
if v.is_null() {
|
2026-11-04 11:30:32 +00:00
|
|
|
|
return Err(format!("{whom}的回應看不懂,請把兩邊的 AnyBot 都更新到最新版"));
|
2026-11-04 09:46:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
Ok(v)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-11-04 11:30:32 +00:00
|
|
|
|
/// Ask the brain: over the lasting connection when it is open, else an ordinary request.
|
傳送: 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 02:04:13 +00:00
|
|
|
|
pub(crate) fn to_brain(s: &Settings, method: &str, rest: &str, query: &[(&str, String)], body: &[u8], secs: u64) -> Result<Value, String> {
|
2026-11-04 11:30:32 +00:00
|
|
|
|
let (st, bytes) = to_brain_raw(s, method, rest, query, body, secs)?;
|
|
|
|
|
|
answer_value(st, &bytes, "大腦")
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn to_brain_raw(s: &Settings, method: &str, rest: &str, query: &[(&str, String)], body: &[u8], secs: u64) -> Result<(u16, Vec<u8>), String> {
|
2026-11-11 03:07:55 +00:00
|
|
|
|
let (st, bytes) = to_brain_any(s, method, rest, query, body, secs)?;
|
|
|
|
|
|
// The brain's own 「沒有這個網址」 (the account server passes every /api/sync path through):
|
|
|
|
|
|
// it runs an AnyBot from before this was asked of it — say so, not "no such address".
|
|
|
|
|
|
if st == 404 && serde_json::from_slice::<Value>(&bytes).map(|v| v["error"] == NO_SUCH_PATH).unwrap_or(false) {
|
|
|
|
|
|
return Err(brain_too_old(&s.brain_name));
|
|
|
|
|
|
}
|
|
|
|
|
|
Ok((st, bytes))
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const NO_SUCH_PATH: &str = "沒有這個網址";
|
|
|
|
|
|
|
|
|
|
|
|
fn brain_too_old(name: &str) -> String {
|
|
|
|
|
|
let name = if name.trim().is_empty() { "大腦" } else { name.trim() };
|
|
|
|
|
|
format!("{name}的 AnyBot 是舊版,還沒有這個功能。請更新{name}:在那台機器的 AnyBot 資料夾執行 make update")
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn to_brain_any(s: &Settings, method: &str, rest: &str, query: &[(&str, String)], body: &[u8], secs: u64) -> Result<(u16, Vec<u8>), String> {
|
2026-11-04 11:30:32 +00:00
|
|
|
|
if s.brain_id.is_empty() {
|
|
|
|
|
|
return Err("沒有選大腦".into());
|
|
|
|
|
|
}
|
|
|
|
|
|
if let Some(r) = crate::tunnel::call(&s.brain_id, method, &format!("/api/sync{rest}"), query, body, secs) {
|
People watch and help on the bots' computer through VNC (noVNC), carried by the account server
The core: the bot works the computer; a person watches it like a colleague, and takes over
when it needs them. VNC is made for that (only what changed, every mouse move and key, touch on
phones), so the pictures sent one by one go, and with them their own input path.
- vnc.rs: a VNC proxy to the box's x11vnc through one docker exec (a Python bridge that ends
with either side). It signs in to the box with the box's own password (its VNC_PASSWORD) and
offers the viewer no password, so the password never leaves the brain. The person's clicks
and keys make the bot's steps wait until 8 s after they stop; text typed in the viewer's box
(any language) is pasted in the box.
- Account server: /screen (the viewer page) and /novnc.js (noVNC 1.6.0, MPL-2.0, bundled);
/relay/vnc/<host> takes the browser's WebSocket (account session, or a 10-minute ticket the
app asks for with POST /relay/screen-ticket; owners and admins) and carries it over that
AnyBot's lasting connection (vopen / vdata / vtext / vclose). Both ends of that connection
wait 2 ms instead of 40 ms to read while things move: a request and its answer took up to
160 ms more than needed.
- Phone page: 看 Bot 的電腦 and 接管 open the viewer page (also on the local network: /api/vnc on
the AnyBot's own phone server). This Mac's own screen moved to the ⋯ menu.
- Mac app: 看畫面 opens the viewer in the browser (a screen of a brain: the brain's computer by
ticket; else this computer's box, noVNC straight from it). The in-app picture viewer, the
live JPEG stream, the person's click/move/scroll/key endpoints and the input shell are gone.
- Opening a Mac app uses LaunchServices (`open -a`): agent-desktop's launch waited on the window
through accessibility and failed without 輔助使用 now and then.
Measured on this Mac (made-up account, local relay + headless brain + the real box): viewer
signed in in 0.4–0.7 s, a request and its answer through relay + brain + box 25–58 ms median;
headless Chrome shows the desktop live in /screen. remote_e2e 28/28 ×2, 149 unit tests, relay 11.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-05 15:05:44 +00:00
|
|
|
|
return r.map(|a| (a.status, a.body));
|
2026-11-04 11:30:32 +00:00
|
|
|
|
}
|
Remove what nothing uses and keep one copy of what was written several times
Unused (found by taking away the dead-code allowances; nothing else used them, tests aside):
computer::specs, quiet_button, the never-made Poke::Spin, ten icons and their SVGs, the
theme's chrome/bubble_agent colours, ImportRow.line, voice's multipart/transcribe/speak
wrappers, and the old keychain writers vault::save/remove/index_add with their live test
(the vault store replaced them; reading old keychain entries for the import stays).
One copy each: percent-encoding (httpd::url_encode, was four), tool arguments (tools::args_of,
was three), the WebSocket handshake (httpd::accept_websocket, was three), the read pacing
(wire::Pace, was two: relay and app), docker with input and a time limit (dk_with_input, was
two). Docs: FEATURES §看畫面 (VNC), protocol (v* frames, /screen, tickets), architecture.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-05 15:21:47 +00:00
|
|
|
|
let q: Vec<String> = query.iter().map(|(k, v)| format!("{k}={}", httpd::url_encode(v))).collect();
|
2026-11-04 11:30:32 +00:00
|
|
|
|
let url = brain_url(s, &format!("{rest}{}{}", if q.is_empty() { "" } else { "?" }, q.join("&")))?;
|
|
|
|
|
|
let auth = format!("Bearer {}", s.host_token);
|
|
|
|
|
|
let r = if method == "GET" { agent(secs).get(&url).header("Authorization", &auth).call() } else { agent(secs).post(&url).header("Authorization", &auth).header("Content-Type", "application/octet-stream").send(body) };
|
|
|
|
|
|
let mut resp = r.map_err(|e| format!("連不到帳號伺服器:{}", why_unreachable(&e)))?;
|
|
|
|
|
|
let st = resp.status().as_u16();
|
|
|
|
|
|
let bytes = resp.body_mut().with_config().limit(200 * 1024 * 1024).read_to_vec().map_err(|_| "和大腦的連線到一半斷掉了".to_string())?;
|
People watch and help on the bots' computer through VNC (noVNC), carried by the account server
The core: the bot works the computer; a person watches it like a colleague, and takes over
when it needs them. VNC is made for that (only what changed, every mouse move and key, touch on
phones), so the pictures sent one by one go, and with them their own input path.
- vnc.rs: a VNC proxy to the box's x11vnc through one docker exec (a Python bridge that ends
with either side). It signs in to the box with the box's own password (its VNC_PASSWORD) and
offers the viewer no password, so the password never leaves the brain. The person's clicks
and keys make the bot's steps wait until 8 s after they stop; text typed in the viewer's box
(any language) is pasted in the box.
- Account server: /screen (the viewer page) and /novnc.js (noVNC 1.6.0, MPL-2.0, bundled);
/relay/vnc/<host> takes the browser's WebSocket (account session, or a 10-minute ticket the
app asks for with POST /relay/screen-ticket; owners and admins) and carries it over that
AnyBot's lasting connection (vopen / vdata / vtext / vclose). Both ends of that connection
wait 2 ms instead of 40 ms to read while things move: a request and its answer took up to
160 ms more than needed.
- Phone page: 看 Bot 的電腦 and 接管 open the viewer page (also on the local network: /api/vnc on
the AnyBot's own phone server). This Mac's own screen moved to the ⋯ menu.
- Mac app: 看畫面 opens the viewer in the browser (a screen of a brain: the brain's computer by
ticket; else this computer's box, noVNC straight from it). The in-app picture viewer, the
live JPEG stream, the person's click/move/scroll/key endpoints and the input shell are gone.
- Opening a Mac app uses LaunchServices (`open -a`): agent-desktop's launch waited on the window
through accessibility and failed without 輔助使用 now and then.
Measured on this Mac (made-up account, local relay + headless brain + the real box): viewer
signed in in 0.4–0.7 s, a request and its answer through relay + brain + box 25–58 ms median;
headless Chrome shows the desktop live in /screen. remote_e2e 28/28 ×2, 149 unit tests, relay 11.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-05 15:05:44 +00:00
|
|
|
|
Ok((st, bytes))
|
2026-11-04 11:30:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-11-04 09:46:43 +00:00
|
|
|
|
/// What changed at the brain since `since` (waits up to LONG_POLL_SECS when nothing has).
|
|
|
|
|
|
pub fn sync_pull(s: &Settings, since: u64, client: &str) -> Result<Value, String> {
|
2026-11-04 11:30:32 +00:00
|
|
|
|
to_brain(s, "GET", "", &[("since", since.to_string()), ("client", client.to_string())], &[], LONG_POLL_SECS + 25)
|
2026-11-04 09:46:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Send edits ("edit") or a chat action ("act") to the brain.
|
|
|
|
|
|
pub fn sync_post(s: &Settings, what: &str, body: &Value) -> Result<Value, String> {
|
2026-11-04 11:30:32 +00:00
|
|
|
|
to_brain(s, "POST", &format!("/{what}"), &[], body.to_string().as_bytes(), 60)
|
2026-11-04 09:46:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// A file for the next message, kept at the brain; gives back its path there.
|
|
|
|
|
|
pub fn sync_upload(s: &Settings, bot: u64, name: &str, bytes: &[u8]) -> Result<String, String> {
|
2026-11-04 11:30:32 +00:00
|
|
|
|
let v = to_brain(s, "POST", &format!("/upload/{bot}"), &[("name", name.to_string())], bytes, 120)?;
|
2026-11-04 09:46:43 +00:00
|
|
|
|
v["path"].as_str().map(String::from).ok_or("大腦沒有收下檔案".into())
|
|
|
|
|
|
}
|
|
|
|
|
|
|
Voice: its own 設定 › 語音, run by the brain for every screen and the phone
Voice was three implementations that broke on their own: speech to text
borrowed the OpenAI key (so with only Grok set up the mic recorded,
then failed), OpenAI's models it hard-coded stop on 2027-02-26, read
aloud was macOS `say` or espeak-ng (silently nothing on Windows, where
espeak isn't installed), and the phone used the browser's own
recognition. Now:
- 設定 › 語音 has 聽 and 說, each a service: off, OpenAI-compatible
(OpenAI, Groq, a Whisper server of your own: the address decides),
xAI or ElevenLabs. An empty key borrows 設定 › 模型's for the same
service. Each side says 可以用 or what it lacks; 聽 has 試試看
(record a sentence, show what was heard), 說 has 試聽 and the voice
list. speech.rs does the calls; xAI's both ways were checked for real
(Mandarin read, then heard back, in Traditional characters).
- The brain does it all: the phone POSTs its recording (MediaRecorder)
to /api/voice/transcribe, screens to /api/sync/voice/transcribe;
answers come back as MP3 from …/voice/speech and are played on the
device (rodio; an <audio> on the phone, 「唸出來」 in a message's
menu). Keys stay on the brain (the voice keys are redacted for
screens like the others).
- No service, no voice anywhere: the mic, 語音聊天, 會議錄音 and 朗讀
only appear once 聽 (and 說) can be called; the phone's state says
which. Without voice the send arrow just rests where 語音聊天 was.
- 會議錄音 is uploaded to the brain, which turns it into text in the
background and hands it to the bot itself: a meeting is longer than
the 35 s the account lets a request wait, and a brain on a server has
no window (the jobs are polled in background()).
- Recognisers answer Mandarin in Simplified: in a Traditional Chinese
window or phone the text becomes Traditional with Taiwan wording.
- Older saves: whoever had an OpenAI key keeps voice input (聽 =
OpenAI); everyone else starts with it off. Bots' macOS voice names
are cleared. 對話詳細資訊's 加入會議 started plain voice input; it
starts a meeting now.
2026-11-10 14:58:18 +00:00
|
|
|
|
/// 語音 on the brain: a recording (`name` says its format) → its text.
|
|
|
|
|
|
pub fn sync_voice_transcribe(s: &Settings, audio: &[u8], name: &str, lang: &str) -> Result<String, String> {
|
|
|
|
|
|
let v = to_brain(s, "POST", "/voice/transcribe", &[("name", name.to_string()), ("lang", lang.to_string()), ("ui", crate::i18n::lang())], audio, 60)?;
|
|
|
|
|
|
Ok(v["text"].as_str().unwrap_or("").to_string())
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// 語音 on the brain: {text, voice, lang, speed} → MP3.
|
|
|
|
|
|
pub fn sync_voice_speech(s: &Settings, body: &Value) -> Result<Vec<u8>, String> {
|
|
|
|
|
|
let (st, bytes) = to_brain_raw(s, "POST", "/voice/speech", &[], body.to_string().as_bytes(), 60)?;
|
|
|
|
|
|
if st == 200 {
|
|
|
|
|
|
return Ok(bytes);
|
|
|
|
|
|
}
|
|
|
|
|
|
Err(answer_value(st, &bytes, "大腦").err().unwrap_or_else(|| format!("大腦的語音服務失敗(HTTP {st})")))
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// 語音 on the brain: the voices its 說 service offers, (id, name).
|
|
|
|
|
|
pub fn sync_voice_voices(s: &Settings) -> Result<Vec<(String, String)>, String> {
|
|
|
|
|
|
let v = to_brain(s, "POST", "/voice/voices", &[], b"{}", 30)?;
|
|
|
|
|
|
Ok(v["voices"].as_array().into_iter().flatten().filter_map(|x| Some((x[0].as_str()?.to_string(), x[1].as_str().unwrap_or("").to_string()))).collect())
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-11-05 08:47:28 +00:00
|
|
|
|
/// The brain's bots' computer as a JPEG (`thumb`: the small picture that never wakes it).
|
|
|
|
|
|
pub fn sync_screen(s: &Settings, thumb: bool) -> Result<Vec<u8>, String> {
|
|
|
|
|
|
let (st, bytes) = to_brain_raw(s, "GET", "/screen", &[("thumb", if thumb { "1" } else { "0" }.to_string())], &[], 30)?;
|
|
|
|
|
|
if !(200..300).contains(&st) {
|
|
|
|
|
|
return Err(why_refused(st, &serde_json::from_slice(&bytes).unwrap_or(Value::Null), "大腦"));
|
|
|
|
|
|
}
|
|
|
|
|
|
Ok(bytes)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
People watch and help on the bots' computer through VNC (noVNC), carried by the account server
The core: the bot works the computer; a person watches it like a colleague, and takes over
when it needs them. VNC is made for that (only what changed, every mouse move and key, touch on
phones), so the pictures sent one by one go, and with them their own input path.
- vnc.rs: a VNC proxy to the box's x11vnc through one docker exec (a Python bridge that ends
with either side). It signs in to the box with the box's own password (its VNC_PASSWORD) and
offers the viewer no password, so the password never leaves the brain. The person's clicks
and keys make the bot's steps wait until 8 s after they stop; text typed in the viewer's box
(any language) is pasted in the box.
- Account server: /screen (the viewer page) and /novnc.js (noVNC 1.6.0, MPL-2.0, bundled);
/relay/vnc/<host> takes the browser's WebSocket (account session, or a 10-minute ticket the
app asks for with POST /relay/screen-ticket; owners and admins) and carries it over that
AnyBot's lasting connection (vopen / vdata / vtext / vclose). Both ends of that connection
wait 2 ms instead of 40 ms to read while things move: a request and its answer took up to
160 ms more than needed.
- Phone page: 看 Bot 的電腦 and 接管 open the viewer page (also on the local network: /api/vnc on
the AnyBot's own phone server). This Mac's own screen moved to the ⋯ menu.
- Mac app: 看畫面 opens the viewer in the browser (a screen of a brain: the brain's computer by
ticket; else this computer's box, noVNC straight from it). The in-app picture viewer, the
live JPEG stream, the person's click/move/scroll/key endpoints and the input shell are gone.
- Opening a Mac app uses LaunchServices (`open -a`): agent-desktop's launch waited on the window
through accessibility and failed without 輔助使用 now and then.
Measured on this Mac (made-up account, local relay + headless brain + the real box): viewer
signed in in 0.4–0.7 s, a request and its answer through relay + brain + box 25–58 ms median;
headless Chrome shows the desktop live in /screen. remote_e2e 28/28 ×2, 149 unit tests, relay 11.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-05 15:05:44 +00:00
|
|
|
|
/// A link for this account's browser to watch the brain's computer (/screen on the account
|
|
|
|
|
|
/// server; one-time, it works for ten minutes).
|
|
|
|
|
|
pub fn screen_ticket(s: &Settings) -> Result<String, String> {
|
|
|
|
|
|
if s.relay_url.is_empty() || s.brain_id.is_empty() {
|
|
|
|
|
|
return Err("這台沒有連到帳號的大腦".into());
|
2026-11-05 14:34:36 +00:00
|
|
|
|
}
|
People watch and help on the bots' computer through VNC (noVNC), carried by the account server
The core: the bot works the computer; a person watches it like a colleague, and takes over
when it needs them. VNC is made for that (only what changed, every mouse move and key, touch on
phones), so the pictures sent one by one go, and with them their own input path.
- vnc.rs: a VNC proxy to the box's x11vnc through one docker exec (a Python bridge that ends
with either side). It signs in to the box with the box's own password (its VNC_PASSWORD) and
offers the viewer no password, so the password never leaves the brain. The person's clicks
and keys make the bot's steps wait until 8 s after they stop; text typed in the viewer's box
(any language) is pasted in the box.
- Account server: /screen (the viewer page) and /novnc.js (noVNC 1.6.0, MPL-2.0, bundled);
/relay/vnc/<host> takes the browser's WebSocket (account session, or a 10-minute ticket the
app asks for with POST /relay/screen-ticket; owners and admins) and carries it over that
AnyBot's lasting connection (vopen / vdata / vtext / vclose). Both ends of that connection
wait 2 ms instead of 40 ms to read while things move: a request and its answer took up to
160 ms more than needed.
- Phone page: 看 Bot 的電腦 and 接管 open the viewer page (also on the local network: /api/vnc on
the AnyBot's own phone server). This Mac's own screen moved to the ⋯ menu.
- Mac app: 看畫面 opens the viewer in the browser (a screen of a brain: the brain's computer by
ticket; else this computer's box, noVNC straight from it). The in-app picture viewer, the
live JPEG stream, the person's click/move/scroll/key endpoints and the input shell are gone.
- Opening a Mac app uses LaunchServices (`open -a`): agent-desktop's launch waited on the window
through accessibility and failed without 輔助使用 now and then.
Measured on this Mac (made-up account, local relay + headless brain + the real box): viewer
signed in in 0.4–0.7 s, a request and its answer through relay + brain + box 25–58 ms median;
headless Chrome shows the desktop live in /screen. remote_e2e 28/28 ×2, 149 unit tests, relay 11.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-05 15:05:44 +00:00
|
|
|
|
let url = format!("{}/relay/screen-ticket", s.relay_url.trim_end_matches('/'));
|
|
|
|
|
|
let mut r = agent(15)
|
|
|
|
|
|
.post(&url)
|
|
|
|
|
|
.header("Authorization", &format!("Bearer {}", s.host_token))
|
|
|
|
|
|
.header("Content-Type", "application/json")
|
|
|
|
|
|
.send(json!({"host": s.brain_id}).to_string().as_bytes())
|
|
|
|
|
|
.map_err(|e| format!("連不到帳號伺服器:{}", why_unreachable(&e)))?;
|
|
|
|
|
|
let v: Value = r.body_mut().read_json().map_err(|_| "帳號伺服器的回答看不懂".to_string())?;
|
|
|
|
|
|
v["ticket"].as_str().map(String::from).ok_or_else(|| "帳號伺服器沒有給看畫面的連結(它可能是舊版,請更新)".into())
|
2026-11-05 14:34:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-11-04 11:30:32 +00:00
|
|
|
|
/// A file the brain keeps (an attachment shown in a chat), as bytes.
|
|
|
|
|
|
pub fn sync_file(s: &Settings, path: &str) -> Result<Vec<u8>, String> {
|
|
|
|
|
|
let (st, bytes) = to_brain_raw(s, "GET", "/file", &[("path", path.to_string())], &[], 120)?;
|
|
|
|
|
|
if !(200..300).contains(&st) {
|
|
|
|
|
|
return Err(why_refused(st, &serde_json::from_slice(&bytes).unwrap_or(Value::Null), "大腦"));
|
|
|
|
|
|
}
|
|
|
|
|
|
Ok(bytes)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
/// A notification on the person's phones (through the relay; phones that turned them on).
|
|
|
|
|
|
pub fn notify(title: &str, body: &str, bot: u64) {
|
|
|
|
|
|
let s = hub().settings();
|
|
|
|
|
|
if s.relay_url.is_empty() || s.host_token.is_empty() {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
let (title, body) = (title.to_string(), body.to_string());
|
|
|
|
|
|
std::thread::spawn(move || {
|
|
|
|
|
|
let _ = relay_post(&format!("{}/relay/host/notify", s.relay_url), &s.host_token, &json!({"title": title, "body": body, "bot": bot}));
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// 發布網站: upload a folder (or one page) to the account server; returns the public address.
|
|
|
|
|
|
pub fn publish_site(name: &str, local: &std::path::Path) -> Result<String, String> {
|
|
|
|
|
|
use base64::Engine;
|
|
|
|
|
|
let s = hub().settings();
|
|
|
|
|
|
if s.relay_url.is_empty() || s.host_token.is_empty() {
|
|
|
|
|
|
return Err("要先在 設定 › 手機與帳號 登入帳號,才能發布網站".into());
|
|
|
|
|
|
}
|
|
|
|
|
|
let mut files = vec![];
|
|
|
|
|
|
let mut total = 0u64;
|
|
|
|
|
|
if local.is_file() {
|
2026-11-11 08:19:06 +00:00
|
|
|
|
let real = std::fs::canonicalize(local).unwrap_or_else(|_| local.to_path_buf());
|
|
|
|
|
|
if crate::tools::is_ignored(local) || crate::tools::is_ignored(&real) {
|
|
|
|
|
|
return Err("這個檔案是機密的,不能發布成公開網站".into());
|
|
|
|
|
|
}
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
let bytes = std::fs::read(local).map_err(|e| e.to_string())?;
|
|
|
|
|
|
let is_html = local.extension().map(|e| e == "html" || e == "htm").unwrap_or(false);
|
|
|
|
|
|
let n = if is_html { "index.html".to_string() } else { local.file_name().unwrap_or_default().to_string_lossy().to_string() };
|
|
|
|
|
|
if bytes.len() > 25 * 1024 * 1024 {
|
|
|
|
|
|
return Err("網頁太大了(最多 25 MB)".into());
|
|
|
|
|
|
}
|
|
|
|
|
|
files.push(json!({"path": n, "data": base64::engine::general_purpose::STANDARD.encode(bytes)}));
|
|
|
|
|
|
} else {
|
|
|
|
|
|
let mut stack = vec![local.to_path_buf()];
|
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
|
|
|
|
let home = std::fs::canonicalize(local).unwrap_or_else(|_| local.to_path_buf());
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
while let Some(d) = stack.pop() {
|
|
|
|
|
|
for e in std::fs::read_dir(&d).map_err(|e| format!("讀不到資料夾:{e}"))?.flatten() {
|
|
|
|
|
|
let p = e.path();
|
|
|
|
|
|
let fname = e.file_name().to_string_lossy().to_string();
|
|
|
|
|
|
if fname.starts_with('.') || fname == "node_modules" {
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
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
|
|
|
|
// Keys and the like stay home, and so does what a link points to outside the
|
|
|
|
|
|
// site's folder (a link to ~/Documents would have put it all on the web).
|
|
|
|
|
|
let real = std::fs::canonicalize(&p).unwrap_or_else(|_| p.clone());
|
|
|
|
|
|
if crate::tools::is_ignored(&p) || crate::tools::is_ignored(&real) || !real.starts_with(&home) {
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
if p.is_dir() {
|
|
|
|
|
|
stack.push(p);
|
|
|
|
|
|
} else if let Ok(bytes) = std::fs::read(&p) {
|
|
|
|
|
|
total += bytes.len() as u64;
|
|
|
|
|
|
if files.len() >= 500 || total > 25 * 1024 * 1024 {
|
|
|
|
|
|
return Err("網站太大了(最多 500 個檔案、25 MB)".into());
|
|
|
|
|
|
}
|
|
|
|
|
|
let rel = p.strip_prefix(local).unwrap_or(&p).to_string_lossy().replace('\\', "/");
|
|
|
|
|
|
files.push(json!({"path": rel, "data": base64::engine::general_purpose::STANDARD.encode(bytes)}));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if !files.iter().any(|f| f["path"] == "index.html") {
|
|
|
|
|
|
return Err("找不到 index.html(網站的首頁)".into());
|
|
|
|
|
|
}
|
|
|
|
|
|
let v = relay_post(&format!("{}/relay/host/sites/{name}", s.relay_url), &s.host_token, &json!({"files": files}))?;
|
|
|
|
|
|
let url = v["url"].as_str().filter(|u| !u.is_empty()).map(String::from).unwrap_or_else(|| format!("{}{}", s.relay_url, v["path"].as_str().unwrap_or("")));
|
|
|
|
|
|
Ok(url)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// 團隊: who else this AnyBot is shared with (user, role).
|
2026-11-13 16:40:16 +00:00
|
|
|
|
/// The team: (account, role). A role ending in 「?」 was invited and hasn't accepted yet.
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
pub fn members(s: &Settings) -> Result<Vec<(String, String)>, String> {
|
|
|
|
|
|
let mut r = agent(10).get(&format!("{}/relay/host/members", s.relay_url)).header("Authorization", &format!("Bearer {}", s.host_token)).call().map_err(|e| e.to_string())?;
|
|
|
|
|
|
let v: Value = serde_json::from_str(&r.body_mut().read_to_string().unwrap_or_default()).unwrap_or(Value::Null);
|
2026-11-13 16:40:16 +00:00
|
|
|
|
Ok(v["members"].as_array().map(|a| a.iter().map(|m| (m["user"].as_str().unwrap_or("").to_string(), format!("{}{}", m["role"].as_str().unwrap_or(""), if m["pending"] == true { "?" } else { "" }))).collect()).unwrap_or_default())
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Share with another account ("member" / "admin"), or stop sharing ("remove").
|
|
|
|
|
|
pub fn set_member(s: &Settings, user: &str, role: &str) -> Result<(), String> {
|
|
|
|
|
|
relay_post(&format!("{}/relay/host/members", s.relay_url), &s.host_token, &json!({"user": user, "role": role})).map(|_| ())
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// The other AnyBots signed in to this account (for 裝置連結).
|
2026-11-04 12:56:06 +00:00
|
|
|
|
/// 加一台電腦: a code (ten minutes, once) another computer uses to join this account, as hands for
|
|
|
|
|
|
/// `for_host` (empty = any AnyBot of the account).
|
|
|
|
|
|
pub fn pair_code(s: &Settings, for_host: &str) -> Result<String, String> {
|
|
|
|
|
|
let v = relay_post(&format!("{}/relay/pair", s.relay_url), &s.host_token, &json!({"for": for_host}))?;
|
|
|
|
|
|
v["code"].as_str().map(String::from).ok_or("帳號伺服器沒有給配對碼".into())
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Join the account with a 配對碼 (no password). Gives the settings to keep.
|
|
|
|
|
|
pub fn pair_claim(base_settings: &Settings, url: &str, code: &str) -> Result<Settings, String> {
|
|
|
|
|
|
let url = check_server(url)?;
|
2026-11-13 16:40:16 +00:00
|
|
|
|
// (The key behind the code stays here: the account server gets the six digits only.)
|
|
|
|
|
|
let (code, link_key) = split_pair_code(code);
|
2026-11-04 12:56:06 +00:00
|
|
|
|
let v = relay_post(&format!("{url}/relay/pair/claim"), "", &json!({"code": code, "name": base_settings.host_name}))?;
|
|
|
|
|
|
let mut s = base_settings.clone();
|
|
|
|
|
|
s.relay_url = url;
|
|
|
|
|
|
s.relay_user = v["user"].as_str().unwrap_or("").to_string();
|
|
|
|
|
|
s.host_id = v["id"].as_str().unwrap_or("").to_string();
|
|
|
|
|
|
s.host_token = v["token"].as_str().unwrap_or("").to_string();
|
|
|
|
|
|
// No password here, so no key for backups (hands keep nothing to back up).
|
|
|
|
|
|
s.backup_key.clear();
|
|
|
|
|
|
s.hands_for = v["for"].as_str().unwrap_or("").to_string();
|
|
|
|
|
|
s.hands_for_name = v["for_name"].as_str().unwrap_or("").to_string();
|
2026-11-13 16:40:16 +00:00
|
|
|
|
s.link_key = link_key;
|
|
|
|
|
|
s.link_keys.clear();
|
2026-11-04 12:56:06 +00:00
|
|
|
|
if s.host_id.is_empty() || s.host_token.is_empty() {
|
|
|
|
|
|
return Err("帳號伺服器沒有給這台電腦的金鑰".into());
|
|
|
|
|
|
}
|
|
|
|
|
|
Ok(s)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-11-04 12:38:45 +00:00
|
|
|
|
/// The account's AnyBots as the account server sees them (for choosing a brain).
|
|
|
|
|
|
pub fn peers(s: &Settings) -> Result<Vec<Value>, String> {
|
|
|
|
|
|
let mut r = agent(15).get(&format!("{}/relay/host/peers", s.relay_url)).header("Authorization", &format!("Bearer {}", s.host_token)).call().map_err(|e| format!("連不到帳號伺服器:{}", why_unreachable(&e)))?;
|
|
|
|
|
|
let st = r.status().as_u16();
|
|
|
|
|
|
let v: Value = serde_json::from_str(&r.body_mut().read_to_string().unwrap_or_default()).unwrap_or(Value::Null);
|
|
|
|
|
|
if !(200..300).contains(&st) {
|
|
|
|
|
|
return Err(why_refused(st, &v, "帳號伺服器"));
|
|
|
|
|
|
}
|
|
|
|
|
|
Ok(v["hosts"].as_array().cloned().unwrap_or_default())
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-11-05 06:25:01 +00:00
|
|
|
|
/// Right after signing in: where this account's bots already are. Another AnyBot of the account
|
|
|
|
|
|
/// that is on now and thinks for itself (not hands, not showing another) is the brain to sync
|
|
|
|
|
|
/// with; with none, the account's newest backup (if there is one) is what to take in.
|
|
|
|
|
|
pub struct AccountFind {
|
|
|
|
|
|
pub brain: Option<(String, String)>,
|
|
|
|
|
|
pub backup: Option<Vec<u8>>,
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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
|
|
|
|
pub fn find_account_bots(s: &Settings, password: &str, code: &str) -> AccountFind {
|
2026-11-05 06:25:01 +00:00
|
|
|
|
let brain = peers(s).ok().and_then(|hosts| pick_brain(&hosts, &s.host_id));
|
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
|
|
|
|
let backup = if brain.is_none() { restore(&s.relay_url, &s.relay_user, password, code).ok() } else { None };
|
2026-11-05 06:25:01 +00:00
|
|
|
|
AccountFind { brain, backup }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// The brain among the account's AnyBots (relay `hosts` rows), never this one.
|
|
|
|
|
|
pub fn pick_brain(hosts: &[Value], me: &str) -> Option<(String, String)> {
|
|
|
|
|
|
hosts
|
|
|
|
|
|
.iter()
|
|
|
|
|
|
.filter(|h| h["online"].as_bool() == Some(true) && h["hands"].as_bool() != Some(true) && h["uses"].as_str().unwrap_or("").is_empty())
|
|
|
|
|
|
.filter_map(|h| Some((h["id"].as_str()?.to_string(), h["name"].as_str().unwrap_or("AnyBot").to_string())))
|
|
|
|
|
|
.find(|(id, _)| !id.is_empty() && id != me)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-11-04 12:38:45 +00:00
|
|
|
|
/// Is this an AnyBot account server? (Gives the address to use.)
|
|
|
|
|
|
pub fn check_server(url: &str) -> Result<String, String> {
|
|
|
|
|
|
let mut u = url.trim().trim_end_matches('/').to_string();
|
|
|
|
|
|
if u.is_empty() {
|
|
|
|
|
|
return Err("請輸入帳號伺服器的網址".into());
|
|
|
|
|
|
}
|
|
|
|
|
|
if !u.contains("://") {
|
|
|
|
|
|
let host = u.split(['/', ':']).next().unwrap_or("");
|
|
|
|
|
|
let plain = host == "localhost" || host.parse::<std::net::IpAddr>().is_ok() || !host.contains('.');
|
|
|
|
|
|
u = format!("{}{u}", if plain { "http://" } else { "https://" });
|
|
|
|
|
|
}
|
|
|
|
|
|
let mut r = agent(15).get(&format!("{u}/api/hello")).call().map_err(|e| format!("連不到 {u}:{}", why_unreachable(&e)))?;
|
|
|
|
|
|
let v: Value = serde_json::from_str(&r.body_mut().read_to_string().unwrap_or_default()).unwrap_or(Value::Null);
|
|
|
|
|
|
if v["app"] != "anybot-relay" {
|
|
|
|
|
|
return Err(format!("{u} 有回應,但不是 AnyBot 帳號伺服器(網址打錯了?)"));
|
|
|
|
|
|
}
|
|
|
|
|
|
Ok(u)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-11-04 12:56:06 +00:00
|
|
|
|
/// AnyBots of the account that lend their hands (not offered as a brain).
|
|
|
|
|
|
pub fn is_hands(id: &str) -> bool {
|
|
|
|
|
|
hands_ids().lock().unwrap().contains(id)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn hands_ids() -> &'static Mutex<std::collections::HashSet<String>> {
|
|
|
|
|
|
static H: OnceLock<Mutex<std::collections::HashSet<String>>> = OnceLock::new();
|
|
|
|
|
|
H.get_or_init(Mutex::default)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-11-05 06:40:01 +00:00
|
|
|
|
/// The account's computers as last seen: id → (name, the brain it uses, lends its hands).
|
Clippy is clean on macOS and Linux, for the app and the relay
Every warning `cargo clippy --all-targets` gave (50 on macOS, 8 more only on
Linux, 1 in the relay), fixed without changing what anything does:
- long types get a name (Peer, Members, Imported, Joining, Mention, Stream…);
- the two big enum variants are boxed (the vault's login plan, joining an
account);
- a test now waits for the copy it relaunched (it left a zombie behind);
- a hint's format had a dead `if` whose two branches were both "";
- the rest is what clippy suggests: sort_by_key, as_chunks, is_none_or,
is_multiple_of, while let, from_ref, next_back, struct init, no casts to
the same type.
Checked: cargo test (177 macOS, 181 Linux), relay tests (11), remote_e2e
28/28, and the live Linux test (X11; Wayland clicks, keys, Chinese typing,
scroll and screenshots).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha2RVfSYmrhqNnqx9Z4
2026-11-07 02:10:28 +00:00
|
|
|
|
type PeerRows = Mutex<HashMap<String, (String, String, bool)>>;
|
|
|
|
|
|
|
|
|
|
|
|
fn peer_rows() -> &'static PeerRows {
|
|
|
|
|
|
static P: OnceLock<PeerRows> = OnceLock::new();
|
2026-11-05 06:40:01 +00:00
|
|
|
|
P.get_or_init(Mutex::default)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Computers of the account that lend their hands to this brain (`me`), by id.
|
|
|
|
|
|
pub fn my_hands(me: &str) -> Vec<String> {
|
|
|
|
|
|
if me.is_empty() {
|
|
|
|
|
|
return vec![];
|
|
|
|
|
|
}
|
|
|
|
|
|
let mut v: Vec<String> = peer_rows().lock().unwrap().iter().filter(|(_, (_, uses, hands))| *hands && uses == me).map(|(id, _)| id.clone()).collect();
|
|
|
|
|
|
v.sort();
|
|
|
|
|
|
v
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-11-05 08:47:28 +00:00
|
|
|
|
fn person_cell() -> &'static Mutex<String> {
|
|
|
|
|
|
static P: OnceLock<Mutex<String>> = OnceLock::new();
|
|
|
|
|
|
P.get_or_init(Mutex::default)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-11-05 11:41:49 +00:00
|
|
|
|
/// The account computer the person last typed on (they are sitting at it). Kept beside the data,
|
|
|
|
|
|
/// so a brain that restarts (an update) still knows it.
|
2026-11-05 08:47:28 +00:00
|
|
|
|
pub fn set_person_host(id: &str) {
|
2026-11-05 11:41:49 +00:00
|
|
|
|
let mut cur = person_cell().lock().unwrap();
|
|
|
|
|
|
if *cur != id {
|
|
|
|
|
|
*cur = id.to_string();
|
|
|
|
|
|
let _ = std::fs::write(person_file(), id);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn person_file() -> std::path::PathBuf {
|
|
|
|
|
|
crate::model::State::path().with_file_name("person-computer.txt")
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// At start: the computer the person used last time.
|
|
|
|
|
|
pub fn load_person_host() -> Option<String> {
|
|
|
|
|
|
let id = std::fs::read_to_string(person_file()).ok()?.trim().to_string();
|
|
|
|
|
|
(!id.is_empty() && id.len() <= 64 && id.chars().all(|c| c.is_ascii_alphanumeric())).then(|| {
|
|
|
|
|
|
*person_cell().lock().unwrap() = id.clone();
|
|
|
|
|
|
id
|
|
|
|
|
|
})
|
2026-11-05 08:47:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn person_host() -> String {
|
|
|
|
|
|
person_cell().lock().unwrap().clone()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// The brain an account computer shows (empty: it thinks for itself), as last seen.
|
|
|
|
|
|
pub fn peer_uses(id: &str) -> String {
|
|
|
|
|
|
peer_rows().lock().unwrap().get(id).map(|r| r.1.clone()).unwrap_or_default()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-11-05 06:40:01 +00:00
|
|
|
|
/// A computer's own name as the account server knows it.
|
|
|
|
|
|
pub fn peer_name(id: &str) -> String {
|
|
|
|
|
|
peer_rows().lock().unwrap().get(id).map(|r| r.0.clone()).unwrap_or_default()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
pub fn devices_online(s: &Settings) -> Vec<(String, String, bool)> {
|
|
|
|
|
|
if s.relay_url.is_empty() {
|
|
|
|
|
|
return vec![];
|
|
|
|
|
|
}
|
|
|
|
|
|
let Ok(mut r) = agent(10).get(&format!("{}/relay/host/peers", s.relay_url)).header("Authorization", &format!("Bearer {}", s.host_token)).call() else { return vec![] };
|
|
|
|
|
|
let v: Value = serde_json::from_str(&r.body_mut().read_to_string().unwrap_or_default()).unwrap_or(Value::Null);
|
2026-11-05 06:40:01 +00:00
|
|
|
|
*peer_rows().lock().unwrap() = v["hosts"]
|
|
|
|
|
|
.as_array()
|
|
|
|
|
|
.into_iter()
|
|
|
|
|
|
.flatten()
|
|
|
|
|
|
.filter_map(|h| Some((h["id"].as_str()?.to_string(), (h["name"].as_str().unwrap_or("").to_string(), h["uses"].as_str().unwrap_or("").to_string(), h["hands"].as_bool() == Some(true)))))
|
|
|
|
|
|
.collect();
|
2026-11-04 12:56:06 +00:00
|
|
|
|
*hands_ids().lock().unwrap() = v["hosts"].as_array().into_iter().flatten().filter(|h| h["hands"].as_bool() == Some(true) || !h["uses"].as_str().unwrap_or("").is_empty()).filter_map(|h| h["id"].as_str().map(String::from)).collect();
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
v["hosts"].as_array().map(|a| a.iter().map(|h| (h["id"].as_str().unwrap_or("").to_string(), h["name"].as_str().unwrap_or("").to_string(), h["online"].as_bool().unwrap_or(false))).collect()).unwrap_or_default()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ---------- the phone page ----------
|
|
|
|
|
|
|
|
|
|
|
|
const PAGE: &str = include_str!("../mobile/index.html");
|
People watch and help on the bots' computer through VNC (noVNC), carried by the account server
The core: the bot works the computer; a person watches it like a colleague, and takes over
when it needs them. VNC is made for that (only what changed, every mouse move and key, touch on
phones), so the pictures sent one by one go, and with them their own input path.
- vnc.rs: a VNC proxy to the box's x11vnc through one docker exec (a Python bridge that ends
with either side). It signs in to the box with the box's own password (its VNC_PASSWORD) and
offers the viewer no password, so the password never leaves the brain. The person's clicks
and keys make the bot's steps wait until 8 s after they stop; text typed in the viewer's box
(any language) is pasted in the box.
- Account server: /screen (the viewer page) and /novnc.js (noVNC 1.6.0, MPL-2.0, bundled);
/relay/vnc/<host> takes the browser's WebSocket (account session, or a 10-minute ticket the
app asks for with POST /relay/screen-ticket; owners and admins) and carries it over that
AnyBot's lasting connection (vopen / vdata / vtext / vclose). Both ends of that connection
wait 2 ms instead of 40 ms to read while things move: a request and its answer took up to
160 ms more than needed.
- Phone page: 看 Bot 的電腦 and 接管 open the viewer page (also on the local network: /api/vnc on
the AnyBot's own phone server). This Mac's own screen moved to the ⋯ menu.
- Mac app: 看畫面 opens the viewer in the browser (a screen of a brain: the brain's computer by
ticket; else this computer's box, noVNC straight from it). The in-app picture viewer, the
live JPEG stream, the person's click/move/scroll/key endpoints and the input shell are gone.
- Opening a Mac app uses LaunchServices (`open -a`): agent-desktop's launch waited on the window
through accessibility and failed without 輔助使用 now and then.
Measured on this Mac (made-up account, local relay + headless brain + the real box): viewer
signed in in 0.4–0.7 s, a request and its answer through relay + brain + box 25–58 ms median;
headless Chrome shows the desktop live in /screen. remote_e2e 28/28 ×2, 149 unit tests, relay 11.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-05 15:05:44 +00:00
|
|
|
|
/// The bots' computer, watched and used in a browser (noVNC; see vnc.rs).
|
|
|
|
|
|
const SCREEN_PAGE: &str = include_str!("../mobile/screen.html");
|
|
|
|
|
|
const NOVNC: &str = include_str!("../mobile/novnc.js");
|
2026-11-05 11:20:29 +00:00
|
|
|
|
pub const MANIFEST: &str = r##"{"name":"AnyBot","short_name":"AnyBot","start_url":"./","display":"standalone","background_color":"#121212","theme_color":"#121212","icons":[{"src":"icon.svg","sizes":"any","type":"image/svg+xml"},{"src":"icon-192.png","sizes":"192x192","type":"image/png","purpose":"any maskable"},{"src":"icon-512.png","sizes":"512x512","type":"image/png","purpose":"any maskable"}]}"##;
|
|
|
|
|
|
/// The app's icon, the same drawing everywhere (icons/anybot.svg is the Mac/Linux one).
|
|
|
|
|
|
pub const ICON: &str = include_str!("../mobile/icon.svg");
|
|
|
|
|
|
/// PNG sizes for the iPhone home screen (it ignores SVG) and Android.
|
|
|
|
|
|
pub const ICON_PNGS: [(&str, &[u8]); 3] = [("icon-180.png", include_bytes!("../mobile/icon-180.png")), ("icon-192.png", include_bytes!("../mobile/icon-192.png")), ("icon-512.png", include_bytes!("../mobile/icon-512.png"))];
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
|
|
|
|
|
|
pub fn page() -> Resp {
|
2026-11-13 16:40:16 +00:00
|
|
|
|
Resp::bytes("text/html; charset=utf-8", PAGE.as_bytes().to_vec()).with_header("Content-Security-Policy", &format!("default-src 'self'; img-src 'self' blob: data:; media-src 'self' blob:; frame-src 'self' blob:; style-src 'self' 'unsafe-inline'; {}; connect-src 'self' ws: wss:; base-uri 'none'; object-src 'none'; frame-ancestors 'none'", httpd::script_src(PAGE)))
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
|
|
mod tests {
|
|
|
|
|
|
use super::*;
|
|
|
|
|
|
|
Voice: its own 設定 › 語音, run by the brain for every screen and the phone
Voice was three implementations that broke on their own: speech to text
borrowed the OpenAI key (so with only Grok set up the mic recorded,
then failed), OpenAI's models it hard-coded stop on 2027-02-26, read
aloud was macOS `say` or espeak-ng (silently nothing on Windows, where
espeak isn't installed), and the phone used the browser's own
recognition. Now:
- 設定 › 語音 has 聽 and 說, each a service: off, OpenAI-compatible
(OpenAI, Groq, a Whisper server of your own: the address decides),
xAI or ElevenLabs. An empty key borrows 設定 › 模型's for the same
service. Each side says 可以用 or what it lacks; 聽 has 試試看
(record a sentence, show what was heard), 說 has 試聽 and the voice
list. speech.rs does the calls; xAI's both ways were checked for real
(Mandarin read, then heard back, in Traditional characters).
- The brain does it all: the phone POSTs its recording (MediaRecorder)
to /api/voice/transcribe, screens to /api/sync/voice/transcribe;
answers come back as MP3 from …/voice/speech and are played on the
device (rodio; an <audio> on the phone, 「唸出來」 in a message's
menu). Keys stay on the brain (the voice keys are redacted for
screens like the others).
- No service, no voice anywhere: the mic, 語音聊天, 會議錄音 and 朗讀
only appear once 聽 (and 說) can be called; the phone's state says
which. Without voice the send arrow just rests where 語音聊天 was.
- 會議錄音 is uploaded to the brain, which turns it into text in the
background and hands it to the bot itself: a meeting is longer than
the 35 s the account lets a request wait, and a brain on a server has
no window (the jobs are polled in background()).
- Recognisers answer Mandarin in Simplified: in a Traditional Chinese
window or phone the text becomes Traditional with Taiwan wording.
- Older saves: whoever had an OpenAI key keeps voice input (聽 =
OpenAI); everyone else starts with it off. Bots' macOS voice names
are cleared. 對話詳細資訊's 加入會議 started plain voice input; it
starts a meeting now.
2026-11-10 14:58:18 +00:00
|
|
|
|
fn voice_req(path: &str, role: &str, body: &[u8]) -> Req {
|
|
|
|
|
|
let (path, q) = path.split_once('?').unwrap_or((path, ""));
|
|
|
|
|
|
let query = q.split('&').filter_map(|kv| kv.split_once('=')).map(|(k, v)| (k.to_string(), v.to_string())).collect();
|
|
|
|
|
|
let headers = [("x-anybot-role".to_string(), role.to_string())].into_iter().collect();
|
|
|
|
|
|
Req { method: "POST".into(), path: path.into(), query, headers, body: body.to_vec(), peer: String::new() }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
傳送: 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 02:04:13 +00:00
|
|
|
|
/// 傳送 is the owner's: a team member or an admin can't send through this brain, and a
|
|
|
|
|
|
/// computer takes parcels only from its own brain.
|
|
|
|
|
|
#[test]
|
|
|
|
|
|
fn sending_between_devices_is_the_owners_and_the_brains() {
|
|
|
|
|
|
for role in ["admin", "member", "device"] {
|
|
|
|
|
|
let r = handle(voice_req("/api/drop/new", role, br#"{"text":"x","to":"phone"}"#), true);
|
|
|
|
|
|
assert_eq!(r.status, 403, "{role}");
|
|
|
|
|
|
}
|
|
|
|
|
|
assert_eq!(handle(voice_req("/api/sync/drop/new", "owner", b"{}"), true).status, 403, "the screens' road isn't the phone's");
|
|
|
|
|
|
let put = json!({"tool": crate::drops::PUT, "args": "{}"});
|
|
|
|
|
|
let code = |s: &Settings, via_relay: bool, from: &str| device_run(&put, s, via_relay, from).status;
|
|
|
|
|
|
// A screen of brain "b", a pair of hands for "b".
|
|
|
|
|
|
let screen = Settings { brain_id: "b".into(), ..Default::default() };
|
|
|
|
|
|
let hands = Settings { hands_for: "b".into(), device_link: true, ..Default::default() };
|
|
|
|
|
|
assert_eq!(code(&screen, true, "other"), 403);
|
|
|
|
|
|
assert_eq!(code(&hands, true, "other"), 403);
|
|
|
|
|
|
assert_eq!(code(&screen, false, "b"), 403, "only through the account server, which says who asks");
|
|
|
|
|
|
// A computer with no brain of its own and 裝置連結 off takes nothing.
|
|
|
|
|
|
assert_eq!(code(&Settings::default(), true, "b"), 403);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
Voice: its own 設定 › 語音, run by the brain for every screen and the phone
Voice was three implementations that broke on their own: speech to text
borrowed the OpenAI key (so with only Grok set up the mic recorded,
then failed), OpenAI's models it hard-coded stop on 2027-02-26, read
aloud was macOS `say` or espeak-ng (silently nothing on Windows, where
espeak isn't installed), and the phone used the browser's own
recognition. Now:
- 設定 › 語音 has 聽 and 說, each a service: off, OpenAI-compatible
(OpenAI, Groq, a Whisper server of your own: the address decides),
xAI or ElevenLabs. An empty key borrows 設定 › 模型's for the same
service. Each side says 可以用 or what it lacks; 聽 has 試試看
(record a sentence, show what was heard), 說 has 試聽 and the voice
list. speech.rs does the calls; xAI's both ways were checked for real
(Mandarin read, then heard back, in Traditional characters).
- The brain does it all: the phone POSTs its recording (MediaRecorder)
to /api/voice/transcribe, screens to /api/sync/voice/transcribe;
answers come back as MP3 from …/voice/speech and are played on the
device (rodio; an <audio> on the phone, 「唸出來」 in a message's
menu). Keys stay on the brain (the voice keys are redacted for
screens like the others).
- No service, no voice anywhere: the mic, 語音聊天, 會議錄音 and 朗讀
only appear once 聽 (and 說) can be called; the phone's state says
which. Without voice the send arrow just rests where 語音聊天 was.
- 會議錄音 is uploaded to the brain, which turns it into text in the
background and hands it to the bot itself: a meeting is longer than
the 35 s the account lets a request wait, and a brain on a server has
no window (the jobs are polled in background()).
- Recognisers answer Mandarin in Simplified: in a Traditional Chinese
window or phone the text becomes Traditional with Taiwan wording.
- Older saves: whoever had an OpenAI key keeps voice input (聽 =
OpenAI); everyone else starts with it off. Bots' macOS voice names
are cleared. 對話詳細資訊's 加入會議 started plain voice input; it
starts a meeting now.
2026-11-10 14:58:18 +00:00
|
|
|
|
/// The phone's and the screens' recordings go through the brain's 設定 › 語音.
|
|
|
|
|
|
#[test]
|
|
|
|
|
|
fn the_brain_hears_for_the_phone_and_the_screens() {
|
|
|
|
|
|
let server = std::net::TcpListener::bind("127.0.0.1:0").unwrap();
|
|
|
|
|
|
let base = format!("http://127.0.0.1:{}/v1", server.local_addr().unwrap().port());
|
|
|
|
|
|
let fake = std::thread::spawn(move || {
|
|
|
|
|
|
use std::io::{Read, Write};
|
|
|
|
|
|
for _ in 0..2 {
|
|
|
|
|
|
let (mut s, _) = server.accept().unwrap();
|
|
|
|
|
|
s.set_read_timeout(Some(Duration::from_millis(500))).unwrap();
|
|
|
|
|
|
let (mut buf, mut got) = (vec![0u8; 65536], vec![]);
|
|
|
|
|
|
while let Ok(n) = s.read(&mut buf) {
|
|
|
|
|
|
if n == 0 {
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
got.extend_from_slice(&buf[..n]);
|
|
|
|
|
|
if got.windows(4).any(|w| w == b"--\r\n") {
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
let reply = r#"{"text":"帮我开灯"}"#;
|
|
|
|
|
|
let _ = s.write_all(format!("HTTP/1.1 200 OK\r\nContent-Type: application/json\r\nContent-Length: {}\r\nConnection: close\r\n\r\n{reply}", reply.len()).as_bytes());
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
// Not set up: said so, and the phone hides its mic.
|
|
|
|
|
|
hub().set_voice(Default::default());
|
|
|
|
|
|
let r = handle(voice_req("/api/voice/transcribe?name=voice.webm", "owner", &[7u8; 4000]), true);
|
|
|
|
|
|
assert_eq!(r.status, 409);
|
|
|
|
|
|
let e = crate::speech::Engine { kind: crate::model::VoiceKind::Xai, base, key: "k".into(), ..Default::default() };
|
|
|
|
|
|
hub().set_voice(crate::speech::Engines { listen: Some(e), speak: None });
|
|
|
|
|
|
// A member may talk too; the phone says it is a Traditional Chinese one.
|
|
|
|
|
|
let r = handle(voice_req("/api/voice/transcribe?name=voice.webm&ui=zh-TW", "member", &[7u8; 4000]), true);
|
|
|
|
|
|
assert_eq!(r.status, 200, "{}", String::from_utf8_lossy(&r.body));
|
|
|
|
|
|
let v: Value = serde_json::from_slice(&r.body).unwrap();
|
|
|
|
|
|
assert_eq!(v["text"], "幫我開燈");
|
|
|
|
|
|
// A screen of this brain, through the account.
|
|
|
|
|
|
let r = handle(voice_req("/api/sync/voice/transcribe?name=voice.m4a&ui=zh-TW", "mirror", &[7u8; 4000]), true);
|
|
|
|
|
|
assert_eq!(r.status, 200);
|
|
|
|
|
|
// Nothing to read aloud with: 409, not a crash.
|
|
|
|
|
|
let r = handle(voice_req("/api/voice/speech", "owner", br#"{"text":"hi"}"#), true);
|
|
|
|
|
|
assert_eq!(r.status, 409);
|
|
|
|
|
|
fake.join().unwrap();
|
|
|
|
|
|
hub().set_voice(Default::default());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-11-05 07:00:31 +00:00
|
|
|
|
#[test]
|
|
|
|
|
|
fn model_requests_go_only_to_private_addresses() {
|
|
|
|
|
|
assert!(private_host("10.184.10.252") && private_host("192.168.1.5") && private_host("localhost") && private_host("nas.local"));
|
|
|
|
|
|
assert!(!private_host("api.x.ai") && !private_host("8.8.8.8"));
|
2026-11-05 07:48:20 +00:00
|
|
|
|
// A cloud VM's metadata service answers on link-local: the hands must never reach it.
|
|
|
|
|
|
assert!(!private_host("169.254.169.254") && !private_host("169.254.0.1"));
|
2026-11-05 07:00:31 +00:00
|
|
|
|
assert_eq!(host_port("http://10.184.10.252:8000/v1"), Some(("10.184.10.252".into(), 8000)));
|
|
|
|
|
|
assert_eq!(host_port("https://api.x.ai/v1"), Some(("api.x.ai".into(), 443)));
|
|
|
|
|
|
assert_eq!(model_fetch_here(&json!({"url": "https://api.x.ai/v1/chat/completions"}).to_string()).status, 403);
|
2026-11-05 07:48:20 +00:00
|
|
|
|
assert_eq!(model_fetch_here(&json!({"url": "http://169.254.169.254/latest/meta-data/"}).to_string()).status, 403);
|
2026-11-11 08:19:06 +00:00
|
|
|
|
assert_eq!(model_fetch_here(&json!({"url": "http://127.0.0.1:8793/api/state"}).to_string()).status, 403);
|
|
|
|
|
|
assert_eq!(model_fetch_here(&json!({"url": "http://localhost:11434/v1/chat/completions"}).to_string()).status, 403);
|
2026-11-05 07:48:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-11-07 13:27:07 +00:00
|
|
|
|
#[test]
|
|
|
|
|
|
fn a_certificate_this_computer_doesnt_trust_says_what_to_do() {
|
|
|
|
|
|
let e = ureq::Error::Rustls(rustls::Error::InvalidCertificate(rustls::CertificateError::UnknownIssuer));
|
|
|
|
|
|
assert!(why_unreachable(&e).contains("anybot-ca.crt"), "{}", why_unreachable(&e));
|
|
|
|
|
|
// Any other certificate problem keeps the general words.
|
|
|
|
|
|
let e = ureq::Error::Rustls(rustls::Error::InvalidCertificate(rustls::CertificateError::Expired));
|
|
|
|
|
|
assert!(why_unreachable(&e).contains("憑證不對"));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-11-05 07:48:20 +00:00
|
|
|
|
#[test]
|
|
|
|
|
|
fn lan_login_lock_is_per_device() {
|
|
|
|
|
|
// One noisy device guessing passwords must not lock the owner's phone out (a single
|
|
|
|
|
|
// global counter used to do exactly that).
|
|
|
|
|
|
let mut s = Settings { password: httpd::hash_password("pw-123"), ..Default::default() };
|
|
|
|
|
|
s.host_name = "測試 Mac".into();
|
|
|
|
|
|
hub().set_settings(&s);
|
|
|
|
|
|
let bad = |ip: &str| handle(Req { method: "POST".into(), path: "/api/login".into(), body: br#"{"password":"nope"}"#.to_vec(), peer: ip.into(), ..Default::default() }, false);
|
|
|
|
|
|
for _ in 0..MAX_FAILS {
|
|
|
|
|
|
assert_eq!(bad("192.168.1.66:5000").status, 401);
|
|
|
|
|
|
}
|
|
|
|
|
|
// The noisy device is now locked out…
|
|
|
|
|
|
assert_eq!(bad("192.168.1.66:5000").status, 429);
|
|
|
|
|
|
// …while every other device on the LAN can still sign in.
|
|
|
|
|
|
let ok = handle(Req { method: "POST".into(), path: "/api/login".into(), body: br#"{"password":"pw-123"}"#.to_vec(), peer: "192.168.1.77:5001".into(), ..Default::default() }, false);
|
|
|
|
|
|
assert_eq!(ok.status, 200);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-11-11 03:07:55 +00:00
|
|
|
|
#[test]
|
|
|
|
|
|
fn a_brain_too_old_for_a_request_says_to_update_it() {
|
|
|
|
|
|
// A stand-in account server passing /api/sync/… to a brain from before 記憶 and 傳送:
|
|
|
|
|
|
// its own 「沒有這個網址」 for /memory; for /sync/x a real 404 of a newer brain's.
|
|
|
|
|
|
let l = std::net::TcpListener::bind("127.0.0.1:0").unwrap();
|
|
|
|
|
|
let port = l.local_addr().unwrap().port();
|
|
|
|
|
|
std::thread::spawn(move || {
|
|
|
|
|
|
for c in l.incoming().take(2) {
|
|
|
|
|
|
let mut c = c.unwrap();
|
|
|
|
|
|
let mut got = vec![];
|
|
|
|
|
|
let mut buf = [0u8; 4096];
|
|
|
|
|
|
while !got.windows(4).any(|w| w == b"\r\n\r\n") {
|
|
|
|
|
|
match std::io::Read::read(&mut c, &mut buf) {
|
|
|
|
|
|
Ok(0) | Err(_) => break,
|
|
|
|
|
|
Ok(n) => got.extend_from_slice(&buf[..n]),
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
let head = String::from_utf8_lossy(&got).to_string();
|
|
|
|
|
|
let r = if head.starts_with("GET /relay/hosts/b-old/api/sync/memory ") { Resp::error(404, NO_SUCH_PATH) } else { Resp::error(404, "找不到這個 Bot") };
|
|
|
|
|
|
httpd::write_response(&mut c, &r);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
let s = Settings { relay_url: format!("http://127.0.0.1:{port}"), host_token: "t".into(), brain_id: "b-old".into(), brain_name: "雲端大腦".into(), ..Default::default() };
|
|
|
|
|
|
let e = to_brain(&s, "GET", "/memory", &[], &[], 10).unwrap_err();
|
|
|
|
|
|
assert!(e.contains("雲端大腦的 AnyBot 是舊版") && e.contains("make update"), "{e}");
|
|
|
|
|
|
// Any other refusal reads as the brain said it.
|
|
|
|
|
|
assert_eq!(to_brain(&s, "GET", "/x", &[], &[], 10).unwrap_err(), "找不到這個 Bot");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-11-05 07:48:20 +00:00
|
|
|
|
#[test]
|
|
|
|
|
|
fn roles_gate_the_sync_and_hands_apis() {
|
|
|
|
|
|
// 大腦 sync (mirror) and 裝置連結 (device) are separate doors on the hands machine:
|
|
|
|
|
|
// a chat admin must not reach either, and a brain may not run tools through the sync door.
|
|
|
|
|
|
assert!(role_allows("device", "POST", &["api", "device", "run"]));
|
|
|
|
|
|
assert!(!role_allows("device", "GET", &["api", "sync"]));
|
|
|
|
|
|
assert!(role_allows("mirror", "GET", &["api", "sync"]));
|
|
|
|
|
|
assert!(role_allows("mirror", "POST", &["api", "sync", "edit"]));
|
|
|
|
|
|
assert!(!role_allows("mirror", "POST", &["api", "device", "run"]));
|
|
|
|
|
|
assert!(role_allows("admin", "POST", &["api", "bots", "1", "send"]));
|
|
|
|
|
|
assert!(!role_allows("admin", "POST", &["api", "device", "run"]));
|
|
|
|
|
|
assert!(!role_allows("admin", "GET", &["api", "sync"]));
|
2026-11-13 15:36:34 +00:00
|
|
|
|
// A role the relay didn't name is nobody's.
|
|
|
|
|
|
assert!(!role_allows("none", "GET", &["api", "state"]));
|
|
|
|
|
|
// 區網 can't switch a guard off; turning one on, or an ask rule, is fine.
|
|
|
|
|
|
assert!(loosens_guard("setting", &json!({"key": "direct_mode", "value": true})));
|
|
|
|
|
|
assert!(!loosens_guard("setting", &json!({"key": "direct_mode", "value": false})));
|
|
|
|
|
|
assert!(loosens_guard("setting", &json!({"key": "rule_add", "list": "allow", "value": "x"})));
|
|
|
|
|
|
assert!(!loosens_guard("setting", &json!({"key": "rule_add", "list": "ask", "value": "x"})));
|
|
|
|
|
|
assert!(loosens_guard("mcp", &json!({"add": {"url": "https://x"}})));
|
2026-11-05 07:48:20 +00:00
|
|
|
|
assert!(role_allows("member", "POST", &["api", "bots", "1", "send"]));
|
|
|
|
|
|
assert!(!role_allows("member", "POST", &["api", "bots", "1", "stop"]));
|
|
|
|
|
|
|
|
|
|
|
|
// A hands machine takes tool orders only through the relay, only when the person opened
|
|
|
|
|
|
// it (裝置連結), and only from the brain it was told to serve.
|
|
|
|
|
|
let open_for_one = Settings { device_link: true, hands_for: "brain1".into(), hands_for_name: "雲端大腦".into(), ..Default::default() };
|
|
|
|
|
|
assert_eq!(device_run(&json!({"tool": "x"}), &open_for_one, false, "brain1").status, 403);
|
|
|
|
|
|
assert_eq!(device_run(&json!({"tool": "x"}), &Settings { device_link: false, hands_for: "brain1".into(), ..Default::default() }, true, "brain1").status, 403);
|
|
|
|
|
|
assert_eq!(device_run(&json!({"tool": "x"}), &open_for_one, true, "other-brain").status, 403);
|
|
|
|
|
|
// The chosen brain reaches past the gates (and gets "this tool can't run remotely" for x).
|
|
|
|
|
|
assert_eq!(device_run(&json!({"tool": "x"}), &open_for_one, true, "brain1").status, 400);
|
2026-11-13 16:40:16 +00:00
|
|
|
|
// Paired with a key: only what the brain signed for this computer, once, and in time.
|
|
|
|
|
|
let key = new_link_key();
|
|
|
|
|
|
assert_eq!(split_pair_code(&format!("135 790-{key}")), ("135790".to_string(), key.clone()));
|
|
|
|
|
|
assert_eq!(split_pair_code("135790"), ("135790".to_string(), String::new()));
|
|
|
|
|
|
let hands = Settings { link_key: key.clone(), host_id: "h1".into(), ..open_for_one.clone() };
|
|
|
|
|
|
let brain = Settings { link_keys: vec![new_link_key(), key.clone()], ..Default::default() };
|
|
|
|
|
|
assert_eq!(device_run(&json!({"tool": "x"}), &hands, true, "brain1").status, 403, "unsigned");
|
|
|
|
|
|
let cmd = signed_run(&brain, "h1", "x", "{}", "大腦");
|
|
|
|
|
|
assert_eq!(device_run(&cmd, &hands, true, "brain1").status, 400, "signed: gets as far as the tool");
|
|
|
|
|
|
assert_eq!(device_run(&cmd, &hands, true, "brain1").status, 403, "the same one again");
|
|
|
|
|
|
let mut other = signed_run(&brain, "h1", "x", "{}", "大腦");
|
|
|
|
|
|
other["args"] = json!("{\"cmd\":\"rm\"}");
|
|
|
|
|
|
assert_eq!(device_run(&other, &hands, true, "brain1").status, 403, "changed on the way");
|
|
|
|
|
|
assert_eq!(device_run(&signed_run(&brain, "h2", "x", "{}", "大腦"), &hands, true, "brain1").status, 403, "signed for another computer");
|
|
|
|
|
|
let mut old = signed_run(&brain, "h1", "x", "{}", "大腦");
|
|
|
|
|
|
old["sig"]["t"] = json!(old["sig"]["t"].as_u64().unwrap() - 3600);
|
|
|
|
|
|
assert_eq!(device_run(&old, &hands, true, "brain1").status, 403, "an old one");
|
|
|
|
|
|
assert_eq!(device_run(&signed_run(&Settings { link_keys: vec![new_link_key()], ..Default::default() }, "h1", "x", "{}", "大腦"), &hands, true, "brain1").status, 403, "another brain's key");
|
2026-11-05 07:00:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
#[test]
|
|
|
|
|
|
fn phone_login_and_api() {
|
|
|
|
|
|
let mut s = Settings { password: httpd::hash_password("pw-123"), ..Default::default() };
|
|
|
|
|
|
s.host_name = "測試 Mac".into();
|
|
|
|
|
|
hub().set_settings(&s);
|
|
|
|
|
|
// Not signed in: refused.
|
|
|
|
|
|
let r = handle(Req { method: "GET".into(), path: "/api/state".into(), ..Default::default() }, false);
|
|
|
|
|
|
assert_eq!(r.status, 401);
|
|
|
|
|
|
let bad = handle(Req { method: "POST".into(), path: "/api/login".into(), body: br#"{"password":"nope"}"#.to_vec(), ..Default::default() }, false);
|
|
|
|
|
|
assert_eq!(bad.status, 401);
|
|
|
|
|
|
let ok = handle(Req { method: "POST".into(), path: "/api/login".into(), body: br#"{"password":"pw-123","device":"iPhone"}"#.to_vec(), ..Default::default() }, false);
|
|
|
|
|
|
assert_eq!(ok.status, 200);
|
|
|
|
|
|
let token = serde_json::from_slice::<Value>(&ok.body).unwrap()["token"].as_str().unwrap().to_string();
|
|
|
|
|
|
hub().publish(View { host: "測試 Mac".into(), bots: vec![json!({"id": 1, "name": "小助理"})], ..Default::default() });
|
|
|
|
|
|
let mut req = Req { method: "GET".into(), path: "/api/state".into(), ..Default::default() };
|
|
|
|
|
|
req.headers.insert("authorization".into(), format!("Bearer {token}"));
|
|
|
|
|
|
let st = handle(req.clone(), false);
|
|
|
|
|
|
assert_eq!(st.status, 200, "{}", String::from_utf8_lossy(&st.body));
|
|
|
|
|
|
let v: Value = serde_json::from_slice(&st.body).unwrap();
|
|
|
|
|
|
assert_eq!(v["bots"][0]["name"], "小助理");
|
|
|
|
|
|
// Sending queues a command for the app.
|
|
|
|
|
|
let mut send = Req { method: "POST".into(), path: "/api/bots/1/send".into(), body: r#"{"text":"你好"}"#.as_bytes().to_vec(), ..Default::default() };
|
|
|
|
|
|
send.headers = req.headers.clone();
|
|
|
|
|
|
assert_eq!(handle(send, false).status, 200);
|
|
|
|
|
|
let cmds = hub().take_cmds();
|
|
|
|
|
|
assert!(cmds.iter().any(|c| matches!(c, Cmd::DeviceAdded(d) if d.name == "iPhone")));
|
安全、修正: harden sandboxes, approval gates, vault, relay roles, and fix protocol/UI bugs
- macOS 沙盒與工具 (tools.rs, policy.rs, docindex.rs): block AppleScript raw events and
concatenation outside the sandbox; stop exposing ~/.ssh or localhost sockets in Sealed
mode; deny writes to shell profiles, LaunchAgents and .git/hooks; expand secret-file
ignores and enforce symlink/policy checks across SSH, device and document search.
- 電腦操作與遮罩 (computer.rs, agent.rs, marks.rs, desktop.rs, cloudbox.rs, portal.rs):
forbid clicking or typing into AnyBot's own windows; extend the sensitive-action hard
gate to raw coordinates, Return/Delete submits and remote devices; stop batch steps if
the front app changes; black out secrets on zoom, show, >600-node trees, adjacent OTP
labels, box screenshots and control text lists; preserve non-text Wayland clipboards.
- 保險庫與瀏覽器 (vault.rs, vault_store.rs, browser.rs, botbrowser.rs, web.rs, box/browser):
verify tab host and HTTPS atomically at fill time; taint filled tabs against browser_eval
and PDF export while masking card/CVC values and screenshots; remember sites only on
always-allow; drop --remote-allow-origins=*; gate private URLs and block metadata/Docker
ports, OrbStack 198.18/15 and IPv6 transition ranges.
- 帳號伺服器、同步與傳送 (relay/, remote.rs, mirror_ui.rs, share.rs, drops.rs): isolate
paired hands hosts from brain sync, tickets, pairing and backup overwrites; redact
routine trigger secrets and clear REDACTED when endpoints change; isolate channel and
team-member turns from owner memories, appctl and grants; scrub shared bot exports and
reset grants/routines on import; validate drop IDs and serialize chunk writes.
- 網路與協定穩定性 (httpd.rs, tunnel.rs, vnc.rs, Caddyfile*): fix chunked integer overflow
and CRLF header injection; enforce Origin checks, connection/job caps, 200 MB backup
reads, unique atomic temp files and ASCII hex guards; bound deflate unzip and VNC sniff
buffers; move VNC stdin/text off the tunnel loop.
- 介面、排程、語言與其他修正 (app.rs, i18n.rs, providers.rs, skills.rs, routines.rs,
setup.rs, store.rs, preview.rs, attach.rs, speech.rs, teams.rs, mcp.rs, voice.rs):
wire up the delete-routine confirmation dialog and mirror run-now; preserve unsaved
mirror edits across brief disconnects; give Chinese skills distinct folders and approval
gates; convert parsed tool JSON fields without corrupting code fences, URLs or paths;
fix Hourly DST offsets and time out unattended routine approvals; lock --install-skill,
cap docx/xlsx unzip sizes, isolate test env keys, and tighten local file permissions.
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-12 06:34:10 +00:00
|
|
|
|
assert!(cmds.contains(&Cmd::Send { bot: 1, text: "你好".into(), attachments: vec![], from: String::new(), memories: Some(vec![]), member: false }) || cmds.contains(&Cmd::Send { bot: 1, text: "你好".into(), attachments: vec![], from: String::new(), memories: None, member: false }));
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
// The Mac's own screen stays closed unless allowed.
|
|
|
|
|
|
let mut mac = Req { method: "GET".into(), path: "/api/screen/mac".into(), ..Default::default() };
|
|
|
|
|
|
mac.headers = req.headers.clone();
|
|
|
|
|
|
assert_eq!(handle(mac, false).status, 403);
|
|
|
|
|
|
// Device link needs the relay and the switch.
|
|
|
|
|
|
assert_eq!(handle(Req { method: "POST".into(), path: "/api/device/run".into(), body: br#"{"tool":"shell"}"#.to_vec(), ..Default::default() }, true).status, 403);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-11-05 06:25:01 +00:00
|
|
|
|
#[test]
|
|
|
|
|
|
fn the_brain_is_an_online_one_that_thinks_for_itself() {
|
|
|
|
|
|
let hosts = vec![
|
|
|
|
|
|
json!({"id": "me", "name": "這台", "online": true, "hands": false, "uses": ""}),
|
|
|
|
|
|
json!({"id": "h", "name": "伺服器手腳", "online": true, "hands": true, "uses": ""}),
|
|
|
|
|
|
json!({"id": "s", "name": "筆電", "online": true, "hands": false, "uses": "b"}),
|
|
|
|
|
|
json!({"id": "old", "name": "舊的", "online": false, "hands": false, "uses": ""}),
|
|
|
|
|
|
json!({"id": "b", "name": "家裡的 Mac", "online": true, "hands": false, "uses": ""}),
|
|
|
|
|
|
];
|
|
|
|
|
|
assert_eq!(pick_brain(&hosts, "me"), Some(("b".into(), "家裡的 Mac".into())));
|
|
|
|
|
|
assert_eq!(pick_brain(&hosts[..4], "me"), None);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
AnyBot: first commit of the working desktop app
Rust/egui rebuild of Grok Bot as of 2026-11-04: chat with streaming
providers (xAI, OpenAI, Claude, Gemini, OpenRouter, OpenCode Go, Ollama,
custom), tools and approvals, the bot's Docker computer, computer use on
macOS / Linux X11 / Wayland, AnyBot's browser with a full DevTools-based
toolset, the encrypted vault, pinned grid and sidebar sections, Markdown
with Mermaid diagrams, phone access through the relay, and the Linux
build and test scripts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3oEtWeHh58zA7ErHa
2026-11-04 08:51:51 +00:00
|
|
|
|
#[test]
|
|
|
|
|
|
fn team_roles() {
|
|
|
|
|
|
assert!(role_allows("member", "POST", &["api", "bots", "3", "send"]));
|
|
|
|
|
|
assert!(role_allows("member", "GET", &["api", "state"]));
|
|
|
|
|
|
for (m, p) in [("POST", &["api", "bots", "3", "answer"][..]), ("POST", &["api", "bots", "3", "stop"][..]), ("GET", &["api", "screen", "box"][..]), ("POST", &["api", "device", "run"][..])] {
|
|
|
|
|
|
assert!(!role_allows("member", m, p), "{p:?}");
|
|
|
|
|
|
}
|
|
|
|
|
|
assert!(role_allows("admin", "POST", &["api", "bots", "3", "answer"]));
|
|
|
|
|
|
assert!(!role_allows("admin", "POST", &["api", "device", "run"]));
|
|
|
|
|
|
assert!(role_allows("device", "POST", &["api", "device", "run"]) && !role_allows("device", "GET", &["api", "state"]));
|
|
|
|
|
|
assert!(!role_allows("stranger", "GET", &["api", "state"]));
|
|
|
|
|
|
// The relay's word reaches handle() as headers.
|
|
|
|
|
|
let req = req_from_json(&json!({"method": "POST", "path": "/api/bots/1/answer", "user": "amy", "role": "member", "body": ""}));
|
|
|
|
|
|
assert_eq!(handle(req, true).status, 403);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
|
fn relay_messages_round_trip() {
|
|
|
|
|
|
let r = Resp::bytes("image/jpeg", vec![1, 2, 3]).with_header("X-Size", "2x2");
|
|
|
|
|
|
let j = resp_to_json(&r);
|
|
|
|
|
|
assert_eq!(j["status"], 200);
|
|
|
|
|
|
let req = req_from_json(&json!({"method": "POST", "path": "/api/bots/2/send", "query": {"since": "4"}, "body": "eyJ0ZXh0IjoiaGkifQ=="}));
|
|
|
|
|
|
assert_eq!(req.json()["text"], "hi");
|
|
|
|
|
|
assert_eq!(req.query["since"], "4");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
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-04 16:52:10 +00:00
|
|
|
|
|
|
|
|
|
|
/// Where the one-step installer lives (it also installs AnyBot on a computer that has nothing yet).
|
|
|
|
|
|
pub const INSTALL_URL: &str = "https://code.30cm.net/daniel.w/AnyBot/raw/branch/main/install.sh";
|
One installer for every platform, first run included
install.sh now covers every common Linux distro (apt, dnf, yum, pacman,
zypper, apk, xbps), macOS on arm64/x86_64, and hands off to install.ps1
under Git Bash. install.ps1 + install.cmd give Windows a double-click.
Autostart: systemd user unit on Linux, launchd on macOS, Task Scheduler
on Windows. A terminal guides the role choice and the first key or bot;
agents get --print JSON and ANYBOT_NONINTERACTIVE=1 with env seeding.
`加一台電腦` shows the Windows and the Mac/Linux line together.
2026-11-10 06:07:01 +00:00
|
|
|
|
/// Windows (x64 and arm64). A PowerShell one-liner; Git Bash running install.sh hands off to this.
|
|
|
|
|
|
pub const INSTALL_PS1: &str = "https://code.30cm.net/daniel.w/AnyBot/raw/branch/main/install.ps1";
|
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-04 16:52:10 +00:00
|
|
|
|
|
One installer for every platform, first run included
install.sh now covers every common Linux distro (apt, dnf, yum, pacman,
zypper, apk, xbps), macOS on arm64/x86_64, and hands off to install.ps1
under Git Bash. install.ps1 + install.cmd give Windows a double-click.
Autostart: systemd user unit on Linux, launchd on macOS, Task Scheduler
on Windows. A terminal guides the role choice and the first key or bot;
agents get --print JSON and ANYBOT_NONINTERACTIVE=1 with env seeding.
`加一台電腦` shows the Windows and the Mac/Linux line together.
2026-11-10 06:07:01 +00:00
|
|
|
|
/// The Unix line 「加一台電腦」 shows. Pasted into a macOS or any Linux terminal (desktop or
|
|
|
|
|
|
/// headless), it installs AnyBot when it isn't there yet and joins as hands.
|
2026-11-13 16:40:16 +00:00
|
|
|
|
/// (`code`: the six digits, or 「135790-key」 when this brain gave a key with it.)
|
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-04 16:52:10 +00:00
|
|
|
|
pub fn pair_line(relay_url: &str, code: &str) -> String {
|
|
|
|
|
|
format!("curl -fsSL {INSTALL_URL} | sh -s -- hands {} {code}", relay_url.trim_end_matches('/'))
|
|
|
|
|
|
}
|
2026-11-05 06:25:01 +00:00
|
|
|
|
|
One installer for every platform, first run included
install.sh now covers every common Linux distro (apt, dnf, yum, pacman,
zypper, apk, xbps), macOS on arm64/x86_64, and hands off to install.ps1
under Git Bash. install.ps1 + install.cmd give Windows a double-click.
Autostart: systemd user unit on Linux, launchd on macOS, Task Scheduler
on Windows. A terminal guides the role choice and the first key or bot;
agents get --print JSON and ANYBOT_NONINTERACTIVE=1 with env seeding.
`加一台電腦` shows the Windows and the Mac/Linux line together.
2026-11-10 06:07:01 +00:00
|
|
|
|
/// Every platform, Unix last so pasting the whole block still fills the address and the code
|
|
|
|
|
|
/// (the parser uses the last two words).
|
|
|
|
|
|
pub fn pair_block(relay_url: &str, code: &str) -> String {
|
|
|
|
|
|
let url = relay_url.trim_end_matches('/');
|
|
|
|
|
|
format!(
|
|
|
|
|
|
"Windows PowerShell:\n$env:ANYBOT_NONINTERACTIVE='1'; $env:ANYBOT_MODE='hands'; $env:ANYBOT_PAIR_URL='{url}'; $env:ANYBOT_PAIR_CODE='{code}'; irm {INSTALL_PS1} | iex\n\nMac / Linux(任何發行版,沒有螢幕也可以):\n{}",
|
|
|
|
|
|
pair_line(relay_url, code)
|
|
|
|
|
|
)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-11-05 06:25:01 +00:00
|
|
|
|
/// 登入後同步 against a real account server: ANYBOT_RELAY_URL=http://127.0.0.1:PORT
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
|
|
mod account_sync_live {
|
|
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
|
#[ignore]
|
|
|
|
|
|
fn a_new_computer_gets_the_accounts_bots_after_signing_in() {
|
|
|
|
|
|
let url = std::env::var("ANYBOT_RELAY_URL").expect("ANYBOT_RELAY_URL");
|
|
|
|
|
|
let (user, pw) = (format!("t{}", crate::httpd::random_hex(4)), "sync-pass-123");
|
|
|
|
|
|
// The first computer signs up and backs up its bots.
|
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
|
|
|
|
let a = relay_join(&Settings { host_name: "第一台".into(), ..Default::default() }, &url, &user, pw, true, "", "").unwrap();
|
2026-11-05 06:25:01 +00:00
|
|
|
|
let mut st = crate::model::State::samples();
|
|
|
|
|
|
st.remote = Default::default();
|
|
|
|
|
|
backup_now(&a, &serde_json::to_vec(&st).unwrap()).unwrap();
|
|
|
|
|
|
// A new computer signs in: no other brain is on, so the backup is what it takes in.
|
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
|
|
|
|
let b = relay_join(&Settings { host_name: "新電腦".into(), ..Default::default() }, &url, &user, pw, false, "", "").unwrap();
|
|
|
|
|
|
let found = find_account_bots(&b, pw, "");
|
2026-11-05 06:25:01 +00:00
|
|
|
|
assert!(found.brain.is_none());
|
|
|
|
|
|
let got: crate::model::State = serde_json::from_slice(&found.backup.expect("backup")).unwrap();
|
|
|
|
|
|
let mut here = crate::model::State::first_run();
|
|
|
|
|
|
assert_eq!(here.take_in_bots(&got), 5);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|