2026-11-04 09:46:43 +00:00
|
|
|
|
// 大腦: one AnyBot of the account keeps the bots, chats, memory and schedules (the brain, usually
|
|
|
|
|
|
// `anybot --serve` next to the account server). Every other AnyBot signed in to the account shows
|
|
|
|
|
|
// the brain's bots in its own window and lends its hands (screen, files, browser) through 裝置連結.
|
|
|
|
|
|
//
|
|
|
|
|
|
// The brain side answers "what changed since version N?" per screen: the settings (bots without
|
|
|
|
|
|
// their chats) when they changed, and for each bot only the messages from the first one that
|
|
|
|
|
|
// changed. The screen side keeps a copy, sends the person's edits back as small operations, and
|
|
|
|
|
|
// turns chat actions (send, stop, approve…) into requests. When the brain can't be reached the
|
|
|
|
|
|
// window stays readable and waits.
|
|
|
|
|
|
|
|
|
|
|
|
use super::*;
|
技能: / 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
|
|
|
|
use crate::memory::Skill;
|
2026-11-04 09:46:43 +00:00
|
|
|
|
use crate::remote::{self, SyncKind};
|
|
|
|
|
|
use serde_json::{json, Value};
|
|
|
|
|
|
use std::hash::{Hash, Hasher};
|
|
|
|
|
|
use std::sync::atomic::AtomicU64;
|
|
|
|
|
|
|
|
|
|
|
|
/// Settings that belong to each computer, never to the brain.
|
|
|
|
|
|
const LOCAL_KEYS: &[&str] = &["remote", "theme", "accent", "sidebar_collapsed", "sidebar_width", "selected", "machine_label", "local_execution", "local_never", "messages_send", "messages_no_ask"];
|
|
|
|
|
|
/// Bot fields the brain alone changes (its chat, and what a turn leaves behind).
|
目標: /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
|
|
|
|
const BOT_RUNTIME: &[&str] = &["id", "messages", "threads", "unread", "last_turn", "context_tokens", "goal"];
|
2026-11-04 09:46:43 +00:00
|
|
|
|
/// Stands in for a key or token the brain doesn't hand out.
|
|
|
|
|
|
pub const REDACTED: &str = "••••(已設定,在大腦上)";
|
|
|
|
|
|
|
|
|
|
|
|
// ---------- shared ----------
|
|
|
|
|
|
|
|
|
|
|
|
/// The settings as JSON: everything but the chats (messages and earlier conversations).
|
|
|
|
|
|
pub(super) fn config_json(st: &mut State) -> Value {
|
|
|
|
|
|
let mut bots = std::mem::take(&mut st.bots);
|
|
|
|
|
|
let mut top = serde_json::to_value(&*st).unwrap_or(Value::Null);
|
|
|
|
|
|
let mut arr = Vec::with_capacity(bots.len());
|
|
|
|
|
|
for b in bots.iter_mut() {
|
|
|
|
|
|
let m = std::mem::take(&mut b.messages);
|
|
|
|
|
|
let th = std::mem::take(&mut b.threads);
|
|
|
|
|
|
arr.push(serde_json::to_value(&*b).unwrap_or(Value::Null));
|
|
|
|
|
|
b.messages = m;
|
|
|
|
|
|
b.threads = th;
|
|
|
|
|
|
}
|
|
|
|
|
|
st.bots = bots;
|
|
|
|
|
|
top["bots"] = Value::Array(arr);
|
|
|
|
|
|
top
|
|
|
|
|
|
}
|
|
|
|
|
|
|
安全、修正: 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
|
|
|
|
const TRIGGER_SECRETS: [&str; 4] = ["token", "apiKey", "secret", "api_key"];
|
|
|
|
|
|
|
|
|
|
|
|
fn redact_triggers(v: &mut Value) {
|
|
|
|
|
|
match v {
|
|
|
|
|
|
Value::Object(m) => {
|
|
|
|
|
|
for k in TRIGGER_SECRETS {
|
|
|
|
|
|
if m.get(k).and_then(Value::as_str).is_some_and(|s| !s.is_empty()) {
|
|
|
|
|
|
m.insert(k.to_string(), Value::String(REDACTED.into()));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
for x in m.values_mut() {
|
|
|
|
|
|
redact_triggers(x);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
Value::Array(a) => a.iter_mut().for_each(redact_triggers),
|
|
|
|
|
|
_ => {}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-11-04 09:46:43 +00:00
|
|
|
|
/// Keys and tokens stay on the brain.
|
|
|
|
|
|
fn redact(top: &mut Value) {
|
|
|
|
|
|
if let Some(o) = top.as_object_mut() {
|
|
|
|
|
|
o.remove("remote");
|
|
|
|
|
|
}
|
|
|
|
|
|
let hide = |v: &mut Value| {
|
|
|
|
|
|
if v.as_str().map(|s| !s.is_empty()).unwrap_or(false) {
|
|
|
|
|
|
*v = Value::String(REDACTED.into());
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
if let Some(ps) = top["providers"].as_object_mut() {
|
|
|
|
|
|
for p in ps.values_mut() {
|
|
|
|
|
|
hide(&mut p["api_key"]);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
for c in top["channels"].as_array_mut().into_iter().flatten() {
|
|
|
|
|
|
hide(&mut c["token"]);
|
|
|
|
|
|
}
|
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
|
|
|
|
// 設定 › 語音's own keys (ElevenLabs, or one just for voice).
|
|
|
|
|
|
if let Some(v) = top.get_mut("voice").and_then(Value::as_object_mut) {
|
|
|
|
|
|
for side in ["listen", "speak"] {
|
|
|
|
|
|
if let Some(e) = v.get_mut(side).and_then(Value::as_object_mut) {
|
|
|
|
|
|
if let Some(k) = e.get_mut("api_key") {
|
|
|
|
|
|
hide(k);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-11-04 09:46:43 +00:00
|
|
|
|
for m in top["mcp_servers"].as_array_mut().into_iter().flatten() {
|
|
|
|
|
|
for k in ["env", "headers"] {
|
|
|
|
|
|
for v in m[k].as_object_mut().into_iter().flat_map(|o| o.values_mut()) {
|
|
|
|
|
|
hide(v);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
安全、修正: 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
|
|
|
|
for b in top["bots"].as_array_mut().into_iter().flatten() {
|
|
|
|
|
|
for r in b["routines"].as_array_mut().into_iter().flatten() {
|
|
|
|
|
|
redact_triggers(&mut r["trigger"]);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-11-04 09:46:43 +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
|
|
|
|
fn clear_redacted(v: &mut Value) {
|
|
|
|
|
|
match v {
|
|
|
|
|
|
Value::String(s) if s == REDACTED => s.clear(),
|
|
|
|
|
|
Value::Object(o) => o.values_mut().for_each(clear_redacted),
|
|
|
|
|
|
Value::Array(a) => a.iter_mut().for_each(clear_redacted),
|
|
|
|
|
|
_ => {}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Put the brain's own keys back wherever an edit still carries the stand-in — unless the
|
|
|
|
|
|
/// target address or command of that object changed (otherwise changing `base_url`/`url` to an
|
|
|
|
|
|
/// attacker's server while keeping `REDACTED` would make the brain send its real secret there).
|
2026-11-04 09:46:43 +00:00
|
|
|
|
fn unredact(new: &mut Value, old: &Value) {
|
|
|
|
|
|
match new {
|
安全、修正: 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
|
|
|
|
Value::String(s) if s == REDACTED => {
|
|
|
|
|
|
*new = old.as_str().map(|s| Value::String(s.to_string())).unwrap_or_else(|| Value::String(String::new()));
|
|
|
|
|
|
}
|
2026-11-04 09:46:43 +00:00
|
|
|
|
Value::Object(o) => {
|
安全、修正: 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 endpoint_changed = ["base_url", "url", "command", "args"].iter().any(|k| o.contains_key(*k) && o.get(*k) != old.get(*k));
|
|
|
|
|
|
if endpoint_changed {
|
|
|
|
|
|
for k in ["api_key", "token", "secret", "apiKey", "env", "headers"] {
|
|
|
|
|
|
if let Some(v) = o.get_mut(k) {
|
|
|
|
|
|
clear_redacted(v);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-11-04 09:46:43 +00:00
|
|
|
|
for (k, v) in o.iter_mut() {
|
|
|
|
|
|
unredact(v, old.get(k).unwrap_or(&Value::Null));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
Value::Array(a) => {
|
|
|
|
|
|
for (i, v) in a.iter_mut().enumerate() {
|
安全、修正: 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 key = |x: &Value| x.get("id").cloned().filter(|x| !x.is_null()).or_else(|| x.get("name").cloned().filter(|s| s.as_str().is_some_and(|t| !t.is_empty())));
|
2026-11-04 09:46:43 +00:00
|
|
|
|
let twin = old.as_array().and_then(|olds| match key(v) {
|
|
|
|
|
|
Some(k) => olds.iter().find(|o| key(o).as_ref() == Some(&k)),
|
|
|
|
|
|
None => olds.get(i),
|
|
|
|
|
|
});
|
|
|
|
|
|
unredact(v, twin.unwrap_or(&Value::Null));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
_ => {}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// A cheap fingerprint of one message: enough to see it changed (streaming, a tool finishing…).
|
|
|
|
|
|
fn msg_sig(m: &Message) -> u64 {
|
|
|
|
|
|
let mut h = std::collections::hash_map::DefaultHasher::new();
|
|
|
|
|
|
(m.role as u8, m.text.len(), m.thinking.len(), m.error, m.summary, m.images.len(), m.attachments.len(), m.at, &m.tool_call_id, &m.reactions).hash(&mut h);
|
|
|
|
|
|
m.text.chars().rev().take(48).collect::<String>().hash(&mut h);
|
|
|
|
|
|
for c in &m.tool_calls {
|
|
|
|
|
|
(&c.id, c.args.len(), c.status as u8).hash(&mut h);
|
|
|
|
|
|
}
|
|
|
|
|
|
h.finish()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn threads_sig(b: &Bot) -> u64 {
|
|
|
|
|
|
let mut h = std::collections::hash_map::DefaultHasher::new();
|
|
|
|
|
|
for (t, msgs) in &b.threads {
|
|
|
|
|
|
(t, msgs.len()).hash(&mut h);
|
|
|
|
|
|
}
|
|
|
|
|
|
h.finish()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn hash_value(v: &Value) -> u64 {
|
|
|
|
|
|
let mut h = std::collections::hash_map::DefaultHasher::new();
|
|
|
|
|
|
v.to_string().hash(&mut h);
|
|
|
|
|
|
h.finish()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-11-04 11:30:32 +00:00
|
|
|
|
/// What names an item in a list: its id, else its name, else (plain values) the value itself.
|
|
|
|
|
|
fn item_key(x: &Value) -> Option<Value> {
|
|
|
|
|
|
match x {
|
|
|
|
|
|
Value::Object(o) => o.get("id").filter(|v| !v.is_null()).or_else(|| o.get("name").filter(|v| v.is_string())).cloned(),
|
|
|
|
|
|
Value::Array(_) | Value::Null => None,
|
|
|
|
|
|
v => Some(v.clone()),
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Every item has its own key, and no two share one.
|
|
|
|
|
|
fn keyed(a: &[Value]) -> bool {
|
|
|
|
|
|
let mut seen = std::collections::HashSet::new();
|
|
|
|
|
|
a.iter().all(|x| item_key(x).map(|k| seen.insert(k.to_string())).unwrap_or(false))
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// The smallest change from `old` to `new`: lists of named things and maps change item by item,
|
|
|
|
|
|
/// so two computers editing different items of one list don't undo each other.
|
|
|
|
|
|
pub(super) fn patch_of(old: &Value, new: &Value) -> Value {
|
|
|
|
|
|
match (old, new) {
|
|
|
|
|
|
(Value::Object(o), Value::Object(n)) => {
|
|
|
|
|
|
let put: serde_json::Map<String, Value> = n.iter().filter(|(k, v)| o.get(*k) != Some(*v)).map(|(k, v)| (k.clone(), v.clone())).collect();
|
|
|
|
|
|
let del: Vec<&String> = o.keys().filter(|k| !n.contains_key(*k)).collect();
|
|
|
|
|
|
json!({"map": {"put": put, "del": del}})
|
|
|
|
|
|
}
|
|
|
|
|
|
(Value::Array(o), Value::Array(n)) if keyed(o) && keyed(n) => {
|
|
|
|
|
|
let key = |x: &Value| item_key(x).unwrap_or(Value::Null);
|
|
|
|
|
|
let put: Vec<&Value> = n.iter().filter(|x| !o.iter().any(|y| key(y) == key(x) && y == *x)).collect();
|
|
|
|
|
|
let del: Vec<Value> = o.iter().map(key).filter(|k| !n.iter().any(|x| key(x) == *k)).collect();
|
|
|
|
|
|
let common_old: Vec<Value> = o.iter().map(key).filter(|k| n.iter().any(|x| key(x) == *k)).collect();
|
|
|
|
|
|
let common_new: Vec<Value> = n.iter().map(key).filter(|k| o.iter().any(|x| key(x) == *k)).collect();
|
|
|
|
|
|
let mut p = json!({"list": {"put": put, "del": del}});
|
|
|
|
|
|
if common_old != common_new {
|
|
|
|
|
|
p["list"]["order"] = Value::Array(n.iter().map(key).collect());
|
|
|
|
|
|
}
|
|
|
|
|
|
p
|
|
|
|
|
|
}
|
|
|
|
|
|
_ => json!({"value": new}),
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Apply a change made by `patch_of` to whatever the value is now.
|
|
|
|
|
|
pub(super) fn apply_patch(cur: &mut Value, p: &Value) {
|
|
|
|
|
|
if let Some(v) = p.get("value") {
|
|
|
|
|
|
*cur = v.clone();
|
|
|
|
|
|
} else if let Some(m) = p.get("map") {
|
|
|
|
|
|
if !cur.is_object() {
|
|
|
|
|
|
*cur = json!({});
|
|
|
|
|
|
}
|
|
|
|
|
|
let o = cur.as_object_mut().expect("object");
|
|
|
|
|
|
for (k, v) in m["put"].as_object().into_iter().flatten() {
|
|
|
|
|
|
o.insert(k.clone(), v.clone());
|
|
|
|
|
|
}
|
|
|
|
|
|
for k in m["del"].as_array().into_iter().flatten().filter_map(Value::as_str) {
|
|
|
|
|
|
o.remove(k);
|
|
|
|
|
|
}
|
|
|
|
|
|
} else if let Some(l) = p.get("list") {
|
|
|
|
|
|
if !cur.is_array() {
|
|
|
|
|
|
*cur = json!([]);
|
|
|
|
|
|
}
|
|
|
|
|
|
let a = cur.as_array_mut().expect("array");
|
|
|
|
|
|
let key = |x: &Value| item_key(x).unwrap_or(Value::Null);
|
|
|
|
|
|
for item in l["put"].as_array().into_iter().flatten() {
|
|
|
|
|
|
match a.iter_mut().find(|x| key(x) == key(item)) {
|
|
|
|
|
|
Some(x) => *x = item.clone(),
|
|
|
|
|
|
None => a.push(item.clone()),
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
let del: Vec<Value> = l["del"].as_array().cloned().unwrap_or_default();
|
|
|
|
|
|
a.retain(|x| !del.contains(&key(x)));
|
|
|
|
|
|
if let Some(order) = l["order"].as_array() {
|
|
|
|
|
|
a.sort_by_key(|x| order.iter().position(|k| *k == key(x)).unwrap_or(usize::MAX));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-11-04 09:46:43 +00:00
|
|
|
|
/// The person's edits since `base`, as operations the brain applies one by one.
|
|
|
|
|
|
pub(super) fn diff_ops(base: &Value, cur: &Value) -> Vec<Value> {
|
|
|
|
|
|
let mut ops = vec![];
|
|
|
|
|
|
let (Some(b), Some(c)) = (base.as_object(), cur.as_object()) else { return ops };
|
|
|
|
|
|
for (k, v) in c {
|
|
|
|
|
|
if k == "bots" || LOCAL_KEYS.contains(&k.as_str()) {
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
if b.get(k) != Some(v) {
|
2026-11-04 11:30:32 +00:00
|
|
|
|
let p = patch_of(b.get(k).unwrap_or(&Value::Null), v);
|
|
|
|
|
|
ops.push(if p.get("value").is_some() { json!({"op": "set", "key": k, "value": v}) } else { json!({"op": "patch", "key": k, "patch": p}) });
|
2026-11-04 09:46:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
let id = |x: &Value| x["id"].as_u64().unwrap_or(0);
|
|
|
|
|
|
let empty = vec![];
|
|
|
|
|
|
let old = base["bots"].as_array().unwrap_or(&empty);
|
|
|
|
|
|
let new = cur["bots"].as_array().unwrap_or(&empty);
|
|
|
|
|
|
for nb in new {
|
|
|
|
|
|
match old.iter().find(|o| id(o) == id(nb)) {
|
|
|
|
|
|
None => ops.push(json!({"op": "bot_add", "bot": nb})),
|
|
|
|
|
|
Some(ob) => {
|
|
|
|
|
|
for (k, v) in nb.as_object().into_iter().flatten() {
|
|
|
|
|
|
if k == "unread" {
|
|
|
|
|
|
if ob[k] == true && *v == false {
|
|
|
|
|
|
ops.push(json!({"op": "bot_read", "id": id(nb)}));
|
|
|
|
|
|
}
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
if BOT_RUNTIME.contains(&k.as_str()) {
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
if ob.get(k) != Some(v) {
|
2026-11-04 11:30:32 +00:00
|
|
|
|
let p = patch_of(ob.get(k).unwrap_or(&Value::Null), v);
|
|
|
|
|
|
ops.push(if p.get("value").is_some() { json!({"op": "bot_set", "id": id(nb), "key": k, "value": v}) } else { json!({"op": "bot_patch", "id": id(nb), "key": k, "patch": p}) });
|
2026-11-04 09:46:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
for ob in old {
|
|
|
|
|
|
if !new.iter().any(|n| id(n) == id(ob)) {
|
|
|
|
|
|
ops.push(json!({"op": "bot_del", "id": id(ob)}));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
let order = |a: &Vec<Value>| a.iter().map(id).collect::<Vec<_>>();
|
|
|
|
|
|
let (oo, no) = (order(old), order(new));
|
|
|
|
|
|
let kept: Vec<u64> = oo.iter().copied().filter(|i| no.contains(i)).collect();
|
|
|
|
|
|
let kept_new: Vec<u64> = no.iter().copied().filter(|i| oo.contains(i)).collect();
|
|
|
|
|
|
if kept != kept_new {
|
|
|
|
|
|
ops.push(json!({"op": "bot_order", "ids": no}));
|
|
|
|
|
|
}
|
|
|
|
|
|
ops
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-11-04 11:07:55 +00:00
|
|
|
|
/// Replay edit operations on settings JSON: a screen keeps its own not-yet-confirmed edits on
|
|
|
|
|
|
/// top of what the brain last sent, so typing isn't undone by the brain's slightly older copy.
|
|
|
|
|
|
pub(super) fn apply_ops(cfg: &mut Value, ops: &[Value]) {
|
|
|
|
|
|
let id = |x: &Value| x["id"].as_u64().unwrap_or(0);
|
|
|
|
|
|
for op in ops {
|
|
|
|
|
|
let target = op["id"].as_u64().unwrap_or(0);
|
|
|
|
|
|
match op["op"].as_str().unwrap_or("") {
|
|
|
|
|
|
"set" => {
|
|
|
|
|
|
if let Some(k) = op["key"].as_str() {
|
|
|
|
|
|
cfg[k] = op["value"].clone();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-11-04 11:30:32 +00:00
|
|
|
|
"patch" => {
|
|
|
|
|
|
if let Some(k) = op["key"].as_str() {
|
|
|
|
|
|
apply_patch(&mut cfg[k], &op["patch"]);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
"bot_patch" => {
|
|
|
|
|
|
if let (Some(b), Some(k)) = (cfg["bots"].as_array_mut().and_then(|a| a.iter_mut().find(|b| id(b) == target)), op["key"].as_str()) {
|
|
|
|
|
|
apply_patch(&mut b[k], &op["patch"]);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-11-04 11:07:55 +00:00
|
|
|
|
"bot_add" => {
|
|
|
|
|
|
if let Some(a) = cfg["bots"].as_array_mut() {
|
|
|
|
|
|
if !a.iter().any(|b| id(b) == id(&op["bot"])) {
|
|
|
|
|
|
a.push(op["bot"].clone());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
"bot_del" => {
|
|
|
|
|
|
if let Some(a) = cfg["bots"].as_array_mut() {
|
|
|
|
|
|
a.retain(|b| id(b) != target);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
"bot_set" | "bot_read" => {
|
|
|
|
|
|
if let Some(b) = cfg["bots"].as_array_mut().and_then(|a| a.iter_mut().find(|b| id(b) == target)) {
|
|
|
|
|
|
if op["op"] == "bot_read" {
|
|
|
|
|
|
b["unread"] = json!(false);
|
|
|
|
|
|
} else if let Some(k) = op["key"].as_str() {
|
|
|
|
|
|
b[k] = op["value"].clone();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
"bot_order" => {
|
|
|
|
|
|
let ids: Vec<u64> = op["ids"].as_array().into_iter().flatten().filter_map(Value::as_u64).collect();
|
|
|
|
|
|
if let Some(a) = cfg["bots"].as_array_mut() {
|
|
|
|
|
|
a.sort_by_key(|b| ids.iter().position(|i| *i == id(b)).unwrap_or(usize::MAX));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
_ => {}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// A schedule edited on a screen keeps what the brain knows about runs (when it last ran, when it
|
|
|
|
|
|
/// runs next), so an older copy can't make a routine run twice.
|
|
|
|
|
|
fn keep_run_times(new: &mut Value, old: &Value) {
|
|
|
|
|
|
for r in new.as_array_mut().into_iter().flatten() {
|
|
|
|
|
|
let Some(o) = old.as_array().and_then(|a| a.iter().find(|o| o["id"] == r["id"])) else { continue };
|
|
|
|
|
|
let last = |x: &Value| x["last_run"].as_i64();
|
|
|
|
|
|
if last(o) > last(r) || r["last_run"].is_null() {
|
|
|
|
|
|
r["last_run"] = o["last_run"].clone();
|
|
|
|
|
|
}
|
|
|
|
|
|
let same = ["schedule", "trigger", "paused"].iter().all(|k| r[*k] == o[*k]);
|
|
|
|
|
|
if same {
|
|
|
|
|
|
r["next_run"] = o["next_run"].clone();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-11-04 09:46:43 +00:00
|
|
|
|
// ---------- the brain's side ----------
|
|
|
|
|
|
|
|
|
|
|
|
/// What the brain last sent each screen.
|
|
|
|
|
|
#[derive(Default)]
|
|
|
|
|
|
pub struct Screens {
|
|
|
|
|
|
seen: HashMap<String, Seen>,
|
|
|
|
|
|
/// The settings fingerprint, refreshed now and then while something changes.
|
|
|
|
|
|
pub(super) cfg_hash: u64,
|
|
|
|
|
|
cfg_at: Option<Instant>,
|
2026-11-04 11:07:55 +00:00
|
|
|
|
/// The last edit (by number) each screen sent, so it knows which of its edits are in.
|
|
|
|
|
|
acked: HashMap<String, u64>,
|
2026-11-04 09:46:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Default)]
|
|
|
|
|
|
struct Seen {
|
|
|
|
|
|
version: u64,
|
|
|
|
|
|
config: u64,
|
|
|
|
|
|
bots: HashMap<u64, Vec<u64>>,
|
|
|
|
|
|
threads: HashMap<u64, u64>,
|
|
|
|
|
|
at: Option<Instant>,
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ---------- the screen's side ----------
|
|
|
|
|
|
|
|
|
|
|
|
pub enum Incoming {
|
|
|
|
|
|
Pull(Value),
|
|
|
|
|
|
Offline(String),
|
2026-11-04 11:30:32 +00:00
|
|
|
|
/// A file from the brain arrived (its local copy's path).
|
|
|
|
|
|
File(String),
|
2026-11-04 09:46:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-11-04 11:07:55 +00:00
|
|
|
|
/// What a screen sends to the brain, one at a time and in order.
|
|
|
|
|
|
enum Out {
|
|
|
|
|
|
Edit { seq: u64, ops: Vec<Value> },
|
|
|
|
|
|
Act(Value),
|
記憶: 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
|
|
|
|
Send { bot: u64, text: String, atts: Vec<crate::attach::Attachment>, memories: Option<Vec<String>> },
|
技能: / 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
|
|
|
|
Move { ops: Vec<Value>, n: usize, skills: Vec<Skill> },
|
|
|
|
|
|
/// 技能 on a screen: done at the brain (see [`App::mirror_skill`]); the answer goes to `note`.
|
|
|
|
|
|
Skill { body: Value, note: SkillNote, busy: Arc<AtomicBool> },
|
連接器: 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
|
|
|
|
/// 連接器 › 重新連線 on a screen: the servers run at the brain.
|
|
|
|
|
|
McpReconnect(String),
|
技能: / 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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Where a skill request's answer is shown: (worked, words).
|
|
|
|
|
|
pub(super) type SkillNote = Arc<Mutex<Option<(bool, String)>>>;
|
|
|
|
|
|
|
|
|
|
|
|
/// What the brain is asked for a skill request: a folder or `.md` file named by its path on this
|
|
|
|
|
|
/// computer (`{"local": …}`) goes up whole, read here — the brain can't see this disk.
|
|
|
|
|
|
fn skill_request(body: Value) -> Result<Value, String> {
|
|
|
|
|
|
match body["local"].as_str() {
|
|
|
|
|
|
Some(p) => Ok(json!({"package": crate::skills::package_from_path(&crate::tools::expand_home(p))?})),
|
|
|
|
|
|
None => Ok(body),
|
|
|
|
|
|
}
|
2026-11-04 11:07:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-11-11 06:47:20 +00:00
|
|
|
|
/// The bots whose turn ended well since the last update (`seen` keeps when each bot's last turn
|
|
|
|
|
|
/// ended). Only an end heard while connected counts, and only a recent one: connecting, or coming
|
|
|
|
|
|
/// back after a while, never reads old answers out.
|
|
|
|
|
|
fn just_finished<'a>(seen: &mut HashMap<u64, i64>, turns: impl IntoIterator<Item = (u64, Option<&'a TurnSettlement>)>, now_ms: i64) -> Vec<u64> {
|
|
|
|
|
|
let mut out = vec![];
|
|
|
|
|
|
for (id, t) in turns {
|
|
|
|
|
|
let Some(t) = t else { continue };
|
|
|
|
|
|
let before = seen.insert(id, t.settled_at_ms);
|
|
|
|
|
|
if before.is_some_and(|s| s < t.settled_at_ms) && t.outcome == TurnOutcome::Success && now_ms - t.settled_at_ms < 120_000 {
|
|
|
|
|
|
out.push(id);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
out
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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
|
|
|
|
/// An edit sent to the brain and not yet confirmed: (its number, the operations).
|
|
|
|
|
|
type Pending = (u64, Vec<Value>);
|
|
|
|
|
|
|
2026-11-04 09:46:43 +00:00
|
|
|
|
#[derive(Default)]
|
|
|
|
|
|
pub struct Mirror {
|
|
|
|
|
|
/// This window shows a brain (instead of its own bots).
|
|
|
|
|
|
pub on: bool,
|
|
|
|
|
|
/// Heard from the brain lately.
|
|
|
|
|
|
pub online: bool,
|
|
|
|
|
|
/// The brain's settings as last received (edits are what differs from this).
|
|
|
|
|
|
pub(super) base: Value,
|
|
|
|
|
|
pub status: Arc<Mutex<String>>,
|
|
|
|
|
|
rx: Option<Receiver<Incoming>>,
|
|
|
|
|
|
tx: Option<Sender<Incoming>>,
|
|
|
|
|
|
gen: Arc<AtomicU64>,
|
|
|
|
|
|
version: Arc<AtomicU64>,
|
|
|
|
|
|
client: String,
|
|
|
|
|
|
/// This computer's own data, kept aside while it shows the brain.
|
|
|
|
|
|
local: Option<State>,
|
|
|
|
|
|
started: bool,
|
|
|
|
|
|
/// A request to the brain failed (shown above the message box).
|
|
|
|
|
|
pub(super) error: Arc<Mutex<String>>,
|
|
|
|
|
|
/// The person chose a brain in 設定 (applied on the next frame).
|
|
|
|
|
|
pub(super) want: Option<(String, String)>,
|
|
|
|
|
|
pub(super) leave: bool,
|
|
|
|
|
|
pub(super) moving: Arc<AtomicBool>,
|
2026-11-05 06:25:01 +00:00
|
|
|
|
/// Just signed in: copy this computer's bots to the brain once it answers.
|
|
|
|
|
|
pub(super) move_after_join: bool,
|
2026-11-04 09:46:43 +00:00
|
|
|
|
pub(super) move_note: Arc<Mutex<String>>,
|
2026-11-04 11:07:55 +00:00
|
|
|
|
/// Requests to the brain, sent in order by one worker.
|
|
|
|
|
|
outbox: Option<Sender<Out>>,
|
|
|
|
|
|
/// Edits sent but not yet confirmed (by number).
|
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
|
|
|
|
pending: Arc<Mutex<Vec<Pending>>>,
|
2026-11-04 11:07:55 +00:00
|
|
|
|
seq: u64,
|
|
|
|
|
|
/// Something didn't reach the brain: ask for everything again.
|
|
|
|
|
|
resync: Arc<AtomicBool>,
|
|
|
|
|
|
/// Why the brain can't be reached (shown above the chat), and since when.
|
|
|
|
|
|
pub(super) reason: String,
|
|
|
|
|
|
down_since: Option<Instant>,
|
2026-11-04 11:30:32 +00:00
|
|
|
|
/// Files from the brain being fetched (by local path).
|
|
|
|
|
|
fetching: std::collections::HashSet<String>,
|
2026-11-04 12:56:06 +00:00
|
|
|
|
/// 加一台電腦: the line to run on the new computer (or why there is none), and when it was made.
|
|
|
|
|
|
pub(super) pair: Arc<Mutex<(String, bool, Option<Instant>)>>,
|
2026-11-05 08:47:28 +00:00
|
|
|
|
/// The bots' own computer on the brain: {label, running, available, busy}.
|
|
|
|
|
|
pub(super) box_state: Value,
|
|
|
|
|
|
/// Each bot's computers on the brain, by bot id: {names: [{name, kind}], current, missing}.
|
|
|
|
|
|
pub(super) computers: HashMap<u64, Value>,
|
連接器: 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
|
|
|
|
/// The connectors at the brain, as [`App::mcp_state`] gives them.
|
|
|
|
|
|
pub(super) mcp_state: Value,
|
2026-11-11 06:47:20 +00:00
|
|
|
|
/// When each bot's last turn ended, as last heard (a newer one ending well is read aloud).
|
|
|
|
|
|
settled: HashMap<u64, i64>,
|
2026-11-05 08:47:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// What a computer is, in a word a screen can show next to its name.
|
|
|
|
|
|
pub(super) fn computer_kind(t: &crate::tools::Target, r: &crate::tools::Roles) -> &'static str {
|
|
|
|
|
|
use crate::tools::Place;
|
|
|
|
|
|
if t.name == r.own {
|
|
|
|
|
|
"own"
|
|
|
|
|
|
} else if r.person.as_deref() == Some(t.name.as_str()) {
|
|
|
|
|
|
"person"
|
|
|
|
|
|
} else {
|
|
|
|
|
|
match t.place {
|
|
|
|
|
|
Place::Local { .. } if r.server => "server",
|
|
|
|
|
|
Place::Local { .. } => "this",
|
|
|
|
|
|
Place::Device { .. } => "device",
|
|
|
|
|
|
_ => "ssh",
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-11-04 11:30:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Where a screen keeps its copy of a file the brain has.
|
|
|
|
|
|
fn local_copy(brain_path: &str, name: &str) -> PathBuf {
|
|
|
|
|
|
let h = crate::httpd::sha256_hex(brain_path);
|
|
|
|
|
|
let name: String = name.chars().filter(|c| !matches!(c, '/' | '\\' | '\0' | ':')).take(80).collect();
|
|
|
|
|
|
State::path().with_file_name("brain-files").join(format!("{}-{name}", &h[..16]))
|
2026-11-04 09:46:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn cache_path() -> PathBuf {
|
|
|
|
|
|
State::path().with_file_name("brain-copy.json")
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl App {
|
|
|
|
|
|
/// The brain: answer the screens' requests (on the app's thread, where the state is).
|
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
|
|
|
|
pub(super) fn brain_serve(&mut self, ctx: &egui::Context) {
|
2026-11-04 09:46:43 +00:00
|
|
|
|
let reqs = remote::hub().take_sync();
|
|
|
|
|
|
if reqs.is_empty() {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
for r in reqs {
|
|
|
|
|
|
let v = match r.kind {
|
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
|
|
|
|
// 手機 (not a screen): what the desktop does, done the same way.
|
|
|
|
|
|
SyncKind::Phone { action, body, role } => {
|
|
|
|
|
|
if self.mir.on {
|
|
|
|
|
|
json!({"error": "這台 AnyBot 連著別的大腦,請在大腦上操作"})
|
|
|
|
|
|
} else {
|
|
|
|
|
|
self.phone_act(ctx, &action, &body, &role)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-11-04 09:46:43 +00:00
|
|
|
|
SyncKind::Pull { client, since } => self.brain_pull(&client, since),
|
2026-11-04 11:30:32 +00:00
|
|
|
|
SyncKind::Models(name) => {
|
|
|
|
|
|
let kind = serde_json::from_value::<crate::providers::ProviderKind>(json!(name)).ok();
|
|
|
|
|
|
match kind {
|
|
|
|
|
|
Some(kind) => {
|
|
|
|
|
|
let ps = self.state.provider(kind);
|
|
|
|
|
|
let (base, key) = (crate::providers::resolve_base(kind, &ps.base_url), crate::providers::resolve_key(kind, &ps.api_key));
|
|
|
|
|
|
let reply = r.reply;
|
|
|
|
|
|
// The list can take a while; the app doesn't wait for it.
|
|
|
|
|
|
std::thread::spawn(move || {
|
|
|
|
|
|
let _ = reply.send(match crate::providers::list_models(kind, &base, &key) {
|
|
|
|
|
|
Ok(models) => json!({"models": models}),
|
|
|
|
|
|
Err(e) => json!({"error": e}),
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
None => json!({"error": "大腦不認得這個模型服務(兩邊 AnyBot 版本不同?)"}),
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-11-04 09:46:43 +00:00
|
|
|
|
SyncKind::Edit(body) => {
|
|
|
|
|
|
if self.mir.on {
|
|
|
|
|
|
json!({"error": "這台 AnyBot 本身連著別的大腦"})
|
|
|
|
|
|
} else {
|
|
|
|
|
|
self.brain_edit(&body)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
let _ = r.reply.send(v);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Keep the settings fingerprint fresh (at most once a second) so screens hear of edits.
|
|
|
|
|
|
pub(super) fn brain_watch(&mut self) {
|
|
|
|
|
|
if self.mir.on || !self.dirty || self.scr.cfg_at.map(|t| t.elapsed().as_millis() < 1000).unwrap_or(false) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
self.scr.cfg_at = Some(Instant::now());
|
|
|
|
|
|
let mut c = config_json(&mut self.state);
|
|
|
|
|
|
redact(&mut c);
|
|
|
|
|
|
self.scr.cfg_hash = hash_value(&c);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn brain_pull(&mut self, client: &str, since: u64) -> Value {
|
|
|
|
|
|
if self.mir.on {
|
|
|
|
|
|
return json!({"error": "這台 AnyBot 本身連著別的大腦"});
|
|
|
|
|
|
}
|
|
|
|
|
|
let version = remote::hub().version();
|
|
|
|
|
|
// Forget screens not heard from in a day.
|
|
|
|
|
|
self.scr.seen.retain(|_, s| s.at.map(|t| t.elapsed().as_secs() < 86_400).unwrap_or(false));
|
|
|
|
|
|
let seen = self.scr.seen.entry(client.to_string()).or_default();
|
|
|
|
|
|
// A screen that missed an answer (or is new) gets everything again.
|
|
|
|
|
|
if seen.version != since || since == 0 {
|
|
|
|
|
|
*seen = Seen::default();
|
|
|
|
|
|
}
|
|
|
|
|
|
seen.at = Some(Instant::now());
|
|
|
|
|
|
seen.version = version;
|
2026-11-04 11:07:55 +00:00
|
|
|
|
let acked = self.scr.acked.get(client).copied().unwrap_or(0);
|
|
|
|
|
|
let mut out = json!({"version": version, "brain": self.state.remote.host_name, "edit_seq": acked});
|
2026-11-04 09:46:43 +00:00
|
|
|
|
let mut c = config_json(&mut self.state);
|
|
|
|
|
|
redact(&mut c);
|
|
|
|
|
|
let ch = hash_value(&c);
|
|
|
|
|
|
if seen.config != ch {
|
|
|
|
|
|
seen.config = ch;
|
|
|
|
|
|
out["config"] = c;
|
|
|
|
|
|
}
|
|
|
|
|
|
let mut bots = vec![];
|
|
|
|
|
|
let mut threads = vec![];
|
|
|
|
|
|
for b in &self.state.bots {
|
|
|
|
|
|
let sigs: Vec<u64> = b.messages.iter().map(msg_sig).collect();
|
|
|
|
|
|
let old = seen.bots.get(&b.id);
|
|
|
|
|
|
let from = match old {
|
|
|
|
|
|
Some(o) => o.iter().zip(sigs.iter()).position(|(a, b)| a != b).unwrap_or(o.len().min(sigs.len())),
|
|
|
|
|
|
None => 0,
|
|
|
|
|
|
};
|
|
|
|
|
|
if old.map(|o| o.len() != sigs.len() || from < sigs.len()).unwrap_or(true) {
|
|
|
|
|
|
bots.push(json!({"id": b.id, "from": from, "messages": &b.messages[from..]}));
|
|
|
|
|
|
}
|
|
|
|
|
|
seen.bots.insert(b.id, sigs);
|
|
|
|
|
|
let ts = threads_sig(b);
|
|
|
|
|
|
if seen.threads.get(&b.id) != Some(&ts) {
|
|
|
|
|
|
seen.threads.insert(b.id, ts);
|
|
|
|
|
|
threads.push(json!({"id": b.id, "threads": b.threads}));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
seen.bots.retain(|id, _| self.state.bots.iter().any(|b| b.id == *id));
|
|
|
|
|
|
out["bots"] = Value::Array(bots);
|
|
|
|
|
|
out["threads"] = Value::Array(threads);
|
|
|
|
|
|
out["live"] = self.streams.iter().map(|(id, l)| (id.to_string(), json!({"status": l.status, "paused": l.paused}))).collect::<serde_json::Map<_, _>>().into();
|
|
|
|
|
|
out["approvals"] = self
|
|
|
|
|
|
.approvals
|
|
|
|
|
|
.iter()
|
|
|
|
|
|
.map(|(id, a)| {
|
|
|
|
|
|
let kind = match a.kind {
|
|
|
|
|
|
ApprovalKind::Action => "action",
|
|
|
|
|
|
ApprovalKind::EnableTools => "tools",
|
|
|
|
|
|
ApprovalKind::EnableThisComputer => "local",
|
2026-11-05 09:29:55 +00:00
|
|
|
|
ApprovalKind::Handoff => "handoff",
|
問題卡、搜尋: 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
|
|
|
|
ApprovalKind::Question => "question",
|
2026-11-04 09:46:43 +00:00
|
|
|
|
};
|
|
|
|
|
|
json!({"bot": id, "call_id": a.call_id, "tool": a.tool, "reason": a.reason, "grant": a.grant, "kind": kind})
|
|
|
|
|
|
})
|
|
|
|
|
|
.collect();
|
連接器: 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
|
|
|
|
// The connectors run here too: whether each is connected, or why not.
|
|
|
|
|
|
out["mcp"] = self.mcp_state();
|
2026-11-05 08:47:28 +00:00
|
|
|
|
// The bots' computer lives here; a screen shows its state, not its own computer's.
|
|
|
|
|
|
let run = crate::cloudbox::run_state();
|
|
|
|
|
|
out["box"] = json!({"label": run.label(), "running": run.is_running(), "available": crate::cloudbox::available(), "busy": crate::cloudbox::is_busy()});
|
|
|
|
|
|
// Which computers each bot has (only the brain knows the account's other computers).
|
|
|
|
|
|
out["computers"] = self
|
|
|
|
|
|
.state
|
|
|
|
|
|
.bots
|
|
|
|
|
|
.iter()
|
|
|
|
|
|
.map(|b| {
|
|
|
|
|
|
let t = self.targets_for(b);
|
|
|
|
|
|
let r = self.roles_for(b, &t);
|
|
|
|
|
|
let (current, missing) = Self::chosen_computer(b, &t, &r);
|
|
|
|
|
|
let names: Vec<Value> = t.iter().map(|x| json!({"name": x.name, "kind": computer_kind(x, &r)})).collect();
|
|
|
|
|
|
(b.id.to_string(), json!({"names": names, "current": current, "missing": missing}))
|
|
|
|
|
|
})
|
|
|
|
|
|
.collect::<serde_json::Map<_, _>>()
|
|
|
|
|
|
.into();
|
2026-11-04 09:46:43 +00:00
|
|
|
|
out
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// A screen's edits.
|
|
|
|
|
|
pub(super) fn brain_edit(&mut self, body: &Value) -> Value {
|
|
|
|
|
|
let mut applied = 0;
|
2026-11-04 11:07:55 +00:00
|
|
|
|
let total = body["ops"].as_array().map(|a| a.len()).unwrap_or(0);
|
2026-11-04 09:46:43 +00:00
|
|
|
|
for op in body["ops"].as_array().into_iter().flatten() {
|
|
|
|
|
|
let ok = match op["op"].as_str().unwrap_or("") {
|
|
|
|
|
|
"set" => self.brain_set_top(op["key"].as_str().unwrap_or(""), op["value"].clone()),
|
|
|
|
|
|
"bot_add" => {
|
|
|
|
|
|
let mut v = op["bot"].clone();
|
安全、修正: 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
|
|
|
|
unredact(&mut v, &Value::Null);
|
2026-11-04 09:46:43 +00:00
|
|
|
|
match serde_json::from_value::<Bot>(v.take()) {
|
|
|
|
|
|
Ok(mut b) => {
|
|
|
|
|
|
if b.id == 0 || self.state.bot(b.id).is_some() {
|
|
|
|
|
|
b.id = self.state.next_id.max(1);
|
|
|
|
|
|
}
|
|
|
|
|
|
self.state.next_id = self.state.next_id.max(b.id + 1);
|
|
|
|
|
|
self.state.bots.push(b);
|
2026-11-05 06:25:01 +00:00
|
|
|
|
self.state.fix_primary();
|
2026-11-04 09:46:43 +00:00
|
|
|
|
true
|
|
|
|
|
|
}
|
|
|
|
|
|
Err(_) => false,
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
"bot_del" => {
|
|
|
|
|
|
let id = op["id"].as_u64().unwrap_or(0);
|
2026-11-05 06:25:01 +00:00
|
|
|
|
if self.state.bot(id).is_none() {
|
2026-11-04 09:46:43 +00:00
|
|
|
|
false
|
|
|
|
|
|
} else {
|
|
|
|
|
|
self.stop(id);
|
|
|
|
|
|
self.state.bots.retain(|b| b.id != id);
|
2026-11-05 06:25:01 +00:00
|
|
|
|
self.state.fix_primary();
|
2026-11-04 09:46:43 +00:00
|
|
|
|
true
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
"merge" => self.brain_merge_top(op["key"].as_str().unwrap_or(""), &op["value"]),
|
2026-11-04 11:30:32 +00:00
|
|
|
|
"patch" => {
|
|
|
|
|
|
let key = op["key"].as_str().unwrap_or("");
|
|
|
|
|
|
let mut v = self.top_value(key);
|
|
|
|
|
|
apply_patch(&mut v, &op["patch"]);
|
|
|
|
|
|
self.brain_set_top(key, v)
|
|
|
|
|
|
}
|
|
|
|
|
|
"bot_patch" => {
|
|
|
|
|
|
let (id, key) = (op["id"].as_u64().unwrap_or(0), op["key"].as_str().unwrap_or(""));
|
|
|
|
|
|
match self.state.bot(id).map(|b| serde_json::to_value(b).ok().map(|v| v[key].clone()).unwrap_or(Value::Null)) {
|
|
|
|
|
|
Some(mut v) => {
|
|
|
|
|
|
let old = v.clone();
|
|
|
|
|
|
apply_patch(&mut v, &op["patch"]);
|
|
|
|
|
|
unredact(&mut v, &old);
|
|
|
|
|
|
self.brain_set_bot(id, key, v)
|
|
|
|
|
|
}
|
|
|
|
|
|
None => false,
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-11-04 09:46:43 +00:00
|
|
|
|
"bot_set" => self.brain_set_bot(op["id"].as_u64().unwrap_or(0), op["key"].as_str().unwrap_or(""), op["value"].clone()),
|
|
|
|
|
|
"bot_read" => match self.state.bot_mut(op["id"].as_u64().unwrap_or(0)) {
|
|
|
|
|
|
Some(b) => {
|
|
|
|
|
|
b.unread = false;
|
|
|
|
|
|
true
|
|
|
|
|
|
}
|
|
|
|
|
|
None => false,
|
|
|
|
|
|
},
|
|
|
|
|
|
"bot_order" => {
|
|
|
|
|
|
let ids: Vec<u64> = op["ids"].as_array().into_iter().flatten().filter_map(Value::as_u64).collect();
|
|
|
|
|
|
self.state.bots.sort_by_key(|b| ids.iter().position(|i| *i == b.id).unwrap_or(usize::MAX));
|
|
|
|
|
|
true
|
|
|
|
|
|
}
|
|
|
|
|
|
_ => false,
|
|
|
|
|
|
};
|
|
|
|
|
|
if ok {
|
|
|
|
|
|
applied += 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-11-04 11:07:55 +00:00
|
|
|
|
if let (Some(client), Some(seq)) = (body["client"].as_str(), body["seq"].as_u64()) {
|
|
|
|
|
|
self.scr.acked.insert(client.to_string(), seq);
|
|
|
|
|
|
// Something was refused: send that screen the settings again, so it drops it.
|
|
|
|
|
|
if applied < total {
|
|
|
|
|
|
if let Some(s) = self.scr.seen.get_mut(client) {
|
|
|
|
|
|
s.config = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-11-04 09:46:43 +00:00
|
|
|
|
if applied > 0 {
|
|
|
|
|
|
self.mark();
|
|
|
|
|
|
// Screens hear of it at once.
|
|
|
|
|
|
self.scr.cfg_at = None;
|
|
|
|
|
|
self.brain_watch();
|
|
|
|
|
|
}
|
|
|
|
|
|
json!({"ok": true, "applied": applied})
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-11-04 11:30:32 +00:00
|
|
|
|
/// One top-level setting as JSON (with the brain's real keys).
|
|
|
|
|
|
fn top_value(&mut self, key: &str) -> Value {
|
|
|
|
|
|
let bots = std::mem::take(&mut self.state.bots);
|
|
|
|
|
|
let v = serde_json::to_value(&self.state).map(|t| t[key].clone()).unwrap_or(Value::Null);
|
|
|
|
|
|
self.state.bots = bots;
|
|
|
|
|
|
v
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-11-04 09:46:43 +00:00
|
|
|
|
fn brain_set_top(&mut self, key: &str, mut value: Value) -> bool {
|
|
|
|
|
|
if key.is_empty() || key == "bots" || LOCAL_KEYS.contains(&key) {
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
let bots = std::mem::take(&mut self.state.bots);
|
|
|
|
|
|
let mut top = serde_json::to_value(&self.state).unwrap_or(Value::Null);
|
|
|
|
|
|
unredact(&mut value, &top[key]);
|
|
|
|
|
|
// Counters never go back (a screen may be behind).
|
|
|
|
|
|
if key.starts_with("next_") {
|
|
|
|
|
|
value = json!(value.as_u64().unwrap_or(0).max(top[key].as_u64().unwrap_or(0)));
|
|
|
|
|
|
}
|
|
|
|
|
|
top[key] = value;
|
|
|
|
|
|
let ok = match serde_json::from_value::<State>(top) {
|
|
|
|
|
|
Ok(mut st) => {
|
|
|
|
|
|
st.remote = std::mem::take(&mut self.state.remote);
|
|
|
|
|
|
self.state = st;
|
|
|
|
|
|
true
|
|
|
|
|
|
}
|
|
|
|
|
|
Err(_) => false,
|
|
|
|
|
|
};
|
|
|
|
|
|
self.state.bots = bots;
|
|
|
|
|
|
ok
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// 搬到大腦: add what the brain doesn't have yet (keys it lacks, skills and connectors by name).
|
|
|
|
|
|
fn brain_merge_top(&mut self, key: &str, value: &Value) -> bool {
|
|
|
|
|
|
let bots = std::mem::take(&mut self.state.bots);
|
|
|
|
|
|
let top = serde_json::to_value(&self.state).unwrap_or(Value::Null);
|
|
|
|
|
|
self.state.bots = bots;
|
|
|
|
|
|
let mut cur = top[key].clone();
|
|
|
|
|
|
match (key, &mut cur) {
|
|
|
|
|
|
("providers", Value::Object(o)) => {
|
|
|
|
|
|
for (k, v) in value.as_object().into_iter().flatten() {
|
|
|
|
|
|
let missing = o.get(k).map(|x| x["api_key"].as_str().unwrap_or("").is_empty()).unwrap_or(true);
|
|
|
|
|
|
if missing && v["api_key"].as_str().map(|s| !s.is_empty() && s != REDACTED).unwrap_or(false) {
|
|
|
|
|
|
o.insert(k.clone(), v.clone());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
("skills" | "mcp_servers", Value::Array(a)) => {
|
|
|
|
|
|
for v in value.as_array().into_iter().flatten() {
|
|
|
|
|
|
if !a.iter().any(|x| x["name"] == v["name"]) {
|
|
|
|
|
|
a.push(v.clone());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
_ => return false,
|
|
|
|
|
|
}
|
|
|
|
|
|
self.brain_set_top(key, cur)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn brain_set_bot(&mut self, id: u64, key: &str, value: Value) -> bool {
|
|
|
|
|
|
if BOT_RUNTIME.contains(&key) {
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
let Some(i) = self.state.bots.iter().position(|b| b.id == id) else { return false };
|
|
|
|
|
|
let b = &mut self.state.bots[i];
|
|
|
|
|
|
let msgs = std::mem::take(&mut b.messages);
|
|
|
|
|
|
let threads = std::mem::take(&mut b.threads);
|
|
|
|
|
|
let mut v = serde_json::to_value(&*b).unwrap_or(Value::Null);
|
2026-11-04 11:07:55 +00:00
|
|
|
|
let mut value = value;
|
安全、修正: 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
|
|
|
|
unredact(&mut value, &v[key]);
|
2026-11-04 11:07:55 +00:00
|
|
|
|
if key == "routines" {
|
|
|
|
|
|
keep_run_times(&mut value, &v["routines"]);
|
|
|
|
|
|
}
|
2026-11-04 09:46:43 +00:00
|
|
|
|
v[key] = value;
|
|
|
|
|
|
let ok = match serde_json::from_value::<Bot>(v) {
|
|
|
|
|
|
Ok(nb) => {
|
|
|
|
|
|
*b = nb;
|
|
|
|
|
|
true
|
|
|
|
|
|
}
|
|
|
|
|
|
Err(_) => false,
|
|
|
|
|
|
};
|
|
|
|
|
|
let b = &mut self.state.bots[i];
|
|
|
|
|
|
b.messages = msgs;
|
|
|
|
|
|
b.threads = threads;
|
|
|
|
|
|
ok
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ---------- the screen ----------
|
|
|
|
|
|
|
|
|
|
|
|
/// Once at start: a brain was chosen earlier, so show its copy.
|
|
|
|
|
|
pub(super) fn mirror_boot(&mut self) {
|
|
|
|
|
|
if self.mir.started || self.demo {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
self.mir.started = true;
|
|
|
|
|
|
self.mir.client = crate::httpd::random_hex(8);
|
|
|
|
|
|
if !self.state.remote.brain_id.is_empty() && !self.state.remote.host_token.is_empty() {
|
|
|
|
|
|
self.mirror_enter();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Start showing the brain: this computer's own bots are kept aside, untouched.
|
|
|
|
|
|
fn mirror_enter(&mut self) {
|
|
|
|
|
|
let ids: Vec<u64> = self.streams.keys().copied().collect();
|
|
|
|
|
|
for id in ids {
|
|
|
|
|
|
self.stop(id);
|
|
|
|
|
|
}
|
|
|
|
|
|
self.approvals.clear();
|
|
|
|
|
|
let local = self.state.clone();
|
|
|
|
|
|
if let Some(copy) = std::fs::read_to_string(cache_path()).ok().and_then(|s| serde_json::from_str::<State>(&s).ok()).filter(|s| !s.bots.is_empty()) {
|
|
|
|
|
|
self.state = copy;
|
|
|
|
|
|
self.keep_local_fields(&local);
|
|
|
|
|
|
// Edits wait for the brain's own answer; the copy may be old.
|
|
|
|
|
|
}
|
|
|
|
|
|
self.mir.base = Value::Null;
|
|
|
|
|
|
self.mir.local = Some(local);
|
|
|
|
|
|
self.mir.on = true;
|
2026-11-05 09:10:05 +00:00
|
|
|
|
// The bots' computer is the brain's now; this one's box isn't kept awake.
|
|
|
|
|
|
crate::cloudbox::set_brain(false);
|
2026-11-04 09:46:43 +00:00
|
|
|
|
self.mir.online = false;
|
|
|
|
|
|
self.mir.version.store(0, Ordering::SeqCst);
|
2026-11-04 11:07:55 +00:00
|
|
|
|
self.mir.pending.lock().unwrap().clear();
|
|
|
|
|
|
self.mir.reason.clear();
|
|
|
|
|
|
self.mir.down_since = None;
|
2026-11-04 09:46:43 +00:00
|
|
|
|
*self.mir.status.lock().unwrap() = "正在連到大腦…".into();
|
|
|
|
|
|
self.mirror_worker();
|
2026-11-04 11:07:55 +00:00
|
|
|
|
self.mirror_outbox();
|
2026-11-04 12:56:06 +00:00
|
|
|
|
crate::tunnel::hello(&self.state.remote.brain_id, self.state.remote.device_link);
|
2026-11-04 09:46:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Back to this computer's own bots.
|
|
|
|
|
|
fn mirror_leave(&mut self) {
|
|
|
|
|
|
self.mir.gen.fetch_add(1, Ordering::SeqCst);
|
|
|
|
|
|
self.mir.on = false;
|
2026-11-05 09:10:05 +00:00
|
|
|
|
crate::cloudbox::set_brain(true);
|
2026-11-04 09:46:43 +00:00
|
|
|
|
self.mir.online = false;
|
2026-11-04 11:07:55 +00:00
|
|
|
|
self.mir.outbox = None;
|
2026-11-04 09:46:43 +00:00
|
|
|
|
self.streams.clear();
|
|
|
|
|
|
self.approvals.clear();
|
2026-11-11 06:47:20 +00:00
|
|
|
|
self.mir.settled.clear();
|
2026-11-04 09:46:43 +00:00
|
|
|
|
if let Some(mut local) = self.mir.local.take() {
|
|
|
|
|
|
let mut remote = self.state.remote.clone();
|
|
|
|
|
|
remote.brain_id.clear();
|
|
|
|
|
|
remote.brain_name.clear();
|
2026-11-04 12:38:45 +00:00
|
|
|
|
remote.hands_for.clear();
|
|
|
|
|
|
remote.hands_for_name.clear();
|
2026-11-04 09:46:43 +00:00
|
|
|
|
local.remote = remote;
|
|
|
|
|
|
local.theme = self.state.theme;
|
|
|
|
|
|
local.accent = self.state.accent;
|
|
|
|
|
|
if local.bot(local.selected).is_none() {
|
|
|
|
|
|
local.selected = local.primary_bot;
|
|
|
|
|
|
}
|
|
|
|
|
|
self.state = local;
|
|
|
|
|
|
} else {
|
安全、修正: 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
|
|
|
|
// Never keep REDACTED placeholders as real keys when leaving mirror mode without a saved local state.
|
|
|
|
|
|
let mut v = serde_json::to_value(&self.state).unwrap_or(Value::Null);
|
|
|
|
|
|
clear_redacted(&mut v);
|
|
|
|
|
|
if let Ok(st) = serde_json::from_value::<State>(v) {
|
|
|
|
|
|
self.state = st;
|
|
|
|
|
|
}
|
2026-11-04 09:46:43 +00:00
|
|
|
|
self.state.remote.brain_id.clear();
|
|
|
|
|
|
self.state.remote.brain_name.clear();
|
2026-11-04 12:38:45 +00:00
|
|
|
|
self.state.remote.hands_for.clear();
|
|
|
|
|
|
self.state.remote.hands_for_name.clear();
|
2026-11-04 09:46:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
self.state.save();
|
|
|
|
|
|
self.dirty = false;
|
2026-11-04 12:56:06 +00:00
|
|
|
|
crate::tunnel::hello("", self.state.remote.device_link);
|
2026-11-04 09:46:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn keep_local_fields(&mut self, from: &State) {
|
|
|
|
|
|
let st = &mut self.state;
|
|
|
|
|
|
st.remote = from.remote.clone();
|
|
|
|
|
|
st.theme = from.theme;
|
|
|
|
|
|
st.accent = from.accent;
|
|
|
|
|
|
st.sidebar_collapsed = from.sidebar_collapsed;
|
|
|
|
|
|
st.sidebar_width = from.sidebar_width;
|
|
|
|
|
|
st.machine_label = from.machine_label.clone();
|
|
|
|
|
|
st.local_execution = from.local_execution;
|
|
|
|
|
|
st.local_never = from.local_never;
|
|
|
|
|
|
st.messages_send = from.messages_send;
|
|
|
|
|
|
st.messages_no_ask = from.messages_no_ask;
|
|
|
|
|
|
if st.bot(from.selected).is_some() {
|
|
|
|
|
|
st.selected = from.selected;
|
|
|
|
|
|
} else if st.bot(st.selected).is_none() {
|
|
|
|
|
|
st.selected = st.primary_bot;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn mirror_worker(&mut self) {
|
|
|
|
|
|
let gen = self.mir.gen.fetch_add(1, Ordering::SeqCst) + 1;
|
|
|
|
|
|
let (tx, rx) = channel();
|
|
|
|
|
|
self.mir.rx = Some(rx);
|
|
|
|
|
|
self.mir.tx = Some(tx.clone());
|
2026-11-04 11:07:55 +00:00
|
|
|
|
let (g, version, client, s, resync) = (self.mir.gen.clone(), self.mir.version.clone(), self.mir.client.clone(), self.state.remote.clone(), self.mir.resync.clone());
|
2026-11-04 09:46:43 +00:00
|
|
|
|
let repaint = self.repaint_fn();
|
|
|
|
|
|
std::thread::spawn(move || {
|
|
|
|
|
|
let mut backoff = 1u64;
|
|
|
|
|
|
while g.load(Ordering::SeqCst) == gen {
|
2026-11-04 11:07:55 +00:00
|
|
|
|
let since = if resync.swap(false, Ordering::SeqCst) { 0 } else { version.load(Ordering::SeqCst) };
|
|
|
|
|
|
match remote::sync_pull(&s, since, &client) {
|
2026-11-04 09:46:43 +00:00
|
|
|
|
Ok(v) => {
|
|
|
|
|
|
backoff = 1;
|
|
|
|
|
|
if g.load(Ordering::SeqCst) != gen {
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
version.store(v["version"].as_u64().unwrap_or(0), Ordering::SeqCst);
|
|
|
|
|
|
let _ = tx.send(Incoming::Pull(v));
|
|
|
|
|
|
}
|
|
|
|
|
|
Err(e) => {
|
|
|
|
|
|
let _ = tx.send(Incoming::Offline(e));
|
|
|
|
|
|
// Start over (with everything) once it is back.
|
|
|
|
|
|
version.store(0, Ordering::SeqCst);
|
|
|
|
|
|
std::thread::sleep(std::time::Duration::from_secs(backoff));
|
|
|
|
|
|
backoff = (backoff * 2).min(20);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
repaint();
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
記憶: 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
|
|
|
|
pub(super) fn repaint_fn(&self) -> Arc<dyn Fn() + Send + Sync> {
|
2026-11-04 09:46:43 +00:00
|
|
|
|
match &self.ctx_handle {
|
|
|
|
|
|
Some(c) => {
|
|
|
|
|
|
let c = c.clone();
|
|
|
|
|
|
Arc::new(move || c.request_repaint())
|
|
|
|
|
|
}
|
|
|
|
|
|
None => Arc::new(|| {}),
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Every frame on a screen: take in what the brain sent.
|
|
|
|
|
|
pub(super) fn mirror_tick(&mut self) {
|
|
|
|
|
|
if let Some((id, name)) = self.mir.want.take() {
|
|
|
|
|
|
if self.mir.on {
|
|
|
|
|
|
self.mirror_leave();
|
|
|
|
|
|
}
|
2026-11-04 12:38:45 +00:00
|
|
|
|
// This computer's hands are for that brain only.
|
|
|
|
|
|
self.state.remote.hands_for = id.clone();
|
|
|
|
|
|
self.state.remote.hands_for_name = name.clone();
|
2026-11-04 09:46:43 +00:00
|
|
|
|
self.state.remote.brain_id = id;
|
|
|
|
|
|
self.state.remote.brain_name = name;
|
|
|
|
|
|
self.state.save();
|
|
|
|
|
|
self.mirror_enter();
|
|
|
|
|
|
}
|
|
|
|
|
|
if std::mem::take(&mut self.mir.leave) && self.mir.on {
|
|
|
|
|
|
self.mirror_leave();
|
|
|
|
|
|
}
|
|
|
|
|
|
if !self.mir.on {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
let mut got = vec![];
|
|
|
|
|
|
if let Some(rx) = &self.mir.rx {
|
|
|
|
|
|
while let Ok(m) = rx.try_recv() {
|
|
|
|
|
|
got.push(m);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
for m in got {
|
|
|
|
|
|
match m {
|
|
|
|
|
|
Incoming::Offline(e) => {
|
|
|
|
|
|
self.mir.online = false;
|
安全、修正: 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
|
|
|
|
// Keep `self.mir.base` so edits made during a brief disconnect are diffed
|
|
|
|
|
|
// and replayed on top of the brain's config when the connection returns.
|
2026-11-04 11:07:55 +00:00
|
|
|
|
self.mir.down_since.get_or_insert_with(Instant::now);
|
|
|
|
|
|
*self.mir.status.lock().unwrap() = format!("連不到大腦:{e}");
|
|
|
|
|
|
self.mir.reason = e;
|
2026-11-04 09:46:43 +00:00
|
|
|
|
}
|
2026-11-04 11:30:32 +00:00
|
|
|
|
Incoming::File(path) => {
|
|
|
|
|
|
self.mir.fetching.remove(&path);
|
|
|
|
|
|
self.att.thumbs.remove(&path);
|
|
|
|
|
|
}
|
2026-11-04 09:46:43 +00:00
|
|
|
|
Incoming::Pull(v) => {
|
|
|
|
|
|
if let Some(e) = v["error"].as_str() {
|
|
|
|
|
|
self.mir.online = false;
|
2026-11-04 11:07:55 +00:00
|
|
|
|
self.mir.down_since.get_or_insert_with(Instant::now);
|
2026-11-04 09:46:43 +00:00
|
|
|
|
*self.mir.status.lock().unwrap() = e.to_string();
|
2026-11-04 11:07:55 +00:00
|
|
|
|
self.mir.reason = e.to_string();
|
2026-11-04 09:46:43 +00:00
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
self.mir.online = true;
|
2026-11-04 11:07:55 +00:00
|
|
|
|
self.mir.down_since = None;
|
|
|
|
|
|
self.mir.reason.clear();
|
2026-11-04 09:46:43 +00:00
|
|
|
|
*self.mir.status.lock().unwrap() = format!("已連到大腦「{}」", v["brain"].as_str().unwrap_or(&self.state.remote.brain_name));
|
|
|
|
|
|
self.mirror_apply(v);
|
2026-11-05 06:25:01 +00:00
|
|
|
|
if std::mem::take(&mut self.mir.move_after_join) {
|
|
|
|
|
|
self.mirror_move_local();
|
|
|
|
|
|
}
|
2026-11-04 09:46:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn mirror_apply(&mut self, v: Value) {
|
2026-11-04 11:07:55 +00:00
|
|
|
|
// Edits the brain has taken in are no longer "on the way".
|
|
|
|
|
|
let acked = v["edit_seq"].as_u64().unwrap_or(0);
|
|
|
|
|
|
self.mir.pending.lock().unwrap().retain(|(s, _)| *s > acked);
|
2026-11-04 09:46:43 +00:00
|
|
|
|
if v["config"].is_object() {
|
2026-11-04 11:07:55 +00:00
|
|
|
|
// What the brain will have once the edits on the way arrive, and on top of that what
|
|
|
|
|
|
// the person changed here and hasn't sent yet.
|
|
|
|
|
|
let inflight: Vec<Value> = self.mir.pending.lock().unwrap().iter().flat_map(|(_, o)| o.clone()).collect();
|
|
|
|
|
|
let unsaved = if self.mir.base.is_object() { diff_ops(&self.mir.base, &config_json(&mut self.state)) } else { vec![] };
|
|
|
|
|
|
let mut base = v["config"].clone();
|
|
|
|
|
|
apply_ops(&mut base, &inflight);
|
|
|
|
|
|
let mut cfg = base.clone();
|
|
|
|
|
|
apply_ops(&mut cfg, &unsaved);
|
|
|
|
|
|
if !unsaved.is_empty() {
|
|
|
|
|
|
self.dirty = true;
|
|
|
|
|
|
}
|
2026-11-04 09:46:43 +00:00
|
|
|
|
let local = std::mem::replace(&mut self.state, State::first_run());
|
|
|
|
|
|
match serde_json::from_value::<State>(cfg.clone()) {
|
|
|
|
|
|
Ok(mut st) => {
|
|
|
|
|
|
// Chats stay as they are (they come separately).
|
|
|
|
|
|
let mut old = local.bots.clone();
|
|
|
|
|
|
for b in st.bots.iter_mut() {
|
|
|
|
|
|
if let Some(o) = old.iter_mut().find(|o| o.id == b.id) {
|
|
|
|
|
|
b.messages = std::mem::take(&mut o.messages);
|
|
|
|
|
|
b.threads = std::mem::take(&mut o.threads);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
self.state = st;
|
|
|
|
|
|
self.keep_local_fields(&local);
|
2026-11-04 11:07:55 +00:00
|
|
|
|
self.mir.base = base;
|
2026-11-04 09:46:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
Err(e) => {
|
|
|
|
|
|
self.state = local;
|
|
|
|
|
|
*self.mir.error.lock().unwrap() = format!("大腦的設定讀不出來(兩邊 AnyBot 版本不同?):{e}");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
for d in v["bots"].as_array().into_iter().flatten() {
|
|
|
|
|
|
let id = d["id"].as_u64().unwrap_or(0);
|
|
|
|
|
|
let from = d["from"].as_u64().unwrap_or(0) as usize;
|
2026-11-04 11:30:32 +00:00
|
|
|
|
let mut msgs: Vec<Message> = serde_json::from_value(d["messages"].clone()).unwrap_or_default();
|
|
|
|
|
|
self.mirror_files(&mut msgs);
|
2026-11-04 09:46:43 +00:00
|
|
|
|
if let Some(b) = self.state.bot_mut(id) {
|
2026-11-05 08:47:28 +00:00
|
|
|
|
// The brain sends what changed from message `from` on, sure this copy has the
|
|
|
|
|
|
// ones before. A copy that is shorter (cleared here, or an answer lost on the
|
|
|
|
|
|
// way) would get them appended in the wrong place — the same message twice and
|
|
|
|
|
|
// half-written replies piling up. Ask for the whole chat again instead.
|
|
|
|
|
|
if b.messages.len() < from {
|
|
|
|
|
|
self.mir.resync.store(true, Ordering::SeqCst);
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
2026-11-04 09:46:43 +00:00
|
|
|
|
b.messages.truncate(from);
|
|
|
|
|
|
b.messages.extend(msgs);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
for d in v["threads"].as_array().into_iter().flatten() {
|
|
|
|
|
|
if let Some(b) = self.state.bot_mut(d["id"].as_u64().unwrap_or(0)) {
|
|
|
|
|
|
b.threads = serde_json::from_value(d["threads"].clone()).unwrap_or_default();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
// Who is working, and what waits for the person.
|
|
|
|
|
|
let live: HashMap<u64, (Option<String>, bool)> = v["live"].as_object().into_iter().flatten().filter_map(|(k, l)| Some((k.parse().ok()?, (l["status"].as_str().map(String::from), l["paused"].as_bool().unwrap_or(false))))).collect();
|
|
|
|
|
|
self.streams.retain(|id, _| live.contains_key(id));
|
|
|
|
|
|
for (id, (status, paused)) in live {
|
|
|
|
|
|
let l = self.streams.entry(id).or_insert_with(|| Live {
|
|
|
|
|
|
cancel: Arc::new(AtomicBool::new(false)),
|
|
|
|
|
|
started: Instant::now(),
|
|
|
|
|
|
last: Instant::now(),
|
|
|
|
|
|
produced: true,
|
|
|
|
|
|
status: None,
|
|
|
|
|
|
paused: false,
|
安全、修正: 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
|
|
|
|
paused_at: None,
|
|
|
|
|
|
unattended: false,
|
2026-11-04 09:46:43 +00:00
|
|
|
|
steer: Arc::default(),
|
|
|
|
|
|
turn_id: String::new(),
|
|
|
|
|
|
direct: Arc::default(),
|
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
|
|
|
|
turn: 0,
|
2026-11-04 09:46:43 +00:00
|
|
|
|
});
|
|
|
|
|
|
l.status = status;
|
|
|
|
|
|
l.paused = paused;
|
|
|
|
|
|
l.last = Instant::now();
|
|
|
|
|
|
}
|
|
|
|
|
|
let mut waiting = HashMap::new();
|
|
|
|
|
|
for a in v["approvals"].as_array().into_iter().flatten() {
|
|
|
|
|
|
let id = a["bot"].as_u64().unwrap_or(0);
|
|
|
|
|
|
let kind = match a["kind"].as_str().unwrap_or("") {
|
|
|
|
|
|
"tools" => ApprovalKind::EnableTools,
|
|
|
|
|
|
"local" => ApprovalKind::EnableThisComputer,
|
2026-11-05 09:29:55 +00:00
|
|
|
|
"handoff" => ApprovalKind::Handoff,
|
問題卡、搜尋: 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
|
|
|
|
"question" => ApprovalKind::Question,
|
2026-11-04 09:46:43 +00:00
|
|
|
|
_ => ApprovalKind::Action,
|
|
|
|
|
|
};
|
|
|
|
|
|
let (reply, _) = channel();
|
|
|
|
|
|
let s = |k: &str| a[k].as_str().unwrap_or("").to_string();
|
|
|
|
|
|
waiting.insert(id, Approval { call_id: s("call_id"), tool: s("tool"), reason: s("reason"), grant: s("grant"), reply, kind });
|
|
|
|
|
|
}
|
|
|
|
|
|
let ctx = self.ctx_handle.clone();
|
|
|
|
|
|
for (id, a) in waiting {
|
|
|
|
|
|
let new = self.approvals.get(&id).map(|o| o.call_id != a.call_id).unwrap_or(true);
|
|
|
|
|
|
self.approvals.insert(id, a);
|
|
|
|
|
|
if new {
|
|
|
|
|
|
if let Some(c) = &ctx {
|
|
|
|
|
|
self.on_new_approval(c, id);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-11-05 08:47:28 +00:00
|
|
|
|
if v["box"].is_object() {
|
|
|
|
|
|
self.mir.box_state = v["box"].clone();
|
|
|
|
|
|
}
|
連接器: 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
|
|
|
|
if v["mcp"].is_object() {
|
|
|
|
|
|
self.mir.mcp_state = v["mcp"].clone();
|
|
|
|
|
|
}
|
2026-11-05 08:47:28 +00:00
|
|
|
|
if let Some(c) = v["computers"].as_object() {
|
|
|
|
|
|
self.mir.computers = c.iter().filter_map(|(k, x)| Some((k.parse().ok()?, x.clone()))).collect();
|
|
|
|
|
|
}
|
2026-11-04 09:46:43 +00:00
|
|
|
|
let keep: Vec<u64> = v["approvals"].as_array().into_iter().flatten().filter_map(|a| a["bot"].as_u64()).collect();
|
|
|
|
|
|
self.approvals.retain(|id, _| keep.contains(id));
|
|
|
|
|
|
if self.state.bot(self.state.selected).is_none() {
|
|
|
|
|
|
self.state.selected = self.state.primary_bot;
|
|
|
|
|
|
}
|
2026-11-11 06:47:20 +00:00
|
|
|
|
// 朗讀每個回答: the brain finishes the turns, this screen reads them (a brain on a server
|
|
|
|
|
|
// has nobody to read to). Its answer came in this same update.
|
|
|
|
|
|
let turns: Vec<(u64, Option<TurnSettlement>)> = self.state.bots.iter().map(|b| (b.id, b.last_turn.clone())).collect();
|
|
|
|
|
|
for id in just_finished(&mut self.mir.settled, turns.iter().map(|(id, t)| (*id, t.as_ref())), chrono::Utc::now().timestamp_millis()) {
|
|
|
|
|
|
self.read_reply(id);
|
|
|
|
|
|
}
|
2026-11-04 09:46:43 +00:00
|
|
|
|
self.mirror_save_copy();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-11-04 11:30:32 +00:00
|
|
|
|
/// Files in the brain's chats live on the brain: show local copies, fetched once.
|
|
|
|
|
|
fn mirror_files(&mut self, msgs: &mut [Message]) {
|
|
|
|
|
|
for a in msgs.iter_mut().flat_map(|m| m.attachments.iter_mut()) {
|
|
|
|
|
|
if std::path::Path::new(&a.path).exists() {
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
let local = local_copy(&a.path, &a.name);
|
|
|
|
|
|
let lp = local.display().to_string();
|
|
|
|
|
|
let brain_path = std::mem::replace(&mut a.path, lp.clone());
|
|
|
|
|
|
if local.exists() || !self.mir.fetching.insert(lp.clone()) {
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
let (s, tx, repaint) = (self.state.remote.clone(), self.mir.tx.clone(), self.repaint_fn());
|
|
|
|
|
|
std::thread::spawn(move || {
|
|
|
|
|
|
if let Ok(bytes) = remote::sync_file(&s, &brain_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
|
|
|
|
if let Some(dir) = local.parent() {
|
|
|
|
|
|
crate::httpd::ensure_private_dir(dir);
|
2026-11-04 11:30:32 +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
|
|
|
|
let _ = crate::httpd::write_private(&local, &bytes);
|
2026-11-04 11:30:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
if let Some(tx) = tx {
|
|
|
|
|
|
let _ = tx.send(Incoming::File(lp));
|
|
|
|
|
|
}
|
|
|
|
|
|
repaint();
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-11-04 09:46:43 +00:00
|
|
|
|
fn mirror_save_copy(&mut self) {
|
|
|
|
|
|
if let Ok(s) = serde_json::to_string(&self.state) {
|
安全、修正: 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 _ = crate::httpd::write_private(&cache_path(), s.as_bytes());
|
2026-11-04 09:46:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Saving on a screen: edits go to the brain; this computer's own file keeps its own bots.
|
|
|
|
|
|
pub(super) fn mirror_save(&mut self) {
|
|
|
|
|
|
if let Some(local) = self.mir.local.as_mut() {
|
|
|
|
|
|
local.remote = self.state.remote.clone();
|
|
|
|
|
|
local.theme = self.state.theme;
|
|
|
|
|
|
local.accent = self.state.accent;
|
|
|
|
|
|
local.sidebar_collapsed = self.state.sidebar_collapsed;
|
|
|
|
|
|
local.sidebar_width = self.state.sidebar_width;
|
|
|
|
|
|
local.machine_label = self.state.machine_label.clone();
|
|
|
|
|
|
local.local_execution = self.state.local_execution;
|
|
|
|
|
|
local.local_never = self.state.local_never;
|
|
|
|
|
|
local.messages_send = self.state.messages_send;
|
|
|
|
|
|
local.messages_no_ask = self.state.messages_no_ask;
|
|
|
|
|
|
local.save();
|
|
|
|
|
|
}
|
|
|
|
|
|
if !self.mir.online || !self.mir.base.is_object() {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
let cur = config_json(&mut self.state);
|
|
|
|
|
|
let ops = diff_ops(&self.mir.base, &cur);
|
|
|
|
|
|
if ops.is_empty() {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
self.mir.base = cur;
|
2026-11-04 11:07:55 +00:00
|
|
|
|
self.mir.seq += 1;
|
|
|
|
|
|
let seq = self.mir.seq;
|
|
|
|
|
|
self.mir.pending.lock().unwrap().push((seq, ops.clone()));
|
|
|
|
|
|
self.mirror_out(Out::Edit { seq, ops });
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn mirror_out(&mut self, o: Out) {
|
|
|
|
|
|
if let Some(tx) = &self.mir.outbox {
|
|
|
|
|
|
let _ = tx.send(o);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// One worker sends everything to the brain in order (a rename before the message that uses
|
|
|
|
|
|
/// it, two quick edits in the order they were made).
|
|
|
|
|
|
fn mirror_outbox(&mut self) {
|
|
|
|
|
|
let (tx, rx) = channel::<Out>();
|
|
|
|
|
|
self.mir.outbox = Some(tx);
|
|
|
|
|
|
let (s, err, client, pending, resync) = (self.state.remote.clone(), self.mir.error.clone(), self.mir.client.clone(), self.mir.pending.clone(), self.mir.resync.clone());
|
|
|
|
|
|
let (note, busy) = (self.mir.move_note.clone(), self.mir.moving.clone());
|
|
|
|
|
|
let repaint = self.repaint_fn();
|
2026-11-04 09:46:43 +00:00
|
|
|
|
std::thread::spawn(move || {
|
2026-11-04 11:07:55 +00:00
|
|
|
|
for o in rx {
|
|
|
|
|
|
match o {
|
|
|
|
|
|
Out::Edit { seq, ops } => {
|
|
|
|
|
|
if let Err(e) = remote::sync_post(&s, "edit", &json!({"ops": ops, "client": client, "seq": seq})) {
|
|
|
|
|
|
*err.lock().unwrap() = format!("剛才的改動沒有存到大腦:{e}");
|
|
|
|
|
|
pending.lock().unwrap().retain(|(n, _)| *n != seq);
|
|
|
|
|
|
resync.store(true, Ordering::SeqCst);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
Out::Act(body) => {
|
|
|
|
|
|
if let Err(e) = remote::sync_post(&s, "act", &body) {
|
|
|
|
|
|
*err.lock().unwrap() = format!("大腦沒有收到:{e}");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
連接器: 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
|
|
|
|
Out::McpReconnect(name) => {
|
|
|
|
|
|
if let Err(e) = remote::sync_post(&s, "mcp", &json!({"name": name})) {
|
|
|
|
|
|
*err.lock().unwrap() = format!("大腦沒有重新連線:{e}");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
記憶: 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
|
|
|
|
Out::Send { bot, text, atts, memories } => {
|
2026-11-04 11:07:55 +00:00
|
|
|
|
let mut paths = vec![];
|
|
|
|
|
|
for a in &atts {
|
|
|
|
|
|
match std::fs::read(&a.path).map_err(|e| format!("讀不到這個檔案({e})")).and_then(|b| remote::sync_upload(&s, bot, &a.name, &b)) {
|
|
|
|
|
|
Ok(p) => paths.push(p),
|
|
|
|
|
|
Err(e) => *err.lock().unwrap() = format!("「{}」沒有傳到大腦:{e}", a.name),
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
記憶: 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
|
|
|
|
let mut body = json!({"bot": bot, "action": "send", "text": text, "attachments": paths});
|
|
|
|
|
|
if let Some(m) = memories {
|
|
|
|
|
|
body["memories"] = json!(m);
|
|
|
|
|
|
}
|
|
|
|
|
|
if let Err(e) = remote::sync_post(&s, "act", &body) {
|
2026-11-04 11:07:55 +00:00
|
|
|
|
*err.lock().unwrap() = format!("訊息沒有送到大腦:{e}");
|
|
|
|
|
|
// Take back the message shown ahead of time.
|
|
|
|
|
|
resync.store(true, Ordering::SeqCst);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
技能: / 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
|
|
|
|
Out::Move { ops, n, skills } => {
|
|
|
|
|
|
let mut said = match remote::sync_post(&s, "edit", &json!({"ops": ops})) {
|
|
|
|
|
|
Ok(_) if n == 0 => "已同步:大腦上已經有這台的 Bot;模型金鑰、技能和連接器有缺的已補上".to_string(),
|
2026-11-04 11:30:32 +00:00
|
|
|
|
Ok(_) => format!("已把 {n} 個 Bot(連同聊天)搬到大腦"),
|
2026-11-04 11:07:55 +00:00
|
|
|
|
Err(e) => format!("搬移失敗:{e}"),
|
|
|
|
|
|
};
|
技能: / 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
|
|
|
|
// This computer's skills go up whole (with their files), one by one.
|
|
|
|
|
|
let failed: Vec<String> = skills
|
|
|
|
|
|
.iter()
|
|
|
|
|
|
.filter_map(|k| crate::skills::package_of(k).and_then(|p| remote::sync_post(&s, "skill", &json!({"package": p}))).err().map(|e| format!("「{}」:{e}", k.name)))
|
|
|
|
|
|
.collect();
|
|
|
|
|
|
if !failed.is_empty() {
|
|
|
|
|
|
said.push_str(&format!(";這些技能沒有搬過去:{}", failed.join("、")));
|
|
|
|
|
|
}
|
|
|
|
|
|
*note.lock().unwrap() = said;
|
|
|
|
|
|
busy.store(false, Ordering::SeqCst);
|
|
|
|
|
|
}
|
|
|
|
|
|
Out::Skill { body, note, busy } => {
|
|
|
|
|
|
*note.lock().unwrap() = Some(match skill_request(body).and_then(|b| remote::sync_post(&s, "skill", &b)) {
|
|
|
|
|
|
Ok(v) => (true, v["text"].as_str().unwrap_or("好了").to_string()),
|
|
|
|
|
|
Err(e) => (false, e),
|
|
|
|
|
|
});
|
2026-11-04 11:07:55 +00:00
|
|
|
|
busy.store(false, Ordering::SeqCst);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
repaint();
|
2026-11-04 09:46:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// A chat action on a screen goes to the brain.
|
|
|
|
|
|
pub(super) fn mirror_act(&mut self, body: Value) {
|
|
|
|
|
|
if !self.mir.online {
|
|
|
|
|
|
*self.mir.error.lock().unwrap() = "連不到大腦,現在只能看。".into();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2026-11-04 11:07:55 +00:00
|
|
|
|
self.mirror_out(Out::Act(body));
|
2026-11-04 09:46:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
連接器: 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
|
|
|
|
/// 連接器 › 重新連線 on a screen: the brain connects it again; its line says 連線中… until
|
|
|
|
|
|
/// the brain's next word on it.
|
|
|
|
|
|
pub(super) fn mirror_mcp_reconnect(&mut self, name: &str) {
|
|
|
|
|
|
if !self.mir.online {
|
|
|
|
|
|
*self.mir.error.lock().unwrap() = "連不到大腦,現在只能看。".into();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
if self.mir.mcp_state["servers"].is_object() {
|
|
|
|
|
|
self.mir.mcp_state["servers"][name] = json!({});
|
|
|
|
|
|
}
|
|
|
|
|
|
self.mir.mcp_state["busy"] = json!(true);
|
|
|
|
|
|
self.mirror_out(Out::McpReconnect(name.to_string()));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
技能: / 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
|
|
|
|
/// 技能 on a screen — add one from the market, install from an address or a folder here,
|
|
|
|
|
|
/// delete one — is done by the brain: the bots read skills from the brain's disk, and a
|
|
|
|
|
|
/// folder left there would bring a deleted skill back when the brain restarts. Turning one
|
|
|
|
|
|
/// on or off stays an ordinary edit. Edits made before go first.
|
|
|
|
|
|
pub(super) fn mirror_skill(&mut self, body: Value, note: SkillNote, busy: Arc<AtomicBool>) {
|
|
|
|
|
|
if !self.mir.online {
|
|
|
|
|
|
*note.lock().unwrap() = Some((false, "連不到大腦,技能沒有改。".into()));
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
if busy.swap(true, Ordering::SeqCst) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
*note.lock().unwrap() = None;
|
|
|
|
|
|
if self.dirty {
|
|
|
|
|
|
self.mirror_save();
|
|
|
|
|
|
}
|
|
|
|
|
|
self.mirror_out(Out::Skill { body, note, busy });
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-11-04 09:46:43 +00:00
|
|
|
|
/// Send a message through the brain: files go up first, then the text.
|
記憶: 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
|
|
|
|
pub(super) fn mirror_send(&mut self, bot: u64, text: String, atts: Vec<crate::attach::Attachment>, memories: Option<Vec<String>>) -> bool {
|
2026-11-04 09:46:43 +00:00
|
|
|
|
if !self.mir.online {
|
|
|
|
|
|
*self.mir.error.lock().unwrap() = "連不到大腦,訊息沒有送出。".into();
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
// Shown at once; the brain's copy replaces it.
|
|
|
|
|
|
if !self.streams.contains_key(&bot) {
|
|
|
|
|
|
if let Some(b) = self.state.bot_mut(bot) {
|
記憶: 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
|
|
|
|
b.messages.push(Message { attachments: atts.clone(), memories: memories.clone().unwrap_or_default(), ..Message::user(&text) });
|
2026-11-04 09:46:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-11-04 11:07:55 +00:00
|
|
|
|
// Settings changed just before go first.
|
|
|
|
|
|
if self.dirty {
|
|
|
|
|
|
self.mirror_save();
|
|
|
|
|
|
}
|
記憶: 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
|
|
|
|
self.mirror_out(Out::Send { bot, text, atts, memories });
|
2026-11-04 09:46:43 +00:00
|
|
|
|
true
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// 把這台的 Bot 搬到大腦: copy this computer's own bots (with their chats), keys, skills and
|
|
|
|
|
|
/// connectors to the brain, as new bots there.
|
|
|
|
|
|
pub(super) fn mirror_move_local(&mut self) {
|
|
|
|
|
|
let Some(local) = self.mir.local.clone() else { return };
|
|
|
|
|
|
if self.mir.moving.swap(true, Ordering::SeqCst) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
let mut ops: Vec<Value> = vec![];
|
2026-11-04 11:30:32 +00:00
|
|
|
|
// Skip what the brain already has: the same starter bot never used here, or a bot moved
|
|
|
|
|
|
// before (same name, same chat).
|
|
|
|
|
|
let last = |b: &Bot| b.messages.last().map(|m| (m.at, m.text.clone()));
|
|
|
|
|
|
let moving: Vec<&Bot> = local
|
|
|
|
|
|
.bots
|
|
|
|
|
|
.iter()
|
|
|
|
|
|
.filter(|b| !self.state.bots.iter().any(|o| o.name == b.name && (b.messages.is_empty() || (o.messages.len() == b.messages.len() && last(o) == last(b)))))
|
|
|
|
|
|
.collect();
|
|
|
|
|
|
for b in moving.iter().copied() {
|
2026-11-04 09:46:43 +00:00
|
|
|
|
let mut v = serde_json::to_value(b).unwrap_or(Value::Null);
|
|
|
|
|
|
v["id"] = json!(0);
|
|
|
|
|
|
ops.push(json!({"op": "bot_add", "bot": v}));
|
|
|
|
|
|
}
|
|
|
|
|
|
let top = serde_json::to_value(&local).unwrap_or(Value::Null);
|
連接器: 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
|
|
|
|
ops.push(json!({"op": "merge", "key": "providers", "value": top["providers"]}));
|
|
|
|
|
|
// Connectors run at the brain: one that names this computer's own folders (e.g.
|
|
|
|
|
|
// 「files」 on ~/Documents) would fail there, so it stays here.
|
|
|
|
|
|
let servers: Vec<&crate::mcp::Server> = local.mcp_servers.iter().filter(|s| !crate::mcp::names_this_computer(s)).collect();
|
|
|
|
|
|
ops.push(json!({"op": "merge", "key": "mcp_servers", "value": servers}));
|
技能: / 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
|
|
|
|
// Skills the brain doesn't have yet go up with their files (a bare entry in the list
|
|
|
|
|
|
// would leave its scripts on this computer).
|
|
|
|
|
|
let skills: Vec<Skill> = local.skills.iter().filter(|k| !self.state.skills.iter().any(|b| b.name == k.name)).cloned().collect();
|
2026-11-04 11:30:32 +00:00
|
|
|
|
let n = moving.len();
|
2026-11-04 11:07:55 +00:00
|
|
|
|
*self.mir.move_note.lock().unwrap() = "搬移中…".into();
|
技能: / 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
|
|
|
|
self.mirror_out(Out::Move { ops, n, skills });
|
2026-11-04 09:46:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// The bar above the chat while showing a brain.
|
|
|
|
|
|
pub(super) fn mirror_banner(&mut self, ui: &mut egui::Ui) {
|
|
|
|
|
|
if !self.mir.on {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
let p = self.pal;
|
|
|
|
|
|
let err = std::mem::take(&mut *self.mir.error.lock().unwrap());
|
|
|
|
|
|
if !err.is_empty() {
|
|
|
|
|
|
self.notice = Some(err);
|
|
|
|
|
|
}
|
|
|
|
|
|
if self.mir.online {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2026-11-04 11:07:55 +00:00
|
|
|
|
// A blip (the account server restarting) isn't worth a warning.
|
|
|
|
|
|
let connecting = self.mir.down_since.is_none();
|
|
|
|
|
|
let (title, reason, tail) = match self.mir.down_since {
|
|
|
|
|
|
None => (format!("正在連到大腦「{}」…", self.state.remote.brain_name), String::new(), String::new()),
|
|
|
|
|
|
Some(t) if t.elapsed().as_secs() < 4 => return,
|
|
|
|
|
|
Some(_) => (format!("連不到大腦「{}」", self.state.remote.brain_name), self.mir.reason.clone(), t("之前的對話還能看,但現在不能傳訊息。連回來後會自動恢復。")),
|
|
|
|
|
|
};
|
|
|
|
|
|
ui.ctx().request_repaint_after(std::time::Duration::from_secs(1));
|
2026-11-04 09:46:43 +00:00
|
|
|
|
ui.vertical_centered(|ui| {
|
|
|
|
|
|
ui.set_max_width(TRANSCRIPT_MAX_WIDTH.min(ui.available_width() - 48.0));
|
2026-11-04 11:07:55 +00:00
|
|
|
|
Frame::new().fill(if connecting { p.hover } else { p.danger.gamma_multiply(0.08) }).corner_radius(8).inner_margin(Margin::symmetric(12, 8)).show(ui, |ui| {
|
|
|
|
|
|
ui.vertical(|ui| {
|
外觀: a real bold weight, and 設定 › 一般 as cards of rows
- 思源黑體 Bold is bundled next to Regular: titles, bold words and headings in replies, the chosen page and
choice are set in it (粉圓體 and the system font keep their one weight; replies still fake bold there)
- 設定 › 一般 rearranged: 外觀, 記憶與文件, 通知, Bot, 帳戶 — each a card whose rows hold one thing, the name on the
left and its control on the right, at most one small line under the name, the rest behind the ?
- choices are one segmented control everywhere on the page; switches instead of checkboxes; plain names
(聊天的顏色, 用意思找記憶, Bot 可以翻的資料夾)
- the page list: the chosen page in ink, a yellow dot on 更新 when a newer build waits
- cards on the other pages take the same quiet fill and corners
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha3QxSfoydRPM9mjj6d
2026-11-11 13:54:24 +00:00
|
|
|
|
ui.label(RichText::new(title).size(FONT_SM).strong().family(crate::bold()).color(p.text));
|
2026-11-04 11:07:55 +00:00
|
|
|
|
for line in [reason, tail] {
|
|
|
|
|
|
if !line.is_empty() {
|
|
|
|
|
|
ui.add(egui::Label::new(RichText::new(line).size(FONT_SM).color(p.text2)).wrap());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2026-11-04 09:46:43 +00:00
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
ui.add_space(6.0);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
|
|
mod tests {
|
|
|
|
|
|
use super::*;
|
|
|
|
|
|
|
2026-11-11 06:47:20 +00:00
|
|
|
|
#[test]
|
|
|
|
|
|
fn a_screen_reads_only_turns_it_saw_end() {
|
|
|
|
|
|
let turn = |at: i64, outcome| TurnSettlement { turn_id: format!("t{at}"), outcome, settled_at_ms: at };
|
|
|
|
|
|
let now = 1_000_000;
|
|
|
|
|
|
let mut seen = HashMap::new();
|
|
|
|
|
|
// Connecting: turns that ended before are not read out.
|
|
|
|
|
|
let (a, b) = (turn(now - 5_000, TurnOutcome::Success), turn(now - 9_000, TurnOutcome::Success));
|
|
|
|
|
|
assert!(just_finished(&mut seen, [(1, Some(&a)), (2, Some(&b)), (3, None)], now).is_empty());
|
|
|
|
|
|
// Nothing new: nothing read (every update says the same).
|
|
|
|
|
|
assert!(just_finished(&mut seen, [(1, Some(&a)), (2, Some(&b))], now).is_empty());
|
|
|
|
|
|
// Bot 1 finished again: read; bot 2 failed: not.
|
|
|
|
|
|
let (a2, b2) = (turn(now - 100, TurnOutcome::Success), turn(now - 50, TurnOutcome::Error));
|
|
|
|
|
|
assert_eq!(just_finished(&mut seen, [(1, Some(&a2)), (2, Some(&b2))], now), vec![1]);
|
|
|
|
|
|
// Long ago (heard only after being away): not read.
|
|
|
|
|
|
let a3 = turn(now - 600_000 + 1, TurnOutcome::Success);
|
|
|
|
|
|
let mut seen2 = HashMap::from([(1, now - 700_000)]);
|
|
|
|
|
|
assert!(just_finished(&mut seen2, [(1, Some(&a3))], now).is_empty());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-11-04 09:46:43 +00:00
|
|
|
|
#[test]
|
|
|
|
|
|
fn edits_become_small_operations() {
|
|
|
|
|
|
let base = json!({"theme": "light", "folders": ["a"], "bots": [{"id": 1, "name": "A", "unread": true}, {"id": 2, "name": "B"}]});
|
|
|
|
|
|
let cur = json!({"theme": "dark", "folders": ["a", "b"], "bots": [{"id": 1, "name": "A2", "unread": false}, {"id": 3, "name": "C"}]});
|
|
|
|
|
|
let ops = diff_ops(&base, &cur);
|
|
|
|
|
|
// theme is this computer's own; folders changed.
|
2026-11-04 11:30:32 +00:00
|
|
|
|
assert!(ops.iter().any(|o| o["op"] == "patch" && o["key"] == "folders" && o["patch"]["list"]["put"] == json!(["b"])));
|
2026-11-04 09:46:43 +00:00
|
|
|
|
assert!(!ops.iter().any(|o| o["key"] == "theme"));
|
|
|
|
|
|
assert!(ops.iter().any(|o| o["op"] == "bot_set" && o["key"] == "name" && o["value"] == "A2"));
|
|
|
|
|
|
assert!(ops.iter().any(|o| o["op"] == "bot_read" && o["id"] == 1));
|
|
|
|
|
|
assert!(ops.iter().any(|o| o["op"] == "bot_add" && o["bot"]["id"] == 3));
|
|
|
|
|
|
assert!(ops.iter().any(|o| o["op"] == "bot_del" && o["id"] == 2));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
|
fn keys_stay_on_the_brain() {
|
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
|
|
|
|
let mut v = json!({"remote": {"host_token": "x"}, "providers": {"xai": {"api_key": "sk-1"}, "openai": {"api_key": ""}}, "channels": [{"id": 4, "token": "t"}], "voice": {"listen": {"kind": "eleven_labs", "api_key": "el-1"}, "speak": {"kind": "xai", "api_key": ""}}});
|
2026-11-04 09:46:43 +00:00
|
|
|
|
let old = v.clone();
|
|
|
|
|
|
redact(&mut v);
|
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
|
|
|
|
assert_eq!((v["voice"]["listen"]["api_key"].as_str(), v["voice"]["speak"]["api_key"].as_str()), (Some(REDACTED), Some("")));
|
|
|
|
|
|
let mut voice = v["voice"].clone();
|
|
|
|
|
|
unredact(&mut voice, &old["voice"]);
|
|
|
|
|
|
assert_eq!(voice["listen"]["api_key"], "el-1");
|
2026-11-04 09:46:43 +00:00
|
|
|
|
assert!(v.get("remote").is_none());
|
|
|
|
|
|
assert_eq!(v["providers"]["xai"]["api_key"], REDACTED);
|
|
|
|
|
|
assert_eq!(v["providers"]["openai"]["api_key"], "");
|
|
|
|
|
|
assert_eq!(v["channels"][0]["token"], REDACTED);
|
|
|
|
|
|
// An edit that kept the stand-in keeps the real key.
|
|
|
|
|
|
let mut edit = v["providers"].clone();
|
|
|
|
|
|
edit["openai"]["api_key"] = json!("sk-new");
|
|
|
|
|
|
unredact(&mut edit, &old["providers"]);
|
|
|
|
|
|
assert_eq!(edit["xai"]["api_key"], "sk-1");
|
|
|
|
|
|
assert_eq!(edit["openai"]["api_key"], "sk-new");
|
|
|
|
|
|
let mut ch = v["channels"].clone();
|
|
|
|
|
|
unredact(&mut ch, &old["channels"]);
|
|
|
|
|
|
assert_eq!(ch[0]["token"], "t");
|
安全、修正: 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
|
|
|
|
// Changing base_url while keeping REDACTED must NEVER send the brain's real key to the new server.
|
|
|
|
|
|
let mut exfil = v["providers"].clone();
|
|
|
|
|
|
exfil["xai"]["base_url"] = json!("https://evil.example/v1");
|
|
|
|
|
|
unredact(&mut exfil, &old["providers"]);
|
|
|
|
|
|
assert_eq!(exfil["xai"]["api_key"], "");
|
|
|
|
|
|
// Routine trigger tokens are redacted too.
|
|
|
|
|
|
let mut with_trig = json!({"bots": [{"id": 1, "routines": [{"id": 9, "trigger": {"kind": "github", "token": "ghp_secret"}}]}]});
|
|
|
|
|
|
redact(&mut with_trig);
|
|
|
|
|
|
assert_eq!(with_trig["bots"][0]["routines"][0]["trigger"]["token"], REDACTED);
|
2026-11-04 09:46:43 +00:00
|
|
|
|
}
|
2026-11-04 11:07:55 +00:00
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
|
fn edits_replay_on_a_newer_copy() {
|
|
|
|
|
|
let base = json!({"folders": ["a"], "bots": [{"id": 1, "name": "A", "unread": true}, {"id": 2, "name": "B"}]});
|
|
|
|
|
|
let cur = json!({"folders": ["a", "b"], "bots": [{"id": 2, "name": "B"}, {"id": 1, "name": "A2", "unread": false}, {"id": 3, "name": "C"}]});
|
|
|
|
|
|
let ops = diff_ops(&base, &cur);
|
|
|
|
|
|
let mut again = base.clone();
|
|
|
|
|
|
apply_ops(&mut again, &ops);
|
|
|
|
|
|
assert_eq!(again, cur);
|
|
|
|
|
|
// The brain meanwhile renamed bot 2: the screen's own edit stays, the brain's shows too.
|
|
|
|
|
|
let mut newer = json!({"folders": ["a"], "bots": [{"id": 1, "name": "A", "unread": true}, {"id": 2, "name": "B from brain"}]});
|
|
|
|
|
|
apply_ops(&mut newer, &ops);
|
|
|
|
|
|
assert_eq!(newer["bots"][1]["name"], "A2");
|
|
|
|
|
|
assert_eq!(newer["bots"][0]["name"], "B from brain");
|
|
|
|
|
|
assert_eq!(newer["folders"], json!(["a", "b"]));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
|
fn an_old_copy_cant_make_a_routine_run_twice() {
|
|
|
|
|
|
let brain = json!([{"id": 7, "schedule": "daily", "trigger": null, "paused": false, "last_run": 200, "next_run": 300}]);
|
|
|
|
|
|
let mut edit = json!([{"id": 7, "title": "new", "schedule": "daily", "trigger": null, "paused": false, "last_run": 100, "next_run": 150}]);
|
|
|
|
|
|
keep_run_times(&mut edit, &brain);
|
|
|
|
|
|
assert_eq!(edit[0]["last_run"], 200);
|
|
|
|
|
|
assert_eq!(edit[0]["next_run"], 300);
|
|
|
|
|
|
assert_eq!(edit[0]["title"], "new");
|
|
|
|
|
|
// A new schedule gets worked out again.
|
|
|
|
|
|
let mut moved = json!([{"id": 7, "schedule": "weekly", "trigger": null, "paused": false, "last_run": 100, "next_run": null}]);
|
|
|
|
|
|
keep_run_times(&mut moved, &brain);
|
|
|
|
|
|
assert_eq!(moved[0]["last_run"], 200);
|
|
|
|
|
|
assert!(moved[0]["next_run"].is_null());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
|
fn failures_read_as_words_not_codes() {
|
|
|
|
|
|
let w = remote::why_refused(502, &Value::Null, "大腦");
|
|
|
|
|
|
assert!(!w.contains("502") && w.contains("帳號伺服器"));
|
|
|
|
|
|
let off = remote::why_refused(503, &json!({"error": "那台 AnyBot 目前離線(電腦關機、睡眠,或 AnyBot 沒開)"}), "大腦");
|
|
|
|
|
|
assert!(off.starts_with("大腦目前離線"));
|
|
|
|
|
|
assert!(remote::why_refused(401, &Value::Null, "大腦").contains("重新登入"));
|
|
|
|
|
|
assert!(remote::why_unreachable(&ureq::Error::HostNotFound).contains("網路"));
|
|
|
|
|
|
}
|
2026-11-04 11:30:32 +00:00
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
|
fn two_computers_edit_one_list_without_undoing_each_other() {
|
|
|
|
|
|
let base = json!({"skills": [{"name": "a", "on": true}, {"name": "b", "on": true}], "providers": {"xai": {"model": "1"}, "openai": {"model": "1"}}, "bots": [{"id": 1, "memories": ["x", "y"]}]});
|
|
|
|
|
|
// Laptop turns skill a off, changes xai, forgets memory x.
|
|
|
|
|
|
let mut laptop = base.clone();
|
|
|
|
|
|
laptop["skills"][0]["on"] = json!(false);
|
|
|
|
|
|
laptop["providers"]["xai"]["model"] = json!("2");
|
|
|
|
|
|
laptop["bots"][0]["memories"] = json!(["y"]);
|
|
|
|
|
|
// Meanwhile the desk computer turned skill b off, changed openai, and the bot learned z.
|
|
|
|
|
|
let mut brain = base.clone();
|
|
|
|
|
|
brain["skills"][1]["on"] = json!(false);
|
|
|
|
|
|
brain["skills"].as_array_mut().unwrap().push(json!({"name": "c", "on": true}));
|
|
|
|
|
|
brain["providers"]["openai"]["model"] = json!("3");
|
|
|
|
|
|
brain["bots"][0]["memories"] = json!(["x", "y", "z"]);
|
|
|
|
|
|
let ops = diff_ops(&base, &laptop);
|
|
|
|
|
|
assert!(ops.iter().all(|o| o["op"] != "set" || o["key"] != "skills"), "{ops:?}");
|
|
|
|
|
|
apply_ops(&mut brain, &ops);
|
|
|
|
|
|
assert_eq!(brain["skills"], json!([{"name": "a", "on": false}, {"name": "b", "on": false}, {"name": "c", "on": true}]));
|
|
|
|
|
|
assert_eq!(brain["providers"], json!({"xai": {"model": "2"}, "openai": {"model": "3"}}));
|
|
|
|
|
|
assert_eq!(brain["bots"][0]["memories"], json!(["y", "z"]));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
技能: / 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
|
|
|
|
/// A skill folder named on a screen goes up read here (the brain can't see this disk); an
|
|
|
|
|
|
/// address, a market name or a delete goes as it is.
|
|
|
|
|
|
#[test]
|
|
|
|
|
|
fn a_skill_folder_here_goes_up_whole() {
|
|
|
|
|
|
let src = std::env::temp_dir().join(format!("anybot-screen-pkg-{}", std::process::id()));
|
|
|
|
|
|
std::fs::create_dir_all(src.join("references")).unwrap();
|
|
|
|
|
|
std::fs::write(src.join("SKILL.md"), "---\nname: 週報\ndescription: 整理每週進度\n---\n\n照 references/a.md 寫\n").unwrap();
|
|
|
|
|
|
std::fs::write(src.join("references/a.md"), "# 格式").unwrap();
|
|
|
|
|
|
let b = skill_request(json!({"local": src.display().to_string()})).unwrap();
|
|
|
|
|
|
assert!(b["package"]["skill_md"].as_str().unwrap().contains("name: 週報"));
|
|
|
|
|
|
assert_eq!(b["package"]["files"][0]["path"], "references/a.md");
|
|
|
|
|
|
assert!(b.get("local").is_none(), "no path of this computer goes to the brain");
|
|
|
|
|
|
std::fs::remove_dir_all(&src).unwrap();
|
|
|
|
|
|
for as_is in [json!({"install": "https://github.com/anthropics/skills/tree/main/skills/pdf"}), json!({"builtin": "pdf"}), json!({"name": "週報", "remove": true})] {
|
|
|
|
|
|
assert_eq!(skill_request(as_is.clone()).unwrap(), as_is);
|
|
|
|
|
|
}
|
|
|
|
|
|
assert!(skill_request(json!({"local": "/nonexistent/anybot-skill"})).is_err());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-11-04 11:30:32 +00:00
|
|
|
|
#[test]
|
|
|
|
|
|
fn lists_without_names_are_sent_whole() {
|
|
|
|
|
|
let p = patch_of(&json!([[1], [2]]), &json!([[2]]));
|
|
|
|
|
|
assert_eq!(p, json!({"value": [[2]]}));
|
|
|
|
|
|
let mut cur = json!([{"id": 1}, {"id": 2}]);
|
|
|
|
|
|
apply_patch(&mut cur, &patch_of(&json!([{"id": 1}, {"id": 2}]), &json!([{"id": 2}, {"id": 1}])));
|
|
|
|
|
|
assert_eq!(cur, json!([{"id": 2}, {"id": 1}]));
|
|
|
|
|
|
}
|
2026-11-04 09:46:43 +00:00
|
|
|
|
}
|