fix: 第二輪獨立審查的 P1——提醒不算這一輪的要求、安靜那步的起跑期限、斷線時附件不再遺失
- 說了就做的提醒(和 hook 的「還不能結束」)不再被當成這一輪的起點:記下做過的事、學技能與重播、發布前的「這一輪的任務」都從使用者真正的要求算起;回顧裡也不列成「使用者中途說」 - 安靜的那一步:UI 收到提醒時把「第一次回應」期限重設回 120 秒;這一步的輸出以空的思考事件告訴看門狗它正在回答(原本思考不串流的模型 35 秒就被判中斷) - 螢幕電腦斷線時送出附件:上傳也在斷線期間重送;有一個檔案上傳不了就不送文字,整則(文字和附件)放回輸入框;放回時不覆蓋已經打的字 - 等待連上大腦時不開設定、Bot 編輯等視窗(那時改的東西進門後會被丟掉) 已驗證: cargo test 740 通過(新增 a_nudge_is_not_the_person_talking;an_announced_step_is_carried_out_without_the_person 加驗安靜那步的輸出事件);verify-anybot 重跑 chat.md「說了就做」「/ 指令」、autonomy.md「智慧模式一直開著」結果相同,ctl down 無殘留 未驗證: 螢幕電腦斷線時附件重送與退回(要帳號伺服器與第二台電腦,只在程式層修正、無端到端測試);看門狗的 120 秒期限在真的慢模型上(要真的模型);手機頁面畫面那一層(這台沒有 Google Chrome) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
e644d88446
commit
16ce1c6008
22
src/agent.rs
22
src/agent.rs
|
|
@ -344,7 +344,7 @@ pub(crate) fn worth_noting(turn: &[Message]) -> bool {
|
||||||
const NOTE_MIN_LOOKS: usize = 5;
|
const NOTE_MIN_LOOKS: usize = 5;
|
||||||
|
|
||||||
fn memory_note(job: &Job, history: &[Message]) {
|
fn memory_note(job: &Job, history: &[Message]) {
|
||||||
let Some(start) = history.iter().rposition(|m| m.role == Role::User && !m.steer) else { return };
|
let Some(start) = history.iter().rposition(|m| m.role == Role::User && !m.steer && !only_in_turn(m)) else { return };
|
||||||
if !worth_noting(&history[start..]) {
|
if !worth_noting(&history[start..]) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -361,7 +361,7 @@ fn memory_note(job: &Job, history: &[Message]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn learn(job: &Job, history: &[Message], cancel: &AtomicBool, send: &dyn Fn(StreamEvent)) {
|
fn learn(job: &Job, history: &[Message], cancel: &AtomicBool, send: &dyn Fn(StreamEvent)) {
|
||||||
let Some(start) = history.iter().rposition(|m| m.role == Role::User && !m.steer) else { return };
|
let Some(start) = history.iter().rposition(|m| m.role == Role::User && !m.steer && !only_in_turn(m)) else { return };
|
||||||
let turn = &history[start..];
|
let turn = &history[start..];
|
||||||
if !crate::memory::worth_learning(turn) {
|
if !crate::memory::worth_learning(turn) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -1033,7 +1033,7 @@ pub fn compaction_cut(h: &[Message]) -> Option<usize> {
|
||||||
|
|
||||||
/// AnyBot's own words to the model inside one turn (a nudge, a hook's 「not yet」): the chat in
|
/// AnyBot's own words to the model inside one turn (a nudge, a hook's 「not yet」): the chat in
|
||||||
/// the window never has them, so a summary is never cut at one (the window finds the cut by it).
|
/// the window never has them, so a summary is never cut at one (the window finds the cut by it).
|
||||||
fn only_in_turn(m: &Message) -> bool {
|
pub(crate) fn only_in_turn(m: &Message) -> bool {
|
||||||
m.role == Role::User && m.text.starts_with("【AnyBot:")
|
m.role == Role::User && m.text.starts_with("【AnyBot:")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1668,7 +1668,7 @@ enum Gate {
|
||||||
|
|
||||||
/// What the turn is about (its first message) and the skills it read, for the check.
|
/// What the turn is about (its first message) and the skills it read, for the check.
|
||||||
fn turn_brief(history: &[Message]) -> (String, String) {
|
fn turn_brief(history: &[Message]) -> (String, String) {
|
||||||
let start = history.iter().rposition(|m| m.role == Role::User && !m.steer).unwrap_or(0);
|
let start = history.iter().rposition(|m| m.role == Role::User && !m.steer && !only_in_turn(m)).unwrap_or(0);
|
||||||
let task = history.get(start).map(|m| m.text.clone()).unwrap_or_default();
|
let task = history.get(start).map(|m| m.text.clone()).unwrap_or_default();
|
||||||
let skills: Vec<&str> = history[start..].iter().filter(|m| m.role == Role::Tool && m.tool_name == "use_skill").map(|m| m.text.as_str()).collect();
|
let skills: Vec<&str> = history[start..].iter().filter(|m| m.role == Role::Tool && m.tool_name == "use_skill").map(|m| m.text.as_str()).collect();
|
||||||
let skills = skills.join("\n\n");
|
let skills = skills.join("\n\n");
|
||||||
|
|
@ -2174,10 +2174,12 @@ pub fn spawn(job: Job, bot_id: u64, tx: Sender<(u64, StreamEvent)>, cancel: Arc<
|
||||||
};
|
};
|
||||||
// A quiet step after a nudge: nothing shows until it is known to be worth showing
|
// A quiet step after a nudge: nothing shows until it is known to be worth showing
|
||||||
// (its words and calls come whole with StepDone); the watchdog still hears it work.
|
// (its words and calls come whole with StepDone); the watchdog still hears it work.
|
||||||
let hushed = |ev: StreamEvent| {
|
// (Words and calls as they come say only 「it is answering」: an empty thought, which
|
||||||
if matches!(ev, StreamEvent::Alive | StreamEvent::Retrying(_) | StreamEvent::Text(_) | StreamEvent::Thinking(_) | StreamEvent::ToolCall(_)) {
|
// adds nothing to the chat but tells the watchdog output started.)
|
||||||
send(StreamEvent::Alive)
|
let hushed = |ev: StreamEvent| match ev {
|
||||||
}
|
StreamEvent::Alive | StreamEvent::Retrying(_) => send(StreamEvent::Alive),
|
||||||
|
StreamEvent::Text(_) | StreamEvent::Thinking(_) | StreamEvent::ToolCall(_) => send(StreamEvent::Thinking(String::new())),
|
||||||
|
_ => {}
|
||||||
};
|
};
|
||||||
let tried_quick = quick.clone();
|
let tried_quick = quick.clone();
|
||||||
let mut attempt = 0;
|
let mut attempt = 0;
|
||||||
|
|
@ -5675,9 +5677,10 @@ echo '<meta charset=utf-8><title>done</title>送出了' > done.html; (setsid pyt
|
||||||
let job = smart_job(port, vec![Message::user("研究一下怎麼生圖")], None, Duration::from_secs(300), true);
|
let job = smart_job(port, vec![Message::user("研究一下怎麼生圖")], None, Duration::from_secs(300), true);
|
||||||
let (tx, rx) = channel();
|
let (tx, rx) = channel();
|
||||||
spawn(Job { direct: Arc::new(AtomicBool::new(true)), ..job }, 1, tx, Arc::new(AtomicBool::new(false)), eframe::egui::Context::default());
|
spawn(Job { direct: Arc::new(AtomicBool::new(true)), ..job }, 1, tx, Arc::new(AtomicBool::new(false)), eframe::egui::Context::default());
|
||||||
let (mut shown, mut results, mut nudged) = (vec![], vec![], false);
|
let (mut shown, mut results, mut nudged, mut quiet_output) = (vec![], vec![], false, false);
|
||||||
loop {
|
loop {
|
||||||
match rx.recv_timeout(Duration::from_secs(20)).expect("loop stalled") {
|
match rx.recv_timeout(Duration::from_secs(20)).expect("loop stalled") {
|
||||||
|
(_, StreamEvent::Thinking(t)) if t.is_empty() => quiet_output = true,
|
||||||
(_, StreamEvent::StepDone(m)) => shown.push((m.text.clone(), m.tool_calls.len())),
|
(_, StreamEvent::StepDone(m)) => shown.push((m.text.clone(), m.tool_calls.len())),
|
||||||
(_, StreamEvent::ToolResult(m)) => results.push(m.text.clone()),
|
(_, StreamEvent::ToolResult(m)) => results.push(m.text.clone()),
|
||||||
(_, StreamEvent::Retrying(w)) if w.contains("接著做") => nudged = true,
|
(_, StreamEvent::Retrying(w)) if w.contains("接著做") => nudged = true,
|
||||||
|
|
@ -5690,6 +5693,7 @@ echo '<meta charset=utf-8><title>done</title>送出了' > done.html; (setsid pyt
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assert!(nudged, "the person sees why it goes on");
|
assert!(nudged, "the person sees why it goes on");
|
||||||
|
assert!(quiet_output, "the quiet step's output still tells the watchdog it is answering");
|
||||||
assert_eq!(shown.len(), 3, "the announcement, the step, the answer: {shown:?}");
|
assert_eq!(shown.len(), 3, "the announcement, the step, the answer: {shown:?}");
|
||||||
assert_eq!(shown[1].1, 1, "the quiet step's call is shown with its step");
|
assert_eq!(shown[1].1, 1, "the quiet step's call is shown with its step");
|
||||||
assert!(results.iter().any(|r| r.contains("page-written")), "{results:?}");
|
assert!(results.iter().any(|r| r.contains("page-written")), "{results:?}");
|
||||||
|
|
|
||||||
|
|
@ -3040,9 +3040,11 @@ impl App {
|
||||||
live.produced = true;
|
live.produced = true;
|
||||||
live.status = None;
|
live.status = None;
|
||||||
}
|
}
|
||||||
|
// A new try (or a quiet step after a nudge): the first-response deadline again.
|
||||||
StreamEvent::Retrying(msg) => {
|
StreamEvent::Retrying(msg) => {
|
||||||
live.status = Some(msg.clone());
|
live.status = Some(msg.clone());
|
||||||
live.started = Instant::now();
|
live.started = Instant::now();
|
||||||
|
live.produced = false;
|
||||||
}
|
}
|
||||||
// A new model step gets the first-response deadline again.
|
// A new model step gets the first-response deadline again.
|
||||||
StreamEvent::NextStep(_) => {
|
StreamEvent::NextStep(_) => {
|
||||||
|
|
@ -6998,16 +7000,19 @@ impl eframe::App for App {
|
||||||
ctx.send_viewport_cmd(egui::ViewportCommand::Maximized(!zoomed));
|
ctx.send_viewport_cmd(egui::ViewportCommand::Maximized(!zoomed));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if self.mirror_waiting_at_door() {
|
// (At the door nothing is edited: before the brain's first answer an edit had nothing to
|
||||||
|
// be compared with and was dropped once it came.)
|
||||||
|
let at_door = self.mirror_waiting_at_door();
|
||||||
|
if at_door {
|
||||||
self.mirror_door(ui);
|
self.mirror_door(ui);
|
||||||
} else {
|
} else {
|
||||||
self.sidebar(ui);
|
self.sidebar(ui);
|
||||||
self.main_pane(ui);
|
self.main_pane(ui);
|
||||||
}
|
|
||||||
self.bot_editor(ctx);
|
self.bot_editor(ctx);
|
||||||
self.memory_page(ctx);
|
self.memory_page(ctx);
|
||||||
self.drops_page(ctx);
|
self.drops_page(ctx);
|
||||||
self.settings(ctx);
|
self.settings(ctx);
|
||||||
|
}
|
||||||
self.delete_dialog(ctx);
|
self.delete_dialog(ctx);
|
||||||
self.delete_routine_dialog(ctx);
|
self.delete_routine_dialog(ctx);
|
||||||
self.routines_window(ctx);
|
self.routines_window(ctx);
|
||||||
|
|
|
||||||
|
|
@ -434,7 +434,7 @@ pub enum Incoming {
|
||||||
File(String),
|
File(String),
|
||||||
/// A message that couldn't reach the brain however long it was tried: its words go back
|
/// A message that couldn't reach the brain however long it was tried: its words go back
|
||||||
/// into that bot's input (when the person hasn't typed something else there since).
|
/// into that bot's input (when the person hasn't typed something else there since).
|
||||||
Unsent { bot: u64, text: String },
|
Unsent { bot: u64, text: String, atts: Vec<crate::attach::Attachment> },
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Each message and chat action from this screen gets a name of its own (this screen's, then a
|
/// Each message and chat action from this screen gets a name of its own (this screen's, then a
|
||||||
|
|
@ -1215,10 +1215,11 @@ impl App {
|
||||||
self.mir.fetching.remove(&path);
|
self.mir.fetching.remove(&path);
|
||||||
self.att.thumbs.remove(&path);
|
self.att.thumbs.remove(&path);
|
||||||
}
|
}
|
||||||
Incoming::Unsent { bot, text } => {
|
Incoming::Unsent { bot, text, atts } => {
|
||||||
if self.drafts.get(&bot).is_none_or(|d| d.trim().is_empty()) {
|
// (Put before what was typed since, never in place of it.)
|
||||||
self.drafts.insert(bot, text);
|
let draft = self.drafts.entry(bot).or_default();
|
||||||
}
|
*draft = if draft.trim().is_empty() { text } else { format!("{text}\n{draft}") };
|
||||||
|
self.att.pending.entry(bot).or_default().extend(atts);
|
||||||
}
|
}
|
||||||
Incoming::Pull(v) => {
|
Incoming::Pull(v) => {
|
||||||
if let Some(e) = v["error"].as_str() {
|
if let Some(e) = v["error"].as_str() {
|
||||||
|
|
@ -1542,23 +1543,36 @@ impl App {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Out::Send { bot, id, text, atts, memories } => {
|
Out::Send { bot, id, text, atts, memories } => {
|
||||||
|
// The files first (each asked again while the line is down); one that can't
|
||||||
|
// go keeps the whole message here — words without their file would be a
|
||||||
|
// different message.
|
||||||
let mut paths = vec![];
|
let mut paths = vec![];
|
||||||
|
let mut failed = None;
|
||||||
for a in &atts {
|
for a in &atts {
|
||||||
match std::fs::read(&a.path).map_err(|e| format!("讀不到這個檔案({e})")).and_then(|b| remote::sync_upload(&s, bot, &a.name, &b)) {
|
match std::fs::read(&a.path).map_err(|e| format!("讀不到這個檔案({e})")).and_then(|b| remote::sync_upload_sure(&s, bot, &a.name, &b, &waiting)) {
|
||||||
Ok(p) => paths.push(p),
|
Ok(p) => paths.push(p),
|
||||||
Err(e) => *err.lock().unwrap() = format!("「{}」沒有傳到大腦:{e}", a.name),
|
Err(e) => {
|
||||||
|
failed = Some(format!("「{}」沒有傳到大腦:{e}", a.name));
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
let sent = match failed {
|
||||||
|
Some(e) => Err(e),
|
||||||
|
None => {
|
||||||
let mut body = json!({"bot": bot, "action": "send", "id": id, "text": text, "attachments": paths});
|
let mut body = json!({"bot": bot, "action": "send", "id": id, "text": text, "attachments": paths});
|
||||||
if let Some(m) = memories {
|
if let Some(m) = memories {
|
||||||
body["memories"] = json!(m);
|
body["memories"] = json!(m);
|
||||||
}
|
}
|
||||||
if let Err(e) = remote::sync_post_sure(&s, "act", &body, &waiting) {
|
remote::sync_post_sure(&s, "act", &body, &waiting).map(|_| ())
|
||||||
|
}
|
||||||
|
};
|
||||||
|
if let Err(e) = sent {
|
||||||
*err.lock().unwrap() = format!("訊息沒有送到大腦(已放回輸入框):{e}");
|
*err.lock().unwrap() = format!("訊息沒有送到大腦(已放回輸入框):{e}");
|
||||||
// Take back the message shown ahead of time; its words go back to the input.
|
// Take back the message shown ahead of time; its words and files go back to the input.
|
||||||
resync.store(true, Ordering::SeqCst);
|
resync.store(true, Ordering::SeqCst);
|
||||||
if let Some(tx) = &back {
|
if let Some(tx) = &back {
|
||||||
let _ = tx.send(Incoming::Unsent { bot, text: text.clone() });
|
let _ = tx.send(Incoming::Unsent { bot, text: text.clone(), atts: atts.clone() });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sending.fetch_sub(1, Ordering::AcqRel);
|
sending.fetch_sub(1, Ordering::AcqRel);
|
||||||
|
|
|
||||||
|
|
@ -382,7 +382,8 @@ fn brief_steps(turn: &[crate::model::Message]) -> Vec<(String, Option<crate::mod
|
||||||
use crate::model::Role;
|
use crate::model::Role;
|
||||||
let mut steps: Vec<(String, Option<crate::model::ToolCall>)> = vec![];
|
let mut steps: Vec<(String, Option<crate::model::ToolCall>)> = vec![];
|
||||||
for (i, m) in turn.iter().enumerate() {
|
for (i, m) in turn.iter().enumerate() {
|
||||||
if m.role == Role::User && i > 0 {
|
// (AnyBot's own nudges inside a turn are not the person's words.)
|
||||||
|
if m.role == Role::User && i > 0 && !crate::agent::only_in_turn(m) {
|
||||||
steps.push((format!("(使用者中途說:{})", cut(&m.text, 300)), None));
|
steps.push((format!("(使用者中途說:{})", cut(&m.text, 300)), None));
|
||||||
}
|
}
|
||||||
for c in &m.tool_calls {
|
for c in &m.tool_calls {
|
||||||
|
|
@ -1093,6 +1094,21 @@ pub fn api_write(state: &mut crate::model::State, b: &serde_json::Value) -> serd
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
/// AnyBot's own nudge inside a turn (說了就做) is not the person's words: the look back
|
||||||
|
/// lists only what they typed in between.
|
||||||
|
#[test]
|
||||||
|
fn a_nudge_is_not_the_person_talking() {
|
||||||
|
use crate::model::Message;
|
||||||
|
let turn = vec![
|
||||||
|
Message::user("研究一下"),
|
||||||
|
Message::assistant("我把它整理成一頁。", "x"),
|
||||||
|
Message { wake: true, ..Message::user("【AnyBot:你剛才說了接下來要做什麼,但那一則沒有呼叫任何工具…】") },
|
||||||
|
Message::user("順便看一下價格"),
|
||||||
|
];
|
||||||
|
let steps: Vec<String> = brief_steps(&turn).into_iter().map(|(s, _)| s).collect();
|
||||||
|
assert_eq!(steps, vec!["(使用者中途說:順便看一下價格)".to_string()], "{steps:?}");
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn anybots_own_problems_are_reported_apart_from_the_skill() {
|
fn anybots_own_problems_are_reported_apart_from_the_skill() {
|
||||||
let out = r#"{"save": true, "name": "Threads 回覆", "description": "回覆貼文", "instructions": "1. 開貼文", "replay": [], "tool_issues": ["browser_fill_contact 被誤用來打字", " ", "多行字只能用剪貼簿貼上"]}"#;
|
let out = r#"{"save": true, "name": "Threads 回覆", "description": "回覆貼文", "instructions": "1. 開貼文", "replay": [], "tool_issues": ["browser_fill_contact 被誤用來打字", " ", "多行字只能用剪貼簿貼上"]}"#;
|
||||||
|
|
|
||||||
|
|
@ -2684,11 +2684,21 @@ const SURE_TRY_SECS: u64 = 20;
|
||||||
/// for up to SURE_SECS. `waiting` is told before each new try. A refusal from the brain itself
|
/// for up to SURE_SECS. `waiting` is told before each new try. A refusal from the brain itself
|
||||||
/// (not the line) is answered at once.
|
/// (not the line) is answered at once.
|
||||||
pub fn sync_post_sure(s: &Settings, what: &str, body: &Value, waiting: &dyn Fn()) -> Result<Value, String> {
|
pub fn sync_post_sure(s: &Settings, what: &str, body: &Value, waiting: &dyn Fn()) -> Result<Value, String> {
|
||||||
let bytes = body.to_string();
|
post_sure(s, &format!("/{what}"), &[], body.to_string().as_bytes(), SURE_TRY_SECS, waiting)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// sync_upload, asked again while the line is down (a file sent twice is only a second copy at
|
||||||
|
/// the brain, never a second message).
|
||||||
|
pub fn sync_upload_sure(s: &Settings, bot: u64, name: &str, bytes: &[u8], waiting: &dyn Fn()) -> Result<String, String> {
|
||||||
|
let v = post_sure(s, &format!("/upload/{bot}"), &[("name", name.to_string())], bytes, 120, waiting)?;
|
||||||
|
v["path"].as_str().map(String::from).ok_or("大腦沒有收下檔案".into())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn post_sure(s: &Settings, rest: &str, query: &[(&str, String)], bytes: &[u8], try_secs: u64, waiting: &dyn Fn()) -> Result<Value, String> {
|
||||||
let until = Instant::now() + Duration::from_secs(SURE_SECS);
|
let until = Instant::now() + Duration::from_secs(SURE_SECS);
|
||||||
let mut wait = 500u64;
|
let mut wait = 500u64;
|
||||||
loop {
|
loop {
|
||||||
let r = to_brain_any(s, "POST", &format!("/{what}"), &[], bytes.as_bytes(), SURE_TRY_SECS);
|
let r = to_brain_any(s, "POST", rest, query, bytes, try_secs);
|
||||||
// (502–504: the account server couldn't reach the brain, or gave up waiting for it.)
|
// (502–504: the account server couldn't reach the brain, or gave up waiting for it.)
|
||||||
let again = match &r {
|
let again = match &r {
|
||||||
Err(_) => true,
|
Err(_) => true,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue