目標: the goal goes with its chat, stays out of shared bot files, and 停止 between turns pauses it
- 清除聊天記錄 and 開始新對話 clear the goal first (it used to stay, and stopping the turn left a 「目標暫停」 line in the emptied chat) - a shared bot file no longer carries the goal; importing drops one that is there - 停止 while the check is reading the chat pauses the goal instead of doing nothing - 「繼續」 on a cut-off turn takes up a goal the restart paused - AnyBot's own line never lands between a step and its result, and stays above a 「繼續」 card - FEATURES.md: channels and team members can't set a goal (it said they could) Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Uirha3QxSfoydRPM9mjj6d
This commit is contained in:
parent
31f41f62c6
commit
5ae7cda6bb
|
|
@ -1360,9 +1360,9 @@ computer_use_screenshot、click、mouse_move、mouse_button(按住/放開)
|
|||
- **技能在大腦上**:Bot 在大腦上跑,技能也從大腦的硬碟讀。所以在大腦的螢幕(連到大腦的電腦)上,設定 › 整合的「加入」「安裝」「刪除」都請大腦做:GitHub/網址由大腦自己下載;填這台電腦上的資料夾或 .md 檔,就在這台讀好,連同 scripts/、references/ 和其他附檔整包交給大腦;刪除時大腦連資料夾一起刪,大腦重開也不會再冒出來。「開啟」照舊是一般的設定同步。「把這台的 Bot 搬到大腦」時,這台有、大腦沒有的技能也是整包交過去(連同開關和可重播的步驟)。手機本來就是請大腦做。大腦是舊版時,螢幕上的這些動作會說要先更新大腦。
|
||||
- **用 / 指定技能**:輸入框第一個字打「/」,上面就列出開著的技能(名稱開頭符合的先、名稱含有的次之、再來是說明裡有的,例如「/簡報」找到 pptx);點一下,或 ↑↓ 選、Enter/Tab 帶入,輸入框變成「/pptx 」接著打要做的事,Esc 關掉清單。電腦和手機都有,Bot 正在做事時不列(那時打的字會併進正在做的事)。送出後由大腦認出「/名稱」,在這則訊息後面替模型加一行「使用者用 /pptx 指定了技能「pptx」:先用 use_skill 讀出它的完整做法」,所以從手機、訊息管道打的也算;不是技能名稱的(例如 /Users/… 路徑)不加。新加的技能(技能市集、GitHub 安裝、Bot 存的或自己學會的、「教我做」)馬上就在清單裡:電腦直接讀技能名單(大腦的螢幕讀的是大腦同步過來的那份);手機每次打出新的「/」會向大腦再拿一次名單,拿到前先列手上已有的。篩選本身不連網,也不多送東西給模型(技能清單本來就在系統指示裡)。
|
||||
- **/goal 目標**(照 Claude Code 的 /goal 做):給 Bot 一個「做到什麼程度才算完成」的條件,它就一輪接一輪做下去,不用每一步都叫它。關鍵是**做事的模型不能自己宣布完成**:每一輪結束後,另一個模型(Bot 的「執行步驟用的模型」,通常是快速模型;設成「關閉」就用 Bot 自己的模型)只看這段對話(Bot 說的話、用了哪些工具、工具回了什麼),判斷條件成立了沒有。
|
||||
- **用法**:「/goal 所有測試都通過,而且 clippy 沒有新的警告」設定並馬上開始做(已經有目標就換掉);「/goal」看目前的目標、做了多久、檢查了幾輪、最近一次檢查的理由;「/goal clear」清除(stop、off、reset、none、cancel、清除、取消、停止也可以)。在 / 清單最上面,標「指令和技能」。電腦、大腦的螢幕、手機、訊息管道打的都算,由大腦處理。條件最多 4000 字;群組聊天還不能設目標。
|
||||
- **用法**:「/goal 所有測試都通過,而且 clippy 沒有新的警告」設定並馬上開始做(已經有目標就換掉);「/goal」看目前的目標、做了多久、檢查了幾輪、最近一次檢查的理由;「/goal clear」清除(stop、off、reset、none、cancel、清除、取消、停止也可以)。在 / 清單最上面,標「指令和技能」。電腦、大腦的螢幕、手機打的都算,由大腦處理;訊息管道(Slack、Telegram…)和團隊成員打的不算指令,別人不能替你設目標。條件最多 4000 字;群組聊天還不能設目標。「清除聊天記錄」和「開始新對話」會連目標一起清掉;分享 Bot 的檔案不含目標。
|
||||
- **檢查的結果**:還沒達成 → AnyBot 自己送出一則標「目標」的「還沒達成:(理由)」開始下一輪,理由就是下一步該做什麼;達成 → 聊天裡一行「目標達成:…(N 輪 · 多久)」,目標清掉;做不到 → 「目標做不到,已清除:…」;Bot 在等你回答或動手(登入、付款、做決定)→「目標暫停,等你回覆:…」,不會一直空轉。
|
||||
- **煞車**(比 Claude Code 嚴,因為 AnyBot 一輪最多 100 步、用的是你自己的金鑰):一個目標做 20 輪還沒達成就暫停問你;連續 3 輪都沒有用任何工具(只是在說話)就暫停;這一輪出錯、你按了停止、檢查的模型沒回應、AnyBot 重新啟動過,也都是暫停。暫停時目標還在,**傳一句話(例如「繼續」)就接著做**,用完 20 輪的再給 20 輪;不要了就 /goal clear。
|
||||
- **煞車**(比 Claude Code 嚴,因為 AnyBot 一輪最多 100 步、用的是你自己的金鑰):一個目標做 20 輪還沒達成就暫停問你;連續 3 輪都沒有用任何工具(只是在說話)就暫停;這一輪出錯、你按了停止(兩輪之間正在檢查時按也算)、檢查的模型沒回應、AnyBot 重新啟動過,也都是暫停。重新啟動後按中斷卡片上的「繼續」,目標也跟著接下去。暫停時目標還在,**傳一句話(例如「繼續」)就接著做**,用完 20 輪的再給 20 輪;不要了就 /goal clear。
|
||||
- **看得到的地方**:輸入框上方一行「目標進行中 · 12 分 · 3 輪」(檢查時是「正在檢查有沒有達成…」,暫停時是「目標暫停 · 原因」),滑過去看條件和最近一次的理由,右邊「清除目標」;窄視窗時字會縮成「…」,不會擠掉按鈕。AnyBot 自己的那幾行(達成、暫停、狀態)在聊天中間用小字顯示,不是 Bot 的話,**不會送給模型**,也不算檢查的證據。手機一樣,大腦的螢幕看到的是大腦同步過來的。
|
||||
- **通知**:目標進行中的每一輪不再各通知一次「完成了」;達成、做不到、暫停時才通知(你不在電腦前時,手機也會收到),例如「Master 達成目標了」「Master 在等你回覆」。
|
||||
- **模型讀到的**:你的「/goal …」後面多一行,說明這是目標、每輪會有另一個模型檢查,所以要用實際的結果證明(指令輸出、測試結果、檔案內容、畫面),需要你做什麼就直接問;「還沒達成」那則後面也提醒它接著做。檢查用的模型讀的是從設定目標那則訊息起的對話(太長就讀最新的約 24000 字;每個工具結果留開頭和結尾,測試的總結通常在最後),並知道已經第幾輪、做了多久,所以條件裡寫「最多 10 輪」也算數。
|
||||
|
|
|
|||
|
|
@ -1472,6 +1472,8 @@ impl App {
|
|||
return;
|
||||
}
|
||||
if self.state.bot(bot_id).and_then(|b| b.messages.last()).map(|m| m.interrupted).unwrap_or(false) {
|
||||
// 目標: 「繼續」 is the person saying go on — a goal the restart paused goes on too.
|
||||
self.goal_heard(bot_id);
|
||||
self.start_reply(ctx, bot_id);
|
||||
}
|
||||
}
|
||||
|
|
@ -1569,6 +1571,7 @@ impl App {
|
|||
}
|
||||
return;
|
||||
}
|
||||
self.goal_stop(bot_id);
|
||||
self.approvals.remove(&bot_id);
|
||||
if let Some(call) = self.app_pending.remove(&bot_id) {
|
||||
let _ = call.reply.send(("已停止".into(), false));
|
||||
|
|
@ -2249,6 +2252,9 @@ impl App {
|
|||
}
|
||||
// 討論串: put this conversation aside and start fresh; earlier ones can come back.
|
||||
if menu_ui::item(ui, p, Icon::NewChat, "開始新對話").clicked() {
|
||||
if !self.mir.on {
|
||||
self.goal_drop(id);
|
||||
}
|
||||
self.stop(id);
|
||||
if self.mir.on {
|
||||
self.mirror_act(serde_json::json!({"bot": id, "action": "new"}));
|
||||
|
|
@ -2347,6 +2353,7 @@ impl App {
|
|||
// screen still had it, and its next changes landed in the wrong place.
|
||||
self.mirror_act(serde_json::json!({"bot": id, "action": "clear"}));
|
||||
} else {
|
||||
self.goal_drop(id);
|
||||
self.stop(id);
|
||||
if let Some(b) = self.state.bot_mut(id) {
|
||||
b.messages.clear();
|
||||
|
|
|
|||
|
|
@ -83,10 +83,8 @@ impl App {
|
|||
let selected = self.state.selected;
|
||||
if let Some(b) = self.state.bot_mut(bot_id) {
|
||||
let m = Message { note: true, ..Message::assistant(text, "") };
|
||||
match b.messages.len() {
|
||||
n if streaming && n > 0 => b.messages.insert(n - 1, m),
|
||||
_ => b.messages.push(m),
|
||||
}
|
||||
let at = note_index(&b.messages, streaming);
|
||||
b.messages.insert(at, m);
|
||||
if bot_id != selected {
|
||||
b.unread = true;
|
||||
}
|
||||
|
|
@ -106,6 +104,31 @@ impl App {
|
|||
crate::remote::notify(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, ¬e);
|
||||
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)
|
||||
|
|
@ -182,7 +205,7 @@ impl App {
|
|||
}
|
||||
let Some(b) = self.state.bot_mut(bot_id) else { return };
|
||||
let name = b.name.clone();
|
||||
// Cleared, or set again, while it was being checked.
|
||||
// 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();
|
||||
|
|
@ -257,3 +280,43 @@ impl App {
|
|||
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.
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -492,6 +492,7 @@ impl App {
|
|||
}
|
||||
}
|
||||
Cmd::Clear { bot } => {
|
||||
self.goal_drop(bot);
|
||||
self.stop(bot);
|
||||
if let Some(b) = self.state.bot_mut(bot) {
|
||||
b.messages.clear();
|
||||
|
|
@ -499,6 +500,7 @@ impl App {
|
|||
self.mark();
|
||||
}
|
||||
Cmd::NewThread { bot } => {
|
||||
self.goal_drop(bot);
|
||||
self.stop(bot);
|
||||
if let Some(b) = self.state.bot_mut(bot) {
|
||||
if !b.messages.is_empty() {
|
||||
|
|
|
|||
18
src/share.rs
18
src/share.rs
|
|
@ -40,7 +40,7 @@ fn scrub(v: &mut Value) {
|
|||
pub fn export(b: &Bot) -> String {
|
||||
let mut v = serde_json::to_value(b).unwrap_or(Value::Null);
|
||||
if let Value::Object(m) = &mut v {
|
||||
for k in ["messages", "threads", "allow_rules", "unread", "last_turn", "workdir", "pinned", "id"] {
|
||||
for k in ["messages", "threads", "allow_rules", "unread", "last_turn", "goal", "workdir", "pinned", "id"] {
|
||||
m.remove(k);
|
||||
}
|
||||
if let Some(Value::Array(routines)) = m.get_mut("routines") {
|
||||
|
|
@ -79,6 +79,8 @@ pub fn import(text: &str, new_id: u64, next_routine: &mut u64, now: i64) -> Resu
|
|||
if let Value::Object(m) = &mut v {
|
||||
m.insert("id".into(), Value::from(new_id));
|
||||
m.insert("messages".into(), Value::Array(vec![]));
|
||||
// (A goal belongs to the chat it was set in; a file from before export left it out.)
|
||||
m.remove("goal");
|
||||
}
|
||||
let mut b: Bot = serde_json::from_value(v).map_err(|e| format!("檔案內容不完整:{e}"))?;
|
||||
for r in b.routines.iter_mut() {
|
||||
|
|
@ -115,6 +117,20 @@ pub fn choose_open() -> Option<std::path::PathBuf> {
|
|||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn a_goal_stays_with_its_chat() {
|
||||
let st = crate::model::State::demo();
|
||||
let mut b = st.bots[1].clone();
|
||||
b.goal = Some(crate::goal::Goal::new("測試通過", 1));
|
||||
let text = export(&b);
|
||||
assert!(!text.contains("測試通過"));
|
||||
// A file that carries one anyway (hand-made, or from a build that exported it).
|
||||
let with = text.replacen("\"name\"", "\"goal\":{\"condition\":\"x\",\"since\":1},\"name\"", 1);
|
||||
assert!(with.contains("\"goal\""));
|
||||
let mut next = 1;
|
||||
assert_eq!(import(&with, 99, &mut next, crate::routines::now()).unwrap().goal, None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn shared_bots_leave_secrets_and_chat_behind() {
|
||||
let mut st = crate::model::State::demo();
|
||||
|
|
|
|||
Loading…
Reference in New Issue