diff --git a/docs/feature-map/connectors.md b/docs/feature-map/connectors.md index 2beb0c5..68a889c 100644 --- a/docs/feature-map/connectors.md +++ b/docs/feature-map/connectors.md @@ -8,7 +8,7 @@ - 登入帳號(OAuth):遠端連接器回「要先登入」時,到那個連接器自己的頁按「登入」(只在大腦本機),或在聊天請 Bot 登入:瀏覽器打開登入頁,登入完自動接上;瀏覽器在別台電腦、登入後那頁打不開時,把那頁網址貼回聊天。Token 存在大腦、加密,不會同步到螢幕或手機;快到期自動換新,401 時換一次再試。 - 帳號、密碼:給要用帳號密碼登入的伺服器。在指令、環境變數、網址或標頭寫「{username}」「{password}」,就填在那裡;都沒寫時,本機伺服器收到環境變數 `MCP_USERNAME`、`MCP_PASSWORD`,遠端伺服器收到 Basic 驗證。 - 「給 Bot 的使用說明」:寫進 Bot 的系統指示(例如「查詢客戶資料時先用 search_customers」)。 -- 頁面跟其他 App 的設定一樣是「清單+各自的頁」:最上面一張小卡「連接器(MCP)」和兩個按鈕「瀏覽市集」「新增連接器」;下面「已加入」每個連接器一列,只有名稱、色點和狀態(「已連上,N 個工具」「連線中…」「未連線」「已關閉」或紅字錯誤原因)、開關和 ›。按那一列(開關以外的地方)進到它自己的頁:最上面名稱、狀態、「登入」(遠端的)「重新連線」和開關(下面一行是登入或改名沒成功的原因);接著「工具(N)」列它自己的工具(名字和一行說明,滑過看全文;超過 8 個有「搜尋工具」;連上之後才有);再下面「設定」卡是它的欄位(名稱、指令或網址、環境變數、標頭、帳號和密碼並排、給 Bot 的使用說明——每個欄位名稱都在輸入框上面;名稱打完按 Enter、離開欄位或離開這一頁才改,Esc 放回原來的;空白或跟別的連接器同名不改並說原因;改名後登入、「一律允許」、金鑰、密碼和在清單裡的位置都留著;在螢幕電腦上改名是請大腦改它自己那一個,新名字等大腦更新回來才出現,連不到大腦時不改;手機和 Bot 的 `manage_connectors` 不能改名);最下面紅字「移除這個連接器」,再按「確定移除」才移除。左上「‹ 連接器」回清單。不再有把所有連接器的工具攤在一起的「可以用的工具」。「新增連接器」是它自己的頁(同樣的欄位,名稱在上、框在下),按「新增」後直接到新連接器的頁看它連線。 +- 頁面跟其他 App 的設定一樣是「清單+各自的頁」:最上面一張小卡「連接器(MCP)」和兩個按鈕「瀏覽市集」「新增連接器」;下面「已加入」每個連接器一列,只有名稱、色點和狀態(「已連上,N 個工具」「連線中…」「未連線」「已關閉」或紅字錯誤原因)、開關和 ›。按那一列(開關以外的地方)進到它自己的頁:最上面名稱、狀態、「登入」(遠端的)「重新連線」和開關(下面一行是登入或改名沒成功的原因);接著「工具(N)」列它自己的工具(名字和一行說明,滑過看全文;超過 8 個有「搜尋工具」;連上之後才有);再下面「設定」卡是它的欄位(名稱、指令或網址、環境變數、標頭、帳號和密碼並排、給 Bot 的使用說明——每個欄位名稱都在輸入框上面;名稱打完按 Enter、離開欄位或離開這一頁才改,Esc 放回原來的;空白或跟別的連接器同名不改並說原因;改名後登入、「一律允許」、金鑰、密碼和在清單裡的位置都留著;在螢幕電腦上改名是請大腦改它自己那一個,新名字等大腦更新回來才出現(等的時候寫「正在請大腦改名…」、欄位暫時不能改),連不到大腦時不改;移除連接器時它的「一律允許」也一起刪;手機和 Bot 的 `manage_connectors` 不能改名);最下面紅字「移除這個連接器」,再按「確定移除」才移除。左上「‹ 連接器」回清單。不再有把所有連接器的工具攤在一起的「可以用的工具」。「新增連接器」是它自己的頁(同樣的欄位,名稱在上、框在下),按「新增」後直接到新連接器的頁看它連線。 - 「瀏覽市集」頁的「連接器市集」:8 個常用的(files、memory、thinking、fetch、git、time、playwright、github),按「加入」就能用;要金鑰的(github)會打開「新增連接器」頁並填好,補上 Token 再按「新增」。 - 同一頁的「公用市集(官方 MCP Registry)」:搜尋用網址連的連接器,按「加入」會打開填好的「新增連接器」頁;還有「{…}」沒換成你的值時,按不下「新增」。 - 給 Bot 的方式:所有連接器加起來 20 個工具以內,每個工具直接給,名字是 `mcp__連接器__工具`;超過 20 個,只給 `find_connector_tool` 和 `use_connector_tool`。 diff --git a/docs/feature-map/safety.md b/docs/feature-map/safety.md index bce967f..d9b7000 100644 --- a/docs/feature-map/safety.md +++ b/docs/feature-map/safety.md @@ -4,7 +4,7 @@ Bot 要動到你的電腦、對外送出或做收不回來的事時,先問你 ## 子功能 -- 允許請求:黃色卡片停在輸入框上方,「允許 {Bot} {動作}嗎?」加細節框。按鈕:「允許」、「一律允許{類別}」(有能記住的類別才有)、「拒絕」。電腦工具沒開、或「在這台電腦上執行」沒開時,一律允許的按鈕就是「一律允許」,會打開什麼寫在滑過的說明裡。輸入框空著時 Enter 允許、Esc 拒絕——設定視窗開著、或游標在別的輸入框(連接器名稱、搜尋框…)時不算,那裡的 Enter 不會替你按允許。 +- 允許請求:黃色卡片停在輸入框上方,「允許 {Bot} {動作}嗎?」加細節框。按鈕:「允許」、「一律允許{類別}」(有能記住的類別才有)、「拒絕」。電腦工具沒開、或「在這台電腦上執行」沒開時,一律允許的按鈕就是「一律允許」,會打開什麼寫在滑過的說明裡。輸入框空著時 Enter 允許、Esc 拒絕——有任何對話框開著(設定、Bot 設定、記憶、檔案或頁面…)、或游標在別的輸入框時不算,那裡的 Enter/Esc 不會替你回答卡片(Esc 照樣關對話框)。 - 允許卡片:一句「它想在你的電腦上執行:」+指令,三個按鈕「允許」「一律允許」(滑過說明它會打開什麼)「拒絕」;下面一行灰字「之後都直接操作,不再一個個問」:允許這一筆並打開直接操作(還沒開、管理員沒鎖時才有)。等你的卡片(允許、問題、交給你處理)都是同一種黃:淡黃底、細黃框。 - 一律允許記在那個 Bot 身上(例如「修改檔案」、「npm install」、某個連接器),Bot 設定 ›「電腦操作」的「已設定「一律允許」」看得到,按 × 移除。 - 拒絕後停下:同一輪裡 Bot 再提一模一樣的操作(同一個工具、同樣的參數),直接替你拒絕、不再問,直到你再傳一則訊息(工作中插話也算)。按停止、關視窗不算拒絕。 diff --git a/src/app.rs b/src/app.rs index 35f7749..c03730a 100644 --- a/src/app.rs +++ b/src/app.rs @@ -3978,16 +3978,18 @@ impl App { }); }); ui.add_space(6.0); - // Enter / Esc answer this card only while nothing else is being typed in: not with the - // settings open over it, nor with the caret in another field (a connector's name, a - // search) — an Enter there used to say yes to whatever the bot was waiting on. + // Enter / Esc answer this card only while nothing else is being typed in: not with any + // dialog open over it (settings, Bot 設定, 記憶, a page or file…: a button pressed there + // leaves no caret, and Enter said yes behind it, Esc said no instead of closing it), nor + // with the caret in another field (a connector's name, a search). // (Where the caret was as this frame began: a field that takes the Enter first lets go // of the caret before this card looks, so the last frame's is what counts.) let composer = egui::Id::unique(("composer", bot.id)); let seen = egui::Id::unique("approval-dock-caret"); let before: Option = ctx.data(|d| d.get_temp(seen)).flatten(); let elsewhere = before.or_else(|| ctx.memory(|m| m.focused())).is_some_and(|f| f != composer); - if answer.is_none() && draft_empty && !typing && !elsewhere && !self.show_settings && shown > 0.6 && !egui::Popup::is_any_open(ctx) { + let dialog_open = self.show_settings || ctx.memory(|m| m.top_modal_layer()).is_some(); + if answer.is_none() && draft_empty && !typing && !elsewhere && !dialog_open && shown > 0.6 && !egui::Popup::is_any_open(ctx) { let (pressed, _) = ui.input_mut(chat_ui::take_enter); if enter || pressed { answer = Some(ApprovalAnswer::Once); @@ -4101,7 +4103,8 @@ impl App { // A question with nothing to click starts with the caret in its field — not while the // settings are open over it (it took the caret from whatever was being typed there); // it gets it once they close. - if q.options.is_empty() && !self.show_settings && self.ask_focus.as_ref() != Some(&(call_id.clone(), step)) { + let dialog_open = self.show_settings || ui.ctx().memory(|m| m.top_modal_layer()).is_some(); + if q.options.is_empty() && !dialog_open && self.ask_focus.as_ref() != Some(&(call_id.clone(), step)) { self.ask_focus = Some((call_id.clone(), step)); field.request_focus(); } @@ -7915,6 +7918,19 @@ mod tests { frame(&mut app, vec![], false); frame(&mut app, vec![enter], false); assert!(got.try_recv().is_err(), "an Enter with the settings open isn't a yes"); + // Another dialog over the chat (Bot 設定, 記憶…), nothing focused in it: no yes, no no. + app.show_settings = false; + let modal_frame = |app: &mut super::App, events: Vec| { + let mut out = ctx.run_ui(egui::RawInput { events, ..Default::default() }, |ui| { + app.composer(ui, &ctx, &bot); + egui::Modal::new(egui::Id::unique("some-dialog")).show(ui.ctx(), |ui| ui.label("Bot 設定")); + }); + out.textures_delta.clear(); + }; + modal_frame(&mut app, vec![]); + modal_frame(&mut app, vec![egui::Event::Key { key: Key::Enter, physical_key: None, pressed: true, repeat: false, modifiers: egui::Modifiers::NONE }]); + modal_frame(&mut app, vec![egui::Event::Key { key: Key::Escape, physical_key: None, pressed: true, repeat: false, modifiers: egui::Modifiers::NONE }]); + assert!(got.try_recv().is_err(), "keys in another dialog don't answer the card"); } /// Enter in an empty box with a step waiting for a yes is the yes. (The box took the Enter diff --git a/src/app/channels_ui.rs b/src/app/channels_ui.rs index c0d8254..9468fe6 100644 --- a/src/app/channels_ui.rs +++ b/src/app/channels_ui.rs @@ -513,6 +513,7 @@ impl App { crate::mcp::Change::Remove(s) => { crate::mcp::forget(&s.name); let _ = crate::mcp_oauth::logout(&s.name); + self.forget_mcp_grants(&s.name); } // (Logged out: the link that still carries the token goes too.) crate::mcp::Change::Logout(n) => self.mcp_reconnect(n), @@ -739,6 +740,14 @@ impl App { } } + /// A connector removed: its 「一律允許」 go too — a later one given its name doesn't get them. + pub(super) fn forget_mcp_grants(&mut self, name: &str) { + let grant = format!("mcp:{name}"); + for b in &mut self.state.bots { + b.allow_rules.retain(|r| *r != grant); + } + } + /// The connectors' state as this window shows it (on a screen, the brain's; in a screenshot /// or the layout audit, a made-up one marked `demo`). fn mcp_view(&self, tools: bool) -> serde_json::Value { @@ -845,7 +854,11 @@ impl App { } // (Renamed on a screen: until the brain's update brings the new name, it is the old one.) let renaming = self.ch.mcp_renaming.as_ref().filter(|r| r.1 == name && r.2.elapsed() < std::time::Duration::from_secs(30)).map(|r| r.0.clone()); - let Some(i) = self.state.mcp_servers.iter().position(|s| s.name == name).or_else(|| renaming.and_then(|old| self.state.mcp_servers.iter().position(|s| s.name == old))) else { + let exact = self.state.mcp_servers.iter().position(|s| s.name == name); + // (Still under its old name: the brain hasn't sent the new one yet. Its fields wait — + // an edit now would name a connector the brain no longer has.) + let waiting = exact.is_none(); + let Some(i) = exact.or_else(|| renaming.and_then(|old| self.state.mcp_servers.iter().position(|s| s.name == old))) else { self.ch.mcp_page = Page::List; return; }; @@ -911,7 +924,10 @@ impl App { let mut done = false; let mut name_field = None; section(ui, "設定", p); - setting_card(ui, p, |ui| { + if waiting { + hint(ui, "正在請大腦改名…", p); + } + ui.add_enabled_ui(!waiting, |ui| setting_card(ui, p, |ui| { let s = &mut self.state.mcp_servers[i]; let draft = self.ch.mcp_name.get_or_insert_with(|| (name.to_string(), name.to_string())); if draft.0 != name { @@ -977,7 +993,7 @@ impl App { form_row(ui, "給 Bot 的使用說明(選填)", p, |ui| { ui.add(egui::TextEdit::multiline(&mut s.instructions).id_salt(("mcp-field", "instructions")).desired_rows(1).desired_width(ui.available_width()).hint_text(t("例如:查詢客戶資料時先用 search_customers"))); }); - }); + })); // (Renamed: the page follows it.) self.ch.name_field = name_field; if done { @@ -1002,6 +1018,7 @@ impl App { if remove { let gone = self.state.mcp_servers.remove(i); let _ = crate::mcp_oauth::logout(&gone.name); + self.forget_mcp_grants(&gone.name); self.ch.mcp_note.lock().unwrap().clear(); self.ch.mcp_name = None; self.ch.mcp_page = Page::List; diff --git a/src/app/remote_ui.rs b/src/app/remote_ui.rs index 7f4dd67..d85906d 100644 --- a/src/app/remote_ui.rs +++ b/src/app/remote_ui.rs @@ -1610,6 +1610,7 @@ impl App { // (mcp_poll connects or drops it when the list changes.) if b["remove"].as_bool().unwrap_or(false) { self.state.mcp_servers.retain(|m| m.name != name); + self.forget_mcp_grants(&name); } else if let Some(m) = self.state.mcp_servers.iter_mut().find(|m| m.name == name) { m.enabled = b["enabled"].as_bool().unwrap_or(m.enabled); } @@ -2006,6 +2007,9 @@ mod phone_act_tests { assert!(app.phone_act(&ctx, "mcp", &json!({"name": new, "rename": bad}), "owner")["error"].is_string(), "{bad:?}"); } assert!(app.phone_act(&ctx, "mcp", &json!({"name": new, "rename": "y"}), "admin")["error"].is_string(), "the owner's only"); + // Removed: its 「一律允許」 go with it (one given its name later starts from nothing). + assert_eq!(app.phone_act(&ctx, "mcp", &json!({"name": new, "remove": true}), "owner")["ok"], true); + assert!(!app.state.bots[0].allow_rules.iter().any(|r| r.starts_with("mcp:gh-"))); let _ = crate::mcp_oauth::logout(&new); } diff --git a/src/i18n_table.rs b/src/i18n_table.rs index 382dec5..7f019f6 100644 --- a/src/i18n_table.rs +++ b/src/i18n_table.rs @@ -749,6 +749,7 @@ pub const ROWS: &[(&str, &str, &str)] = &[ ("關著:不列進任何 Bot 的說明", "Off: not given to any bot", "オフ:どの Bot にも渡されません"), ("接上 Model Context Protocol 伺服器,Bot 就能用它的工具(例如 GitHub、Notion、資料庫、你公司的內部系統)。本機伺服器填指令(例如 npx -y @modelcontextprotocol/server-filesystem ~/Documents);遠端伺服器填網址(Streamable HTTP),需要時加上 Authorization 標頭。", "Connect Model Context Protocol servers and bots can use their tools (GitHub, Notion, databases, your company's own systems). A local server takes a command (e.g. npx -y @modelcontextprotocol/server-filesystem ~/Documents); a remote one an address (Streamable HTTP), with an Authorization header if needed.", "Model Context Protocol サーバーを接続すると、Bot がそのツールを使えます(GitHub、Notion、データベース、社内システムなど)。ローカルのサーバーはコマンド(例:npx -y @modelcontextprotocol/server-filesystem ~/Documents)、リモートのサーバーはアドレス(Streamable HTTP)を入力し、必要なら Authorization ヘッダーを付けます。"), ("開著的技能會列在 Bot 的目錄裡,需要時自動載入。", "Skills that are on are listed in the bots' catalog and loaded when needed.", "オンのスキルは Bot のカタログに載り、必要なときに読み込まれます。"), + ("正在請大腦改名…", "Asking the brain to rename it…", "ブレインに名前の変更を依頼しています…"), ("連不到大腦,名稱沒有改。", "Can't reach the brain; the name wasn't changed.", "ブレインに接続できないため、名前は変更していません。"), ("這個連接器已經被改名或移除了,名稱沒有改。", "This connector was renamed or removed meanwhile; the name wasn't changed.", "このコネクタは別の場所で名前変更または削除されたため、名前は変更していません。"), ("名稱不能空白,沒有改。", "A name can't be empty; it wasn't changed.", "名前は空にできません。変更していません。"),