fix: AnyBot 瀏覽器的步驟也照你的「一律詢問」和自動審核——樣式規則一律比對,直接操作不再略過
InBotsBrowser(AnyBot 自己的瀏覽器、web_fetch)從來不經自動審核,所以: - `tool(browser_click)`、`web(domain:…)` 這些樣式規則對 AnyBot 瀏覽器完全沒作用(地圖拿它們當例子); - 直接操作時,本機或內部網路的網址、從別台電腦上傳檔案直接做,連「一律詢問」都不看; - 「一律允許」過的本機網址(browser:private)也不看規則。 修好前的證據:an_ask_pattern_stops_the_bots_browser、private_pages_and_uploads_go_through_the_persons_rules 在舊程式失敗(點擊、開網址、web_fetch 都直接跑;一律允許過的內部網址沒問)。測試用帳號裡別台電腦的 瀏覽器(連不到就失敗)和 web_fetch 本機網址(本來就擋),舊程式也不會在這台開真的瀏覽器。 修法(steps.rs 的 InBotsBrowser,跟連接器同一套): - 安全規則先(中繼資料、鎖定時的本機網址),再比對「一律詢問」樣式(ask_pattern:只比對、不問模型)—— 本來不用問、一律允許過的瀏覽器步驟和 web_fetch 也比;符合就一張卡寫那條規則、沒有「一律允許」, 按了允許就不再跳下面那張。 - 本來就要問的(本機網址、上傳:這台的工作資料夾外、別台電腦的檔案)交給 reviewed():自動審核的 允許樣式不跳卡片(結果最後寫「自動審核:符合…」),話寫的規則給審核員看;直接操作只看「一律詢問」 (以前直接跳過)。一律允許過的不再給審核員看,跟連接器一樣。 - 不用問的步驟不給審核員看:點一下不會多等一次模型。 - 卡片沒有電腦名稱時不再寫「(在 上)」。 地圖:browser 加真的步驟「照你的「一律詢問」」(樣式卡、web_fetch 也問、內部網址給審核員看, 全部拒絕、沒開瀏覽器)和陷阱;autonomy、safety、FEATURES 第 16 節、SECURITY 照實寫。 沒碰 src/botbrowser.rs、src/remote.rs(loosens_guard 沒碰);tool_specs_are_locked、 approval_decisions_are_characterized 沒有 diff。 已驗證: 全部 cargo test(不帶金鑰、DOCKER_HOST 指到不存在)682 通過,含新的 an_ask_pattern_stops_the_bots_browser、 private_pages_and_uploads_go_through_the_persons_rules、the_bots_browser_is_not_held_up_by_rules_about_other_things; clippy -D warnings、lint-sh、verify-approval-routing run.sh --replay(跟基準一樣); verify-anybot:browser 每一步可跑的照 md 原文冷跑全過(target/verify-anybot/20261118-192608: 「在瀏覽器打開 http://127.0.0.1:9/(符合你的「一律詢問」規則:web(domain:127.0.0.1))」只有允許/拒絕, web_fetch 也問,192.168.1.5 先給審核員看,全部 denied、沒開瀏覽器),autonomy 也全過(-192347) 未驗證: 直接操作那一半的實機(區網的手機打不開,靠 agent 測試);真的開網頁、點、上傳(scratch 沒有 Docker, 在這台開會出現真的瀏覽器);動到瀏覽器那條路要人跑的 --ignored 實機測試(沒跑): agent::tests::{a_brain_without_chrome_browses_on_its_box, a_finished_job_closes_its_tabs, the_box_browser_uses_the_box_disk, the_words_on_a_form_reach_its_controls, two_jobs_keep_to_their_own_tabs}、 botbrowser::tests::{a_finished_job_quits_its_chrome, a_finished_job_quits_its_firefox, a_persons_firefox_profile, reads_a_real_page}、 browser::tests::{a_send_is_seen_with_the_post_it_answers_and_its_own_address, drives_a_dashboard, lines_go_in_whole_and_numbers_stay_put, numbers_controls_inside_web_components} 未簽: 審批路徑、瀏覽器——要人類跑 --ignored 並簽名才能合併,沒有合併、沒有推 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Uirha5sXAsDLzxz6UZJgoC
This commit is contained in:
parent
3e1f960488
commit
4303646e51
|
|
@ -803,7 +803,7 @@ AnyBot 是一個桌面聊天 App,介面和運作方式照 Grok Bot 重做。
|
||||||
0. **不需要許可的**
|
0. **不需要許可的**
|
||||||
- App 操作工具(第 26 節),只有「刪除例行任務」會先問。
|
- App 操作工具(第 26 節),只有「刪除例行任務」會先問。
|
||||||
- 讀公開網頁。
|
- 讀公開網頁。
|
||||||
- AnyBot 自己的瀏覽器。
|
- AnyBot 自己的瀏覽器——但自動審核開著時,符合樣式的「一律詢問」(`tool(browser_click)`、`web(domain:…)`,`web_fetch` 也算)照樣問、沒有「一律允許」(只比對,不問模型);要問的那幾步(本機或內部網路的網址、上傳檔案)照第 7 步交給自動審核或直接操作,直接操作時「一律詢問」照樣擋(以前瀏覽器完全不經自動審核,直接操作連本機網址都不看規則)。
|
||||||
1. **決定在哪台電腦做**
|
1. **決定在哪台電腦做**
|
||||||
- 操作螢幕和讀你自己的瀏覽器:一律在「你的電腦」。
|
- 操作螢幕和讀你自己的瀏覽器:一律在「你的電腦」。
|
||||||
- 其他工具:用 Bot 指定的電腦,沒指定就用預設電腦。
|
- 其他工具:用 Bot 指定的電腦,沒指定就用預設電腦。
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@ AnyBot 的 privacy 模型一句话:**Bot 跑在你自己的機器上,你的
|
||||||
- gVisor 是加分不是標配:純 Docker 的 box 與主機共享核心。
|
- gVisor 是加分不是標配:純 Docker 的 box 與主機共享核心。
|
||||||
- 備份安全性以你的帳號密碼強度為上限。
|
- 備份安全性以你的帳號密碼強度為上限。
|
||||||
- relay 是自架元件:它被攻破時洩露的是雜湊、session 清單與備份密文,不是明文。
|
- relay 是自架元件:它被攻破時洩露的是雜湊、session 清單與備份密文,不是明文。
|
||||||
- 「一律允許」過的連接器只再比對**固定樣式**的「一律詢問」(`connector(slack__post_message)` 這種,不問模型):用一般的話寫的規則——包括直接操作填的三條預設(刪除、付款、用我的帳號發文或傳訊息)——擋不住它。
|
- 「一律允許」過的連接器、AnyBot 瀏覽器本來不用問的步驟,只再比對**固定樣式**的「一律詢問」(`connector(slack__post_message)`、`tool(browser_click)`、`web(domain:…)` 這種,不問模型):用一般的話寫的規則——包括直接操作填的三條預設(刪除、付款、用我的帳號發文或傳訊息)——擋不住它們。
|
||||||
|
|
||||||
## 硬化建議
|
## 硬化建議
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,9 @@
|
||||||
|
|
||||||
- `autonomy-direct` 直接操作:打開時一次做完——打開「在這台電腦上執行」、自動審核、所有 Bot 的電腦工具;「一律詢問」規則是空的就填三條預設(刪除檔案或資料夾/付款、購買或轉帳/用我的帳號發文、留言,或傳訊息給別人);進行中的工作下一步起不再問;別的 Bot 在等的「可以用電腦嗎」自動允許。
|
- `autonomy-direct` 直接操作:打開時一次做完——打開「在這台電腦上執行」、自動審核、所有 Bot 的電腦工具;「一律詢問」規則是空的就填三條預設(刪除檔案或資料夾/付款、購買或轉帳/用我的帳號發文、留言,或傳訊息給別人);進行中的工作下一步起不再問;別的 Bot 在等的「可以用電腦嗎」自動允許。
|
||||||
- `autonomy-yolo` 一律放行(/always-approve,也可以打 /yolo):你自己打的指令,一把全開——打開直接操作,之後所有 Bot 要等「允許」的都自動允許,連直接操作還會問的也不問,自動審核也略過。仍然擋:安全規則一律拒絕的;別人傳來的訊息(訊息管道、團隊成員)那一輪照樣等你按;問題卡、「需要處理」和 /plan 的計畫卡照樣等你。打開時已經在等的卡片(你自己的)一起放行。開著時每個聊天的輸入框上方、臉的同一行右邊有一個紅色閃電圖示(不另外佔一行;新對話沒有臉時自己一小行):滑過去看「一律放行 · Bot 做事不再問你」和還會擋什麼,點一下有「關閉一律放行」。「/always-approve off」關掉:要核准的又會問;直接操作是它順手打開的就一起關,本來就開著的留著。「/always-approve status」看現在是不是。管理員鎖了直接操作或「在這台電腦上執行」就打不開。
|
- `autonomy-yolo` 一律放行(/always-approve,也可以打 /yolo):你自己打的指令,一把全開——打開直接操作,之後所有 Bot 要等「允許」的都自動允許,連直接操作還會問的也不問,自動審核也略過。仍然擋:安全規則一律拒絕的;別人傳來的訊息(訊息管道、團隊成員)那一輪照樣等你按;問題卡、「需要處理」和 /plan 的計畫卡照樣等你。打開時已經在等的卡片(你自己的)一起放行。開著時每個聊天的輸入框上方、臉的同一行右邊有一個紅色閃電圖示(不另外佔一行;新對話沒有臉時自己一小行):滑過去看「一律放行 · Bot 做事不再問你」和還會擋什麼,點一下有「關閉一律放行」。「/always-approve off」關掉:要核准的又會問;直接操作是它順手打開的就一起關,本來就開著的留著。「/always-approve status」看現在是不是。管理員鎖了直接操作或「在這台電腦上執行」就打不開。
|
||||||
- `autonomy-still-asks` 直接操作仍會問或擋:安全規則擋的;符合「一律詢問」規則的(連接器的工具也算;「一律允許」過的連接器只比對樣式);畫面上目標寫著付款、傳送、刪除這類字的點擊;用「郵件」「訊息」寄送(「訊息」開了「無需詢問直接傳送」除外);沙盒外的 AppleScript(選「一律允許」前);打電話、傳簡訊、在 X 發文;用保險庫的卡片。問題卡和「需要處理」也照樣等你。
|
- `autonomy-still-asks` 直接操作仍會問或擋:安全規則擋的;符合「一律詢問」規則的(連接器的工具、AnyBot 瀏覽器開本機網址和上傳也算;「一律允許」過的只比對樣式);畫面上目標寫著付款、傳送、刪除這類字的點擊;用「郵件」「訊息」寄送(「訊息」開了「無需詢問直接傳送」除外);沙盒外的 AppleScript(選「一律允許」前);打電話、傳簡訊、在 X 發文;用保險庫的卡片。問題卡和「需要處理」也照樣等你。
|
||||||
- `autonomy-review` 自動審核:兩組用一般的話寫的規則「無需詢問直接允許」「一律詢問」,由這個 Bot 的模型判斷,兩邊都符合時「一律詢問」優先。符合允許就直接做;符合詢問就問你,而且沒有「一律允許」;都不符合照常問;審核沒回應就先問你。連接器的工具也經過它,「一律允許」過的除外。
|
- `autonomy-review` 自動審核:兩組用一般的話寫的規則「無需詢問直接允許」「一律詢問」,由這個 Bot 的模型判斷,兩邊都符合時「一律詢問」優先。符合允許就直接做;符合詢問就問你,而且沒有「一律允許」;都不符合照常問;審核沒回應就先問你。連接器的工具、AnyBot 瀏覽器要問的步驟(本機網址、上傳)也經過它,「一律允許」過的除外。
|
||||||
- `autonomy-patterns` 固定樣式的規則:規則也可以寫成 `shell(git *)`(指令;允許要 `a && b` 每一段都符合,詢問只要一段)、`file(~/Projects/**)`(檔案或資料夾,** 任何層、* 一層)、`connector(gitlab__*)`(連接器的工具)、`web(domain:example.com)`(那個網站和它底下的網址)、`tool(browser_click)`(工具的名字)。樣式先判斷、每次一樣、不呼叫模型:要問的步驟和連接器的工具(「一律允許」過也一樣)符合「一律詢問」的樣式一定問(模型說允許也沒用);指令、檔案不用問或「一律允許」過的不比對;符合允許的樣式就允許,但用一般的話寫的「一律詢問」還是會先讓模型看一次;有藏起來的指令($()、反引號)的,樣式不會允許。`connector(…)` 對不上任何連接器的工具時,新增的地方會說。
|
- `autonomy-patterns` 固定樣式的規則:規則也可以寫成 `shell(git *)`(指令;允許要 `a && b` 每一段都符合,詢問只要一段)、`file(~/Projects/**)`(檔案或資料夾,** 任何層、* 一層)、`connector(gitlab__*)`(連接器的工具)、`web(domain:example.com)`(那個網站和它底下的網址)、`tool(browser_click)`(工具的名字)。樣式先判斷、每次一樣、不呼叫模型:要問的步驟、連接器的工具、AnyBot 瀏覽器的步驟和 `web_fetch`(「一律允許」過、本來不用問的也一樣)符合「一律詢問」的樣式一定問(模型說允許也沒用);指令、檔案不用問或「一律允許」過的不比對;符合允許的樣式就允許,但用一般的話寫的「一律詢問」還是會先讓模型看一次;有藏起來的指令($()、反引號)的,樣式不會允許。`connector(…)` 對不上任何連接器的工具時,新增的地方會說。
|
||||||
- `autonomy-hooks` Hooks:使用者(和管理員)自己的程式,AnyBot 在固定的時間點跑它們,格式跟 Claude Code 一樣(hooks.json)。PreToolUse 可以擋下一步(exit 2 或 deny)、改參數、要先問或省掉一次詢問(但擋不過安全規則,也省不掉付款/傳送/刪除這類每次問);PostToolUse 改 Bot 讀到的結果或加一句;UserPromptSubmit、SessionStart 補資訊給模型或擋下這一輪;Stop 叫它多做(一輪最多 3 次);Notification 跟著通知跑。hook 自己出錯(結束碼不對、逾時、JSON 看不懂)就當它不在,紀錄檔寫原因。
|
- `autonomy-hooks` Hooks:使用者(和管理員)自己的程式,AnyBot 在固定的時間點跑它們,格式跟 Claude Code 一樣(hooks.json)。PreToolUse 可以擋下一步(exit 2 或 deny)、改參數、要先問或省掉一次詢問(但擋不過安全規則,也省不掉付款/傳送/刪除這類每次問);PostToolUse 改 Bot 讀到的結果或加一句;UserPromptSubmit、SessionStart 補資訊給模型或擋下這一輪;Stop 叫它多做(一輪最多 3 次);Notification 跟著通知跑。hook 自己出錯(結束碼不對、逾時、JSON 看不懂)就當它不在,紀錄檔寫原因。
|
||||||
- `autonomy-remote` 從手機打開:直接連線(同一個網路)的手機關得掉,但打不開直接操作、新增不了「無需詢問直接允許」規則和連接器(「這項設定會讓 Bot 不用問就動手,不能從區網連線…打開」);要在電腦上的 AnyBot,或用帳號連線。
|
- `autonomy-remote` 從手機打開:直接連線(同一個網路)的手機關得掉,但打不開直接操作、新增不了「無需詢問直接允許」規則和連接器(「這項設定會讓 Bot 不用問就動手,不能從區網連線…打開」);要在電腦上的 AnyBot,或用帳號連線。
|
||||||
|
|
||||||
|
|
@ -32,8 +32,8 @@
|
||||||
- **看狀態、關掉**(covers `autonomy-yolo`):打「/always-approve status」「/always-approve off」,再請它改名。指令:`$CTL phone send '/always-approve status' && $CTL phone wait-text '現在是一律放行' --in '#msgs' && $CTL phone send '/always-approve off' && $CTL phone wait-text '已關閉一律放行' --in '#msgs' && $CTL wait-api /api/settings '.direct_mode == false' && $CTL phone send '再改 [[call update_bot {"name":"關掉後的名字"}]]' && $CTL phone click '#ask button[data-a="reject"]' && $CTL phone wait-text '使用者拒絕了這個操作' --in '#msgs'`。看到:「現在是一律放行…」「已關閉一律放行:…「直接操作」也關了」;改名又跳卡片。
|
- **看狀態、關掉**(covers `autonomy-yolo`):打「/always-approve status」「/always-approve off」,再請它改名。指令:`$CTL phone send '/always-approve status' && $CTL phone wait-text '現在是一律放行' --in '#msgs' && $CTL phone send '/always-approve off' && $CTL phone wait-text '已關閉一律放行' --in '#msgs' && $CTL wait-api /api/settings '.direct_mode == false' && $CTL phone send '再改 [[call update_bot {"name":"關掉後的名字"}]]' && $CTL phone click '#ask button[data-a="reject"]' && $CTL phone wait-text '使用者拒絕了這個操作' --in '#msgs'`。看到:「現在是一律放行…」「已關閉一律放行:…「直接操作」也關了」;改名又跳卡片。
|
||||||
- **手機打不開直接操作**(covers `autonomy-remote`、`autonomy-direct`、`autonomy-review`):重新整理,帳戶選單 › 設定 › 權限,按「直接操作」。指令:`$CTL phone open --listed && $CTL phone click '#b-me' && $CTL phone click '#sheet-in .opt' --text 設定 && $CTL phone click '[data-go="perms"]' && $CTL phone wait-text '刪除檔案或資料夾' && $CTL phone click 'label.sw:has([data-sset="direct_mode"])' && $CTL phone click '#sheet-in .opt' --text 打開 && $CTL phone wait-text '不能從區網連線' && $CTL phone shot autonomy-perms && $CTL wait-api /api/settings '.direct_mode == false'`。看到:「一律詢問(優先)」裡三條預設規則;按開關、確認「打開」後跳出「這項設定會讓 Bot 不用問就動手,不能從區網連線…」,直接操作還是關的。
|
- **手機打不開直接操作**(covers `autonomy-remote`、`autonomy-direct`、`autonomy-review`):重新整理,帳戶選單 › 設定 › 權限,按「直接操作」。指令:`$CTL phone open --listed && $CTL phone click '#b-me' && $CTL phone click '#sheet-in .opt' --text 設定 && $CTL phone click '[data-go="perms"]' && $CTL phone wait-text '刪除檔案或資料夾' && $CTL phone click 'label.sw:has([data-sset="direct_mode"])' && $CTL phone click '#sheet-in .opt' --text 打開 && $CTL phone wait-text '不能從區網連線' && $CTL phone shot autonomy-perms && $CTL wait-api /api/settings '.direct_mode == false'`。看到:「一律詢問(優先)」裡三條預設規則;按開關、確認「打開」後跳出「這項設定會讓 Bot 不用問就動手,不能從區網連線…」,直接操作還是關的。
|
||||||
- **桌面的閃電圖示**(covers `autonomy-yolo`):指令:要開視窗——第一步之後 `$CTL stop && ABV_ALLOW_WINDOW=1 $CTL desktop-shot autonomy-yolo ANYBOT_SHOT_REAL=1 && $CTL serve`。看到:臉的同一行右邊一個紅色閃電圖示。
|
- **桌面的閃電圖示**(covers `autonomy-yolo`):指令:要開視窗——第一步之後 `$CTL stop && ABV_ALLOW_WINDOW=1 $CTL desktop-shot autonomy-yolo ANYBOT_SHOT_REAL=1 && $CTL serve`。看到:臉的同一行右邊一個紅色閃電圖示。
|
||||||
- **直接操作照樣問、允許的樣式**(covers `autonomy-still-asks`、`autonomy-patterns`):指令:走不到——直接連線的手機打不開直接操作(上面那步)、也加不了「無需詢問直接允許」規則(同樣 403),scratch 也沒有你的電腦的指令和檔案。看到:連接器的樣式(「一律允許」過也問)在 [connectors](connectors.md) 的「一律允許也照樣式問」;最接近的真路是 `cargo test direct_mode_still_asks_a_connector_step_its_ask_rule_names`(用設定的開關打開直接操作:符合 `connector(…)` 的步驟跳卡片、沒有「一律允許」;一律放行照樣放行)和下面 `agent::` 的幾個(允許的樣式不跳卡片、結果寫「自動審核:符合…」)。
|
- **直接操作照樣問、允許的樣式**(covers `autonomy-still-asks`、`autonomy-patterns`):指令:走不到——直接連線的手機打不開直接操作(上面那步)、也加不了「無需詢問直接允許」規則(同樣 403),scratch 也沒有你的電腦的指令和檔案。看到:連接器的樣式(「一律允許」過也問)在 [connectors](connectors.md) 的「一律允許也照樣式問」,瀏覽器的樣式和審核員在 [browser](browser.md) 的「照你的「一律詢問」」;最接近的真路是 `cargo test direct_mode_still_asks_a_connector_step_its_ask_rule_names`(用設定的開關打開直接操作:符合 `connector(…)` 的步驟跳卡片、沒有「一律允許」;一律放行照樣放行)和下面 `agent::` 的幾個(允許的樣式不跳卡片、結果寫「自動審核:符合…」)。
|
||||||
- 自動測試:`cargo test always`、`cargo test gate::`(`pattern_rules_decide_before_the_model`)、`cargo test agent::`(`a_review_that_fails_asks_instead_of_allowing`、`an_ask_pattern_stops_direct_mode_without_asking_a_model`、`a_connector_ask_rule_stops_direct_mode`、`a_connector_step_in_direct_mode_is_reviewed_by_the_sentence_rules`、`a_connector_allow_rule_lets_it_run_and_an_ask_rule_wins`、`rules_about_other_things_leave_a_connector_alone`、`an_ask_pattern_wins_over_a_connectors_grant`、`connector_decisions_are_characterized`)、`cargo test direct_mode_still_asks`、`cargo test hooks::`、`cargo test remote::`(`roles_gate_the_sync_and_hands_apis`)。
|
- 自動測試:`cargo test always`、`cargo test gate::`(`pattern_rules_decide_before_the_model`)、`cargo test agent::`(`a_review_that_fails_asks_instead_of_allowing`、`an_ask_pattern_stops_direct_mode_without_asking_a_model`、`a_connector_ask_rule_stops_direct_mode`、`a_connector_step_in_direct_mode_is_reviewed_by_the_sentence_rules`、`a_connector_allow_rule_lets_it_run_and_an_ask_rule_wins`、`rules_about_other_things_leave_a_connector_alone`、`an_ask_pattern_wins_over_a_connectors_grant`、`connector_decisions_are_characterized`、`an_ask_pattern_stops_the_bots_browser`、`private_pages_and_uploads_go_through_the_persons_rules`)、`cargo test direct_mode_still_asks`、`cargo test hooks::`、`cargo test remote::`(`roles_gate_the_sync_and_hands_apis`)。
|
||||||
|
|
||||||
## 陷阱
|
## 陷阱
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,10 +30,11 @@ Bot 用 AnyBot 自己的瀏覽器上網、登入網站、點按、打字、送
|
||||||
|
|
||||||
- **公開網頁以外不讀**(covers `browser-fetch`):請 Bot 用 `web_fetch` 讀本機網址。指令:`$CTL phone send '[[call web_fetch {"url":"http://127.0.0.1:9/"}]]' && $CTL phone wait-text 'web_fetch 只讀公開的網頁' --in '#msgs' && $CTL api GET /api/bots/1 --jq '[.messages[].tools[]? | {name, status}]'`。看到:「web_fetch 只讀公開的網頁,「127.0.0.1」是這台電腦或內部網路的位址。要看本機或區網上的服務,用 shell(例如 curl)或 browser_open。」;步驟 failed。
|
- **公開網頁以外不讀**(covers `browser-fetch`):請 Bot 用 `web_fetch` 讀本機網址。指令:`$CTL phone send '[[call web_fetch {"url":"http://127.0.0.1:9/"}]]' && $CTL phone wait-text 'web_fetch 只讀公開的網頁' --in '#msgs' && $CTL api GET /api/bots/1 --jq '[.messages[].tools[]? | {name, status}]'`。看到:「web_fetch 只讀公開的網頁,「127.0.0.1」是這台電腦或內部網路的位址。要看本機或區網上的服務,用 shell(例如 curl)或 browser_open。」;步驟 failed。
|
||||||
- **中繼資料擋下、本機網址先問**(covers `browser-actions`):`open` 雲端中繼資料,再 `open` 本機網址、按「拒絕」。指令:`$CTL phone send '[[call browser {"action":"open","url":"http://169.254.169.254/latest/meta-data/"}]]' && $CTL phone wait-text '禁止在瀏覽器開啟雲端中繼資料' --in '#msgs' && $CTL phone send '[[call browser {"action":"open","url":"http://127.0.0.1:9/"}]]' && $CTL phone wait-text '在瀏覽器開啟本機或內部網路網址' --in '#ask' && $CTL phone shot browser-private && $CTL api GET '/api/state?since=0' --jq '.approvals[0] | {tool, can_always}' && $CTL phone click '#ask button[data-a="reject"]' && $CTL phone wait-text '使用者拒絕了開啟這個內部網址' --in '#msgs' && $CTL api GET /api/bots/1 --jq '[.messages[].tools[]? | select(.name == "browser_open") | .status]'`。看到:中繼資料沒有卡片就「被安全規則擋下:禁止在瀏覽器開啟雲端中繼資料(169.254.169.254)…」;本機網址跳卡片「在瀏覽器開啟本機或內部網路網址:http://127.0.0.1:9/」(可以一律允許);拒絕後兩步都是 denied。
|
- **中繼資料擋下、本機網址先問**(covers `browser-actions`):`open` 雲端中繼資料,再 `open` 本機網址、按「拒絕」。指令:`$CTL phone send '[[call browser {"action":"open","url":"http://169.254.169.254/latest/meta-data/"}]]' && $CTL phone wait-text '禁止在瀏覽器開啟雲端中繼資料' --in '#msgs' && $CTL phone send '[[call browser {"action":"open","url":"http://127.0.0.1:9/"}]]' && $CTL phone wait-text '在瀏覽器開啟本機或內部網路網址' --in '#ask' && $CTL phone shot browser-private && $CTL api GET '/api/state?since=0' --jq '.approvals[0] | {tool, can_always}' && $CTL phone click '#ask button[data-a="reject"]' && $CTL phone wait-text '使用者拒絕了開啟這個內部網址' --in '#msgs' && $CTL api GET /api/bots/1 --jq '[.messages[].tools[]? | select(.name == "browser_open") | .status]'`。看到:中繼資料沒有卡片就「被安全規則擋下:禁止在瀏覽器開啟雲端中繼資料(169.254.169.254)…」;本機網址跳卡片「在瀏覽器開啟本機或內部網路網址:http://127.0.0.1:9/」(可以一律允許);拒絕後兩步都是 denied。
|
||||||
|
- **照你的「一律詢問」**(covers `browser-actions`、`browser-fetch`):打開自動審核,「一律詢問」加 `web(domain:127.0.0.1)` 和一句「打開內部網站前先問我」;`open` 本機網址、`web_fetch` 它,再 `open` 另一個內部網址,都按「拒絕」。指令:`$CTL phone click '[data-back]' && $CTL phone click '#b-me' && $CTL phone click '#sheet-in .opt' --text 設定 && $CTL phone click '[data-go="perms"]' && $CTL phone click 'label.sw:has([data-sset="auto_review"])' && $CTL wait-api /api/settings '.auto_review == true' && $CTL phone click '[data-addrule="ask"]' && $CTL phone type '#ask-in' 'web(domain:127.0.0.1)' && $CTL phone click '#ask-ok' && $CTL phone click '[data-addrule="ask"]' && $CTL phone type '#ask-in' '打開內部網站前先問我' && $CTL phone click '#ask-ok' && $CTL wait-api /api/settings '.ask_rules | length == 2' && $CTL model-reply 你是動作審核員 '{"verdict":"ask","rule":"打開內部網站前先問我"}' && $CTL phone open --listed && $CTL phone click '.row[data-bot="1"]' && $CTL phone send '[[call browser {"action":"open","url":"http://127.0.0.1:9/"}]]' && $CTL phone wait-text '規則:web(domain:127.0.0.1)' --in '#ask' && $CTL phone shot browser-rule && $CTL wait-api '/api/state?since=0' '.approvals[0].can_always == false' && $CTL phone click '#ask button[data-a="reject"]' && $CTL wait-api '/api/state?since=0' '.bots[0].busy == false' && $CTL phone send '[[call web_fetch {"url":"http://127.0.0.1:9/"}]]' && $CTL phone wait-text '規則:web(domain:127.0.0.1)' --in '#ask' && $CTL phone click '#ask button[data-a="reject"]' && $CTL wait-api '/api/state?since=0' '.bots[0].busy == false' && $CTL phone send '[[call browser {"action":"open","url":"http://192.168.1.5/"}]]' && $CTL phone wait-text '規則:打開內部網站前先問我' --in '#ask' && $CTL phone shot browser-review && $CTL phone click '#ask button[data-a="reject"]' && $CTL model-reply --clear && $CTL model 'select(.rule == "你是動作審核員") | .user[0:40]' && $CTL api GET /api/bots/1 --jq '[.messages[].tools[]? | select(.name == "browser_open" or .name == "web_fetch") | .status]'`。看到:本機網址不再是平常那張(可以一律允許)的卡,而是「在瀏覽器打開 http://127.0.0.1:9/(符合你的「一律詢問」規則:web(domain:127.0.0.1))」,只有「允許」「拒絕」;`web_fetch` 也停下來問;192.168.1.5 是平常的內部網址卡,但先給審核員看(「要審核的動作:在瀏覽器開啟本機或內部網路網址:http://192.168.1.5/」),說詢問就寫那條規則;每一步都是 denied,沒有開瀏覽器。
|
||||||
- **已送帳本、設定檔**(covers `browser-gate`、`browser-profiles`):請 Bot 查送過什麼、列設定檔。指令:`$CTL phone send '[[call browser {"action":"sent"}]]' && $CTL phone wait-text '帳本裡最近 30 天沒有送出紀錄' --in '#msgs' && $CTL phone send '[[call browser {"action":"profiles"}]]' && $CTL phone click '.step.done .h' --text 瀏覽器設定檔 && $CTL phone wait-text '預設(使用中)' --in '#msgs' && $CTL api GET /api/bots/1 --jq '[.messages[].tools[]? | .result][-2:]'`。看到:「帳本裡最近 30 天沒有送出紀錄(AnyBot 從開始記帳本那天起才有…)」;「AnyBot 瀏覽器的設定檔:預設(使用中)、你的瀏覽器。每個設定檔有自己的登入。…」;兩步都沒開瀏覽器。
|
- **已送帳本、設定檔**(covers `browser-gate`、`browser-profiles`):請 Bot 查送過什麼、列設定檔。指令:`$CTL phone send '[[call browser {"action":"sent"}]]' && $CTL phone wait-text '帳本裡最近 30 天沒有送出紀錄' --in '#msgs' && $CTL phone send '[[call browser {"action":"profiles"}]]' && $CTL phone click '.step.done .h' --text 瀏覽器設定檔 && $CTL phone wait-text '預設(使用中)' --in '#msgs' && $CTL api GET /api/bots/1 --jq '[.messages[].tools[]? | .result][-2:]'`。看到:「帳本裡最近 30 天沒有送出紀錄(AnyBot 從開始記帳本那天起才有…)」;「AnyBot 瀏覽器的設定檔:預設(使用中)、你的瀏覽器。每個設定檔有自己的登入。…」;兩步都沒開瀏覽器。
|
||||||
- **真的開網頁、打字、送出**(covers `browser-actions`、`browser-refs`、`browser-type`、`browser-wait`、`browser-gate`、`browser-own`、`browser-close`、`browser-profiles`):指令:走不到——Bot 的電腦的瀏覽器要 Docker;改開在這台 Mac 會在使用者的螢幕上開真的瀏覽器。看到:最接近的真路是無頭的實機測試(下面):`click` 輸入框回「游標已在…裡」、`type` 多行整段進去、編號不變;在回覆框送出有【系統】那行和留言網址,同一篇再送被擋,搜尋框按 Enter 不算送出。
|
- **真的開網頁、打字、送出**(covers `browser-actions`、`browser-refs`、`browser-type`、`browser-wait`、`browser-gate`、`browser-own`、`browser-close`、`browser-profiles`):指令:走不到——Bot 的電腦的瀏覽器要 Docker;改開在這台 Mac 會在使用者的螢幕上開真的瀏覽器。看到:最接近的真路是無頭的實機測試(下面):`click` 輸入框回「游標已在…裡」、`type` 多行整段進去、編號不變;在回覆框送出有【系統】那行和留言網址,同一篇再送被擋,搜尋框按 Enter 不算送出。
|
||||||
- **桌面的設定檔區塊**(covers `browser-profiles`、`browser-close`):指令:要開視窗——`$CTL stop && ABV_ALLOW_WINDOW=1 $CTL desktop-shot browser ANYBOT_SHOT_REAL=1 ANYBOT_SHOT_VIEW=computers`。看到:設定 › 電腦「AnyBot 瀏覽器設定檔」的使用中設定檔、「開啟視窗」、「做完就關掉瀏覽器」、「發布前檢查」。
|
- **桌面的設定檔區塊**(covers `browser-profiles`、`browser-close`):指令:要開視窗——`$CTL stop && ABV_ALLOW_WINDOW=1 $CTL desktop-shot browser ANYBOT_SHOT_REAL=1 ANYBOT_SHOT_VIEW=computers`。看到:設定 › 電腦「AnyBot 瀏覽器設定檔」的使用中設定檔、「開啟視窗」、「做完就關掉瀏覽器」、「發布前檢查」。
|
||||||
- 自動測試:`cargo test browser::`、`cargo test publish::`、`cargo test evidence::`;實機(無頭 Chrome,或 Brave/Firefox;暫存資料夾、自己的連接埠):`ANYBOT_DATA_DIR=<暫存資料夾> ANYBOT_BROWSER_PORT=9398 ANYBOT_BROWSER_FLAGS=--headless=new cargo test lines_go_in_whole_and_numbers_stay_put -- --ignored`,`a_send_is_seen_with_the_post_it_answers_and_its_own_address` 照同樣跑(Firefox 加 `ANYBOT_BROWSER_ENGINE=firefox ANYBOT_FIREFOX_HEADLESS=1`、`HOME` 也換掉)。
|
- 自動測試:`cargo test browser::`、`cargo test publish::`、`cargo test evidence::`、`cargo test an_ask_pattern_stops_the_bots_browser`、`cargo test private_pages_and_uploads_go_through_the_persons_rules`、`cargo test the_bots_browser_is_not_held_up_by_rules_about_other_things`;實機(無頭 Chrome,或 Brave/Firefox;暫存資料夾、自己的連接埠):`ANYBOT_DATA_DIR=<暫存資料夾> ANYBOT_BROWSER_PORT=9398 ANYBOT_BROWSER_FLAGS=--headless=new cargo test lines_go_in_whole_and_numbers_stay_put -- --ignored`,`a_send_is_seen_with_the_post_it_answers_and_its_own_address` 照同樣跑(Firefox 加 `ANYBOT_BROWSER_ENGINE=firefox ANYBOT_FIREFOX_HEADLESS=1`、`HOME` 也換掉)。
|
||||||
|
|
||||||
## 陷阱
|
## 陷阱
|
||||||
|
|
||||||
|
|
@ -45,7 +46,8 @@ Bot 用 AnyBot 自己的瀏覽器上網、登入網站、點按、打字、送
|
||||||
- 下拉選單用 `select`,`option` 填選項上看得到的字(給 `value` 也行,對下拉選單 `type` 也會改成選選項);什麼都沒給會報錯。
|
- 下拉選單用 `select`,`option` 填選項上看得到的字(給 `value` 也行,對下拉選單 `type` 也會改成選選項);什麼都沒給會報錯。
|
||||||
- `fill` 是保險庫的填入;指著頁面上一個欄位(有 `ref`/`text`、沒有 kind/id/site)時當成 `type`(有 `option` 時當 `select`),不會跑去保險庫。
|
- `fill` 是保險庫的填入;指著頁面上一個欄位(有 `ref`/`text`、沒有 kind/id/site)時當成 `type`(有 `option` 時當 `select`),不會跑去保險庫。
|
||||||
- `eval` 只能讀頁面:不能發請求、讀 cookie 或儲存、送出表單、換頁(會被拒絕);直接呼叫網站內部 API 會被當成機器人。
|
- `eval` 只能讀頁面:不能發請求、讀 cookie 或儲存、送出表單、換頁(會被拒絕);直接呼叫網站內部 API 會被當成機器人。
|
||||||
- 雲端中繼資料位址永遠打不開;本機或內部網路的網址要使用者允許(直接操作模式除外)。
|
- 雲端中繼資料位址永遠打不開;本機或內部網路的網址要使用者允許(直接操作模式除外,但符合「一律詢問」規則的照樣問)。
|
||||||
|
- 自動審核開著時,「一律詢問」寫成樣式(`tool(browser_click)`、`web(domain:example.com)`)的,AnyBot 瀏覽器的步驟和 `web_fetch` 每次都停下來問,本來不用問、一律允許過的也一樣;用一般的話寫的只看本來就要問的(本機網址、上傳檔案)。
|
||||||
- 發布關卡、已送帳本、送出後確認只管 AnyBot 自己的瀏覽器;用螢幕操作送出的,只能從步驟推算。頁面看不出回哪一篇時,只擋 24 小時內同一頁一模一樣的內容。
|
- 發布關卡、已送帳本、送出後確認只管 AnyBot 自己的瀏覽器;用螢幕操作送出的,只能從步驟推算。頁面看不出回哪一篇時,只擋 24 小時內同一頁一模一樣的內容。
|
||||||
- 送出後頁面上沒看到(例如從動態牆送出),結果寫「還沒確認」:不要因此再送一次,回原貼文看。
|
- 送出後頁面上沒看到(例如從動態牆送出),結果寫「還沒確認」:不要因此再送一次,回原貼文看。
|
||||||
- 網頁要上傳檔案(Threads、IG 加相片、表單附件):用 `upload` 直接放進頁面的檔案欄位。用螢幕去點「加入相片」會跳出 Bot 電腦的檔案視窗(「取消」「Open」在最上面),還要在裡面找檔案、按 Open。
|
- 網頁要上傳檔案(Threads、IG 加相片、表單附件):用 `upload` 直接放進頁面的檔案欄位。用螢幕去點「加入相片」會跳出 Bot 電腦的檔案視窗(「取消」「Open」在最上面),還要在裡面找檔案、按 Open。
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ Bot 要動到你的電腦、對外送出或做收不回來的事時,先問你
|
||||||
- `safety-local` 「在這台電腦上執行」:一律允許/每次詢問(預設)/永不允許。永不允許時直接拒絕、不問。
|
- `safety-local` 「在這台電腦上執行」:一律允許/每次詢問(預設)/永不允許。永不允許時直接拒絕、不問。
|
||||||
- `safety-lock` 管理員鎖定:可鎖「直接操作」(AllowDirectMode)、「在這台電腦上執行」(AllowLocalExecution)、「經這台電腦轉送流量」(AllowBoxTrafficViaThisMac)。macOS 用 `defaults` 網域 com.anybot.AnyBot(可由 MDM 強制);其他系統讀 /etc/anybot/policy.json(優先)或家目錄 .anybot/policy.json。true/1/yes 允許;false/0/no 或看不懂的值鎖成關。每次打開設定重讀。
|
- `safety-lock` 管理員鎖定:可鎖「直接操作」(AllowDirectMode)、「在這台電腦上執行」(AllowLocalExecution)、「經這台電腦轉送流量」(AllowBoxTrafficViaThisMac)。macOS 用 `defaults` 網域 com.anybot.AnyBot(可由 MDM 強制);其他系統讀 /etc/anybot/policy.json(優先)或家目錄 .anybot/policy.json。true/1/yes 允許;false/0/no 或看不懂的值鎖成關。每次打開設定重讀。
|
||||||
- `safety-timeout` 沒人在旁邊的一輪(例行任務、事件觸發、訊息管道)等核准超過 15 分鐘,自動結束、算出錯,免得卡住後面的排程和訊息。
|
- `safety-timeout` 沒人在旁邊的一輪(例行任務、事件觸發、訊息管道)等核准超過 15 分鐘,自動結束、算出錯,免得卡住後面的排程和訊息。
|
||||||
- `safety-gates` 每一步的關卡順序:1. 不用問:App 操作工具(刪例行任務、教同事技能、裝外部技能、改自己或別的 Bot 的設定這類會先問)、讀公開網頁、AnyBot 瀏覽器(別人傳來的訊息不能用)。2. 決定在哪台電腦;直接操作開著時第 3、5 步算已開。3. 這個 Bot 的電腦工具沒開 → 問。4. 「在這台電腦上執行」永不允許或被管理員鎖 → 拒絕。5. 它沒開 → 問。6. 照安全規則允許、問或拒絕(連接器的工具:每個連接器第一次問);「一律允許」過的直接做(連接器符合樣式的「一律詢問」照樣問)。7. 要問的交給自動審核或直接操作(連接器的工具也是)。8. 「每次都問」的蓋過第 6、7 步。9. 問你;等的時候按停止=拒絕。
|
- `safety-gates` 每一步的關卡順序:1. 不用問:App 操作工具(刪例行任務、教同事技能、裝外部技能、改自己或別的 Bot 的設定這類會先問)、讀公開網頁、AnyBot 瀏覽器(別人傳來的訊息不能用;符合樣式的「一律詢問」照樣問)。2. 決定在哪台電腦;直接操作開著時第 3、5 步算已開。3. 這個 Bot 的電腦工具沒開 → 問。4. 「在這台電腦上執行」永不允許或被管理員鎖 → 拒絕。5. 它沒開 → 問。6. 照安全規則允許、問或拒絕(連接器的工具:每個連接器第一次問);「一律允許」過的直接做(連接器符合樣式的「一律詢問」照樣問)。7. 要問的交給自動審核或直接操作(連接器的工具也是)。8. 「每次都問」的蓋過第 6、7 步。9. 問你;等的時候按停止=拒絕。
|
||||||
|
|
||||||
## 使用者怎麼到
|
## 使用者怎麼到
|
||||||
|
|
||||||
|
|
|
||||||
99
src/agent.rs
99
src/agent.rs
|
|
@ -4751,6 +4751,105 @@ echo '<meta charset=utf-8><title>done</title>送出了' > done.html; (setsid pyt
|
||||||
assert!(asked.is_empty() && results[0].contains("sum=3"), "自動審核 off: {asked:?} {results:?}");
|
assert!(asked.is_empty() && results[0].contains("sum=3"), "自動審核 off: {asked:?} {results:?}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A turn of AnyBot-browser steps on another computer of the account (「筆電」): what runs
|
||||||
|
/// there fails at once here (no account to reach it), so nothing opens a real browser even when
|
||||||
|
/// a step isn't stopped. Each card is answered `answer`. Returns each card's question and grant,
|
||||||
|
/// the step results, and every request the model got.
|
||||||
|
#[allow(clippy::type_complexity)]
|
||||||
|
fn browser_turn(mut replies: Vec<(u16, String)>, direct: bool, review: Option<Review>, grants: &[&str], answer: ApprovalAnswer) -> (Vec<(String, String)>, Vec<String>, Vec<String>) {
|
||||||
|
replies.push(sse_text("好"));
|
||||||
|
let (port, seen) = fake_http(replies);
|
||||||
|
let job = Job {
|
||||||
|
req: ChatRequest { kind: ProviderKind::Custom, base_url: format!("http://127.0.0.1:{port}/v1"), api_key: String::new(), model: "m".into(), system: String::new(), history: vec![Message::user("看一下網頁")], tools: crate::web::specs_for(&["筆電".to_string()], "筆電"), session: String::new(), effort: String::new() },
|
||||||
|
computers: vec![tools::Target { name: "筆電".into(), place: tools::Place::Device { host: "h-test".into(), dir: String::new() } }],
|
||||||
|
default_computer: "筆電".into(),
|
||||||
|
direct: Arc::new(AtomicBool::new(direct)),
|
||||||
|
review,
|
||||||
|
grants: grants.iter().map(|g| g.to_string()).collect(),
|
||||||
|
..test_job()
|
||||||
|
};
|
||||||
|
let (tx, rx) = channel();
|
||||||
|
spawn(job, 1, tx, Arc::new(AtomicBool::new(false)), eframe::egui::Context::default());
|
||||||
|
let (mut asked, mut results) = (vec![], vec![]);
|
||||||
|
loop {
|
||||||
|
match rx.recv_timeout(Duration::from_secs(20)).expect("loop stalled") {
|
||||||
|
(_, StreamEvent::NeedApproval(a)) => {
|
||||||
|
asked.push((a.reason.clone(), a.grant.clone()));
|
||||||
|
let _ = a.reply.send(answer.clone());
|
||||||
|
}
|
||||||
|
(_, StreamEvent::ToolResult(m)) => results.push(m.text.clone()),
|
||||||
|
(_, StreamEvent::Done) => break,
|
||||||
|
(_, StreamEvent::Error(e)) => panic!("{e}"),
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let seen = seen.lock().unwrap().clone();
|
||||||
|
(asked, results, seen)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 「一律詢問」 patterns about AnyBot-browser steps — `tool(browser_click)`, `web(domain:…)` on an
|
||||||
|
/// open or a web_fetch — stop them, with or without 直接操作, naming the rule, no 「一律允許」,
|
||||||
|
/// no model call (they used to run: the browser never went through the person's rules).
|
||||||
|
#[test]
|
||||||
|
fn an_ask_pattern_stops_the_bots_browser() {
|
||||||
|
for direct in [false, true] {
|
||||||
|
let mine = Review { allow: vec![], ask: vec!["tool(browser_click)".into(), "web(domain:example.com)".into(), "web(domain:127.0.0.1)".into()] };
|
||||||
|
let replies = vec![
|
||||||
|
sse_call("c1", "browser", serde_json::json!({"action": "click", "ref": "3"})),
|
||||||
|
sse_call("c2", "browser", serde_json::json!({"action": "open", "url": "https://shop.example.com/cart"})),
|
||||||
|
sse_call("c3", "web_fetch", serde_json::json!({"url": "http://127.0.0.1:9/"})),
|
||||||
|
];
|
||||||
|
let (asked, results, seen) = browser_turn(replies, direct, Some(mine), &[], ApprovalAnswer::Reject);
|
||||||
|
assert_eq!(asked.len(), 3, "direct={direct}: {asked:?} {results:?}");
|
||||||
|
for ((reason, grant), rule) in asked.iter().zip(["tool(browser_click)", "web(domain:example.com)", "web(domain:127.0.0.1)"]) {
|
||||||
|
assert!(reason.contains(&format!("符合你的「一律詢問」規則:{rule}")) && grant.is_empty(), "{reason} [{grant}]");
|
||||||
|
}
|
||||||
|
assert!(results.iter().all(|r| r.contains("使用者拒絕了這個操作")), "{results:?}");
|
||||||
|
assert_eq!(seen.len(), 4, "no model call to review them");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The page this computer's network calls home (a private address): 「一律允許」 for it
|
||||||
|
/// (`browser:private`) or 直接操作 no longer skip the person's rules — an 「一律詢問」 pattern
|
||||||
|
/// still asks; in 直接操作 the sentence rules are read by the reviewer; 自動審核's allow pattern
|
||||||
|
/// lets it go without the card. The same for a file uploaded from another computer.
|
||||||
|
#[test]
|
||||||
|
fn private_pages_and_uploads_go_through_the_persons_rules() {
|
||||||
|
let open = || sse_call("c1", "browser", serde_json::json!({"action": "open", "url": "http://192.168.1.5/admin"}));
|
||||||
|
let mine = || Some(Review { allow: vec![], ask: vec!["web(domain:192.168.1.5)".into()] });
|
||||||
|
let (asked, _, _) = browser_turn(vec![open()], false, mine(), &["browser:private"], ApprovalAnswer::Reject);
|
||||||
|
assert!(asked.len() == 1 && asked[0].0.contains("web(domain:192.168.1.5)") && asked[0].1.is_empty(), "a granted private page: {asked:?}");
|
||||||
|
let words = || Some(Review { allow: vec![], ask: vec!["打開內部網站前先問我".into()] });
|
||||||
|
let verdict = || sse_text(r#"{"verdict":"ask","rule":"打開內部網站前先問我"}"#);
|
||||||
|
let (asked, _, seen) = browser_turn(vec![open(), verdict()], true, words(), &[], ApprovalAnswer::Reject);
|
||||||
|
assert!(asked.len() == 1 && asked[0].0.contains("在瀏覽器開啟本機或內部網路網址") && asked[0].0.contains("規則:打開內部網站前先問我") && asked[0].1.is_empty(), "直接操作: {asked:?}");
|
||||||
|
assert!(seen.len() == 3 && seen[1].contains("你是動作審核員") && seen[1].contains("192.168.1.5"), "the reviewer read it: {seen:?}");
|
||||||
|
let upload = sse_call("c1", "browser", serde_json::json!({"action": "upload", "ref": "4", "path": "/Users/me/report.pdf"}));
|
||||||
|
let (asked, _, _) = browser_turn(vec![upload, verdict()], true, words(), &[], ApprovalAnswer::Reject);
|
||||||
|
assert!(asked.len() == 1 && asked[0].0.contains("上傳到網頁") && asked[0].0.contains("規則:打開內部網站前先問我"), "an upload in 直接操作: {asked:?}");
|
||||||
|
let allow = Some(Review { allow: vec!["web(domain:192.168.1.5)".into()], ask: vec![] });
|
||||||
|
let (asked, results, _) = browser_turn(vec![open()], false, allow, &[], ApprovalAnswer::Reject);
|
||||||
|
assert!(asked.is_empty() && results[0].contains("自動審核:符合「web(domain:192.168.1.5)」"), "{asked:?} {results:?}");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The other way round: a browser step that needs no permission isn't held up by sentence rules
|
||||||
|
/// (no model call on every click) or by patterns about other things; with no rules, the private
|
||||||
|
/// page's card is the one it always was (「一律允許」 offered), and 直接操作 skips it.
|
||||||
|
#[test]
|
||||||
|
fn the_bots_browser_is_not_held_up_by_rules_about_other_things() {
|
||||||
|
let click = || sse_call("c1", "browser", serde_json::json!({"action": "click", "ref": "3"}));
|
||||||
|
for direct in [false, true] {
|
||||||
|
let others = Some(Review { allow: vec![], ask: vec!["付款前先問我".into(), "tool(browser_type)".into(), "web(domain:other.example)".into(), "shell(*)".into()] });
|
||||||
|
let (asked, results, seen) = browser_turn(vec![click()], direct, others, &[], ApprovalAnswer::Reject);
|
||||||
|
assert!(asked.is_empty() && seen.len() == 2 && !results[0].contains("拒絕"), "direct={direct}: {asked:?} {results:?}");
|
||||||
|
}
|
||||||
|
let open = || sse_call("c1", "browser", serde_json::json!({"action": "open", "url": "http://192.168.1.5/"}));
|
||||||
|
let (asked, _, _) = browser_turn(vec![open()], false, None, &[], ApprovalAnswer::Reject);
|
||||||
|
assert!(asked.len() == 1 && asked[0].0.starts_with("在瀏覽器開啟本機或內部網路網址:http://192.168.1.5/") && asked[0].1 == "browser:private", "{asked:?}");
|
||||||
|
let (asked, _, _) = browser_turn(vec![open()], true, None, &[], ApprovalAnswer::Reject);
|
||||||
|
assert!(asked.is_empty(), "直接操作 with no rules: {asked:?}");
|
||||||
|
}
|
||||||
|
|
||||||
/// A connector step's decision on fixed rules, as Allow / Allow+note (自動審核 let it, the result
|
/// A connector step's decision on fixed rules, as Allow / Allow+note (自動審核 let it, the result
|
||||||
/// says so) / Ask[the grant 「一律允許」 would keep] with why (rule=…, failed, hook), and how many
|
/// says so) / Ask[the grant 「一律允許」 would keep] with why (rule=…, failed, hook), and how many
|
||||||
/// times the reviewer model was asked — 「一律允許」 for the connector or not × 直接操作 or not ×
|
/// times the reviewer model was asked — 「一律允許」 for the connector or not × 直接操作 or not ×
|
||||||
|
|
|
||||||
|
|
@ -540,26 +540,44 @@ impl TurnTool for InBotsBrowser {
|
||||||
// bot goes as it is. The path is made whole here, so the browser takes the
|
// bot goes as it is. The path is made whole here, so the browser takes the
|
||||||
// very file that was checked.
|
// very file that was checked.
|
||||||
let mut call_args = call.args.clone();
|
let mut call_args = call.args.clone();
|
||||||
if call.name == "browser_open" || (call.name == "browser_tabs" && tools::args_of(&call.args)["action"].as_str() == Some("new")) {
|
// The page this step opens, made whole: the safety rules first.
|
||||||
let raw_url = tools::args_of(&call.args)["url"].as_str().unwrap_or("").trim().to_string();
|
let opens = (call.name == "browser_open" || (call.name == "browser_tabs" && tools::args_of(&call.args)["action"].as_str() == Some("new")))
|
||||||
if !raw_url.is_empty() {
|
.then(|| tools::args_of(&call.args)["url"].as_str().unwrap_or("").trim().to_string())
|
||||||
if let Ok(norm) = web::normalize_url(&raw_url) {
|
.filter(|u| !u.is_empty())
|
||||||
if web::is_forbidden_browser_url(&norm) {
|
.and_then(|u| web::normalize_url(&u).ok());
|
||||||
|
let private = opens.as_deref().is_some_and(|norm| !matches!(place, BrowserAt::Box) && web::is_private_browser_url(norm));
|
||||||
|
if opens.as_deref().is_some_and(web::is_forbidden_browser_url) {
|
||||||
s.finish("被安全規則擋下:禁止在瀏覽器開啟雲端中繼資料(169.254.169.254)或系統內部管理端點。", ToolStatus::Denied, None);
|
s.finish("被安全規則擋下:禁止在瀏覽器開啟雲端中繼資料(169.254.169.254)或系統內部管理端點。", ToolStatus::Denied, None);
|
||||||
return Flow::Next;
|
return Flow::Next;
|
||||||
}
|
}
|
||||||
if !matches!(place, BrowserAt::Box) && web::is_private_browser_url(&norm) {
|
if private && matches!(place, BrowserAt::Here) && job.local_locked {
|
||||||
if matches!(place, BrowserAt::Here) && job.local_locked {
|
|
||||||
s.finish("被安全規則擋下:「在這台電腦上執行」已鎖定,不能開啟本機或內部網路位址。", ToolStatus::Denied, None);
|
s.finish("被安全規則擋下:「在這台電腦上執行」已鎖定,不能開啟本機或內部網路位址。", ToolStatus::Denied, None);
|
||||||
return Flow::Next;
|
return Flow::Next;
|
||||||
}
|
}
|
||||||
let direct = job.direct.load(Ordering::Relaxed);
|
// The person's 「一律詢問」 patterns (only compared, no model call) over a browser step that
|
||||||
|
// needs no permission or was 「一律允許」, as for a connector: one card naming the rule; a yes
|
||||||
|
// to it is the yes to this step (no second card below). What would be asked anyway goes
|
||||||
|
// through `reviewed` (自動審核, 直接操作) — never sentences on every click.
|
||||||
|
let on_line = if on.is_empty() { String::new() } else { format!("\n(在 {on} 上)") };
|
||||||
|
let mut said_yes = false;
|
||||||
|
if let Some(Decision::Ask { reason, grant }) = ask_pattern(job, &call.name, &call.args, &format!("{} {}", web::label(&call.name), s.what())) {
|
||||||
|
if s.ask_person(ApprovalKind::Action, format!("{reason}{on_line}"), grant) == ApprovalAnswer::Reject {
|
||||||
|
s.finish("使用者拒絕了這個操作。在他傳下一則訊息之前不要再試同樣的操作,也不要換個寫法做同一件事;告訴他你停在哪裡,問他想怎麼做。", ToolStatus::Denied, None);
|
||||||
|
return Flow::Next;
|
||||||
|
}
|
||||||
|
if cancel.load(Ordering::Relaxed) {
|
||||||
|
return Flow::End;
|
||||||
|
}
|
||||||
|
said_yes = true;
|
||||||
|
}
|
||||||
|
let mut review_note = String::new();
|
||||||
|
if let (true, false, Some(norm)) = (private, said_yes, opens.as_deref()) {
|
||||||
let grant = "browser:private".to_string();
|
let grant = "browser:private".to_string();
|
||||||
if !direct && !s.grants.contains(&grant) {
|
let decision = if s.grants.contains(&grant) { Decision::Allow } else { Decision::Ask { reason: format!("在瀏覽器開啟本機或內部網路網址:{norm}"), grant } };
|
||||||
let (atx, arx) = channel();
|
let (decision, _, note) = reviewed(job, &call.name, &call.args, decision, false, cancel);
|
||||||
send(StreamEvent::ToolStatus(call.id.clone(), ToolStatus::Waiting));
|
review_note = note;
|
||||||
send(StreamEvent::NeedApproval(Approval { call_id: call.id.clone(), tool: call.name.clone(), reason: format!("在瀏覽器開啟本機或內部網路網址:{norm}\n(在 {on} 上)"), grant: grant.clone(), reply: atx, kind: ApprovalKind::Action }));
|
if let Decision::Ask { reason, grant } = decision {
|
||||||
match wait_answer(arx, cancel, said_no) {
|
match s.ask_person(ApprovalKind::Action, format!("{reason}{on_line}"), grant) {
|
||||||
ApprovalAnswer::Once | ApprovalAnswer::Answered(_) => {}
|
ApprovalAnswer::Once | ApprovalAnswer::Answered(_) => {}
|
||||||
ApprovalAnswer::Always(g) => keep_grant(s.grants, g),
|
ApprovalAnswer::Always(g) => keep_grant(s.grants, g),
|
||||||
ApprovalAnswer::Reject => {
|
ApprovalAnswer::Reject => {
|
||||||
|
|
@ -567,8 +585,8 @@ impl TurnTool for InBotsBrowser {
|
||||||
return Flow::Next;
|
return Flow::Next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
if cancel.load(Ordering::Relaxed) {
|
||||||
}
|
return Flow::End;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -593,14 +611,17 @@ impl TurnTool for InBotsBrowser {
|
||||||
} else {
|
} else {
|
||||||
match tools::decide_file_out(&here, &path, s.grants) {
|
match tools::decide_file_out(&here, &path, s.grants) {
|
||||||
Decision::Allow if !direct && !(*s.tools_on && *s.local_on) => Decision::Ask { reason: format!("把「{}」上的檔案上傳到網頁:{}", here.name, named.display()), grant: String::new() },
|
Decision::Allow if !direct && !(*s.tools_on && *s.local_on) => Decision::Ask { reason: format!("把「{}」上的檔案上傳到網頁:{}", here.name, named.display()), grant: String::new() },
|
||||||
Decision::Ask { .. } if direct => Decision::Allow,
|
|
||||||
Decision::Ask { grant, .. } => Decision::Ask { reason: format!("把工作資料夾以外的檔案上傳到網頁:{}", named.display()), grant },
|
Decision::Ask { grant, .. } => Decision::Ask { reason: format!("把工作資料夾以外的檔案上傳到網頁:{}", named.display()), grant },
|
||||||
d => d,
|
d => d,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
// (直接操作 and 自動審核 as for any step: an 「一律詢問」 rule still stops it.)
|
||||||
|
let (decision, _, note) = reviewed(job, &call.name, &call.args, decision, false, cancel);
|
||||||
|
review_note = note;
|
||||||
let refused = match decision {
|
let refused = match decision {
|
||||||
Decision::Allow => None,
|
Decision::Allow => None,
|
||||||
Decision::Deny(r) => Some(format!("被安全規則擋下:{r}")),
|
Decision::Deny(r) => Some(format!("被安全規則擋下:{r}")),
|
||||||
|
Decision::Ask { .. } if said_yes => None,
|
||||||
Decision::Ask { reason, grant } => {
|
Decision::Ask { reason, grant } => {
|
||||||
let (atx, arx) = channel();
|
let (atx, arx) = channel();
|
||||||
send(StreamEvent::ToolStatus(call.id.clone(), ToolStatus::Waiting));
|
send(StreamEvent::ToolStatus(call.id.clone(), ToolStatus::Waiting));
|
||||||
|
|
@ -631,12 +652,14 @@ impl TurnTool for InBotsBrowser {
|
||||||
s.finish("被安全規則擋下:這個檔案是私密或系統檔案,Bot 不能上傳。", ToolStatus::Denied, None);
|
s.finish("被安全規則擋下:這個檔案是私密或系統檔案,Bot 不能上傳。", ToolStatus::Denied, None);
|
||||||
return Flow::Next;
|
return Flow::Next;
|
||||||
}
|
}
|
||||||
let direct = job.direct.load(Ordering::Relaxed);
|
|
||||||
let grant = format!("upload-device:{on}");
|
let grant = format!("upload-device:{on}");
|
||||||
if !direct && !s.grants.contains(&grant) {
|
let decision = if s.grants.contains(&grant) { Decision::Allow } else { Decision::Ask { reason: format!("把「{on}」上的檔案上傳到網頁:{path}"), grant } };
|
||||||
|
let (decision, _, note) = reviewed(job, &call.name, &call.args, decision, false, cancel);
|
||||||
|
review_note = note;
|
||||||
|
if let (Decision::Ask { reason, grant }, false) = (decision, said_yes) {
|
||||||
let (atx, arx) = channel();
|
let (atx, arx) = channel();
|
||||||
send(StreamEvent::ToolStatus(call.id.clone(), ToolStatus::Waiting));
|
send(StreamEvent::ToolStatus(call.id.clone(), ToolStatus::Waiting));
|
||||||
send(StreamEvent::NeedApproval(Approval { call_id: call.id.clone(), tool: call.name.clone(), reason: format!("把「{on}」上的檔案上傳到網頁:{path}\n(在 {on} 上)"), grant, reply: atx, kind: ApprovalKind::Action }));
|
send(StreamEvent::NeedApproval(Approval { call_id: call.id.clone(), tool: call.name.clone(), reason: format!("{reason}\n(在 {on} 上)"), grant, reply: atx, kind: ApprovalKind::Action }));
|
||||||
match wait_answer(arx, cancel, said_no) {
|
match wait_answer(arx, cancel, said_no) {
|
||||||
ApprovalAnswer::Once | ApprovalAnswer::Answered(_) => {}
|
ApprovalAnswer::Once | ApprovalAnswer::Answered(_) => {}
|
||||||
ApprovalAnswer::Always(g) => keep_grant(s.grants, g),
|
ApprovalAnswer::Always(g) => keep_grant(s.grants, g),
|
||||||
|
|
@ -715,6 +738,11 @@ impl TurnTool for InBotsBrowser {
|
||||||
}
|
}
|
||||||
// Which computer's browser it was, like every other step.
|
// Which computer's browser it was, like every other step.
|
||||||
let output = if on.is_empty() { output } else { format!("[{on}] {output}") };
|
let output = if on.is_empty() { output } else { format!("[{on}] {output}") };
|
||||||
|
// 自動審核 let it go: said after the page's words, outside the part marked as the page's.
|
||||||
|
if !review_note.is_empty() {
|
||||||
|
let before = step_note.take();
|
||||||
|
step_note.set(format!("{before}\n{}", review_note.trim_end()));
|
||||||
|
}
|
||||||
s.finish(&output, if ok { ToolStatus::Done } else { ToolStatus::Failed }, img);
|
s.finish(&output, if ok { ToolStatus::Done } else { ToolStatus::Failed }, img);
|
||||||
Flow::Next
|
Flow::Next
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue