瀏覽器步驟沒帶 profile:沿用這一輪上一次指名的設定檔,不再落到使用中的

jenny-Host 11/26:一輪以「拾日(Firefox)」做海巡,93 個點擊、打字、按鍵沒帶 profile,照舊用了使用中的
「Ghost(Firefox)」(browser-profile.txt;任何工作的 browser_open 指名都會改它),9 則拾日的回覆從
Ghost 帳號送出。Jenny 覺得 Bot「記憶錯亂、用錯頁面發文」就是這個。

現在一輪裡沒帶 profile 的 browser_* 步驟補上這一輪上一次指名的那個(參數裡看得到);還沒指名過才用使用中的;
指名別的就從那一步起換過去;browser_profiles 不補。

已驗證: cargo test(931 通過;remote::tests::the_phone_page_binds_where_told_and_keeps_trying 平行跑時搶埠
  失敗一次,單獨重跑 3 次都過,與此無關);新測試 a_browser_step_without_a_profile_stays_in_the_turns_profile。
未驗證: jenny-Host 實機(換版後看她下一輪海巡的步驟參數是否都帶 profile)。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
王性驊 2026-11-27 16:14:27 +08:00
parent 7ca0646881
commit 13a9f5017d
2 changed files with 60 additions and 2 deletions

View File

@ -41,7 +41,7 @@ Bot 用 AnyBot 自己的瀏覽器上網、登入、點按、打字、送出。
- 有些模型經閘道叫 `browser` 時參數送到是空的(`{}`;OpenCode Go · deepseek-v4.1-flash 一天 395 次,思考裡每次都有寫動作):AnyBot 說「參數是空的——不是你沒寫,是沒有送到」,再叫一次還是空的就改用單一動作的工具(`browser_open {url}`、`browser_click {ref|text}`…,AnyBot 照收),紀錄檔記一行「叫 browser 卻沒帶參數;串流裡這個呼叫的原文:…」。對話裡只要出現過一次空的 `browser`(或 `computer`),下一步起工具清單就不再給這個大工具,改給一個動作一個工具(`browser_open`、`browser_click`、`browser_tabs {action}`…,各自只帶自己的欄位;`fill` 和 `computer` 的 `batch` 不拆),紀錄檔記「模型送過空參數的 browser,這段對話改給單一動作的工具」(看的是模型讀得到的對話:那一步被收起進摘要後,下一輪又先給回大工具,再空一次才換)——那個模型在 jenny-Host 叫 `browser` 3719 次有 3452 次空的,叫單一動作的工具卻每次都帶得到參數。參數不是合法 JSON 時說「不是合法的 JSON」(字串裡的換行要寫 \n),不再說成沒給 action。
- 別人傳來的訊息那一輪不能用 AnyBot 瀏覽器、保險庫和 `sent`(帶著使用者的登入)。公開網頁用 `web_fetch`。
- 不同電腦、不同設定檔的登入不共用;沒帶 `profile` 會用到別的。
- 不同電腦、不同設定檔的登入不共用。一輪裡沒帶 `profile` 的瀏覽器步驟用這一輪上一次指名的那個(步驟的參數會補上它),一輪還沒指名過才用使用中的;指名別的就從那一步起換過去(`profiles` 不補)。以前沒帶就用使用中的,別的工作剛換過就落到別的帳號(jenny-Host 11/26:拾日的 9 則回覆從 Ghost 送出)。
- 「做事的電腦」開不了瀏覽器(沒裝 Chrome/Brave…、SSH)時,步驟回「使用者選的電腦「…」現在開不了 AnyBot 的瀏覽器」,不改開在這台 Mac。公開網頁用 `web_fetch`,其他先問。
- 使用者的 Firefox 若已用平常方式開著,要先請他關掉,AnyBot 才開得起來。
- 一模一樣的按鈕(每篇的「回覆」)清單只列一次;要點第二篇,先 `open` 那篇網址。

View File

@ -459,6 +459,8 @@ struct UsedBrowsers {
close: bool,
/// This job's name in the browsers (its tabs are kept apart by it).
job: String,
/// The browser profile this turn last named (see follow_profile).
profile: String,
}
/// Names the jobs of this run (a bot's job on another computer's browser carries it along).
@ -487,7 +489,28 @@ fn with_job(args: &str, job: &str) -> String {
impl UsedBrowsers {
fn new(via_name: &str, bot_id: u64, close: bool) -> Self {
let n = JOB_SEQ.fetch_add(1, Ordering::Relaxed);
UsedBrowsers { list: vec![], screen: String::new(), via_name: via_name.to_string(), close, job: format!("{bot_id}-{}-{n}", crate::model::now_ms()) }
UsedBrowsers { list: vec![], screen: String::new(), via_name: via_name.to_string(), close, job: format!("{bot_id}-{}-{n}", crate::model::now_ms()), profile: String::new() }
}
/// A browser step that names no profile runs in the one this turn last named, not in the
/// computer's current one — which any other job's step may have just changed, and which is
/// what Settings names. jenny-Host, 11/26: 93 clicks, typing and Enter of a turn working as
/// 「拾日」 named no profile, ran in 「Ghost」 (the current one) and nine replies went out
/// from the wrong Threads account.
fn follow_profile(&mut self, c: &mut ToolCall) {
if !c.name.starts_with("browser_") || c.name == "browser_profiles" {
return;
}
let mut v = tools::args_of(&c.args);
let Some(o) = v.as_object_mut() else { return };
match o.get("profile").and_then(|p| p.as_str()).map(str::trim).filter(|p| !p.is_empty()) {
Some(p) => self.profile = p.to_string(),
None if !self.profile.is_empty() => {
o.insert("profile".into(), serde_json::json!(self.profile));
c.args = v.to_string();
}
None => {}
}
}
fn add(&mut self, b: BotBrowser) {
@ -2089,6 +2112,8 @@ struct CallTurn<'a> {
fn run_call(t: CallTurn<'_>, asked: ToolCall) -> Flow {
#[allow(unused_mut)]
let CallTurn { job, bot_id, send, cancel, mut history, mut grants, said_no, refused, trouble, mut tools_on, mut local_on, mut tools_once, mut local_once, mut browsers, sent_count, hooks, hook_base, runs, mut tried, step_sent_at, step_sent, step_note, skill_limit, mut previous, mut plan_changes, last_sent, runs_with, mut replay, mut plan_go, moved } = t;
let mut asked = asked;
browsers.follow_profile(&mut asked);
// The same click twice in one step opens a menu and closes it again (a Wi‑Fi
// menu did exactly that): the second one isn't done.
let twice = matches!(asked.name.as_str(), "computer_use_click" | "browser_click") && previous.as_ref() == Some(&(asked.name.clone(), asked.args.clone()));
@ -4363,6 +4388,39 @@ echo '<meta charset=utf-8><title>done</title>送出了' > done.html; (setsid pyt
assert_eq!(tools::unwrapped_args(r#"{"action":"read"}"#, props), None);
}
/// A browser step that names no profile runs in the one this turn last named (not in the
/// computer's current one); one that names another switches; managing profiles is left as is.
#[test]
fn a_browser_step_without_a_profile_stays_in_the_turns_profile() {
let mut b = UsedBrowsers::new("t", 1, false);
let call = |name: &str, args: &str| ToolCall { id: "c".into(), name: name.into(), args: args.into(), status: ToolStatus::Waiting };
let profile = |c: &ToolCall| tools::args_of(&c.args)["profile"].as_str().map(str::to_string);
// Nothing named yet: left to the computer's current one.
let mut c = call("browser_read", "{}");
b.follow_profile(&mut c);
assert_eq!(profile(&c), None);
let mut c = call("browser_open", r#"{"url":"https://www.threads.com/@shiri.days__","profile":"拾日(Firefox)"}"#);
b.follow_profile(&mut c);
for (name, args) in [("browser_click", r#"{"ref":"20"}"#), ("browser_type", r#"{"ref":"20","value":"嗨"}"#), ("browser_press", r#"{"key":"ctrl+Return","profile":""}"#), ("browser_sent_log", "")] {
let mut c = call(name, args);
b.follow_profile(&mut c);
assert_eq!(profile(&c).as_deref(), Some("拾日(Firefox)"), "{name}");
}
assert_eq!(tools::args_of(&{ let mut c = call("browser_type", r#"{"ref":"20","value":"嗨"}"#); b.follow_profile(&mut c); c }.args)["value"], "嗨", "the rest as it was");
// Another one named: from there on that one.
let mut c = call("browser_open", r#"{"url":"https://x","profile":"Ghost(Firefox)"}"#);
b.follow_profile(&mut c);
let mut c = call("browser_press", r#"{"key":"Enter"}"#);
b.follow_profile(&mut c);
assert_eq!(profile(&c).as_deref(), Some("Ghost(Firefox)"));
// Not a browser step, or managing the profiles: untouched.
for (name, args) in [("browser_profiles", r#"{"name":"新的"}"#), ("shell", r#"{"command":"ls"}"#)] {
let mut c = call(name, args);
b.follow_profile(&mut c);
assert_eq!(c.args, args, "{name}");
}
}
#[test]
fn a_model_that_sent_the_one_tool_empty_gets_the_one_action_tools() {
let start = || {