fix: 下拉選單用 value 選不到卻回報成功、fill 撞到保險庫、sudo 留下 root 的檔案、--ask 不連連接器、容器裡的連接器被誤擋
電腦操作量測時找到的問題:填表題失敗大多是前兩個造成的(正式版有一次接著呼叫保險庫填入 124 次)。 - browser:select 也接受 value/values;對下拉選單 type 會改成選選項;什麼都沒給就報錯,不再回報「已選「」」 - browser:fill 指著頁面上的欄位(有 ref/text、沒有 kind/id/site)時當成 type(有 option 時當 select),不跑去保險庫 - cloudbox:有 sudo 的指令跑完,把 Bot 家目錄裡 root 新留下的檔案都交還給 Bot,不只它的資料夾(之前 ~/.config/chromium 和 ~/.local/share/pki 會留給 root,Bot 的瀏覽器之後開不起來) - app:anybot --ask 沒有視窗,開始前先連好連接器 - mcp:指令是 docker、ssh 這類在別處執行的,不拿參數裡的路徑到本機檢查 - 功能地圖:browser、files、connectors Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Uirha4mzWbjJAWAsDVuBun
This commit is contained in:
parent
eb70608160
commit
3f46911ba4
|
|
@ -29,6 +29,8 @@ Bot 用 AnyBot 自己的瀏覽器上網、登入網站、點按、打字、送
|
|||
- 同一個網站在不同電腦、不同設定檔的登入不共用;沒帶 `profile` 會用到別的設定檔。
|
||||
- 使用者自己的 Firefox 設定檔,如果他已經用平常的方式開著,要先請他關掉那個視窗,AnyBot 才開得起來。
|
||||
- 一模一樣的按鈕(例如每篇貼文都有的「回覆」)在清單裡只列一次;要點第二篇的,先 `open` 那篇貼文的網址再點。
|
||||
- 下拉選單用 `select`,`option` 填選項上看得到的字(給 `value` 也行,對下拉選單 `type` 也會改成選選項);什麼都沒給會報錯。
|
||||
- `fill` 是保險庫的填入;指著頁面上一個欄位(有 `ref`/`text`、沒有 kind/id/site)時當成 `type`(有 `option` 時當 `select`),不會跑去保險庫。
|
||||
- `eval` 只能讀頁面:不能發請求、讀 cookie 或儲存、送出表單、換頁(會被拒絕);直接呼叫網站內部 API 會被當成機器人。
|
||||
- 雲端中繼資料位址永遠打不開;本機或內部網路的網址要使用者允許(直接操作模式除外)。
|
||||
- 發布關卡、已送帳本、送出後確認只管 AnyBot 自己的瀏覽器;用螢幕操作送出的,只能從步驟推算。頁面看不出回哪一篇時,只擋 24 小時內同一頁一模一樣的內容。
|
||||
|
|
|
|||
|
|
@ -33,3 +33,5 @@
|
|||
- 要登入帳號(OAuth)的連接器 AnyBot 還不支援,連線時狀態會說;它若也收 API 金鑰,填在「標頭」。公用市集裡舊式 SSE 的會標「舊式 SSE 連線,AnyBot 還不支援」。
|
||||
- 公用市集只列用網址連的;要在大腦上跑 npm/PyPI 套件的不列。本機連接器要大腦那台裝了 Node.js(npx)或 uv(uvx)。
|
||||
- 在螢幕上改了指令或網址,大腦會清掉密碼(免得送到新的位址),要重新填。
|
||||
- 參數裡的資料夾在這台找不到(在別台電腦設定的),連接器不連,狀態寫「這台電腦上沒有…」;指令是 `docker`、`ssh` 這類在別處執行的,不檢查(路徑在容器或那台主機上)。
|
||||
- `anybot --ask` 沒有視窗,也會先連好連接器再開始。
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ Bot 在它能用的電腦上跑指令、讀寫和搜尋檔案、開背景指令
|
|||
|
||||
- 機密檔案一律不能讀、改、傳、打開或發佈:AnyBot 自己的資料資料夾、.git、.ssh、.gnupg、.aws、Keychains、.env、.pem、.key、id_rsa 開頭的檔案等。
|
||||
- 在這台電腦上:工作資料夾外讀東西先問(可以一律允許);改檔案會問,工作資料夾外的每次都問、不能一律允許;指令除了唯讀的都會問;sudo、rm -rf /、mkfs、dd、shutdown 這類一律拒絕。完整規則見 [safety](safety.md)。
|
||||
- 在 Bot 自己的電腦上,指令和檔案都不用問(可以 sudo,但後面接的一律拒絕指令照樣擋);檔案工具只碰得到它自己的資料夾。
|
||||
- 在 Bot 自己的電腦上,指令和檔案都不用問(可以 sudo,但後面接的一律拒絕指令照樣擋);檔案工具只碰得到它自己的資料夾。有 sudo 的指令整條用 root 跑,跑完它在 Bot 家目錄裡新留下的檔案會交還給 Bot(不只它的資料夾)。
|
||||
- SSH 電腦和帳號裡的其他電腦:讀不用問,改檔案和會改變東西的指令會問。
|
||||
- 開互動的 shell(bash、zsh、PowerShell…)每次都問、沒有一律允許:之後在裡面打的指令不會再一條一條檢查。
|
||||
- 一般指令的輸入是關的,`write_terminal` 打不進去:要互動就用 interactive 重跑,或用參數答掉(-y、--yes)。
|
||||
|
|
|
|||
|
|
@ -5505,6 +5505,11 @@ impl App {
|
|||
let mut app = App::new(ctx, None);
|
||||
app.headless = true;
|
||||
app.asking = true;
|
||||
// 連接器: the window connects them as it draws (there is no drawing here), so a question
|
||||
// asked here had none of them. Connected before it starts.
|
||||
for (name, why) in crate::mcp::sync(&app.state.mcp_servers) {
|
||||
eprintln!("連接器「{name}」連不上:{why}");
|
||||
}
|
||||
let id = app.state.primary_bot;
|
||||
let start = app.state.bot(id).map(|b| b.messages.len()).unwrap_or(0);
|
||||
app.drafts.insert(id, text.to_string());
|
||||
|
|
|
|||
|
|
@ -583,6 +583,21 @@ pub fn wait_loaded(profile: Option<&str>, max_ms: u64) -> bool {
|
|||
|
||||
// ---------- the tools ----------
|
||||
|
||||
/// The option a select names: `option`, or what models trained on Playwright give instead
|
||||
/// (`value`, `values`). It used to read only `option`, and with `value` it chose the empty
|
||||
/// 「請選擇」 and said 「已選「」」: the form went out without its city.
|
||||
fn select_option(args: &Value) -> String {
|
||||
let o = s(args, "option");
|
||||
if !o.is_empty() {
|
||||
return o;
|
||||
}
|
||||
let v = s(args, "value");
|
||||
if !v.is_empty() {
|
||||
return v;
|
||||
}
|
||||
args["values"].as_array().and_then(|a| a.first()).map(|v| v.as_str().map(String::from).unwrap_or_else(|| v.to_string())).unwrap_or_default().trim().to_string()
|
||||
}
|
||||
|
||||
fn s(args: &Value, k: &str) -> String {
|
||||
args.get(k).map(|v| v.as_str().map(String::from).unwrap_or_else(|| if v.is_null() { String::new() } else { v.to_string() })).unwrap_or_default().trim().to_string()
|
||||
}
|
||||
|
|
@ -655,7 +670,7 @@ pub fn describe(name: &str, args: &str) -> String {
|
|||
let target = if !s(&v, "ref").is_empty() { format!("[{}]", s(&v, "ref")) } else { s(&v, "text") };
|
||||
match name {
|
||||
"browser_type" => format!("{target} ← {}", s(&v, "value").chars().take(40).collect::<String>()),
|
||||
"browser_select" => format!("{target} → {}", s(&v, "option")),
|
||||
"browser_select" => format!("{target} → {}", select_option(&v)),
|
||||
"browser_press" => s(&v, "key"),
|
||||
"browser_scroll" => if target.is_empty() { s(&v, "direction") } else { target },
|
||||
"browser_wait" => if s(&v, "text").is_empty() { format!("{} 秒", s(&v, "seconds")) } else { format!("等「{}」", s(&v, "text")) },
|
||||
|
|
@ -730,7 +745,7 @@ actions:
|
|||
- dialog {accept, text}: answer a pop-up dialog the page opened
|
||||
- eval {script}: short read-only JavaScript for data the other actions can't reach; it can't send requests, navigate or submit (site APIs get accounts flagged)
|
||||
- sent {profile, days}: what an account already sent through this browser — AnyBot's own record (which posts, which accounts it answered, kept 60 days); much cheaper than reading a site's own replies page to the end. Sending to a post the same account already answered is refused anyway
|
||||
- fill {kind: login|card|contact, id, site, submit}: sign in / pay card / address from the person's 保險庫 — you never see the secret; the person approves every use (login_id/card_id/contact_id come from vault_list; default login: the current site's)",
|
||||
- fill {kind: login|card|contact, id, site, submit}: sign in / pay card / address from the person's 保險庫 (not for ordinary fields: those are type/select) — you never see the secret; the person approves every use (login_id/card_id/contact_id come from vault_list; default login: the current site's)",
|
||||
"parameters": {"type": "object", "properties": {
|
||||
"action": {"type": "string", "enum": ["open","read","elements","find","table","screenshot","click","hover","type","press","select","scroll","wait","tabs","back","upload","download","pdf","dialog","eval","sent","profiles","fill"]},
|
||||
"url": {"type": "string"},
|
||||
|
|
@ -748,7 +763,7 @@ actions:
|
|||
"append": {"type": "boolean", "description": "type: keep what's in the field"},
|
||||
"submit": {"type": "boolean", "description": "type/fill: press Enter / sign in afterwards"},
|
||||
"key": {"type": "string", "description": "press: Enter, Tab, Escape, ctrl+a…"},
|
||||
"option": {"type": "string", "description": "select: the option's visible text"},
|
||||
"option": {"type": "string", "description": "select: the option's visible text (value works too)"},
|
||||
"direction": {"type": "string", "enum": ["down", "up", "top", "bottom", "back", "forward", "reload"], "description": "scroll: down/up/top/bottom; back: back/forward/reload"},
|
||||
"seconds": {"type": "number"},
|
||||
"days": {"type": "integer", "description": "sent: how far back (default 30, up to 60)"},
|
||||
|
|
@ -802,6 +817,13 @@ pub fn expand_call(c: &mut crate::model::ToolCall) {
|
|||
let mut name = action.to_string();
|
||||
if let Some(o) = v.as_object_mut() {
|
||||
o.remove("action");
|
||||
// 「fill」 with a control on the page and the words for it is Playwright's fill (type
|
||||
// into a field), what models trained on it mean more often than the 保險庫: it went to
|
||||
// the vault, was refused, and the bot tried again and again (the form never went out).
|
||||
let on_page = (o.contains_key("ref") || o.contains_key("text")) && !["kind", "id", "site"].iter().any(|k| o.contains_key(*k));
|
||||
if name == "browser_fill_login" && on_page {
|
||||
name = if o.contains_key("option") || o.contains_key("values") { "browser_select" } else { "browser_type" }.to_string();
|
||||
}
|
||||
if name == "browser_fill_login" {
|
||||
// fill {kind, id} names the exact vault tool and its id field.
|
||||
let kind = o.remove("kind").and_then(|k| k.as_str().map(|s| s.to_string())).unwrap_or_else(|| "login".into());
|
||||
|
|
@ -855,6 +877,12 @@ pub fn run(name: &str, args: &Value) -> Result<(String, Option<String>), String>
|
|||
}
|
||||
let mut tab = Tab::current(profile)?;
|
||||
let r = (|| -> Result<(String, Option<String>), String> {
|
||||
// Typing into a dropdown (a <select>) can't work: picking its option is what was meant.
|
||||
let name = if name == "browser_type" && tab.eval(&format!("(() => {{ const el = {}; return !!el && el.tagName === 'SELECT'; }})()", find_js(&rf, &text))).ok().and_then(|v| v.as_bool()) == Some(true) {
|
||||
"browser_select"
|
||||
} else {
|
||||
name
|
||||
};
|
||||
match name {
|
||||
SEND_INFO => {
|
||||
let mode = s(args, "mode");
|
||||
|
|
@ -942,7 +970,10 @@ pub fn run(name: &str, args: &Value) -> Result<(String, Option<String>), String>
|
|||
Ok((format!("已按 {}。\n{}", s(args, "key"), changes(&before, &after)), None))
|
||||
}
|
||||
"browser_select" => {
|
||||
let option = s(args, "option");
|
||||
let option = select_option(args);
|
||||
if option.is_empty() {
|
||||
return Err("要選哪一個?option 填選項上看得到的字(例如「台中」)。".into());
|
||||
}
|
||||
let sig = page_sig(&mut tab);
|
||||
let before = snapshot(&mut tab);
|
||||
let js = format!(
|
||||
|
|
@ -1404,6 +1435,17 @@ mod tests {
|
|||
assert!(a.contains(r#""card_id":"7""#) && !a.contains("kind"), "{a}");
|
||||
let (n, _) = c(r#"{"action":"fill"}"#);
|
||||
assert_eq!(n, "browser_fill_login");
|
||||
// Playwright's fill (a control and its words): typing, or picking a dropdown's option.
|
||||
let (n, a) = c(r#"{"action":"fill","ref":"3","value":"0912345678"}"#);
|
||||
assert_eq!(n, "browser_type");
|
||||
assert!(a.contains(r#""ref":"3""#) && a.contains("0912345678"), "{a}");
|
||||
assert_eq!(c(r#"{"action":"fill","ref":"4","option":"台中"}"#).0, "browser_select");
|
||||
assert_eq!(c(r#"{"action":"fill","kind":"login","ref":"1"}"#).0, "browser_fill_login", "the vault when it says so");
|
||||
// A select's option as Playwright names it.
|
||||
assert_eq!(select_option(&json!({"value": "台中"})), "台中");
|
||||
assert_eq!(select_option(&json!({"values": ["高雄"]})), "高雄");
|
||||
assert_eq!(select_option(&json!({"option": "台北", "value": "x"})), "台北");
|
||||
assert_eq!(select_option(&json!({})), "");
|
||||
let (n, _) = c(r#"{"action":"nope"}"#);
|
||||
assert_eq!(n, TOOL, "an unknown action stays put (the runner explains it)");
|
||||
// Every internal browser tool is reachable from the one schema.
|
||||
|
|
@ -1690,6 +1732,7 @@ customElements.define('my-panel', class extends HTMLElement { constructor() { su
|
|||
<div id=menu>商品分析</div><div id=sub style="display:none">分潤率排行</div>
|
||||
<div id=dd role=combobox aria-label="排序">預設</div><ul id=opts role=listbox style="display:none"><li role=option>佣金由高到低</li><li role=option>銷量</li></ul>
|
||||
<input id=q placeholder="搜尋商品">
|
||||
<label>城市 <select id=city aria-label="城市"><option value="">請選擇</option><option>台北</option><option>台中</option><option>高雄</option></select></label>
|
||||
<div role=table aria-label="商品"><div role=row><span role=columnheader>商品</span><span role=columnheader>分潤率</span></div><div role=row><span role=cell>手機殼</span><span role=cell>8%</span></div><div role=row><span role=cell>乳液</span><span role=cell>12%</span></div></div>
|
||||
<p id=out>點擊 0</p><a href="/export">匯出報表</a>
|
||||
<script>
|
||||
|
|
@ -1722,6 +1765,14 @@ q.addEventListener('keydown', e => { if (e.key === 'Enter') out.innerText = '搜
|
|||
assert!(r.contains("點擊 60,訂單 3"), "{r}");
|
||||
let (r, _) = run("browser_select", &p(json!({"text": "排序", "option": "佣金由高到低"})))?;
|
||||
assert!(r.contains("佣金由高到低"), "{r}");
|
||||
// A plain <select>: the option given as value, or typed into it, is chosen.
|
||||
run("browser_select", &p(json!({"text": "城市", "value": "台中"})))?;
|
||||
let (v, _) = run("browser_eval", &p(json!({"script": "document.getElementById('city').selectedOptions[0].text"})))?;
|
||||
assert_eq!(v.trim(), "台中");
|
||||
run("browser_type", &p(json!({"text": "城市", "value": "高雄"})))?;
|
||||
let (v, _) = run("browser_eval", &p(json!({"script": "document.getElementById('city').selectedOptions[0].text"})))?;
|
||||
assert_eq!(v.trim(), "高雄");
|
||||
assert!(run("browser_select", &p(json!({"text": "城市"}))).is_err(), "no option: said, not 「已選「」」");
|
||||
let (r, _) = run("browser_type", &p(json!({"text": "搜尋商品", "value": "手機殼", "submit": true})))?;
|
||||
assert!(r.contains("搜尋:手機殼"), "{r}");
|
||||
let (t, _) = run("browser_table", &p(json!({})))?;
|
||||
|
|
|
|||
|
|
@ -1723,8 +1723,12 @@ pub fn exec_wrapper(dir: &str, cmd: &str, interactive: bool, tty: bool, job: &st
|
|||
// uid is not 0"), though the box gives the bot sudo without a password. A command that asks
|
||||
// for sudo runs as the box's root instead (root's sudo needs no setuid), and what it left in
|
||||
// the bot's home is handed back to the bot. Still inside the box, same walls.
|
||||
// What it left anywhere in the bot's home goes back (not only in its folder: a browser it
|
||||
// started that way left ~/.config/chromium and ~/.local/share/pki to root, and the bot's
|
||||
// own browser couldn't open later).
|
||||
let user = if uses_sudo(cmd) {
|
||||
inner = format!("m=$(mktemp); {inner}; rc=$?; find -P {d} -xdev -user root -newer \"$m\" -exec chown -h bot:bot {{}} + 2>/dev/null; rm -f \"$m\"; exit $rc", d = sh_quote(dir));
|
||||
let mine = if dir.starts_with(&format!("{HOME}/")) { sh_quote(HOME) } else { format!("{} {}", sh_quote(HOME), sh_quote(dir)) };
|
||||
inner = format!("m=$(mktemp); {inner}; rc=$?; find -P {mine} -xdev -user root -newer \"$m\" -exec chown -h bot:bot {{}} + 2>/dev/null; rm -f \"$m\"; exit $rc");
|
||||
"root"
|
||||
} else {
|
||||
"bot"
|
||||
|
|
@ -2595,7 +2599,10 @@ mod tests {
|
|||
for c in ["echo pseudo code", "ls sudoers.d", "cat /etc/sudoers", "grep sudo_user log"] {
|
||||
assert!(!uses_sudo(c), "{c}");
|
||||
}
|
||||
assert!(exec_wrapper("/home/bot/bot-1", "sudo apt-get install -y tree", false, false, "j").contains("-u root"));
|
||||
let w = exec_wrapper("/home/bot/bot-1", "sudo apt-get install -y tree", false, false, "j");
|
||||
assert!(w.contains("-u root"));
|
||||
// What root left anywhere in the bot's home goes back to the bot, not only in its folder.
|
||||
assert!(w.contains("find -P '\\''/home/bot'\\'' -xdev -user root"), "{w}");
|
||||
assert!(exec_wrapper("/home/bot/bot-1", "ls", false, false, "j").contains("-u bot"));
|
||||
}
|
||||
|
||||
|
|
|
|||
19
src/mcp.rs
19
src/mcp.rs
|
|
@ -319,8 +319,14 @@ fn spawn_error(command: &str, e: &std::io::Error) -> String {
|
|||
}
|
||||
|
||||
/// A folder the server is given that isn't on this computer (its parent isn't either): usually a
|
||||
/// connector made on another computer, e.g. a Mac's /Users/… on a Linux brain.
|
||||
fn missing_folder(args: &[String]) -> Option<&str> {
|
||||
/// connector made on another computer, e.g. a Mac's /Users/… on a Linux brain. Not for a server
|
||||
/// that runs somewhere else (`docker exec box /home/…`, `ssh host /opt/…`): its paths are there.
|
||||
fn missing_folder<'a>(command: &str, args: &'a [String]) -> Option<&'a str> {
|
||||
const ELSEWHERE: [&str; 8] = ["docker", "podman", "nerdctl", "kubectl", "ssh", "wsl", "orb", "lxc"];
|
||||
let program = std::path::Path::new(command.trim()).file_name().and_then(|n| n.to_str()).unwrap_or("");
|
||||
if ELSEWHERE.contains(&program.trim_end_matches(".exe")) {
|
||||
return None;
|
||||
}
|
||||
args.iter().map(|a| a.trim()).find(|a| {
|
||||
let p = std::path::Path::new(a);
|
||||
p.is_absolute() && !p.exists() && p.parent().is_some_and(|d| d != std::path::Path::new("/") && !d.exists())
|
||||
|
|
@ -344,7 +350,7 @@ fn connect(config: &Server) -> Result<Conn, String> {
|
|||
if s.command.trim().is_empty() {
|
||||
return Err("請給指令或網址".into());
|
||||
}
|
||||
if let Some(dir) = missing_folder(&s.args) {
|
||||
if let Some(dir) = missing_folder(&s.command, &s.args) {
|
||||
return Err(format!("這台電腦上沒有「{dir}」:這個連接器可能是在別台電腦設定的,改成這台的資料夾,或移除它"));
|
||||
}
|
||||
let mut cmd = Command::new(s.command.trim());
|
||||
|
|
@ -1062,9 +1068,12 @@ for line in sys.stdin:
|
|||
assert!(spawn_error("/usr/bin/uvx", &nf).contains("uv"));
|
||||
assert!(spawn_error("my-server", &nf).contains("找不到「my-server」"));
|
||||
let s = |args: &[&str]| args.iter().map(|a| a.to_string()).collect::<Vec<_>>();
|
||||
assert_eq!(missing_folder(&s(&["-y", "x", "/Users-nobody-here/someone/Documents"])), Some("/Users-nobody-here/someone/Documents"));
|
||||
assert_eq!(missing_folder("npx", &s(&["-y", "x", "/Users-nobody-here/someone/Documents"])), Some("/Users-nobody-here/someone/Documents"));
|
||||
// A server in a container or on another host: its paths are there, not here.
|
||||
assert_eq!(missing_folder("docker", &s(&["exec", "-i", "box", "/home-nobody-here/bot/.local/bin/cua-driver", "mcp"])), None);
|
||||
assert_eq!(missing_folder("/usr/bin/ssh", &s(&["host", "/opt-nobody-here/srv/mcp"])), None);
|
||||
let tmp = std::env::temp_dir().join("anybot-mcp-new-file.json");
|
||||
assert_eq!(missing_folder(&s(&[tmp.to_str().unwrap(), "/api", "relative/dir"])), None, "a file to be made, a top-level name and a relative path are fine");
|
||||
assert_eq!(missing_folder("npx", &s(&[tmp.to_str().unwrap(), "/api", "relative/dir"])), None, "a file to be made, a top-level name and a relative path are fine");
|
||||
let one = |command: &str, args: &[&str], url: &str| Server { name: "x".into(), command: command.into(), args: s(args), url: url.into(), ..serde_json::from_str("{\"name\":\"x\"}").unwrap() };
|
||||
let e = connect(&one("npx", &["-y", "@modelcontextprotocol/server-filesystem", "/Users-nobody-here/someone/Documents"], "")).err().unwrap();
|
||||
assert!(e.contains("/Users-nobody-here/someone/Documents"), "{e}");
|
||||
|
|
|
|||
Loading…
Reference in New Issue