AnyBot/src/app/goal_ui.rs

353 lines
17 KiB
Rust
Raw Normal View History

// 目標 (/goal) in the window: 「/goal …」 typed to this brain (here, on one of its screens, on the
// phone), the check after each turn, and the line above the input. What a goal is, how it is
// judged and when it stops: goal.rs.
//
// The loop: a turn ends (settle) → its goal, if one is going, is checked by a second model on a
// thread of its own (goal_tick → goal_judge) → the verdict comes back as StreamEvent::Goal
// (goal_verdict) → not yet: AnyBot's 「[目標]還沒達成:…」 wakes the bot for another turn; met,
// impossible or paused: a line in the chat (a note, never sent to the model) and, when the
// person is away, a notification. Only a brain does this: a screen's turns run on its brain.
use super::*;
use crate::goal::{self, Command, Goal, Judged, Next};
impl App {
/// 「/goal …」: show, clear, or set the goal and start on it.
pub(super) fn goal_command(&mut self, ctx: &egui::Context, bot_id: u64, cmd: Command, text: &str, attachments: Vec<crate::attach::Attachment>, picks: Option<Vec<String>>) {
let now = crate::model::now_ms();
let Some(b) = self.state.bot(bot_id) else { return };
match cmd {
Command::Status => {
let s = goal::status(b.goal.as_ref(), now);
self.goal_note(bot_id, &s);
}
Command::Clear => {
let s = match self.state.bot_mut(bot_id).and_then(|b| b.goal.take()) {
Some(g) => format!("已清除目標:{}", g.condition),
None => "沒有設定目標。".into(),
};
self.goal_checking.remove(&bot_id);
self.goal_note(bot_id, &s);
}
Command::Set(cond) => {
if !b.members.is_empty() {
self.goal_note(bot_id, "群組聊天還不能設目標。");
return;
}
if cond.chars().count() > goal::MAX_CONDITION_CHARS {
self.goal_note(bot_id, &format!("目標太長了(最多 {} 字)。", goal::MAX_CONDITION_CHARS));
return;
}
self.goal_checking.remove(&bot_id);
if self.streams.contains_key(&bot_id) {
// Working: the running turn hears it at its next step, and its end is the
// first one checked.
if let Some(b) = self.state.bot_mut(bot_id) {
b.goal = Some(Goal::new(&cond, now));
}
Bot 之間溝通:ask_bot 問同事並等回答、群組 @點名、共用頁面/「關於你」記憶/教技能;修正插話丟附件、Enter 核准失效等 問同事(ask_bot) - A 問 B 並等它回答:問題放進 B 自己的聊天,B 用自己的模型、工具、記憶和電腦做,最後的回覆交回 A - 最多轉 3 手、不能互等(避免卡死)、對方忙就排隊(10 分鐘逾時)、停止 A 時 B 也停 - message_bot 也加轉手上限;別的 Bot 叫的不算使用者的話(改不了自己的設定) 群組 @點名 - 「@名字」只叫被點到的成員回答;成員在回覆裡 @ 別人就接著說(一輪最多 8 則) - 電腦和手機的輸入框打 @ 會列出成員 - 修正:每個成員帶自己的記憶;成員回覆的每一步都記得是誰說的 共用資源 - Bot 可以讀其他 Bot 的頁面(只能讀,改要請作者改) - 共用的「關於你」記憶:每個 Bot 都帶著,記憶頁可切換查看、編輯;外人的訊息不帶 - teach_skill:把自己會的技能教給同事(先問你);同事名冊列出每個 Bot 會的技能 修正 - 插話(Bot 工作中傳訊息)會帶附件:聊天有檔案卡片,模型看得到圖片;當機復原也帶著 - 輸入框有焦點、框是空的時 Enter 允許待核准的步驟(原本被當成空白送出吃掉) - 大腦的螢幕連不到大腦時,引用、附件、記憶不會先被用掉 - 「還原上一個答案」存在 Bot 上:重開還在,連大腦的畫面和手機都能還原;停止的回合也留著 - Bot 忙時被叫醒(例行任務、message_bot、觸發器)改成排隊開自己的一輪,不再壓成純文字插話 - 停止時結果已回來的步驟標成完成;輸入法剛選字的那一格不送出 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Uirha3a7riWESpv471gDgC
2026-11-13 13:34:03 +00:00
self.queue_steer(bot_id, text.trim().to_string(), attachments);
} else {
let m = Message { goal: cond.clone(), ..person_message(&self.state, bot_id, text.trim(), attachments, picks) };
if let Some(b) = self.state.bot_mut(bot_id) {
b.goal = Some(Goal::new(&cond, m.at));
b.messages.push(m);
}
self.start_reply(ctx, bot_id);
}
}
}
self.dirty = true;
self.save_now = true;
}
/// The person wrote to the bot (not 「/goal」): a paused goal goes on with this turn.
pub(super) fn goal_heard(&mut self, bot_id: u64) {
if let Some(g) = self.state.bot_mut(bot_id).and_then(|b| b.goal.as_mut()) {
g.resume();
}
}
/// 清除目標 above the input: on a screen the brain clears it, as if typed there.
pub(super) fn goal_clear(&mut self, ctx: &egui::Context, bot_id: u64) {
if self.mir.on {
self.mirror_send(bot_id, "/goal clear".into(), vec![], None);
return;
}
self.goal_command(ctx, bot_id, Command::Clear, "/goal clear", vec![], None);
}
/// AnyBot's own line in the chat. While the bot works, its newest message is the one the
/// words stream into, so the line goes just before it.
/btw 支線、送出先顯示;公測前的安全與資源修正(帳號盜用、灌爆、團隊權限、背景指令與連線的上限和清理) 支線與介面 - /btw:Bot 的分身帶著同一段對話和記憶平行做另一件事,做完回報到主聊天;主線在忙時先判斷會不會衝突,會就等主線做完 - 螢幕一次只給一輪工作操作(所有 Bot 適用) - 「/」只列指令,打字才找這個 Bot 自己的技能 - Bot 工作中送出的訊息立刻以淡色顯示(電腦、手機) - 支線修正:沒被讀到的回報照常進聊天、卡片顯示結果、可回答支線的問題、重新產生不吃掉卡片和回報 安全(中繼伺服器) - 大腦回傳的內容只放行安全類型並加沙箱;團隊改成邀請制;手機不照大腦說的類型開檔案 - 沒登入的請求最多 256 KB、接收中的上傳有總量上限、單一 IP 連線上限、常駐連線另計 - 登入次數加上每帳號上限並先計數再驗證;密碼雜湊同時最多 4 個 - 新增電腦要 15 分鐘內剛登入;可改密碼;註冊限速,有邀請碼時第一個帳號也要 - 發布的網站不能送表單和對外連線;Caddy 加安全標頭 安全(大腦) - 區網(明文)不能打開直接操作、加一律允許規則、加連接器;區網登入 30 天沒用失效 - 團隊成員只看得到勾選「團隊成員可以使用」的 Bot - 沒有角色的請求一律拒絕;環境變數的金鑰只送官方位址 資源 - 中繼:小變動每分鐘寫一次、回應有總時限、每台電腦呼叫上限、網站/登入/電腦/配對碼上限、資料檔壞掉不啟動 - App:伺服器回錯誤和連線秒斷時逐次退避;區網看螢幕偵測斷線 - 背景指令:刪 Bot 和支線結束時停掉、最多 24 個、結束 10 分鐘後移除、可用 stop 停掉 - 截圖在收起和歸檔時釋放;刪 Bot 時刪附件和對照表;每晚清稽核資料和暫存;手機圖片快取上限 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Uirha3a7riWESpv471gDgC
2026-11-13 15:36:34 +00:00
pub(super) fn goal_note(&mut self, bot_id: u64, text: &str) {
let streaming = self.streams.contains_key(&bot_id);
let selected = self.state.selected;
if let Some(b) = self.state.bot_mut(bot_id) {
let m = Message { note: true, ..Message::assistant(text, "") };
let at = note_index(&b.messages, streaming);
b.messages.insert(at, m);
if bot_id != selected {
b.unread = true;
}
}
self.dirty = true;
}
/// Tell the person how the goal stands, the way a finished turn is told (only when away).
fn goal_tell(&self, bot_id: u64, title: &str, note: &str) {
if self.demo || !(self.away() && self.state.notify) {
return;
}
let body = first_line(&note.replace('\n', " "), 120);
if !self.headless {
feat: 電腦版不再破版、通知用 AnyBot 的貓、手機網頁像 App;從帳號看畫面不再斷線 電腦版:右側「進行中」的長重試訊息蓋過「停止」、衝出卡片,現在以「…」結尾(滑鼠移上去看 全文);Bot 設定的「團隊成員可以使用…」疊到儲存/取消、權限規則疊到「刪除」、「新增規則」 被切掉、電腦分頁的時間欄被切掉、窄視窗裡允許卡片的按鈕、「已排入…」和輸入框提示被切掉, 都修好。粉圓體比思源黑體寬,寫死寬度的地方用它就擠爆。新的 layout_audit 測試用三種字型、 最窄/一般/寬的視窗、示範和很長的資料,把每個設定分頁、Bot 設定、例行任務、右側面板畫一遍, 字被切掉或疊在一起就失敗(截圖模式也多了 ANYBOT_SHOT_PANEL/STATUS/TAB/SCROLL)。 通知:Mac 上原本用 osascript 的 display notification,橫幅是「工序指令編寫程式」的圖示、 點了還打開它。現在是 AnyBot.app 自己發的(NSUserNotificationCenter:新的 UNUserNotificationCenter 只給有 Apple 開發者簽章的 App 用,AnyBot 自簽),圖示是貓,點一 下打開那個 Bot;不在 .app 裡才退回 osascript。Linux 的 notify-send 帶上 AnyBot 的圖示。 anybot --banner 標題 內文 可以送一則試試。 手機(PWA):manifest 和 service worker 改成 mobile/ 裡一份,帳號伺服器和這台共用;加滿版的 maskable 圖示和 Android 狀態列用的單色貓(原本彩色圖變成白方塊)。每支手機滿版(左右安全 區域、狀態列跟著畫面顏色)、首頁提示裝成 App、換畫面左右滑、iPhone 主畫面 App 從左邊緣滑回 上一頁、按鈕長按不選字、搜尋框不放大。通知可以選要哪幾種(需要你/做完了/例行任務暫停/ 收到檔案)、送測試通知,App 圖示上的數字是正在等你的 Bot。 帳號伺服器:看 Bot 電腦畫面時,瀏覽器回的 Pong 沒算成還活著,靜止畫面一分鐘就被切;看畫面 的票證十分鐘一到就切斷、重連又拿同一張過期的票回不來。現在票證記得誰申請的(那支手機的 登入、帳號裡那台電腦),申請者還有效就一直連著,使用中的票證會續期。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 16:06:12 +00:00
notify::banner_for(title, &body, true, Some(bot_id));
}
feat: 電腦版不再破版、通知用 AnyBot 的貓、手機網頁像 App;從帳號看畫面不再斷線 電腦版:右側「進行中」的長重試訊息蓋過「停止」、衝出卡片,現在以「…」結尾(滑鼠移上去看 全文);Bot 設定的「團隊成員可以使用…」疊到儲存/取消、權限規則疊到「刪除」、「新增規則」 被切掉、電腦分頁的時間欄被切掉、窄視窗裡允許卡片的按鈕、「已排入…」和輸入框提示被切掉, 都修好。粉圓體比思源黑體寬,寫死寬度的地方用它就擠爆。新的 layout_audit 測試用三種字型、 最窄/一般/寬的視窗、示範和很長的資料,把每個設定分頁、Bot 設定、例行任務、右側面板畫一遍, 字被切掉或疊在一起就失敗(截圖模式也多了 ANYBOT_SHOT_PANEL/STATUS/TAB/SCROLL)。 通知:Mac 上原本用 osascript 的 display notification,橫幅是「工序指令編寫程式」的圖示、 點了還打開它。現在是 AnyBot.app 自己發的(NSUserNotificationCenter:新的 UNUserNotificationCenter 只給有 Apple 開發者簽章的 App 用,AnyBot 自簽),圖示是貓,點一 下打開那個 Bot;不在 .app 裡才退回 osascript。Linux 的 notify-send 帶上 AnyBot 的圖示。 anybot --banner 標題 內文 可以送一則試試。 手機(PWA):manifest 和 service worker 改成 mobile/ 裡一份,帳號伺服器和這台共用;加滿版的 maskable 圖示和 Android 狀態列用的單色貓(原本彩色圖變成白方塊)。每支手機滿版(左右安全 區域、狀態列跟著畫面顏色)、首頁提示裝成 App、換畫面左右滑、iPhone 主畫面 App 從左邊緣滑回 上一頁、按鈕長按不選字、搜尋框不放大。通知可以選要哪幾種(需要你/做完了/例行任務暫停/ 收到檔案)、送測試通知,App 圖示上的數字是正在等你的 Bot。 帳號伺服器:看 Bot 電腦畫面時,瀏覽器回的 Pong 沒算成還活著,靜止畫面一分鐘就被切;看畫面 的票證十分鐘一到就切斷、重連又拿同一張過期的票回不來。現在票證記得誰申請的(那支手機的 登入、帳號裡那台電腦),申請者還有效就一直連著,使用中的票證會續期。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 16:06:12 +00:00
crate::remote::notify(crate::remote::Notice::Done, title, &body, bot_id);
}
/// 清除聊天記錄 / 開始新對話: the goal goes with the chat it was set in (Claude Code's /clear
/// removes it too). Before the turn is stopped, so stopping doesn't leave a 「目標暫停」 line
/// in the new chat.
pub(super) fn goal_drop(&mut self, bot_id: u64) {
if let Some(b) = self.state.bot_mut(bot_id) {
b.goal = None;
}
self.goal_checking.remove(&bot_id);
self.goal_due.retain(|(id, _)| *id != bot_id);
}
/// 停止 pressed between two turns of a goal (the check is reading the chat; nothing is
/// running to stop): the goal pauses, or the next turn would start a moment later anyway.
pub(super) fn goal_stop(&mut self, bot_id: u64) {
if self.streams.contains_key(&bot_id) || !self.goal_pending(bot_id) {
return;
}
self.goal_checking.remove(&bot_id);
self.goal_due.retain(|(id, _)| *id != bot_id);
let Some(g) = self.state.bot_mut(bot_id).and_then(|b| b.goal.as_mut()).filter(|g| g.active()) else { return };
let note = goal::after_trouble(g, true);
self.goal_note(bot_id, &note);
self.save_now = true;
}
/// A turn of this bot's goal has ended and its check hasn't spoken yet.
pub(super) fn goal_pending(&self, bot_id: u64) -> bool {
self.goal_checking.contains(&bot_id) || self.goal_due.iter().any(|(id, _)| *id == bot_id)
}
/// Turns that ended since the last frame: check the ones working toward a goal.
pub(super) fn goal_tick(&mut self, ctx: &egui::Context) {
for (bot_id, outcome) in std::mem::take(&mut self.goal_due) {
// Another turn is on its way (typed meanwhile, the next group member): its end is
// the one checked.
if self.streams.contains_key(&bot_id) || self.pending_turns.iter().any(|(id, _)| *id == bot_id) || self.group_next.contains(&bot_id) {
continue;
}
let Some(b) = self.state.bot_mut(bot_id) else { continue };
let Some(g) = b.goal.as_mut().filter(|g| g.active()) else { continue };
match outcome {
TurnOutcome::Success => {
let start = b.messages.iter().rposition(|m| m.role == Role::User && !m.steer).unwrap_or(0);
g.after_turn(b.messages[start..].iter().any(|m| m.role == Role::Assistant && !m.tool_calls.is_empty()));
let g = g.clone();
self.goal_judge(ctx, bot_id, g);
}
TurnOutcome::Cancelled | TurnOutcome::Error => {
let note = goal::after_trouble(g, outcome == TurnOutcome::Cancelled);
let title = format!("{} 的目標暫停了", b.name);
self.goal_note(bot_id, &note);
self.goal_tell(bot_id, &title, &note);
}
}
self.dirty = true;
}
}
/// Ask the bot's quick model (or its own, as its 執行步驟用的模型 setting says) whether the
/// goal holds, on a thread; the answer comes back as StreamEvent::Goal.
fn goal_judge(&mut self, ctx: &egui::Context, bot_id: u64, g: Goal) {
let Some(b) = self.state.bot(bot_id) else { return };
let ps = self.state.provider(b.provider);
let model = match b.step_model.trim() {
"off" => b.model.clone(),
"" => b.provider.quick_model(&b.model).map(String::from).unwrap_or_else(|| b.model.clone()),
m => m.to_string(),
};
feat: 借鏡 pstack/Grok Bot——例行任務執行紀錄、完成看證據、教訓分流、園丁報告、減少操作步驟、網站地圖 1. 例行任務執行紀錄:每次執行記開始/結束、完成/失敗/被停止/中斷、步數與失敗步數、原因,保留最近 20 次(Grok Bot 官方規格);上次失敗或中斷的原因帶進下一次;連續失敗 2 次自動暫停並說明原因;設定頁、手機詳細頁、list_routines 都看得到,沒有紀錄時說「查不到」不說「沒跑過」 2. 完成看證據:evidence.rs 從步驟算出實際成功送出幾次,寫進例行任務紀錄;/goal 評審的摘錄把 Bot 的話標成「不是證據」並附系統統計,對不上以系統為準;評審優先用另一家供應商的模型,失敗退回原本的 3. 教訓分流:自動學技能時,AnyBot 自己的工具問題寫進 tool_issues → 「待改進」清單(同一工具合併計次),不寫進技能;設定 › 更新可看可清除 4. 園丁報告(garden.rs):平日 8:44 掃過去一天的失敗、走冤枉路的執行、自動暫停與重複出現的待改進;週一 8:49 列出失敗多或太耗時的例行任務;沒事不報,可在設定關掉 5. 減少步驟:browser type 多行文字一次放進欄位(先試貼上事件、檢查沒進再用 insertText,Firefox 也行)並回報欄位內容;點進輸入框回「游標已在…」不再說「沒有變化」;元素編號在同一頁重讀時不變;wait 的 after_send 從上次送出算間隔 6. 網站地圖:學技能時同一網站的操作知識整理進「<網站> 網站地圖」(功能/怎麼到/怎麼操作/陷阱),做事的技能只寫特有規則 Mac 465、Linux 469 個測試通過;多行輸入與編號實機測試在 Brave、Firefox 通過。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 15:52:44 +00:00
let own = ChatRequest {
kind: b.provider,
base_url: providers::resolve_base(b.provider, &ps.base_url),
/btw 支線、送出先顯示;公測前的安全與資源修正(帳號盜用、灌爆、團隊權限、背景指令與連線的上限和清理) 支線與介面 - /btw:Bot 的分身帶著同一段對話和記憶平行做另一件事,做完回報到主聊天;主線在忙時先判斷會不會衝突,會就等主線做完 - 螢幕一次只給一輪工作操作(所有 Bot 適用) - 「/」只列指令,打字才找這個 Bot 自己的技能 - Bot 工作中送出的訊息立刻以淡色顯示(電腦、手機) - 支線修正:沒被讀到的回報照常進聊天、卡片顯示結果、可回答支線的問題、重新產生不吃掉卡片和回報 安全(中繼伺服器) - 大腦回傳的內容只放行安全類型並加沙箱;團隊改成邀請制;手機不照大腦說的類型開檔案 - 沒登入的請求最多 256 KB、接收中的上傳有總量上限、單一 IP 連線上限、常駐連線另計 - 登入次數加上每帳號上限並先計數再驗證;密碼雜湊同時最多 4 個 - 新增電腦要 15 分鐘內剛登入;可改密碼;註冊限速,有邀請碼時第一個帳號也要 - 發布的網站不能送表單和對外連線;Caddy 加安全標頭 安全(大腦) - 區網(明文)不能打開直接操作、加一律允許規則、加連接器;區網登入 30 天沒用失效 - 團隊成員只看得到勾選「團隊成員可以使用」的 Bot - 沒有角色的請求一律拒絕;環境變數的金鑰只送官方位址 資源 - 中繼:小變動每分鐘寫一次、回應有總時限、每台電腦呼叫上限、網站/登入/電腦/配對碼上限、資料檔壞掉不啟動 - App:伺服器回錯誤和連線秒斷時逐次退避;區網看螢幕偵測斷線 - 背景指令:刪 Bot 和支線結束時停掉、最多 24 個、結束 10 分鐘後移除、可用 stop 停掉 - 截圖在收起和歸檔時釋放;刪 Bot 時刪附件和對照表;每晚清稽核資料和暫存;手機圖片快取上限 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Uirha3a7riWESpv471gDgC
2026-11-13 15:36:34 +00:00
api_key: providers::resolve_key_for(b.provider, &ps.api_key, &ps.base_url),
model,
system: goal::JUDGE_SYSTEM.into(),
history: vec![Message::user(&goal::brief(&g, &b.messages, crate::model::now_ms()))],
tools: vec![],
session: format!("anybot-goal-{bot_id}"),
effort: String::new(),
};
feat: 借鏡 pstack/Grok Bot——例行任務執行紀錄、完成看證據、教訓分流、園丁報告、減少操作步驟、網站地圖 1. 例行任務執行紀錄:每次執行記開始/結束、完成/失敗/被停止/中斷、步數與失敗步數、原因,保留最近 20 次(Grok Bot 官方規格);上次失敗或中斷的原因帶進下一次;連續失敗 2 次自動暫停並說明原因;設定頁、手機詳細頁、list_routines 都看得到,沒有紀錄時說「查不到」不說「沒跑過」 2. 完成看證據:evidence.rs 從步驟算出實際成功送出幾次,寫進例行任務紀錄;/goal 評審的摘錄把 Bot 的話標成「不是證據」並附系統統計,對不上以系統為準;評審優先用另一家供應商的模型,失敗退回原本的 3. 教訓分流:自動學技能時,AnyBot 自己的工具問題寫進 tool_issues → 「待改進」清單(同一工具合併計次),不寫進技能;設定 › 更新可看可清除 4. 園丁報告(garden.rs):平日 8:44 掃過去一天的失敗、走冤枉路的執行、自動暫停與重複出現的待改進;週一 8:49 列出失敗多或太耗時的例行任務;沒事不報,可在設定關掉 5. 減少步驟:browser type 多行文字一次放進欄位(先試貼上事件、檢查沒進再用 insertText,Firefox 也行)並回報欄位內容;點進輸入框回「游標已在…」不再說「沒有變化」;元素編號在同一頁重讀時不變;wait 的 after_send 從上次送出算間隔 6. 網站地圖:學技能時同一網站的操作知識整理進「<網站> 網站地圖」(功能/怎麼到/怎麼操作/陷阱),做事的技能只寫特有規則 Mac 465、Linux 469 個測試通過;多行輸入與編號實機測試在 Brave、Firefox 通過。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 15:52:44 +00:00
// A model of another family when the person has one: a bot's own model grades its own
// work too kindly (pstack's judges are from a different family). Its own, if that fails.
let mut tries: Vec<ChatRequest> = self.judge_elsewhere(b.provider).map(|(kind, base_url, api_key, model)| ChatRequest { kind, base_url, api_key, model, ..own.clone() }).into_iter().collect();
tries.push(own);
self.goal_checking.insert(bot_id);
let (tx, ctx) = (self.tx.clone(), ctx.clone());
std::thread::spawn(move || {
let cancel = AtomicBool::new(false);
feat: 借鏡 pstack/Grok Bot——例行任務執行紀錄、完成看證據、教訓分流、園丁報告、減少操作步驟、網站地圖 1. 例行任務執行紀錄:每次執行記開始/結束、完成/失敗/被停止/中斷、步數與失敗步數、原因,保留最近 20 次(Grok Bot 官方規格);上次失敗或中斷的原因帶進下一次;連續失敗 2 次自動暫停並說明原因;設定頁、手機詳細頁、list_routines 都看得到,沒有紀錄時說「查不到」不說「沒跑過」 2. 完成看證據:evidence.rs 從步驟算出實際成功送出幾次,寫進例行任務紀錄;/goal 評審的摘錄把 Bot 的話標成「不是證據」並附系統統計,對不上以系統為準;評審優先用另一家供應商的模型,失敗退回原本的 3. 教訓分流:自動學技能時,AnyBot 自己的工具問題寫進 tool_issues → 「待改進」清單(同一工具合併計次),不寫進技能;設定 › 更新可看可清除 4. 園丁報告(garden.rs):平日 8:44 掃過去一天的失敗、走冤枉路的執行、自動暫停與重複出現的待改進;週一 8:49 列出失敗多或太耗時的例行任務;沒事不報,可在設定關掉 5. 減少步驟:browser type 多行文字一次放進欄位(先試貼上事件、檢查沒進再用 insertText,Firefox 也行)並回報欄位內容;點進輸入框回「游標已在…」不再說「沒有變化」;元素編號在同一頁重讀時不變;wait 的 after_send 從上次送出算間隔 6. 網站地圖:學技能時同一網站的操作知識整理進「<網站> 網站地圖」(功能/怎麼到/怎麼操作/陷阱),做事的技能只寫特有規則 Mac 465、Linux 469 個測試通過;多行輸入與編號實機測試在 Brave、Firefox 通過。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 15:52:44 +00:00
let mut judged = Judged::Failed("沒有可以檢查的模型".into());
for req in &tries {
match providers::run_step(req, &cancel, &|_| {}) {
Ok(o) => {
judged = goal::read_verdict(&o.text);
break;
}
Err(e) => {
eprintln!("AnyBot:用 {} 檢查目標沒有回應:{e}", req.model);
judged = Judged::Failed(e);
}
}
}
eprintln!("AnyBot:Bot {bot_id} 的目標檢查:{judged:?}");
let _ = tx.send((bot_id, 0, StreamEvent::Goal(g.since, judged)));
ctx.request_repaint();
});
}
feat: 借鏡 pstack/Grok Bot——例行任務執行紀錄、完成看證據、教訓分流、園丁報告、減少操作步驟、網站地圖 1. 例行任務執行紀錄:每次執行記開始/結束、完成/失敗/被停止/中斷、步數與失敗步數、原因,保留最近 20 次(Grok Bot 官方規格);上次失敗或中斷的原因帶進下一次;連續失敗 2 次自動暫停並說明原因;設定頁、手機詳細頁、list_routines 都看得到,沒有紀錄時說「查不到」不說「沒跑過」 2. 完成看證據:evidence.rs 從步驟算出實際成功送出幾次,寫進例行任務紀錄;/goal 評審的摘錄把 Bot 的話標成「不是證據」並附系統統計,對不上以系統為準;評審優先用另一家供應商的模型,失敗退回原本的 3. 教訓分流:自動學技能時,AnyBot 自己的工具問題寫進 tool_issues → 「待改進」清單(同一工具合併計次),不寫進技能;設定 › 更新可看可清除 4. 園丁報告(garden.rs):平日 8:44 掃過去一天的失敗、走冤枉路的執行、自動暫停與重複出現的待改進;週一 8:49 列出失敗多或太耗時的例行任務;沒事不報,可在設定關掉 5. 減少步驟:browser type 多行文字一次放進欄位(先試貼上事件、檢查沒進再用 insertText,Firefox 也行)並回報欄位內容;點進輸入框回「游標已在…」不再說「沒有變化」;元素編號在同一頁重讀時不變;wait 的 after_send 從上次送出算間隔 6. 網站地圖:學技能時同一網站的操作知識整理進「<網站> 網站地圖」(功能/怎麼到/怎麼操作/陷阱),做事的技能只寫特有規則 Mac 465、Linux 469 個測試通過;多行輸入與編號實機測試在 Brave、Firefox 通過。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 15:52:44 +00:00
/// Another provider the person has set up, for judging a bot's goal: (kind, base url, key,
/// model). Not a local Ollama model (small ones judge poorly), not the bot's own provider.
feat: 發布關卡——已送帳本、發布前檢查、送出後讀頁面留證據、例行任務完成條件、重播可填空格 1. 已送帳本(publish.rs):Bot 用 AnyBot 瀏覽器送出前,系統先讀頁面,看是哪個帳號、回哪一篇(回覆對話框或文章裡的貼文網址、或頁面本身);同一帳號回過同一篇就擋下(記 60 天),頁面看不出回哪篇時只擋 24 小時內同頁同字。搜尋框按 Enter 不算送出。瀏覽器新增 sent 動作,直接從帳本列出帳號回過誰,不必每輪讀完網站的回覆頁 2. 發布前檢查:送出前請另一家供應商的快速模型照基本規則(簡體字、AI 腔、不該公開的內容)、這一輪讀過的技能與自訂規則檢查,沒過就不送並說原因;固定不變的放在系統提示最前面方便快取,同一段字一輪只問一次;設定可關、可加規則 3. 送出後的證據:系統重讀頁面,確認文字出現、輸入框清空,抓出留言自己的網址;寫進 Message.sent(頁面文字偽造不了),送出計數、例行任務紀錄、/goal 評審、手機頁面都以它為準;框裡還留著字就記為沒有送出 4. 完成條件:例行任務可設 target_sends,系統自己數:到數就不准再送,結束時不到算失敗,連續兩輪(50 步)沒有新的送出就停下;喚醒訊息與進展檢查都說明目前計數 5. 重播空格:自動學技能時把每次不同的內容(留言、貼文網址)存成 {{名稱}},replay_skill 用 values 填這次的內容,缺哪格就說哪格 6. 間隔從真正送出那一刻算起;送出後確認最多等 8 秒,框清空 4 秒仍沒看到就先記「還沒確認」 Mac 480 個測試通過;送出前後讀頁面在 Brave、Firefox 實機測試通過。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 17:48:13 +00:00
pub(super) fn judge_elsewhere(&self, own: ProviderKind) -> Option<(ProviderKind, String, String, String)> {
feat: 借鏡 pstack/Grok Bot——例行任務執行紀錄、完成看證據、教訓分流、園丁報告、減少操作步驟、網站地圖 1. 例行任務執行紀錄:每次執行記開始/結束、完成/失敗/被停止/中斷、步數與失敗步數、原因,保留最近 20 次(Grok Bot 官方規格);上次失敗或中斷的原因帶進下一次;連續失敗 2 次自動暫停並說明原因;設定頁、手機詳細頁、list_routines 都看得到,沒有紀錄時說「查不到」不說「沒跑過」 2. 完成看證據:evidence.rs 從步驟算出實際成功送出幾次,寫進例行任務紀錄;/goal 評審的摘錄把 Bot 的話標成「不是證據」並附系統統計,對不上以系統為準;評審優先用另一家供應商的模型,失敗退回原本的 3. 教訓分流:自動學技能時,AnyBot 自己的工具問題寫進 tool_issues → 「待改進」清單(同一工具合併計次),不寫進技能;設定 › 更新可看可清除 4. 園丁報告(garden.rs):平日 8:44 掃過去一天的失敗、走冤枉路的執行、自動暫停與重複出現的待改進;週一 8:49 列出失敗多或太耗時的例行任務;沒事不報,可在設定關掉 5. 減少步驟:browser type 多行文字一次放進欄位(先試貼上事件、檢查沒進再用 insertText,Firefox 也行)並回報欄位內容;點進輸入框回「游標已在…」不再說「沒有變化」;元素編號在同一頁重讀時不變;wait 的 after_send 從上次送出算間隔 6. 網站地圖:學技能時同一網站的操作知識整理進「<網站> 網站地圖」(功能/怎麼到/怎麼操作/陷阱),做事的技能只寫特有規則 Mac 465、Linux 469 個測試通過;多行輸入與編號實機測試在 Brave、Firefox 通過。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 15:52:44 +00:00
providers::ALL_PROVIDERS.into_iter().filter(|k| *k != own && *k != ProviderKind::Ollama).find_map(|kind| {
let ps = self.state.provider(kind);
let key = providers::resolve_key_for(kind, &ps.api_key, &ps.base_url);
let usable = if kind == ProviderKind::Custom { !ps.base_url.trim().is_empty() } else { !kind.needs_key() || !key.is_empty() };
if !usable || (kind.needs_key() && key.is_empty()) {
return None;
}
let model = if ps.default_model.trim().is_empty() { kind.suggested_model().to_string() } else { ps.default_model.trim().to_string() };
Some((kind, providers::resolve_base(kind, &ps.base_url), key, model))
})
}
/// The check has spoken: another turn, or a line saying it is over or paused.
pub(super) fn goal_verdict(&mut self, ctx: &egui::Context, bot_id: u64, since: i64, judged: Judged) {
self.goal_checking.remove(&bot_id);
// The person already started another turn: its end is checked instead.
if self.streams.contains_key(&bot_id) {
return;
}
let Some(b) = self.state.bot_mut(bot_id) else { return };
let name = b.name.clone();
// Cleared, set again or stopped while it was being checked.
let Some(g) = b.goal.as_mut().filter(|g| g.since == since && g.active()) else { return };
let next = goal::after_verdict(g, judged, crate::model::now_ms());
let condition = g.condition.clone();
match next {
Next::Over { note, title } => {
b.goal = None;
self.goal_note(bot_id, &note);
self.goal_tell(bot_id, &format!("{name} {title}"), &note);
主題產生器進設定(底色/對比/強調色/密度/慶祝)+側欄細條+時段問候+目標撒花 Quiet Shell 收尾四件(A3/B2/B3/C/D),一次落地: - C 產生器:theme::shell(tone, accent, contrast, dark)——三個旋紐生成整個殼 (表面=紙朝墨等距階梯、文字=墨回紙、圖表六色=強調色轉色相);設定 › 一般 外觀新增 底色(冷→暖)、對比(0.75→1.35,拉整個殼的階層一起調)、強調色 (黏土/靛藍/苔綠/藍綠/玫紅/琥珀/石板/墨黑)、重設。預設=紙,舊設定檔 serde 補預設。ANYBOT_SHOT_SHELL=tone,accent,contrast 出概念圖 - B3 密度:寬鬆(9/7)/緊湊(8/5) 全域間距開關 - B2 側欄:選中 Bot 不再整條深底——強調色 3px 細條+淺底(Linear 式) - D1 撒花:只在 /goal 目標達成時,該聊天上撒 1.4 秒彩帶(chart_cat 六色, 淡出收尾);設定 › 一般「慶祝動畫」可關;純裝飾,不擋任何操作 - D3 問候:新對話依時段先問「早安/午安/晚上好/夜深了」 - 淺深判定改成亮度函數 theme::is_dark(原先拿 pane 和 LIGHT 常數比對—— 底色旋紐一調就破);markdown 連結色、灰字、遮罩四處跟著改 - 手機 theme-color meta 換紙色;元件庫調查:egui_dock/notify/shadcn-egui 都不引入(自有設計系統+鎖 egui 版本),缺的取色器用八點自家版 已驗證: cargo test 505 全綠(新增 theme 產生器 5 測:預設=紙、對比單調、 冷暖心跳、is_dark 跟旋紐不跟常數;含 layout_audit 三寬度新設定區塊不破版); clippy 31=基線;截圖取樣:冷灰 pane(246,245,247)、紙 pane(248,247,245)、 側欄黏土細條 52px、墨黑殼 0px(強調色確實跟隨)、深色苔綠 152px 未驗證: 撒花只在真 /goal 達成出現,截圖模式不渲染(未目視彩帶飛的樣子, 落點/速度未調校);i18n 新字串(早安/靛藍等)靠自動翻譯,英日語未逐條核; 手機端不吃旋紐(只有 meta 色),自訂色手機同步是下一輪
2026-11-16 09:32:42 +00:00
self.confetti = Some((bot_id, Instant::now()));
}
Next::Pause { note, title } => {
self.goal_note(bot_id, &note);
self.goal_tell(bot_id, &format!("{name} {title}"), &note);
}
Next::Again { text } => self.wake(ctx, bot_id, Message { wake: true, goal: condition, ..Message::user(&text) }),
}
self.dirty = true;
self.save_now = true;
}
/// The line above the input while there is a goal: how it stands (the goal and the newest
/// check on hover) and 清除目標. The words end in … before the button on a narrow window.
pub(super) fn goal_bar(&mut self, ui: &mut egui::Ui, ctx: &egui::Context, bot: &Bot) {
let Some(g) = bot.goal.as_ref() else { return };
let p = self.pal;
let now = crate::model::now_ms();
let text = if g.active() && self.goal_checking.contains(&bot.id) { t("目標 · 正在檢查有沒有達成…") } else { goal::bar_text(g, now) };
let mut tip = format!("{}{}", t("目標:"), g.condition);
if !g.reason.is_empty() {
tip.push_str(&format!("\n\n{}{}", t("最近一次檢查:"), g.reason));
}
let col = if g.active() { p.text2 } else { p.text3 };
let mut clear = false;
ui.horizontal(|ui| {
ui.add_space(14.0);
ui.with_layout(Layout::right_to_left(Align::Center), |ui| {
ui.add_space(10.0);
clear = small_button(ui, "清除目標", p).clicked();
ui.with_layout(Layout::left_to_right(Align::Center), |ui| {
ui.spacing_mut().item_spacing.x = 6.0;
let (r, _) = ui.allocate_exact_size(vec2(13.0, 14.0), egui::Sense::hover());
crate::icons::paint(ui.painter(), egui::Rect::from_center_size(r.center(), vec2(12.0, 12.0)), crate::icons::Icon::Target, if g.active() { p.accent } else { col });
ui.add(egui::Label::new(RichText::new(&text).size(FONT_XS).color(col)).truncate().selectable(false)).on_hover_text(&tip);
});
});
});
ui.add_space(2.0);
if clear {
self.goal_clear(ctx, bot.id);
}
if g.active() {
// The minutes count on.
ctx.request_repaint_after(std::time::Duration::from_secs(30));
}
}
/// A goal's line in the chat (AnyBot's, not the bot's): small, in the middle.
pub(super) fn goal_note_row(&self, ui: &mut egui::Ui, m: &Message) {
let p = self.pal;
ui.add_space(2.0);
ui.vertical_centered(|ui| {
let w = message_max_width(ui.available_width());
ui.set_max_width(w);
Frame::new().fill(p.hover).corner_radius(12).inner_margin(Margin::symmetric(12, 7)).show(ui, |ui| {
ui.horizontal_top(|ui| {
ui.spacing_mut().item_spacing.x = 6.0;
let (r, _) = ui.allocate_exact_size(vec2(13.0, 16.0), egui::Sense::hover());
crate::icons::paint(ui.painter(), egui::Rect::from_center_size(r.center(), vec2(12.0, 12.0)), crate::icons::Icon::Target, p.text3);
ui.add(egui::Label::new(RichText::new(&m.text).size(12.5).line_height(Some(18.0)).color(p.text2)).wrap());
});
});
});
ui.add_space(10.0);
}
}
/// Where AnyBot's own line goes in a chat. At the end — but never between a step and its result
/// or after the reply being written (while the bot works, the newest message is the one its
/// words stream into), and above a 「繼續」 card, which has to stay the newest thing to be pressed.
/btw 支線、送出先顯示;公測前的安全與資源修正(帳號盜用、灌爆、團隊權限、背景指令與連線的上限和清理) 支線與介面 - /btw:Bot 的分身帶著同一段對話和記憶平行做另一件事,做完回報到主聊天;主線在忙時先判斷會不會衝突,會就等主線做完 - 螢幕一次只給一輪工作操作(所有 Bot 適用) - 「/」只列指令,打字才找這個 Bot 自己的技能 - Bot 工作中送出的訊息立刻以淡色顯示(電腦、手機) - 支線修正:沒被讀到的回報照常進聊天、卡片顯示結果、可回答支線的問題、重新產生不吃掉卡片和回報 安全(中繼伺服器) - 大腦回傳的內容只放行安全類型並加沙箱;團隊改成邀請制;手機不照大腦說的類型開檔案 - 沒登入的請求最多 256 KB、接收中的上傳有總量上限、單一 IP 連線上限、常駐連線另計 - 登入次數加上每帳號上限並先計數再驗證;密碼雜湊同時最多 4 個 - 新增電腦要 15 分鐘內剛登入;可改密碼;註冊限速,有邀請碼時第一個帳號也要 - 發布的網站不能送表單和對外連線;Caddy 加安全標頭 安全(大腦) - 區網(明文)不能打開直接操作、加一律允許規則、加連接器;區網登入 30 天沒用失效 - 團隊成員只看得到勾選「團隊成員可以使用」的 Bot - 沒有角色的請求一律拒絕;環境變數的金鑰只送官方位址 資源 - 中繼:小變動每分鐘寫一次、回應有總時限、每台電腦呼叫上限、網站/登入/電腦/配對碼上限、資料檔壞掉不啟動 - App:伺服器回錯誤和連線秒斷時逐次退避;區網看螢幕偵測斷線 - 背景指令:刪 Bot 和支線結束時停掉、最多 24 個、結束 10 分鐘後移除、可用 stop 停掉 - 截圖在收起和歸檔時釋放;刪 Bot 時刪附件和對照表;每晚清稽核資料和暫存;手機圖片快取上限 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Uirha3a7riWESpv471gDgC
2026-11-13 15:36:34 +00:00
pub(super) fn note_index(msgs: &[Message], streaming: bool) -> usize {
let mut i = msgs.len();
if streaming {
while i > 0 && msgs[i - 1].role == Role::Tool {
i -= 1;
}
i = i.saturating_sub(1);
} else if msgs.last().is_some_and(|m| m.interrupted) {
i -= 1;
}
i
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn a_note_never_splits_a_step_from_its_result() {
let user = Message::user("做事");
let step = Message { tool_calls: vec![crate::model::ToolCall { id: "1".into(), name: "shell".into(), args: "{}".into(), status: Default::default() }], ..Message::assistant("", "") };
let result = Message::tool_result("1", "shell", "ok");
let reply = Message::assistant("好了", "");
// Idle: at the end.
assert_eq!(note_index(&[user.clone(), reply.clone()], false), 2);
assert_eq!(note_index(&[], false), 0);
// Working: before the reply being written…
assert_eq!(note_index(&[user.clone(), reply.clone()], true), 1);
// …and before a step whose result is the newest message.
assert_eq!(note_index(&[user.clone(), step.clone(), result.clone()], true), 1);
assert_eq!(note_index(&[], true), 0);
// A 「繼續」 card stays the newest thing.
let card = Message { interrupted: true, ..Message::assistant("被中斷了", "") };
assert_eq!(note_index(&[user, step, result, card], false), 3);
}
}