AnyBot/src/featuremap.rs

188 lines
9.9 KiB
Rust
Raw Normal View History

feat: AnyBot 功能地圖——Bot 用 anybot_guide 認識 AnyBot 本身;修好地圖整理時找到的七個問題 功能地圖(照 Lauren Tan 的 feature map,poteto/verification-skill-example) - docs/feature-map/:20 區加索引,每區四段(子功能/使用者怎麼到/怎麼操作(Bot:、驗證:)/陷阱),內容逐條對照程式;索引寫共同前提、證據與略過的回報、全面檢查順序 - Bot 的系統提示多一行區塊目錄;新工具 anybot_guide 一次讀一區(唯讀) - cargo test featuremap:: 擋漏寫:Bot 能拿到的每個工具、browser/computer 的每個動作、設定視窗每個分頁和區塊、update_settings 的鍵;每區要有四段、不能太長 - 自動學技能:AnyBot 本身怎麼用不抄進技能,地圖錯漏記成待改進;園丁在重複的待改進旁提醒補地圖 - CLAUDE.md:改功能時同一個 commit 一起改地圖 - 側邊欄「分區」工具的說明寫清楚:不是群組聊天 修正 1. 別人傳來的訊息(訊息管道、團隊成員)那一輪不給 AnyBot 瀏覽器、保險庫和已送紀錄(瀏覽器帶著使用者的登入);硬叫也擋下,公開網頁仍可 web_fetch 2. 自動學會的技能加進那個 Bot 自己的技能清單(支線的算主 Bot 的) 3. 按停止一併停掉這個 Bot 的互動終端機(一般背景指令照舊) 4. 設定 › 整合 › 技能、頁面的「刪除」要再按一次確定 5. update_bot 先跳確認卡片,列出每一項要改成什麼 6. Bot 範本的頭像形狀改成存在的形狀,並加測試 7. 文字:直接操作的提示改「設定 → 權限」、金鑰錯誤改「設定 → 模型」、等核准逾時照實說是什麼在等 Mac 490 個測試通過。 Refs: cl3xk7 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 03:15:09 +00:00
// 功能地圖 (Lauren Tan's feature map, poteto/verification-skill-example): AnyBot as behaviour,
// one file per area under docs/feature-map/, each answering the same four questions — what is
// there, how a person gets to it, how an agent drives it, what usually lies. Two readers:
// - the bots: anybot_guide reads one area. AnyBot is a product the bots work inside, and they
// used to learn it by trial and error (a contact fill used 107 times as a typing tool) and
// write what they found into their task skills;
// - agents changing AnyBot: they open the file for the change and check it the way it says.
// Kept as code: the tests below fail when a tool a bot can be given, a browser or screen action,
// or a settings tab or section isn't in the map — a new feature comes with its entry.
use serde_json::{json, Value};
/// One area of the map.
pub struct Area {
pub slug: &'static str,
pub title: &'static str,
pub text: &'static str,
}
/// The map's index: who reads it, the shared conventions, the order of a full sweep (for people
/// and agents changing AnyBot; a bot gets `index_line` instead).
#[cfg(test)]
pub const INDEX: &str = include_str!("../docs/feature-map/README.md");
macro_rules! area {
($slug:literal, $title:literal) => {
Area { slug: $slug, title: $title, text: include_str!(concat!("../docs/feature-map/", $slug, ".md")) }
};
}
/// The areas, in the order of a full sweep.
pub const AREAS: &[Area] = &[
area!("chat", "聊天"),
area!("bots", "Bot 與個人檔案"),
area!("team", "同事、群組與支線"),
area!("memory", "記憶"),
area!("skills", "技能與重播"),
area!("pages", "頁面"),
area!("routines", "例行任務"),
area!("goal", "目標(/goal)"),
feat: /plan 先規劃再動手、聊天裡請 Bot 管理連接器、/always-approve 一律放行;輸入框上方的狀態不再破版 /plan(照 Claude Code 的 plan mode、Cursor 的 Plan Mode、Codex 的 update_plan) - 「/plan 要做的事」:這一輪只給會看的工具(讀檔、搜尋、web_fetch、瀏覽器的打開/讀取/捲動、截圖、anybot_guide、問題卡),在執行那一層擋下其他步驟(回「計畫還沒核准」),不是只靠提示詞。 - Bot 用 submit_plan 交計畫:聊天裡一張「計畫」卡(摘要、步驟、怎麼確認做對了、注意),下面的問題卡「照這個計畫做嗎?」:開始照計畫做/先不要/打字寫要改哪裡。 - 核准後同一輪接著做:工具全開、系統指示換成照計畫做,第 1 步自動進行中;update_plan 每做完一步更新一次(整份清單、只有一步進行中),卡上打勾、輸入框上方「照計畫做 · 2/6 · 這一步」;全部做完留「計畫完成」那一行。 - 「/plan」看狀態、「/plan clear」取消;例行任務、訊息管道、團隊成員的訊息不受影響;群組不能用;支線不帶計畫;清除聊天或新對話一起清;分享 Bot 檔不含。手機:計畫卡、計畫列、取消計畫。 - 新功能地圖 plan.md;研究(Claude Code、Codex、Cursor、Gemini CLI…)的結論寫進提示:只寫建議的做法、通常 3 到 7 步、問題最多 3 題、打勾不要太勤。 聊天裡管理連接器(設定能做的聊天也要能做) - 新工具 manage_connectors(管理 App 能力):list、add、update(含開關)、reconnect、remove。改的就是大腦上 設定 › 整合 › 連接器 那一份,不會寫到手腳電腦的檔案(進化之神之前叫使用者去 nobledesktop 的 ~/.local/share/AnyBot 設)。 - 新增、修改、移除先跳卡片:指令(在大腦上執行)或網址、環境變數、標頭;TOKEN、KEY、SECRET、PASS、AUTH… 和密碼顯示「••••(已填)」。名稱重複、command 和 url 都給、網址不對、還有「{…}」、沒東西可改,在問之前就回給 Bot。 - 加好後等它連上(最多 90 秒)再回報幾個工具或原因;一輪裡連接器的工具變了,下一步起就換新(加完同一輪就能用)。 /always-approve(也可以 /yolo) - 使用者自己打(電腦、大腦的螢幕、手機的擁有者)或 設定 › 權限 ›「一律放行」:打開直接操作,之後所有要等「允許」的都自動允許(含一律詢問規則、付款/傳送/刪除的點擊、寄信、傳訊息、打電話、發文、保險庫卡片),自動審核略過;打開時在等的卡片一起放行。 - 照樣擋:安全規則一律拒絕的;別人傳來的訊息那一輪;問題卡、需要處理、計畫卡。Bot、例行任務、訊息管道打不開;管理員和成員打的變成「【名字】/always-approve」。管理員鎖了直接操作就打不開。 - 開著時每個聊天輸入框上方一條「一律放行」和「關閉」;「/always-approve off」關掉,直接操作是它打開的就一起關。 輸入框上方的狀態 - 好幾行的狀態(模型忙碌重試:錯誤、說明、幾秒後重試)以前疊出那一列、壓到輸入框;現在一行:「模型供應商目前負載過高,15 秒後重試(第 3 次,共 3 次)…」。 已驗證:cargo test 548 通過、1 個失敗(layout_audit 的 設定 › 電腦 被這台 Mac 的 Docker 位址 unix:///Users/daniel/.lima/anybot-gvisor 撐寬;把這次的改動 stash 掉一樣失敗,跟這次無關)。新測試:plan:: 7 個;agent 的計畫模式三個(只看到卡片說開始、先不要什麼都不做、修改後重交);app 的 /plan 從打字到計畫完成、Bot 從聊天加連接器(卡片不露 Token、同一輪就用它的工具算出 sum=5)、/always-approve(之前會問、之後不問直接在這台跑、陌生人的訊息照樣問、off 回原樣);mcp::manage_tests 4 個;狀態一行。截圖看過:計畫卡等你決定/照著做打勾、503 重試那一行。手機頁面 JS 語法檢查和計畫卡四種狀態的 HTML。 未驗證:真的模型走一次 /plan 和加 GitLab 連接器;手機實機;伺服器上的大腦(要 make update-server)。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 02:55:37 +00:00
area!("plan", "計畫(/plan)"),
feat: AnyBot 功能地圖——Bot 用 anybot_guide 認識 AnyBot 本身;修好地圖整理時找到的七個問題 功能地圖(照 Lauren Tan 的 feature map,poteto/verification-skill-example) - docs/feature-map/:20 區加索引,每區四段(子功能/使用者怎麼到/怎麼操作(Bot:、驗證:)/陷阱),內容逐條對照程式;索引寫共同前提、證據與略過的回報、全面檢查順序 - Bot 的系統提示多一行區塊目錄;新工具 anybot_guide 一次讀一區(唯讀) - cargo test featuremap:: 擋漏寫:Bot 能拿到的每個工具、browser/computer 的每個動作、設定視窗每個分頁和區塊、update_settings 的鍵;每區要有四段、不能太長 - 自動學技能:AnyBot 本身怎麼用不抄進技能,地圖錯漏記成待改進;園丁在重複的待改進旁提醒補地圖 - CLAUDE.md:改功能時同一個 commit 一起改地圖 - 側邊欄「分區」工具的說明寫清楚:不是群組聊天 修正 1. 別人傳來的訊息(訊息管道、團隊成員)那一輪不給 AnyBot 瀏覽器、保險庫和已送紀錄(瀏覽器帶著使用者的登入);硬叫也擋下,公開網頁仍可 web_fetch 2. 自動學會的技能加進那個 Bot 自己的技能清單(支線的算主 Bot 的) 3. 按停止一併停掉這個 Bot 的互動終端機(一般背景指令照舊) 4. 設定 › 整合 › 技能、頁面的「刪除」要再按一次確定 5. update_bot 先跳確認卡片,列出每一項要改成什麼 6. Bot 範本的頭像形狀改成存在的形狀,並加測試 7. 文字:直接操作的提示改「設定 → 權限」、金鑰錯誤改「設定 → 模型」、等核准逾時照實說是什麼在等 Mac 490 個測試通過。 Refs: cl3xk7 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 03:15:09 +00:00
area!("computers", "電腦:大腦與手腳"),
area!("files", "檔案與指令"),
area!("browser", "瀏覽器"),
area!("screen", "螢幕操作"),
area!("vault", "保險庫"),
area!("connectors", "連接器(MCP)"),
area!("apps", "Mac App 與電話"),
area!("channels", "訊息管道"),
area!("phone", "手機與帳號"),
area!("safety", "安全與核准"),
area!("settings", "設定總覽"),
area!("garden", "園丁、待改進與更新"),
];
/// The tool a bot reads the map with.
pub const TOOL: &str = "anybot_guide";
pub fn spec() -> Value {
let topics: Vec<&str> = AREAS.iter().map(|a| a.slug).collect();
json!({"name": TOOL,
"description": "Read one area of AnyBot's own feature map: what AnyBot can do there, where the person finds it, which of your tools drive it, and what usually goes wrong. Read it when the person asks about AnyBot itself (can you…, where do I set…, why did…), before working around something AnyBot may already do, and when one of your tools behaves unexpectedly. Don't guess AnyBot's features or settings from memory.",
"parameters": {"type": "object", "properties": {
"topic": {"type": "string", "enum": topics, "description": "The area (the list is in your instructions)."}},
"required": ["topic"]}})
}
/// One line for the instructions: the areas there are (the same every turn, so it caches).
pub fn index_line() -> String {
let list: Vec<String> = AREAS.iter().map(|a| format!("{} {}", a.slug, a.title)).collect();
format!("\n\nAnyBot 功能地圖({TOOL} 讀一區;問到 AnyBot 本身、要繞路之前、工具反應怪怪的,先讀,不要憑印象):{}。", list.join("、"))
}
/// The area a bot asked for (by slug or title).
pub fn read(topic: &str) -> Result<String, String> {
let t = topic.trim();
AREAS
.iter()
.find(|a| a.slug.eq_ignore_ascii_case(t) || a.title == t || a.title.starts_with(t) && !t.is_empty())
.map(|a| a.text.trim().to_string())
.ok_or_else(|| format!("沒有「{t}」這一區。可以讀:{}", AREAS.iter().map(|a| a.slug).collect::<Vec<_>>().join("、")))
}
#[cfg(test)]
mod tests {
use super::*;
/// The whole map, as one text (the areas and the index).
fn map_text() -> String {
std::iter::once(INDEX).chain(AREAS.iter().map(|a| a.text)).collect::<Vec<_>>().join("\n")
}
fn names(specs: &[Value]) -> Vec<String> {
specs.iter().filter_map(|t| t["name"].as_str().map(String::from)).collect()
}
fn actions(specs: &[Value], tool: &str) -> Vec<String> {
specs.iter().filter(|t| t["name"] == tool).flat_map(|t| t["parameters"]["properties"]["action"]["enum"].as_array().cloned().unwrap_or_default()).filter_map(|a| a.as_str().map(String::from)).collect()
}
/// Every tool a bot can be given, from where the window puts them together (app.rs).
fn every_tool() -> Vec<String> {
let one = vec!["x".to_string()];
let mut all = names(&crate::appctl::specs());
all.extend(names(&crate::tools::specs_for(&one, "x")));
all.extend(names(&crate::web::specs_for(&one, "x")));
all.extend(names(&crate::computer::specs_for(&one, "x", true)));
all.extend(names(&crate::macapps::specs()));
all.extend(names(&crate::phone::specs()));
all.extend(names(&crate::vault::specs_for(&crate::vault::Offer { login: true, card: true, contact: true })));
all.push(crate::ask::spec()["name"].as_str().unwrap().to_string());
all.extend([crate::plan::SUBMIT_TOOL, crate::plan::UPDATE_TOOL, crate::outputs::TOOL].map(String::from));
feat: AnyBot 功能地圖——Bot 用 anybot_guide 認識 AnyBot 本身;修好地圖整理時找到的七個問題 功能地圖(照 Lauren Tan 的 feature map,poteto/verification-skill-example) - docs/feature-map/:20 區加索引,每區四段(子功能/使用者怎麼到/怎麼操作(Bot:、驗證:)/陷阱),內容逐條對照程式;索引寫共同前提、證據與略過的回報、全面檢查順序 - Bot 的系統提示多一行區塊目錄;新工具 anybot_guide 一次讀一區(唯讀) - cargo test featuremap:: 擋漏寫:Bot 能拿到的每個工具、browser/computer 的每個動作、設定視窗每個分頁和區塊、update_settings 的鍵;每區要有四段、不能太長 - 自動學技能:AnyBot 本身怎麼用不抄進技能,地圖錯漏記成待改進;園丁在重複的待改進旁提醒補地圖 - CLAUDE.md:改功能時同一個 commit 一起改地圖 - 側邊欄「分區」工具的說明寫清楚:不是群組聊天 修正 1. 別人傳來的訊息(訊息管道、團隊成員)那一輪不給 AnyBot 瀏覽器、保險庫和已送紀錄(瀏覽器帶著使用者的登入);硬叫也擋下,公開網頁仍可 web_fetch 2. 自動學會的技能加進那個 Bot 自己的技能清單(支線的算主 Bot 的) 3. 按停止一併停掉這個 Bot 的互動終端機(一般背景指令照舊) 4. 設定 › 整合 › 技能、頁面的「刪除」要再按一次確定 5. update_bot 先跳確認卡片,列出每一項要改成什麼 6. Bot 範本的頭像形狀改成存在的形狀,並加測試 7. 文字:直接操作的提示改「設定 → 權限」、金鑰錯誤改「設定 → 模型」、等核准逾時照實說是什麼在等 Mac 490 個測試通過。 Refs: cl3xk7 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 03:15:09 +00:00
all.push(crate::teach::view_step_spec()["name"].as_str().unwrap().to_string());
all.extend([crate::mcp::FIND_TOOL, crate::mcp::USE_TOOL, crate::agent::REPLAY_TOOL, crate::tools::HANDOFF_TOOL, "show_card", "react", "send_to_device", "send_file", "open_for_person", "publish_site", TOOL].map(String::from));
all.sort();
all.dedup();
all
}
#[test]
fn every_tool_a_bot_can_be_given_is_on_the_map() {
let map = map_text();
let missing: Vec<String> = every_tool().into_iter().filter(|n| !map.contains(&format!("`{n}`"))).collect();
assert!(missing.is_empty(), "these tools aren't on the feature map (docs/feature-map/, written as `name`): {missing:?}");
}
#[test]
fn every_browser_and_screen_action_is_in_its_area() {
let one = vec!["x".to_string()];
let area = |slug: &str| AREAS.iter().find(|a| a.slug == slug).unwrap().text;
for (slug, tool, specs) in [("browser", crate::browser::TOOL, crate::web::specs_for(&one, "x")), ("screen", crate::computer::TOOL, crate::computer::specs_for(&one, "x", true))] {
let missing: Vec<String> = actions(&specs, tool).into_iter().filter(|a| !area(slug).contains(&format!("`{a}`"))).collect();
assert!(missing.is_empty(), "{slug}.md doesn't name these `{tool}` actions: {missing:?}");
}
}
#[test]
fn every_settings_tab_and_section_is_in_the_settings_area() {
let settings = AREAS.iter().find(|a| a.slug == "settings").unwrap().text;
let sources = [include_str!("app.rs"), include_str!("app/remote_ui.rs"), include_str!("app/vault_ui.rs"), include_str!("app/voice_ui.rs"), include_str!("app/channels_ui.rs"), include_str!("app/computers_ui.rs"), include_str!("app/mirror_ui.rs")];
let mut wanted: Vec<String> = vec![];
for src in sources {
for pat in ["setting_title(ui, \"", "setting_row(ui, p, \""] {
for part in src.split(pat).skip(1) {
if let Some(name) = part.split('"').next().filter(|n| !n.is_empty()) {
wanted.push(name.to_string());
}
}
}
}
// The tabs of the settings window.
let tabs = include_str!("app.rs").split("(SettingsTab::General, \"").nth(1).and_then(|r| r.split(']').next()).unwrap_or("");
wanted.extend(tabs.split("\", Icon::").filter_map(|p| p.rsplit('"').next()).filter(|n| !n.is_empty() && !n.contains(')')).map(String::from));
wanted.push("一般".into());
// What a bot may change itself.
let keys = crate::appctl::specs().into_iter().find(|t| t["name"] == "update_settings").map(|t| t["parameters"]["properties"].as_object().map(|o| o.keys().cloned().collect::<Vec<_>>()).unwrap_or_default()).unwrap_or_default();
wanted.extend(keys.into_iter().map(|k| format!("`{k}`")));
wanted.sort();
wanted.dedup();
assert!(wanted.len() > 15, "the settings scan found too little: {wanted:?}");
let missing: Vec<&String> = wanted.iter().filter(|w| !settings.contains(w.as_str())).collect();
assert!(missing.is_empty(), "settings.md doesn't mention: {missing:?}");
}
#[test]
fn every_area_answers_the_four_questions_and_the_index_lists_it() {
for a in AREAS {
for h in ["## 子功能", "## 使用者怎麼到", "## 怎麼操作", "## 陷阱"] {
assert!(a.text.contains(h), "{}.md has no 「{h}」", a.slug);
}
assert!(a.text.contains("- Bot:") && a.text.contains("- 驗證:"), "{}.md: 怎麼操作 needs a 「- Bot:」 and a 「- 驗證:」 line", a.slug);
assert!(a.text.starts_with(&format!("# {}", a.title)), "{}.md should start with 「# {}」", a.slug, a.title);
assert!(INDEX.contains(&format!("({}.md)", a.slug)), "README.md doesn't list {}.md", a.slug);
// Short enough to read in one go (her rule: behaviour-level, no source needed).
assert!(a.text.chars().count() < 6000, "{}.md is too long ({} chars): split it", a.slug, a.text.chars().count());
}
}
#[test]
fn a_bot_reads_one_area_by_its_name() {
assert!(read("routines").unwrap().starts_with("# 例行任務"));
assert!(read("例行任務").unwrap().starts_with("# 例行任務"));
assert!(read("nope").unwrap_err().contains("routines"));
assert!(index_line().contains("routines 例行任務") && index_line().contains(TOOL));
assert_eq!(spec()["parameters"]["properties"]["topic"]["enum"].as_array().unwrap().len(), AREAS.len());
}
}