fix: 直接連線真的只能收緊;Bot 的電腦和支線換不了瀏覽器設定檔;支線不動大家共用的東西
複審 f3ff553 找到的問題,加上直接連線全部設定的盤點:
A. 直接連線用多一格空白繞過檢查:檢查照原字讀名字,大腦那邊(phone_act)卻先去掉空白
再做,「direct_mode 」「 rule_add」「abilities 」都過關、照做。現在兩邊都照原字讀:
phone_act 的 key/list/op 不再 trim,規則清單只認 ask、allow(以前認不得的都當允許
清單);直接連線上名字不是 AnyBot 認得的一律 400「不認得這個設定」,什麼都不改。
盤點(remote::lan_guard,直接連線送來的每個 api/act):放寬的一律 403——打開直接操作、
打開自動審核、加允許規則、拿掉詢問規則、加連接器或把關掉的打開、打開訊息管道、打開
Bot 的電腦工具(沒帶值也算打開,跟 phone_act 一樣)、分享給團隊、勾回能力或可以用的
電腦、Bot 的電腦從 gVisor 換回標準;收緊的和不動權限的照做。卡片的允許/一律允許照舊
(那是回答眼前那張卡)。「只能收緊、不能放寬」現在是真的。
B. Bot 的電腦裡換瀏覽器設定檔是假的:在 box 裡 add 在大腦建資料夾、set_current 卻寫
「預設」蓋掉這台記著的選擇,Bot 還聽到「已新增並切換」。現在 box 裡新增、切換一律
回「Bot 的電腦上的瀏覽器只有一個設定檔…」,box 裡也不再寫這台的使用中設定檔(以前在
box 開網頁就把它改回「預設」)。
P2 設定檔名字:「阿金」不再模糊對到使用者的「阿金(Firefox)」:只換 AnyBot 自己同名的
設定檔(大小寫不算),其他名字新增全新的;使用者自己的瀏覽器(Firefox 設定檔、「你的
瀏覽器」)Bot 不能換過去——拒絕並請使用者在設定裡換(換了是每一步、每個 Bot 都用他的
登入;這個工具沒有卡片可問)。某一步指名用它也不會變成使用中。
P2 支線:create_bot、create_group、move_to_group、rename_group、delete_group、
delete_skill、skill_install(內建的也是)也擋;連接器、hook 改成只放行「看」的動作
(空白、大小寫都算改);瀏覽器 profiles 的新增、切換擋在步驟(BranchLimits);
save_skill、skillify 不能換掉技能庫裡已有的同名技能(apply 裡 bot_id 早就換成主
Bot,改用原本的支線 id 判斷;save_skill 在寫資料夾之前就擋)。支線的系統提示和
changes_settings 的說明照實列出擋什麼。
P3 oplog::replay_of 不再把 browser_profiles 當只看的。
功能地圖:autonomy(子功能、步驟加直接連線拿掉詢問規則 403、多空白名字 400、打開自動
審核 403、state 確認)、account、profile、phone、branch(Bot 那一行、步驟加支線建 Bot、
換設定檔被擋、陷阱)、browser(子功能、Bot 那一行、步驟加換「你的瀏覽器」被擋);
FEATURES.md、SECURITY.md 同步。工具定義不變;verify-approval-routing 沒有漂移。
已驗證: env -u 金鑰… DOCKER_HOST=unix:///nonexistent cargo test(679 過、46 ignored)、
cargo clippy --bin anybot --all-targets -D warnings、sh deploy/ci/lint-sh.sh、
verify-approval-routing run.sh --replay(沒有漂移,10 個重走都過);7 個新/改的測試在
放回舊程式時都失敗(含複審的繞過:「direct_mode 」照做);verify-anybot 照地圖跑
autonomy、branch、browser、profile、market、phone、channels、connectors 的步驟。
未驗證: --ignored 的實機瀏覽器測試(botbrowser 的 reads_a_real_page、a_persons_firefox_profile、
a_finished_job_quits_its_firefox、a_finished_job_quits_its_chrome,browser 的
lines_go_in_whole_and_numbers_stay_put、a_send_is_seen_with_the_post_it_answers_and_its_own_address)
要人在實機跑、簽名;Bot 的電腦裡的瀏覽器(要 Docker);使用者真的 Firefox 設定檔(scratch
沒有);帳號連線那條路(要帳號伺服器)。
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha5sXAsDLzxz6UZJgoC
This commit is contained in:
parent
f3ff553551
commit
36420f38cb
11
FEATURES.md
11
FEATURES.md
|
|
@ -484,7 +484,7 @@ AnyBot 是一個桌面聊天 App,介面和運作方式照 Grok Bot 重做。
|
||||||
- **螢幕一次給一個**(所有 Bot 都適用,不只支線):一輪工作在某台電腦的螢幕上點擊、打字之後,那個螢幕就是它的;另一輪(同一個 Bot 的支線,或別的 Bot)要在同一個螢幕上點,那一步不執行,Bot 會讀到「「X」的螢幕現在由「Y」在操作(N 秒前還在用)」,請它先做不用螢幕的部分、改用別台電腦或晚點再試。那一輪結束、或停手 2 分鐘後就放開。只是截圖、看畫面不算;Bot 的電腦(Docker)所有 Bot 共用一個桌面,所以算同一個螢幕。瀏覽器每一輪本來就各用各的分頁。
|
- **螢幕一次給一個**(所有 Bot 都適用,不只支線):一輪工作在某台電腦的螢幕上點擊、打字之後,那個螢幕就是它的;另一輪(同一個 Bot 的支線,或別的 Bot)要在同一個螢幕上點,那一步不執行,Bot 會讀到「「X」的螢幕現在由「Y」在操作(N 秒前還在用)」,請它先做不用螢幕的部分、改用別台電腦或晚點再試。那一輪結束、或停手 2 分鐘後就放開。只是截圖、看畫面不算;Bot 的電腦(Docker)所有 Bot 共用一個桌面,所以算同一個螢幕。瀏覽器每一輪本來就各用各的分頁。
|
||||||
- **卡片**:主聊天裡,問的地方出現一張支線卡:任務、狀態(判斷中、等主線、正在做什麼和第幾步、做完了、沒做完、已停止)、「停止支線」、「看過程」(每一步一行)。支線要你核准的步驟,直接在這張卡上按允許或拒絕(手機上顯示在主聊天的核准區,標「支線:」)。
|
- **卡片**:主聊天裡,問的地方出現一張支線卡:任務、狀態(判斷中、等主線、正在做什麼和第幾步、做完了、沒做完、已停止)、「停止支線」、「看過程」(每一步一行)。支線要你核准的步驟,直接在這張卡上按允許或拒絕(手機上顯示在主聊天的核准區,標「支線:」)。
|
||||||
- **回報到主頁面**:做完時——主線正在做事,結果當成插話送進它這一輪(「〔支線回報〕…」,它下一步就讀到,聊天裡一行小字說已交給主線);主線閒著,結果以支線的名義放進主聊天(上面標「支線「任務」」),主線下一輪讀得到。主 Bot 不會為了支線回報自己多回一則(省一輪)。沒做完時說原因,下面有「重開這條支線」。按停止的不回報。
|
- **回報到主頁面**:做完時——主線正在做事,結果當成插話送進它這一輪(「〔支線回報〕…」,它下一步就讀到,聊天裡一行小字說已交給主線);主線閒著,結果以支線的名義放進主聊天(上面標「支線「任務」」),主線下一輪讀得到。主 Bot 不會為了支線回報自己多回一則(省一輪)。沒做完時說原因,下面有「重開這條支線」。按停止的不回報。
|
||||||
- 一個 Bot 同時最多 3 條支線;群組聊天還不能開。支線不存檔:關掉 AnyBot 時還沒做完的支線會停掉,卡片寫「AnyBot 關掉了,這條支線停了」(以前寫「被停止了」,像是你按了停止);當掉後重新啟動才寫「AnyBot 重新啟動,這條支線停了」。支線不能改設定:update_bot、update_settings、update_my_profile、teach_skill,和新增、修改、移除連接器或 hook,一律馬上回「支線改不了設定:回到主線再請它改。」,不跳卡片(以前支線的 update_bot 按允許後會把主 Bot 改名)。側欄、同事名冊、@ 清單、手機的 Bot 列表都看不到支線本身。
|
- 一個 Bot 同時最多 3 條支線;群組聊天還不能開。支線不存檔:關掉 AnyBot 時還沒做完的支線會停掉,卡片寫「AnyBot 關掉了,這條支線停了」(以前寫「被停止了」,像是你按了停止);當掉後重新啟動才寫「AnyBot 重新啟動,這條支線停了」。支線不能改設定或動大家共用的東西:update_bot、update_settings、update_my_profile、teach_skill、create_bot、create_group、move_to_group、rename_group、delete_group、delete_skill、skill_install(內建的也是),連接器和 hook 除了看(列出、重新連線、登入登出)以外的動作,瀏覽器設定檔的新增和切換,一律馬上回「支線改不了設定:回到主線再請它改。」,不跳卡片(以前支線的 update_bot 按允許後會把主 Bot 改名)。save_skill、skillify 可以存新技能(算主 Bot 的),但不能換掉技能庫裡已經有的同名技能。側欄、同事名冊、@ 清單、手機的 Bot 列表都看不到支線本身。
|
||||||
|
|
||||||
### 「/」清單只放指令
|
### 「/」清單只放指令
|
||||||
|
|
||||||
|
|
@ -495,7 +495,7 @@ AnyBot 是一個桌面聊天 App,介面和運作方式照 Grok Bot 重做。
|
||||||
|
|
||||||
- **金鑰不再明文存檔**:state.json 裡的模型金鑰、頻道 token、連接器的密碼、標頭和環境變數,用保險庫的金鑰加密後才寫入(檔案裡是「enc:v1:…」);金鑰在系統鑰匙圈(沒有鑰匙圈的伺服器是資料夾裡的 0600 金鑰檔)。打不開時(鑰匙圈鎖住、換了電腦)保持原樣不清空,不會因為存檔而遺失。舊版讀不懂加密後的檔案:降版要重新填金鑰。寄到帳號伺服器的備份不受影響(備份本來就另外加密)。
|
- **金鑰不再明文存檔**:state.json 裡的模型金鑰、頻道 token、連接器的密碼、標頭和環境變數,用保險庫的金鑰加密後才寫入(檔案裡是「enc:v1:…」);金鑰在系統鑰匙圈(沒有鑰匙圈的伺服器是資料夾裡的 0600 金鑰檔)。打不開時(鑰匙圈鎖住、換了電腦)保持原樣不清空,不會因為存檔而遺失。舊版讀不懂加密後的檔案:降版要重新填金鑰。寄到帳號伺服器的備份不受影響(備份本來就另外加密)。
|
||||||
- **團隊**:加入別人的 AnyBot 要自己按接受(手機登入時會問);成員只看得到勾了「團隊成員可以使用這個 Bot」的 Bot(電腦的 Bot 設定,或手機的 Bot 選單「分享給團隊成員」)。設定裡的成員清單會標「已邀請,等對方接受」。
|
- **團隊**:加入別人的 AnyBot 要自己按接受(手機登入時會問);成員只看得到勾了「團隊成員可以使用這個 Bot」的 Bot(電腦的 Bot 設定,或手機的 Bot 選單「分享給團隊成員」)。設定裡的成員清單會標「已邀請,等對方接受」。
|
||||||
- **區網連線**(同一個網路直接連):只能收緊、不能放寬——不能打開直接操作、加「一律允許」規則、加連接器、勾回能力或可以用的電腦;關掉、加「一律詢問」規則、勾掉能力照樣可以。被擋時說「這會放寬 Bot 能做的事:同一個網路直接連的裝置只能收緊、不能放寬。請在電腦上的 AnyBot 改,或用帳號連線。」(以前說「區網連線(沒有加密)」,現在直接連線是 https;擋的原因是直接連線只憑手機密碼)。手機的區網登入 30 天沒用就失效;看畫面的連線改用一次性的票,登入不放在網址裡。
|
- **區網連線**(同一個網路直接連):只能收緊、不能放寬。擋下:打開直接操作、打開自動審核、加「無需詢問直接允許」規則、拿掉「一律詢問」規則、加連接器或把關掉的打開、打開訊息管道、打開 Bot 的電腦工具、把 Bot 分享給團隊、勾回能力或可以用的電腦、把 Bot 的電腦從強隔離換回標準;每一項反過來都可以,不動權限的(名字、外觀、模型、金鑰、技能、例行任務、記憶、頁面)也可以。設定的名字要一字不差:多一格空白、大小寫不同就回「不認得這個設定」,什麼都不改(以前大腦那邊會先把空白去掉再做,「direct_mode 」這種就繞過了檢查);規則清單只認「ask」「allow」(以前認不得的都當成允許清單)。被擋時說「這會放寬 Bot 能做的事:同一個網路直接連的裝置只能收緊、不能放寬。請在電腦上的 AnyBot 改,或用帳號連線。」(以前說「區網連線(沒有加密)」,現在直接連線是 https;擋的原因是直接連線只憑手機密碼)。卡片上的「允許」「一律允許」照樣可以按(回答的是眼前那張卡)。手機的區網登入 30 天沒用就失效;看畫面的連線改用一次性的票,登入不放在網址裡。
|
||||||
- **帳號伺服器**:大腦回傳的內容只放行不會被當成網頁執行的類型;沒登入的請求最多 256 KB;登入、註冊、配對都有次數限制;兩步驟驗證碼只能用一次;新增電腦要剛登入 15 分鐘內;可以改密碼;每個帳號的登入數、電腦數、發布的網站數都有上限;資料檔壞掉時不啟動(不會被空的蓋掉)。網頁只執行它自己的那幾段程式(依雜湊放行),不再放行任意內嵌程式。
|
- **帳號伺服器**:大腦回傳的內容只放行不會被當成網頁執行的類型;沒登入的請求最多 256 KB;登入、註冊、配對都有次數限制;兩步驟驗證碼只能用一次;新增電腦要剛登入 15 分鐘內;可以改密碼;每個帳號的登入數、電腦數、發布的網站數都有上限;資料檔壞掉時不啟動(不會被空的蓋掉)。網頁只執行它自己的那幾段程式(依雜湊放行),不再放行任意內嵌程式。
|
||||||
- **手腳電腦**:一律拒絕的指令和私密檔案,在手腳這一端自己也會擋,不只靠大腦判斷。
|
- **手腳電腦**:一律拒絕的指令和私密檔案,在手腳這一端自己也會擋,不只靠大腦判斷。
|
||||||
- **背景指令**:同時最多 24 個;刪除 Bot、支線結束時一起停掉;結束 10 分鐘後移除;Bot 可以用 write_terminal 的 stop 停掉;不理會停止的程序兩秒後強制結束;跑在 Bot 的電腦裡的也會在裡面停掉。
|
- **背景指令**:同時最多 24 個;刪除 Bot、支線結束時一起停掉;結束 10 分鐘後移除;Bot 可以用 write_terminal 的 stop 停掉;不理會停止的程序兩秒後強制結束;跑在 Bot 的電腦裡的也會在裡面停掉。
|
||||||
|
|
@ -509,7 +509,7 @@ AnyBot 是一個桌面聊天 App,介面和運作方式照 Grok Bot 重做。
|
||||||
- **帳號伺服器的資源**:閒置的連線從每秒醒 25 次降到 5 次;每條連線的讀取緩衝從 128 KB 降到 32 KB;請求的開頭 15 秒內沒送完就斷(原本最長 90 秒)。本機壓測(100 台電腦連著、3000 個請求、120 次錯誤登入、128 個送一半的請求、3 輪重連):記憶體 32 MB 持平,執行緒和檔案描述元都回到起點,閒置 CPU 約 1.5%(一個核心)。
|
- **帳號伺服器的資源**:閒置的連線從每秒醒 25 次降到 5 次;每條連線的讀取緩衝從 128 KB 降到 32 KB;請求的開頭 15 秒內沒送完就斷(原本最長 90 秒)。本機壓測(100 台電腦連著、3000 個請求、120 次錯誤登入、128 個送一半的請求、3 輪重連):記憶體 32 MB 持平,執行緒和檔案描述元都回到起點,閒置 CPU 約 1.5%(一個核心)。
|
||||||
- **團隊成員在 Bot 忙的時候傳的訊息**不再被丟掉:排在後面,Bot 做完手上的事就輪到它(每個 Bot 最多排 8 則)。成員的話不會插進擁有者正在跑的那一輪。
|
- **團隊成員在 Bot 忙的時候傳的訊息**不再被丟掉:排在後面,Bot 做完手上的事就輪到它(每個 Bot 最多排 8 則)。成員的話不會插進擁有者正在跑的那一輪。
|
||||||
- **群組沒有 @ 時看擅長分派**:訊息的內容對得上某些成員「擅長」寫的事(而且不在它「不找它做的事」裡),就只由那幾位回答,聊天裡會有一行「這題看擅長交給「…」。要其他人也回答,用 @ 點名。」;對不上任何人、或每個人都對得上,就跟以前一樣全員輪流。
|
- **群組沒有 @ 時看擅長分派**:訊息的內容對得上某些成員「擅長」寫的事(而且不在它「不找它做的事」裡),就只由那幾位回答,聊天裡會有一行「這題看擅長交給「…」。要其他人也回答,用 @ 點名。」;對不上任何人、或每個人都對得上,就跟以前一樣全員輪流。
|
||||||
- **手機也能改個人檔案**(擁有者):Bot 設定頁多了「擅長」「不找它做的事」,以及「能力」「會的技能」「可以用的電腦」的開關。區網連線只能勾掉「能力」和「可以用的電腦」、不能勾回(跟其他放寬權限的設定一樣;以前連勾掉也被擋)。
|
- **手機也能改個人檔案**(擁有者):Bot 設定頁多了「擅長」「不找它做的事」,以及「能力」「會的技能」「可以用的電腦」的開關。區網連線只能勾掉「能力」和「可以用的電腦」、不能勾回,電腦工具只能關、不能開(跟其他放寬權限的設定一樣;以前連勾掉也被擋)。
|
||||||
- **視窗沒在前面也照常運作**:視窗縮小、隱藏或被別的 App 整個蓋住時,Bot 送來的東西照樣處理——要你允許的請求會響提示音、任務完成會通知、例行任務準時開始(以前要等你切回 AnyBot 才一起發生)。任務完成且你不在 AnyBot 前面時,也響同一個提示音(設定裡的「提示音」關掉就不響)。Mac 的 App 關掉了 App Nap,被蓋住時系統不會讓它睡著。
|
- **視窗沒在前面也照常運作**:視窗縮小、隱藏或被別的 App 整個蓋住時,Bot 送來的東西照樣處理——要你允許的請求會響提示音、任務完成會通知、例行任務準時開始(以前要等你切回 AnyBot 才一起發生)。任務完成且你不在 AnyBot 前面時,也響同一個提示音(設定裡的「提示音」關掉就不響)。Mac 的 App 關掉了 App Nap,被蓋住時系統不會讓它睡著。
|
||||||
- **伺服器的 Docker**:setup.sh 檢查到用的是 root 的 Docker 會警告(大腦被攻破等於拿到整台主機),建議改 rootless。
|
- **伺服器的 Docker**:setup.sh 檢查到用的是 root 的 Docker 會警告(大腦被攻破等於拿到整台主機),建議改 rootless。
|
||||||
- 手機頁面最多留 40 個圖片/檔案的快取;收起的步驟和歸檔的舊對話不再把截圖留在記憶體。
|
- 手機頁面最多留 40 個圖片/檔案的快取;收起的步驟和歸檔的舊對話不再把截圖留在記憶體。
|
||||||
|
|
@ -1161,7 +1161,8 @@ AnyBot 是一個桌面聊天 App,介面和運作方式照 Grok Bot 重做。
|
||||||
- 「你的瀏覽器」代表你平常的 Chrome(第 23 節)。也聽得懂「你的 chrome」「我的 chrome」「我的瀏覽器」「my chrome」這些說法。
|
- 「你的瀏覽器」代表你平常的 Chrome(第 23 節)。也聽得懂「你的 chrome」「我的 chrome」「我的瀏覽器」「my chrome」這些說法。
|
||||||
- 順序:「預設」排第一,其他依名稱,「你的瀏覽器」排最後。
|
- 順序:「預設」排第一,其他依名稱,「你的瀏覽器」排最後。
|
||||||
- 「使用中」的設定檔會被記住;找不到時回到「預設」。找設定檔不分大小寫。
|
- 「使用中」的設定檔會被記住;找不到時回到「預設」。找設定檔不分大小寫。
|
||||||
- 在某個設定檔打開網址,那個設定檔就會變成使用中。
|
- 在某個設定檔打開網址,那個設定檔就會變成使用中——使用者自己的瀏覽器(Firefox 設定檔、「你的瀏覽器」)除外:那一步用它,使用中的不變。
|
||||||
|
- Bot 的電腦上的瀏覽器只有一個設定檔:在那裡新增或切換會被擋(「Bot 的電腦上的瀏覽器只有一個設定檔…」),也不會改到這台記著的使用中設定檔(以前在那裡開網頁會把它改回「預設」)。
|
||||||
|
|
||||||
### 名稱規則
|
### 名稱規則
|
||||||
|
|
||||||
|
|
@ -1172,7 +1173,7 @@ AnyBot 是一個桌面聊天 App,介面和運作方式照 Grok Bot 重做。
|
||||||
|
|
||||||
### 新增、切換、列出、移除
|
### 新增、切換、列出、移除
|
||||||
|
|
||||||
- Bot 用 `browser` 的 `profiles`:不帶 name 是列出;帶 name 是換到那個設定檔,還沒有就先新增(以前帶 name 也只會列出,什麼都沒換)。
|
- Bot 用 `browser` 的 `profiles`:不帶 name 是列出;帶 name 是換到 AnyBot 自己同名的設定檔(名字要一樣,大小寫不算),沒有就新增一個全新的(以前帶 name 也只會列出,什麼都沒換)。只說「阿金」不會換到使用者的「阿金(Firefox)」,而是新增「阿金」;使用者自己的瀏覽器(Firefox 設定檔、「你的瀏覽器」)Bot 不能換過去:「「X」是使用者自己的瀏覽器(帶著他的登入):Bot 不能自己換過去…請使用者在 設定 › 電腦 ›「AnyBot 瀏覽器設定檔」自己切換。」——換了之後每一步、每個 Bot 都會用他的帳號,所以由使用者在設定裡換(這個工具沒有卡片可以問)。支線不能新增或切換。
|
||||||
- **新增**:名稱已經存在時沿用,不重複建立。新增後自動切過去。
|
- **新增**:名稱已經存在時沿用,不重複建立。新增後自動切過去。
|
||||||
- 「已新增並切換到設定檔「X」(全新的,還沒登入任何網站)…」
|
- 「已新增並切換到設定檔「X」(全新的,還沒登入任何網站)…」
|
||||||
- **切換**:「已切換到「X」,之後 browser 的 open、read 都用它。」
|
- **切換**:「已切換到「X」,之後 browser 的 open、read 都用它。」
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ AnyBot 的 privacy 模型一句话:**Bot 跑在你自己的機器上,你的
|
||||||
|
|
||||||
- 預設只綁 **loopback**;egress 綁環回+自動偵測的 Docker 網橋閘道(docker0 / docker_gwbridge / br-*),**從不綁 0.0.0.0**。
|
- 預設只綁 **loopback**;egress 綁環回+自動偵測的 Docker 網橋閘道(docker0 / docker_gwbridge / br-*),**從不綁 0.0.0.0**。
|
||||||
- 手機連 relay 走你自架的 relay+Caddy HTTPS;`/relay/*` 有登入鎖、錯誤鎖與 session 登出。
|
- 手機連 relay 走你自架的 relay+Caddy HTTPS;`/relay/*` 有登入鎖、錯誤鎖與 session 登出。
|
||||||
- LAN 模式(設定開)才會對區域網路開放,並要求 App 密碼(雜湊比對)。連線走這台自己做的憑證的 HTTPS;不加密的 http 只收這台自己(loopback),和「來源在 Tailscale 的範圍、而且連到的那個位址是這台 Tailscale 通道介面上的位址」的連線——不是只看來源像不像 100.64.0.0/10(Wi-Fi 自己發那一段位址時,那是區網)。看的是連線落在這台的哪個位址,不是封包從哪張網卡進來:同一個 Wi-Fi 上的裝置故意把封包送到這台的 Tailscale 位址,系統可能收下,但那樣明文走過空中的只有它自己的流量;用 Tailscale 連的手機一定走 WireGuard。「Tailscale 通道介面」是:macOS 上同時帶著 Tailscale IPv6 位址(fd7a:115c:a1e0::/48)的 utun 這類點對點介面、Linux 上叫 tailscale… 的介面(或帶著那個 IPv6 位址的)、Windows 上名字有 Tailscale 的介面卡(從 ifconfig、ip -o addr、ipconfig 讀,30 秒更新一次)。只有 100.64.0.0/10 位址的點對點介面(PPPoE、手機的電信 NAT、Cloudflare WARP)不算;Windows 上介面卡改過名字就認不出來,http 一律轉 https。`ANYBOT_PHONE_BIND` 可以讓它只聽一個位址(例如 `127.0.0.1`,前面放代理)。
|
- LAN 模式(設定開)才會對區域網路開放,並要求 App 密碼(雜湊比對)。直接連線只憑這組密碼,所以從那裡改設定只能收緊、不能放寬:打開直接操作或自動審核、加「無需詢問直接允許」規則、拿掉「一律詢問」規則、加或打開連接器、打開訊息管道、打開 Bot 的電腦工具、分享 Bot 給團隊、勾回能力或可以用的電腦、把 Bot 的電腦從 gVisor 換回標準,一律 403;設定名字不是一字不差的(多空白、大小寫不同)回 400、什麼都不改(大腦那邊也照原字讀,不先去空白)。要放寬,在電腦上或經帳號連線。連線走這台自己做的憑證的 HTTPS;不加密的 http 只收這台自己(loopback),和「來源在 Tailscale 的範圍、而且連到的那個位址是這台 Tailscale 通道介面上的位址」的連線——不是只看來源像不像 100.64.0.0/10(Wi-Fi 自己發那一段位址時,那是區網)。看的是連線落在這台的哪個位址,不是封包從哪張網卡進來:同一個 Wi-Fi 上的裝置故意把封包送到這台的 Tailscale 位址,系統可能收下,但那樣明文走過空中的只有它自己的流量;用 Tailscale 連的手機一定走 WireGuard。「Tailscale 通道介面」是:macOS 上同時帶著 Tailscale IPv6 位址(fd7a:115c:a1e0::/48)的 utun 這類點對點介面、Linux 上叫 tailscale… 的介面(或帶著那個 IPv6 位址的)、Windows 上名字有 Tailscale 的介面卡(從 ifconfig、ip -o addr、ipconfig 讀,30 秒更新一次)。只有 100.64.0.0/10 位址的點對點介面(PPPoE、手機的電信 NAT、Cloudflare WARP)不算;Windows 上介面卡改過名字就認不出來,http 一律轉 https。`ANYBOT_PHONE_BIND` 可以讓它只聽一個位址(例如 `127.0.0.1`,前面放代理)。
|
||||||
- 帳號伺服器用 `http://` 時,帳號密碼(登入、建立帳號、兩步驗證、從帳號備份還原)、配對碼和這台電腦的金鑰(長連線、它的備用連線、備份、和大腦同步、手腳的指令)只送到:這台電腦、一個字的名字(當成同一個 Docker 網路裡的機器,例如 `http://relay:8080`),或「位址都是 Tailscale 的、而且這台到它的路由從 Tailscale 通道出去」的伺服器;其他(包括 Wi-Fi 上的 100.x)要 `https://`。這個檢查在開連線的那一刻,對真正要連的那幾個位址做(名字第二次查可能答不一樣):http 的帳號伺服器每個請求都開新的連線(不留著給下一個請求用),所以每個請求都查;長連線(WebSocket)在每次連上、重連時查,連著的時候不會中途再查。不符合就不連:登入、建立帳號、還原、配對直接回到表單說原因;長連線、備用連線和 `--serve` 的 `ANYBOT_ACCOUNT` 寫進狀態或紀錄,之後自己再試(例如 Tailscale 連上後)。http 的帳號伺服器不走代理(代理會照它自己的路把明文轉出去)。`localhost` 只連它查到的這台(loopback)位址,其他位址(例如舊 Mac 的 /etc/hosts 裡的 `fe80::1%lo0`)略過;一個 loopback 都沒有就不連。沒有路由的位址(沒有 IPv6 的電腦上的 IPv6 位址)略過。網址照 HTTP 程式庫自己的讀法讀(`?`、`#` 後面不算主機)。
|
- 帳號伺服器用 `http://` 時,帳號密碼(登入、建立帳號、兩步驗證、從帳號備份還原)、配對碼和這台電腦的金鑰(長連線、它的備用連線、備份、和大腦同步、手腳的指令)只送到:這台電腦、一個字的名字(當成同一個 Docker 網路裡的機器,例如 `http://relay:8080`),或「位址都是 Tailscale 的、而且這台到它的路由從 Tailscale 通道出去」的伺服器;其他(包括 Wi-Fi 上的 100.x)要 `https://`。這個檢查在開連線的那一刻,對真正要連的那幾個位址做(名字第二次查可能答不一樣):http 的帳號伺服器每個請求都開新的連線(不留著給下一個請求用),所以每個請求都查;長連線(WebSocket)在每次連上、重連時查,連著的時候不會中途再查。不符合就不連:登入、建立帳號、還原、配對直接回到表單說原因;長連線、備用連線和 `--serve` 的 `ANYBOT_ACCOUNT` 寫進狀態或紀錄,之後自己再試(例如 Tailscale 連上後)。http 的帳號伺服器不走代理(代理會照它自己的路把明文轉出去)。`localhost` 只連它查到的這台(loopback)位址,其他位址(例如舊 Mac 的 /etc/hosts 裡的 `fe80::1%lo0`)略過;一個 loopback 都沒有就不連。沒有路由的位址(沒有 IPv6 的電腦上的 IPv6 位址)略過。網址照 HTTP 程式庫自己的讀法讀(`?`、`#` 後面不算主機)。
|
||||||
- 一個字的名字(以英文字母開頭,只有字母、數字、`-`、`_`,例如 `relay`)是照「同一個 Docker 網路」相信的:在一般的網路上,路由器的 DNS、系統的搜尋網域或 LLMNR 也可能把這種名字查到區網位址,那時密碼會明文走過區網——Docker 以外,不要用一個字的名字當 http 帳號伺服器的網址。純數字或 0x 開頭的寫法(系統會把 `134744072`、`0x8080808` 讀成 8.8.8.8)不算名字。
|
- 一個字的名字(以英文字母開頭,只有字母、數字、`-`、`_`,例如 `relay`)是照「同一個 Docker 網路」相信的:在一般的網路上,路由器的 DNS、系統的搜尋網域或 LLMNR 也可能把這種名字查到區網位址,那時密碼會明文走過區網——Docker 以外,不要用一個字的名字當 http 帳號伺服器的網址。純數字或 0x 開頭的寫法(系統會把 `134744072`、`0x8080808` 讀成 8.8.8.8)不算名字。
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@
|
||||||
- `account-direct` 同一個網路直接連:先設手機密碼(至少 8 個字)才能打開;列出這台的網址(同一個 Wi-Fi,或都裝了 Tailscale)。區網用 https(這台自己做的憑證);http 只收從 Tailscale 連到這台 Tailscale 位址(Tailscale 通道介面上的 100.x)的,其他一律轉到 https——Wi-Fi 自己發 100.64.x 位址(電信業者 NAT 那一段)時也是區網。同一個位址密碼錯 5 次要等一分鐘。
|
- `account-direct` 同一個網路直接連:先設手機密碼(至少 8 個字)才能打開;列出這台的網址(同一個 Wi-Fi,或都裝了 Tailscale)。區網用 https(這台自己做的憑證);http 只收從 Tailscale 連到這台 Tailscale 位址(Tailscale 通道介面上的 100.x)的,其他一律轉到 https——Wi-Fi 自己發 100.64.x 位址(電信業者 NAT 那一段)時也是區網。同一個位址密碼錯 5 次要等一分鐘。
|
||||||
- `account-bind` 聽哪個位址:預設聽這台的每個位址,連接埠從 8793 起(被占用往後找,照設定頁列出的網址打開)。啟動時的 `ANYBOT_PHONE_BIND`(多半用在 `--serve`)只聽一個位址(`127.0.0.1`:前面有 `tailscale serve`、Caddy 這類代理,或測試用的副本;Tailscale 位址:只給 tailnet),列出的網址也只剩那一個;寫的不是位址就不開直接連線(紀錄和設定頁寫原因)。位址還不在(開機時 Tailscale 還沒連上)、連接埠都被占用或不准用(1024 以下要管理員權限)時照實寫,每 5 秒自己再試,不用關掉再開。`ANYBOT_PHONE_PORT` 換起始的連接埠。
|
- `account-bind` 聽哪個位址:預設聽這台的每個位址,連接埠從 8793 起(被占用往後找,照設定頁列出的網址打開)。啟動時的 `ANYBOT_PHONE_BIND`(多半用在 `--serve`)只聽一個位址(`127.0.0.1`:前面有 `tailscale serve`、Caddy 這類代理,或測試用的副本;Tailscale 位址:只給 tailnet),列出的網址也只剩那一個;寫的不是位址就不開直接連線(紀錄和設定頁寫原因)。位址還不在(開機時 Tailscale 還沒連上)、連接埠都被占用或不准用(1024 以下要管理員權限)時照實寫,每 5 秒自己再試,不用關掉再開。`ANYBOT_PHONE_PORT` 換起始的連接埠。
|
||||||
- `account-devices` 直接連線的裝置:用手機密碼登入過的手機和瀏覽器、最近使用時間,可以逐台「登出」;換手機密碼會把它們全部登出。
|
- `account-devices` 直接連線的裝置:用手機密碼登入過的手機和瀏覽器、最近使用時間,可以逐台「登出」;換手機密碼會把它們全部登出。
|
||||||
- `account-can` 手機可以做什麼:聊天、核准、看 Bot 的電腦一律可以;「從手機看這台電腦的螢幕並操作」和「裝置連結」預設關閉。
|
- `account-can` 手機可以做什麼:聊天、核准、看 Bot 的電腦一律可以;「從手機看這台電腦的螢幕並操作」和「裝置連結」預設關閉。直接連線的手機改設定只能收緊、不能放寬(打開直接操作或自動審核、加「無需詢問直接允許」規則、拿掉「一律詢問」規則、加或打開連接器、打開訊息管道、打開 Bot 的電腦工具、分享給團隊、勾回能力或可以用的電腦、把 Bot 的電腦從強隔離換回標準,都會被擋;反過來都可以),設定的名字不是 AnyBot 認得的(多空白、大小寫不同)一律不做([autonomy](autonomy.md))。用帳號連線或在電腦上就沒有這個限制。
|
||||||
- `account-push` 通知:需要你允許、問你、需要你處理,你不在時做完事,例行任務暫停,收到傳來的檔案——推播到開了通知的手機,點了直接打開那個 Bot。每支手機自己選要哪幾種(需要你/做完了/例行任務暫停/收到傳來的檔案),可以送一則測試通知。圖示是 AnyBot 的貓,Android 狀態列是貓的單色剪影;App 圖示上的數字是正在等你的 Bot。「需要你允許」的通知在 Android 上有「允許/拒絕」(只答那個請求,換了就不答);主畫面圖示長按有「主要 Bot」「未讀」兩個捷徑。
|
- `account-push` 通知:需要你允許、問你、需要你處理,你不在時做完事,例行任務暫停,收到傳來的檔案——推播到開了通知的手機,點了直接打開那個 Bot。每支手機自己選要哪幾種(需要你/做完了/例行任務暫停/收到傳來的檔案),可以送一則測試通知。圖示是 AnyBot 的貓,Android 狀態列是貓的單色剪影;App 圖示上的數字是正在等你的 Bot。「需要你允許」的通知在 Android 上有「允許/拒絕」(只答那個請求,換了就不答);主畫面圖示長按有「主要 Bot」「未讀」兩個捷徑。
|
||||||
|
|
||||||
## 使用者怎麼到
|
## 使用者怎麼到
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@
|
||||||
- `autonomy-review` 自動審核:兩組用一般的話寫的規則「無需詢問直接允許」「一律詢問」,由這個 Bot 的模型判斷,兩邊都符合時「一律詢問」優先。符合允許就直接做;符合詢問就問你,而且沒有「一律允許」;都不符合照常問;審核沒回應就先問你。
|
- `autonomy-review` 自動審核:兩組用一般的話寫的規則「無需詢問直接允許」「一律詢問」,由這個 Bot 的模型判斷,兩邊都符合時「一律詢問」優先。符合允許就直接做;符合詢問就問你,而且沒有「一律允許」;都不符合照常問;審核沒回應就先問你。
|
||||||
- `autonomy-patterns` 固定樣式的規則:規則也可以寫成 `shell(git *)`(指令;允許要 `a && b` 每一段都符合,詢問只要一段)、`file(~/Projects/**)`(檔案或資料夾,** 任何層、* 一層)、`connector(gitlab__*)`(連接器的工具)、`web(domain:example.com)`(那個網站和它底下的網址)、`tool(browser_click)`(工具的名字)。樣式先判斷、每次一樣、不呼叫模型:符合「一律詢問」的樣式一定問(模型說允許也沒用);符合允許的樣式就允許,但用一般的話寫的「一律詢問」還是會先讓模型看一次;有藏起來的指令($()、反引號)的,樣式不會允許。
|
- `autonomy-patterns` 固定樣式的規則:規則也可以寫成 `shell(git *)`(指令;允許要 `a && b` 每一段都符合,詢問只要一段)、`file(~/Projects/**)`(檔案或資料夾,** 任何層、* 一層)、`connector(gitlab__*)`(連接器的工具)、`web(domain:example.com)`(那個網站和它底下的網址)、`tool(browser_click)`(工具的名字)。樣式先判斷、每次一樣、不呼叫模型:符合「一律詢問」的樣式一定問(模型說允許也沒用);符合允許的樣式就允許,但用一般的話寫的「一律詢問」還是會先讓模型看一次;有藏起來的指令($()、反引號)的,樣式不會允許。
|
||||||
- `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 能做的事:同一個網路直接連的裝置只能收緊、不能放寬…」)。擋下的:打開直接操作、打開自動審核、加「無需詢問直接允許」規則、拿掉「一律詢問」規則、加連接器或把關掉的打開、打開訊息管道、打開 Bot 的電腦工具、分享 Bot 給團隊、勾回能力或可以用的電腦、Bot 的電腦從強隔離換回標準。可以的:上面每一項反過來,和不動權限的(名字、外觀、模型、金鑰、技能、例行任務、記憶)。設定的名字要一字不差(多空白、大小寫不同就回「不認得這個設定」,什麼都不改)。要放寬:在電腦上的 AnyBot,或用帳號連線。卡片上的「允許」「一律允許」照樣可以按(那是回答眼前那張卡)。手機的權限頁跟著電腦那邊的改變重讀,不用重新整理。
|
||||||
|
|
||||||
## 使用者怎麼到
|
## 使用者怎麼到
|
||||||
|
|
||||||
|
|
@ -30,7 +30,7 @@
|
||||||
- **一律放行**(covers `autonomy-yolo`、`autonomy-direct`):先看一眼手機的 設定 › 權限(還沒有規則),回聊天打「/always-approve」,再請 Bot 改名。指令:`$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 wait-text '還沒有規則' --in '#list' && $CTL phone click '[data-back]' && $CTL phone click '[data-back]' && $CTL phone click '.row[data-bot="1"]' && $CTL phone send '/always-approve' && $CTL phone wait-text '已一律放行' --in '#msgs' && $CTL wait-api /api/settings '.direct_mode == true' && $CTL phone send '改名 [[call update_bot {"name":"放行後的名字"}]]' && $CTL phone wait-text 放行後的名字 --in '#isl-name' && $CTL api GET /api/bots/1 --jq '[.messages[].tools[]? | select(.name == "update_bot") | .status]'`。看到:「已一律放行:…仍然會擋:…」;直接操作跟著開;改名沒有跳卡片,步驟是 done。
|
- **一律放行**(covers `autonomy-yolo`、`autonomy-direct`):先看一眼手機的 設定 › 權限(還沒有規則),回聊天打「/always-approve」,再請 Bot 改名。指令:`$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 wait-text '還沒有規則' --in '#list' && $CTL phone click '[data-back]' && $CTL phone click '[data-back]' && $CTL phone click '.row[data-bot="1"]' && $CTL phone send '/always-approve' && $CTL phone wait-text '已一律放行' --in '#msgs' && $CTL wait-api /api/settings '.direct_mode == true' && $CTL phone send '改名 [[call update_bot {"name":"放行後的名字"}]]' && $CTL phone wait-text 放行後的名字 --in '#isl-name' && $CTL api GET /api/bots/1 --jq '[.messages[].tools[]? | select(.name == "update_bot") | .status]'`。看到:「已一律放行:…仍然會擋:…」;直接操作跟著開;改名沒有跳卡片,步驟是 done。
|
||||||
- **hook 照樣問、擋下一步**(covers `autonomy-hooks`、`autonomy-yolo`):一律放行開著,請 Bot 加一個擋 `shell` 的 hook,按允許,再請它跑指令。指令:`$CTL phone send '加 hook [[call manage_hooks {"action":"add","event":"PreToolUse","matcher":"shell","command":"echo 這一步被 hook 擋下 >&2; exit 2"}]]' && $CTL phone wait '#ask .ask' && $CTL phone shot autonomy-hook-card && $CTL phone click '#ask button[data-a="once"]' && $CTL wait-api /api/bots/1 '[.messages[].tools[]? | select(.name == "manage_hooks") | .status] == ["done"]' && $CTL datafile hooks/hooks.json && $CTL phone send '跑 [[call shell {"command":"echo hi"}]]' && $CTL phone wait-text 'hook 擋下了這一步' --in '#msgs'`。看到:一律放行也跳「新增一個 hook:每次「PreToolUse」…」的卡片;hooks.json 有那條;指令沒跑,「沒有執行:使用者設定的 hook 擋下了這一步。它說:這一步被 hook 擋下」。
|
- **hook 照樣問、擋下一步**(covers `autonomy-hooks`、`autonomy-yolo`):一律放行開著,請 Bot 加一個擋 `shell` 的 hook,按允許,再請它跑指令。指令:`$CTL phone send '加 hook [[call manage_hooks {"action":"add","event":"PreToolUse","matcher":"shell","command":"echo 這一步被 hook 擋下 >&2; exit 2"}]]' && $CTL phone wait '#ask .ask' && $CTL phone shot autonomy-hook-card && $CTL phone click '#ask button[data-a="once"]' && $CTL wait-api /api/bots/1 '[.messages[].tools[]? | select(.name == "manage_hooks") | .status] == ["done"]' && $CTL datafile hooks/hooks.json && $CTL phone send '跑 [[call shell {"command":"echo hi"}]]' && $CTL phone wait-text 'hook 擋下了這一步' --in '#msgs'`。看到:一律放行也跳「新增一個 hook:每次「PreToolUse」…」的卡片;hooks.json 有那條;指令沒跑,「沒有執行:使用者設定的 hook 擋下了這一步。它說:這一步被 hook 擋下」。
|
||||||
- **看狀態、關掉**(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 click '[data-back]' && $CTL phone click '#b-me' && $CTL phone click '#sheet-in .opt' --text 設定 && $CTL phone click '[data-go="perms"]' && $CTL phone wait-text '刪除檔案或資料夾' --in '#list' && $CTL api POST /api/act/setting '{"key":"rule_add","list":"ask","value":"寄信前先問我"}' && $CTL phone wait-text '寄信前先問我' --in '#list' && $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 click '[data-back]' && $CTL phone click '#b-me' && $CTL phone click '#sheet-in .opt' --text 設定 && $CTL phone click '[data-go="perms"]' && $CTL phone wait-text '刪除檔案或資料夾' --in '#list' && $CTL api POST /api/act/setting '{"key":"rule_add","list":"ask","value":"寄信前先問我"}' && $CTL phone wait-text '寄信前先問我' --in '#list' && $CTL api --expect 403 POST /api/act/setting '{"key":"rule_remove","list":"ask","value":"寄信前先問我"}' && $CTL api --expect 400 POST /api/act/setting '{"key":" rule_add","list":"allow","value":"全部直接做"}' && $CTL api --expect 403 POST /api/act/setting '{"key":"auto_review","value":true}' && $CTL state '{ask: .review_ask_rules, allow: .review_allow_rules}' && $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'`。看到:「一律詢問(優先)」裡三條預設規則(第一步看過的「還沒有規則」沒有留著);另一台加的「寄信前先問我」自己出現;直接連線拿掉它回 403、名字多一格空白的「 rule_add」回 400「不認得這個設定」、打開自動審核回 403,state 裡「寄信前先問我」還在、允許規則是空的;按開關、確認「打開」後跳出「這會放寬 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-review`、`autonomy-patterns`、`autonomy-still-asks`):指令:走不到——scratch 裡會問的是 App 操作工具和連接器的工具,都直接問、不經自動審核(經過的是你的電腦的指令和檔案,scratch 沒有那台)。看到:最接近的真路是下面的自動測試(審核的 system 開頭是「你是動作審核員」,可用 `model-reply` 指定)。
|
- **審核、樣式規則**(covers `autonomy-review`、`autonomy-patterns`、`autonomy-still-asks`):指令:走不到——scratch 裡會問的是 App 操作工具和連接器的工具,都直接問、不經自動審核(經過的是你的電腦的指令和檔案,scratch 沒有那台)。看到:最接近的真路是下面的自動測試(審核的 system 開頭是「你是動作審核員」,可用 `model-reply` 指定)。
|
||||||
- 自動測試:`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`)、`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`)、`cargo test hooks::`、`cargo test remote::`(`roles_gate_the_sync_and_hands_apis`)。
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@
|
||||||
|
|
||||||
## 怎麼操作(verify-anybot)
|
## 怎麼操作(verify-anybot)
|
||||||
|
|
||||||
- Bot:支線裡照常做事;支線不能再開支線,也不能改設定。
|
- Bot:支線裡照常做事;支線不能再開支線,也不能動大家共用的東西(設定、建 Bot、群組、刪除或安裝技能、換掉已有的技能、連接器和 hook、瀏覽器設定檔),要做就寫在結果裡給主線。
|
||||||
|
|
||||||
前提:
|
前提:
|
||||||
|
|
||||||
|
|
@ -25,7 +25,7 @@
|
||||||
- **主線忙的時候開**(covers `branch-btw`、`branch-card`、`branch-report`):Bot 跑 20 秒的指令時打「/」,送「/btw 查一下匯率」。指令:`$CTL phone send '忙 [[call shell {"command":"sleep 20"}]]' && $CTL wait-api '/api/state?since=0' '.bots[0].busy == true' && $CTL phone type '#input' '/' && $CTL phone wait-text '/btw' --in '#slash' && $CTL phone wait-gone '#slash [data-sl]' --text '/goal' && $CTL phone send '/btw 查一下匯率' && $CTL phone wait-text '做完了' --in '.talk.branch' && $CTL phone shot branch-done && $CTL phone wait-text '支線的結果已交給正在做事的主線' --in '#msgs' 40 && $CTL model 'select(.user | test("匯率")) | {kind, user: .user[0:40]}'`。看到:工作中「/」只剩 /btw;卡「支線 查一下匯率 ✓ 做完了」和結果;先問一次會不會衝突(沒帶工具的請求「主線正在做…支線要做…」),主線這一輪讀到「〔支線回報〕支線「查一下匯率」做完了…」。
|
- **主線忙的時候開**(covers `branch-btw`、`branch-card`、`branch-report`):Bot 跑 20 秒的指令時打「/」,送「/btw 查一下匯率」。指令:`$CTL phone send '忙 [[call shell {"command":"sleep 20"}]]' && $CTL wait-api '/api/state?since=0' '.bots[0].busy == true' && $CTL phone type '#input' '/' && $CTL phone wait-text '/btw' --in '#slash' && $CTL phone wait-gone '#slash [data-sl]' --text '/goal' && $CTL phone send '/btw 查一下匯率' && $CTL phone wait-text '做完了' --in '.talk.branch' && $CTL phone shot branch-done && $CTL phone wait-text '支線的結果已交給正在做事的主線' --in '#msgs' 40 && $CTL model 'select(.user | test("匯率")) | {kind, user: .user[0:40]}'`。看到:工作中「/」只剩 /btw;卡「支線 查一下匯率 ✓ 做完了」和結果;先問一次會不會衝突(沒帶工具的請求「主線正在做…支線要做…」),主線這一輪讀到「〔支線回報〕支線「查一下匯率」做完了…」。
|
||||||
- **主線閒著**(covers `branch-report`):等主線做完再開。指令:`$CTL wait-api '/api/state?since=0' '.bots[0].busy == false' && $CTL phone send '/btw 查天氣' && $CTL phone wait-text '支線「查天氣」做完了' --in '#msgs' && $CTL api GET /api/bots/1 --jq '[.messages[] | select(.text | startswith("支線「查天氣」")) | .text]'`。看到:結果貼在主聊天的一則訊息裡(只說一次)。
|
- **主線閒著**(covers `branch-report`):等主線做完再開。指令:`$CTL wait-api '/api/state?since=0' '.bots[0].busy == false' && $CTL phone send '/btw 查天氣' && $CTL phone wait-text '支線「查天氣」做完了' --in '#msgs' && $CTL api GET /api/bots/1 --jq '[.messages[] | select(.text | startswith("支線「查天氣」")) | .text]'`。看到:結果貼在主聊天的一則訊息裡(只說一次)。
|
||||||
- **停止支線**(covers `branch-card`、`branch-report`):指令:`$CTL phone send '/btw 跑 [[call shell {"command":"sleep 30"}]]' && $CTL phone wait '[data-brstop]' && $CTL phone click '[data-brstop]' && $CTL phone wait-gone '[data-brstop]' && $CTL phone wait-text '已停止' --in '#msgs' && $CTL phone wait-text '看過程' --in '#msgs' && $CTL api GET /api/bots/1 --jq '[.messages[] | select(.branch) | [.branch.state, .text[0:12]]]'`。看到:「停止支線」不見、卡寫「已停止」和「看過程(1)」;被停止的不回報(沒有多一則「支線「跑…」」)。
|
- **停止支線**(covers `branch-card`、`branch-report`):指令:`$CTL phone send '/btw 跑 [[call shell {"command":"sleep 30"}]]' && $CTL phone wait '[data-brstop]' && $CTL phone click '[data-brstop]' && $CTL phone wait-gone '[data-brstop]' && $CTL phone wait-text '已停止' --in '#msgs' && $CTL phone wait-text '看過程' --in '#msgs' && $CTL api GET /api/bots/1 --jq '[.messages[] | select(.branch) | [.branch.state, .text[0:12]]]'`。看到:「停止支線」不見、卡寫「已停止」和「看過程(1)」;被停止的不回報(沒有多一則「支線「跑…」」)。
|
||||||
- **卡上核准、改不了設定**(covers `branch-card`、`branch-btw`):支線要登出 ChatGPT(按拒絕);支線改自己的描述、改 Bot 的名字。指令:`$CTL phone send '/btw 登出 [[call chatgpt_login {"action":"logout"}]]' && $CTL phone wait-text '支線:驗證小幫手 想要登出 ChatGPT 方案' --in '#ask' && $CTL api GET '/api/state?since=0' --jq '.approvals[0] | {bot, target, title}' && $CTL phone click '#ask button[data-a="reject"]' && $CTL phone wait-gone '#ask .ask' && $CTL phone send '/btw 改 [[call update_my_profile {"description":"支線改的"}]]' && $CTL phone wait-text '支線改不了設定' --in '#msgs' && $CTL phone send '/btw 改名 [[call update_bot {"name":"支線改的名字"}]]' && $CTL wait-api /api/bots/1 '[.messages[] | select(.text | tostring | startswith("支線「改名"))] | length == 1' && $CTL api GET '/api/state?since=0' --jq '{name: .bots[0].name, approvals}' && $CTL api GET /api/bots/1/detail --jq .description`。看到:卡標題「支線:驗證小幫手 想要登出 ChatGPT 方案」(target 是那條支線);改描述、改名都沒有卡片,馬上回「支線改不了設定:回到主線再請它改。」;名字還是「驗證小幫手」、描述還是空的。
|
- **卡上核准、改不了設定**(covers `branch-card`、`branch-btw`):支線要登出 ChatGPT(按拒絕);支線改自己的描述、改 Bot 的名字。指令:`$CTL phone send '/btw 登出 [[call chatgpt_login {"action":"logout"}]]' && $CTL phone wait-text '支線:驗證小幫手 想要登出 ChatGPT 方案' --in '#ask' && $CTL api GET '/api/state?since=0' --jq '.approvals[0] | {bot, target, title}' && $CTL phone click '#ask button[data-a="reject"]' && $CTL phone wait-gone '#ask .ask' && $CTL phone send '/btw 改 [[call update_my_profile {"description":"支線改的"}]]' && $CTL phone wait-text '支線改不了設定' --in '#msgs' && $CTL phone send '/btw 改名 [[call update_bot {"name":"支線改的名字"}]]' && $CTL wait-api /api/bots/1 '[.messages[] | select(.text | tostring | startswith("支線「改名"))] | length == 1' && $CTL api GET '/api/state?since=0' --jq '{name: .bots[0].name, approvals}' && $CTL api GET /api/bots/1/detail --jq .description && $CTL phone send '/btw 建 [[call create_bot {"name":"支線的 Bot"}]]' && $CTL wait-api /api/bots/1 '[.messages[] | select(.text | tostring | startswith("支線「建"))] | length == 1' && $CTL phone send '/btw 換 [[call browser {"action":"profiles","name":"工作"}]]' && $CTL wait-api /api/bots/1 '[.messages[] | select(.text | tostring | startswith("支線「換"))] | length == 1' && $CTL api GET /api/bots/1 --jq '[.messages[] | select(.text | tostring | test("^支線「(建|換)")) | .text]' && $CTL api GET '/api/state?since=0' --jq '[.bots[].name]'`。看到:卡標題「支線:驗證小幫手 想要登出 ChatGPT 方案」(target 是那條支線);改描述、改名、建 Bot、換瀏覽器設定檔都沒有卡片,馬上回「支線改不了設定:回到主線再請它改。」;名字還是「驗證小幫手」、描述還是空的,Bot 清單只有它。
|
||||||
- **重開 AnyBot**(covers `branch-card`):開一條跑 30 秒的支線,重開。指令:`$CTL phone send '/btw 再跑 [[call shell {"command":"sleep 30"}]]' && $CTL phone wait '[data-brstop]' && $CTL restart && $CTL phone open --listed && $CTL phone click '.row[data-bot="1"]' && $CTL wait-api /api/bots/1 '[.messages[] | select(.branch.task | tostring | startswith("再跑")) | .branch.state] == ["stopped"]' && $CTL api GET /api/bots/1 --jq '[.messages[] | select(.branch.task | tostring | startswith("再跑")) | .branch.note]'`。看到:卡寫「已停止」,原因「AnyBot 關掉了,這條支線停了」(`ctl` 是正常關;當掉後重開寫「AnyBot 重新啟動,這條支線停了」;「被停止了」只在使用者按停止),沒有回報。
|
- **重開 AnyBot**(covers `branch-card`):開一條跑 30 秒的支線,重開。指令:`$CTL phone send '/btw 再跑 [[call shell {"command":"sleep 30"}]]' && $CTL phone wait '[data-brstop]' && $CTL restart && $CTL phone open --listed && $CTL phone click '.row[data-bot="1"]' && $CTL wait-api /api/bots/1 '[.messages[] | select(.branch.task | tostring | startswith("再跑")) | .branch.state] == ["stopped"]' && $CTL api GET /api/bots/1 --jq '[.messages[] | select(.branch.task | tostring | startswith("再跑")) | .branch.note]'`。看到:卡寫「已停止」,原因「AnyBot 關掉了,這條支線停了」(`ctl` 是正常關;當掉後重開寫「AnyBot 重新啟動,這條支線停了」;「被停止了」只在使用者按停止),沒有回報。
|
||||||
- **沒做完**(covers `branch-report`):主 Bot 換成沒金鑰的 xAI 再開支線。指令:`$CTL phone send '換 [[call update_my_profile {"provider":"xai"}]]' && $CTL phone click '#ask button[data-a="once"]' && $CTL wait-api '/api/state?since=0' '.bots[0].provider == "Xai"' && $CTL phone send '/btw 查匯率' && $CTL phone wait-text '支線「查匯率」沒有做完' --in '#msgs' && $CTL phone shot branch-failed && $CTL api GET /api/bots/1 --jq '[.messages[] | select(.error) | .text]'`。看到:主聊天一則「支線「查匯率」沒有做完:還沒有設定 xAI Grok 的 API 金鑰…」(error);手機的卡也寫原因。
|
- **沒做完**(covers `branch-report`):主 Bot 換成沒金鑰的 xAI 再開支線。指令:`$CTL phone send '換 [[call update_my_profile {"provider":"xai"}]]' && $CTL phone click '#ask button[data-a="once"]' && $CTL wait-api '/api/state?since=0' '.bots[0].provider == "Xai"' && $CTL phone send '/btw 查匯率' && $CTL phone wait-text '支線「查匯率」沒有做完' --in '#msgs' && $CTL phone shot branch-failed && $CTL api GET /api/bots/1 --jq '[.messages[] | select(.error) | .text]'`。看到:主聊天一則「支線「查匯率」沒有做完:還沒有設定 xAI Grok 的 API 金鑰…」(error);手機的卡也寫原因。
|
||||||
- **桌面**(covers `branch-card`、`branch-report`、`branch-btw`):指令:要開視窗——`$CTL stop && ABV_ALLOW_WINDOW=1 $CTL desktop-shot branch ANYBOT_SHOT_VIEW=btw`。看到:電腦版的支線卡;沒做完那則的紅色驚嘆號和「重開這條支線」;同時最多 3 條、會衝突就等主線、`context: fork` 靠自動測試。
|
- **桌面**(covers `branch-card`、`branch-report`、`branch-btw`):指令:要開視窗——`$CTL stop && ABV_ALLOW_WINDOW=1 $CTL desktop-shot branch ANYBOT_SHOT_VIEW=btw`。看到:電腦版的支線卡;沒做完那則的紅色驚嘆號和「重開這條支線」;同時最多 3 條、會衝突就等主線、`context: fork` 靠自動測試。
|
||||||
|
|
@ -33,5 +33,5 @@
|
||||||
|
|
||||||
## 陷阱
|
## 陷阱
|
||||||
|
|
||||||
- 支線:一個 Bot 同時最多 3 條;支線不能再開支線,也不能改設定(自己的、別的 Bot 的、AnyBot 的:`update_my_profile`、`update_bot`、`update_settings`、`teach_skill`,新增、修改、移除連接器或 hook,都馬上回「支線改不了設定」、不跳卡片;登入登出 ChatGPT 不算設定,照樣跳卡);支線記的、做的頁面和例行任務都算主 Bot 的。主線在忙時,先用執行步驟用的模型判斷會不會衝突,會就等主線這一輪做完。在 Bot 的電腦上支線有自己的暫時螢幕和瀏覽器(登入從主線複製),看不到主線開著的網頁;在使用者的電腦上還是一次一個。關掉 AnyBot 時,沒做完的支線會停掉(「AnyBot 關掉了,這條支線停了」;當掉後重新啟動的寫「AnyBot 重新啟動,這條支線停了」);被停止的支線不回報。
|
- 支線:一個 Bot 同時最多 3 條;支線不能再開支線,也不能改設定或動大家共用的東西:`update_my_profile`、`update_bot`、`update_settings`、`teach_skill`、`create_bot`、`create_group`、`move_to_group`、`rename_group`、`delete_group`、`delete_skill`、`skill_install`(內建的也是),連接器和 hook 除了看(`manage_connectors` 的 list、reconnect、登入登出,`manage_hooks` 的 list)以外的動作,瀏覽器的 `profiles` 新增或切換,都馬上回「支線改不了設定」、不跳卡片;`save_skill`、`skillify` 存新技能可以(算主 Bot 的),但不能換掉技能庫裡已有的同名技能;登入登出 ChatGPT 不算設定,照樣跳卡;支線記的、做的頁面和例行任務都算主 Bot 的。主線在忙時,先用執行步驟用的模型判斷會不會衝突,會就等主線這一輪做完。在 Bot 的電腦上支線有自己的暫時螢幕和瀏覽器(登入從主線複製),看不到主線開著的網頁;在使用者的電腦上還是一次一個。關掉 AnyBot 時,沒做完的支線會停掉(「AnyBot 關掉了,這條支線停了」;當掉後重新啟動的寫「AnyBot 重新啟動,這條支線停了」);被停止的支線不回報。
|
||||||
- 支線的結果在主線還在做事時交給正在做事的主線(聊天裡一行「支線的結果已交給正在做事的主線」),主線閒著才另外貼一則。
|
- 支線的結果在主線還在做事時交給正在做事的主線(聊天裡一行「支線的結果已交給正在做事的主線」),主線閒著才另外貼一則。
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,9 @@ Bot 用 AnyBot 自己的瀏覽器上網、登入網站、點按、打字、送
|
||||||
|
|
||||||
## 子功能
|
## 子功能
|
||||||
|
|
||||||
- `browser-actions` 一個 `browser` 工具,用 action 分:`open` 開網址並讀出頁面、`read` 讀目前分頁、`elements` 只列可操作的元素、`find` 找字、`table` 讀表格、`screenshot` 截圖(有編號框);`click`、`hover`、`type`、`press`、`select`、`scroll`、`wait`;`tabs` 分頁、`back` 上一頁/下一頁/重新整理;`upload`、`download`、`pdf`;`dialog` 回應網頁跳出的對話框;`eval` 唯讀的小段 JavaScript;`sent` 查帳號已經送過什麼;`profiles` 設定檔:不帶 name 列出,帶 name 換到那個設定檔(還沒有就先新增);`fill` 從保險庫填帳密、卡號、地址([vault](vault.md))。
|
- `browser-actions` 一個 `browser` 工具,用 action 分:`open` 開網址並讀出頁面、`read` 讀目前分頁、`elements` 只列可操作的元素、`find` 找字、`table` 讀表格、`screenshot` 截圖(有編號框);`click`、`hover`、`type`、`press`、`select`、`scroll`、`wait`;`tabs` 分頁、`back` 上一頁/下一頁/重新整理;`upload`、`download`、`pdf`;`dialog` 回應網頁跳出的對話框;`eval` 唯讀的小段 JavaScript;`sent` 查帳號已經送過什麼;`profiles` 設定檔:不帶 name 列出,帶 name 換到 AnyBot 自己那個名字的設定檔(名字要一樣,大小寫不算;沒有就新增一個全新的);`fill` 從保險庫填帳密、卡號、地址([vault](vault.md))。
|
||||||
- `browser-fetch` `web_fetch`:不用登入的公開網頁,直接下載成文字。
|
- `browser-fetch` `web_fetch`:不用登入的公開網頁,直接下載成文字。
|
||||||
- `browser-profiles` 設定檔:Chrome、Brave、Edge、Chromium 或 Firefox。名稱結尾是「(Firefox)」的是使用者自己的 Firefox 設定檔(帶著他的登入);「你的瀏覽器」是使用者平常用的瀏覽器(只能讀)。
|
- `browser-profiles` 設定檔:Chrome、Brave、Edge、Chromium 或 Firefox。名稱結尾是「(Firefox)」的是使用者自己的 Firefox 設定檔(帶著他的登入);「你的瀏覽器」是使用者平常用的瀏覽器(只能讀)。這兩種是使用者自己的:Bot 不會換過去當使用中(要使用者在設定裡換),某一步指名用它也不會變成使用中。Bot 的電腦上的瀏覽器只有一個設定檔。
|
||||||
- `browser-refs` 元素編號:同一頁重讀編號不變;換頁要用新結果的編號。
|
- `browser-refs` 元素編號:同一頁重讀編號不變;換頁要用新結果的編號。
|
||||||
- `browser-type` 打字:`type` 的換行會整段放進去(像貼上),結果說欄位現在裝了什麼。
|
- `browser-type` 打字:`type` 的換行會整段放進去(像貼上),結果說欄位現在裝了什麼。
|
||||||
- `browser-wait` 間隔:`wait` 加 `after_send: true`,從上一次送出起算(最多 900 秒),下一則可以先打好再等。
|
- `browser-wait` 間隔:`wait` 加 `after_send: true`,從上一次送出起算(最多 900 秒),下一則可以先打好再等。
|
||||||
|
|
@ -21,7 +21,7 @@ Bot 用 AnyBot 自己的瀏覽器上網、登入網站、點按、打字、送
|
||||||
|
|
||||||
## 怎麼操作(verify-anybot)
|
## 怎麼操作(verify-anybot)
|
||||||
|
|
||||||
- Bot:先 `open` 或 `read`,再照最新結果的編號(ref)或看得到的字操作,不要憑記憶。每次都帶同一個 `profile`。多行留言直接 `type`,不用剪貼簿;送出用 `press`(例如 ctrl+Return)或 `click` 送出鍵。送出後看結果最後那行【系統】:「已送出,系統重新讀過頁面確認」才算成功;「沒有送出」或「發布前檢查沒通過」就照它說的做。防重複先用 `sent`(帶 profile)看回過誰,比讀網站的回覆頁便宜。換設定檔用 `profiles` 帶 name(沒有就新增並換過去)。
|
- Bot:先 `open` 或 `read`,再照最新結果的編號(ref)或看得到的字操作,不要憑記憶。每次都帶同一個 `profile`。多行留言直接 `type`,不用剪貼簿;送出用 `press`(例如 ctrl+Return)或 `click` 送出鍵。送出後看結果最後那行【系統】:「已送出,系統重新讀過頁面確認」才算成功;「沒有送出」或「發布前檢查沒通過」就照它說的做。防重複先用 `sent`(帶 profile)看回過誰,比讀網站的回覆頁便宜。換設定檔用 `profiles` 帶 name(沒有就新增並換過去);使用者自己的瀏覽器要請他在設定裡換,Bot 的電腦上和支線裡不能換。
|
||||||
|
|
||||||
前提:
|
前提:
|
||||||
|
|
||||||
|
|
@ -30,7 +30,7 @@ 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 wait-text '在 執行 AnyBot 的這台電腦 上' --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/」「(在 執行 AnyBot 的這台電腦 上)」(Bot 的電腦都開不了瀏覽器,開的會是 AnyBot 在這台的;可以一律允許);拒絕後兩步都是 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 wait-text '在 執行 AnyBot 的這台電腦 上' --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/」「(在 執行 AnyBot 的這台電腦 上)」(Bot 的電腦都開不了瀏覽器,開的會是 AnyBot 在這台的;可以一律允許);拒絕後兩步都是 denied。
|
||||||
- **已送帳本、設定檔**(covers `browser-gate`、`browser-profiles`、`browser-actions`):請 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:]' && $CTL phone send '[[call browser {"action":"profiles","name":"工作"}]]' && $CTL phone wait-text '已新增並切換到設定檔「工作」' --in '#msgs' && $CTL phone send '[[call browser {"action":"profiles","name":"預設"}]]' && $CTL phone wait-text '已切換到「預設」' --in '#msgs' && $CTL api GET /api/bots/1 --jq '[.messages[].tools[]? | select(.label == "瀏覽器設定檔") | .detail]' && $CTL datafile browser-profile.txt`。看到:「帳本裡最近 30 天沒有送出紀錄(AnyBot 從開始記帳本那天起才有…)」;「AnyBot 瀏覽器的設定檔:預設(使用中)、你的瀏覽器。每個設定檔有自己的登入。…」;「已新增並切換到設定檔「工作」(全新的,還沒登入任何網站)…現在:預設、工作(使用中)、你的瀏覽器」;「已切換到「預設」…」;三個設定檔步驟寫「列出設定檔」「切換到「工作」」「切換到「預設」」;記著的使用中設定檔是「預設」;都沒開瀏覽器。
|
- **已送帳本、設定檔**(covers `browser-gate`、`browser-profiles`、`browser-actions`):請 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:]' && $CTL phone send '[[call browser {"action":"profiles","name":"工作"}]]' && $CTL phone wait-text '已新增並切換到設定檔「工作」' --in '#msgs' && $CTL phone send '[[call browser {"action":"profiles","name":"預設"}]]' && $CTL phone wait-text '已切換到「預設」' --in '#msgs' && $CTL phone send '[[call browser {"action":"profiles","name":"你的瀏覽器"}]]' && $CTL phone wait-text '是使用者自己的瀏覽器' --in '#msgs' && $CTL api GET /api/bots/1 --jq '[.messages[].tools[]? | select(.label == "瀏覽器設定檔") | .detail]' && $CTL datafile browser-profile.txt`。看到:「帳本裡最近 30 天沒有送出紀錄(AnyBot 從開始記帳本那天起才有…)」;「AnyBot 瀏覽器的設定檔:預設(使用中)、你的瀏覽器。每個設定檔有自己的登入。…」;「已新增並切換到設定檔「工作」(全新的,還沒登入任何網站)…現在:預設、工作(使用中)、你的瀏覽器」;「已切換到「預設」…」;換到「你的瀏覽器」被擋:「「你的瀏覽器」是使用者自己的瀏覽器(帶著他的登入):Bot 不能自己換過去…請使用者在 設定 › 電腦 ›「AnyBot 瀏覽器設定檔」自己切換。」;設定檔步驟寫「列出設定檔」「切換到「工作」」「切換到「預設」」「切換到「你的瀏覽器」」(最後一個 failed);記著的使用中設定檔是「預設」;都沒開瀏覽器。
|
||||||
- **真的開網頁、打字、送出**(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::`;實機(無頭 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` 也換掉)。
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
## 子功能
|
## 子功能
|
||||||
|
|
||||||
- `phone-pages` 頁面:Bot 清單(分區、工作中/等你)、聊天(附檔、拍照、語音輸入、插話、停止;叫醒 Bot 的訊息上方標是什麼叫醒的:目標、例行任務、觸發、訊息管道、來自其他 Bot、監看)、允許請求卡片(「一律允許」「允許一次」或「允許」、「拒絕」、「全部允許,之後直接操作」;卡片太高時卡在內面自己捲,輸入框不會被頂出螢幕)、問題卡、「需要處理」與接管、Bot 設定、例行任務(詳細頁有最近幾次執行和送出證據)、頁面、記憶、檔案預覽、Bot 的電腦畫面、設定(一般、模型、權限、整合、電腦、保險庫、手機與帳號、更新,能改的比電腦少;開著的設定頁跟著電腦那邊的改變重讀,不用重新整理)、傳送到其他裝置。
|
- `phone-pages` 頁面:Bot 清單(分區、工作中/等你)、聊天(附檔、拍照、語音輸入、插話、停止;叫醒 Bot 的訊息上方標是什麼叫醒的:目標、例行任務、觸發、訊息管道、來自其他 Bot、監看)、允許請求卡片(「一律允許」「允許一次」或「允許」、「拒絕」、「全部允許,之後直接操作」;卡片太高時卡在內面自己捲,輸入框不會被頂出螢幕)、問題卡、「需要處理」與接管、Bot 設定、例行任務(詳細頁有最近幾次執行和送出證據)、頁面、記憶、檔案預覽、Bot 的電腦畫面、設定(一般、模型、權限、整合、電腦、保險庫、手機與帳號、更新,能改的比電腦少;開著的設定頁跟著電腦那邊的改變重讀,不用重新整理;直接連線只能收緊、不能放寬,見 [autonomy](autonomy.md))、傳送到其他裝置。
|
||||||
- `phone-cards` 手機上的卡(允許、需要處理、問題卡)只答它畫出來的那一張:那張已經在電腦或另一支手機上回答、被停止、或換成下一張時,按了不算,聊天裡寫「手機上的回答沒有用上…」;開了很久沒重新整理的舊頁面也一樣。螢幕電腦上的卡也是;比大腦舊的螢幕電腦答不了任何卡,要在那台 設定 › 更新 換新版(重新整理沒用)。支線的卡沒用上時,寫在主線的聊天。
|
- `phone-cards` 手機上的卡(允許、需要處理、問題卡)只答它畫出來的那一張:那張已經在電腦或另一支手機上回答、被停止、或換成下一張時,按了不算,聊天裡寫「手機上的回答沒有用上…」;開了很久沒重新整理的舊頁面也一樣。螢幕電腦上的卡也是;比大腦舊的螢幕電腦答不了任何卡,要在那台 設定 › 更新 換新版(重新整理沒用)。支線的卡沒用上時,寫在主線的聊天。
|
||||||
- `phone-look` 長相(和電腦版同一份設計規格:字級、間距、圓角都是同一組數字):Bot 的回答不放在泡泡裡,像文件一樣直接排在畫面上,用宋體(思源宋體,沒有就用系統的宋體)、16px、行距寬;裡面的表格只有橫向細線、數字欄靠右,提示框([!NOTE] 等)同一種淡底、只有圖示依種類上色,程式碼是淡底圓角塊。你自己的訊息(泡泡)和所有按鈕、清單、設定用黑體。手機沒有字型選項。
|
- `phone-look` 長相(和電腦版同一份設計規格:字級、間距、圓角都是同一組數字):Bot 的回答不放在泡泡裡,像文件一樣直接排在畫面上,用宋體(思源宋體,沒有就用系統的宋體)、16px、行距寬;裡面的表格只有橫向細線、數字欄靠右,提示框([!NOTE] 等)同一種淡底、只有圖示依種類上色,程式碼是淡底圓角塊。你自己的訊息(泡泡)和所有按鈕、清單、設定用黑體。手機沒有字型選項。
|
||||||
- `phone-colors` 顏色跟電腦版一樣:電腦上 設定 › 一般 › 外觀 的主題(淺色/深色/跟隨系統)、底色、強調色、對比,手機照著穿;手機自己的「外觀」可以選「跟著電腦」(預設)、「跟著手機」、「淺色」、「深色」。狀態列的顏色跟著畫面。舊版的電腦沒送顏色時,手機用內建的「紙」。
|
- `phone-colors` 顏色跟電腦版一樣:電腦上 設定 › 一般 › 外觀 的主題(淺色/深色/跟隨系統)、底色、強調色、對比,手機照著穿;手機自己的「外觀」可以選「跟著電腦」(預設)、「跟著手機」、「淺色」、「深色」。狀態列的顏色跟著畫面。舊版的電腦沒送顏色時,手機用內建的「紙」。
|
||||||
|
|
|
||||||
|
|
@ -40,5 +40,5 @@
|
||||||
- 「模型可讀長度」和「可以用的電腦」在「電腦操作」裡,要先勾「讓這個 Bot 查看、修改檔案和執行指令」才看得到;電腦只有一台時不顯示「可以用的電腦」。
|
- 「模型可讀長度」和「可以用的電腦」在「電腦操作」裡,要先勾「讓這個 Bot 查看、修改檔案和執行指令」才看得到;電腦只有一台時不顯示「可以用的電腦」。
|
||||||
- 能力或技能全部勾回來就是「全部」:之後新增的能力類別、新裝的技能也自動算它的。它自己的電腦一定能用,拿不掉。
|
- 能力或技能全部勾回來就是「全部」:之後新增的能力類別、新裝的技能也自動算它的。它自己的電腦一定能用,拿不掉。
|
||||||
- Bot 設定要按「儲存」才算;關掉或按「取消」就不存(手機的 Bot 設定每一項改了就存)。
|
- Bot 設定要按「儲存」才算;關掉或按「取消」就不存(手機的 Bot 設定每一項改了就存)。
|
||||||
- 手機用同一個網路直接連時,能力和可以用的電腦只能勾掉、不能勾回:勾回要在電腦上改、用帳號連線,或請 Bot 用 `update_my_profile`。
|
- 手機用同一個網路直接連時只能收緊:能力和可以用的電腦只能勾掉、不能勾回,電腦工具只能關、不能開,不能分享給團隊;要放寬在電腦上改、用帳號連線,或請 Bot 用 `update_my_profile`(會先跳卡片)。
|
||||||
- (驗證)說明裡有沒有某段字(名冊、Soul),假模型的紀錄看不到全文:用 `model-reply <那段字> <回答>` 比對。
|
- (驗證)說明裡有沒有某段字(名冊、Soul),假模型的紀錄看不到全文:用 `model-reply <那段字> <回答>` 比對。
|
||||||
|
|
|
||||||
17
src/agent.rs
17
src/agent.rs
|
|
@ -1557,6 +1557,15 @@ const UNTRUSTED_BROWSER: &str = "被安全規則擋下:這則訊息是別人
|
||||||
|
|
||||||
/// Why a step isn't run for a turn whose message came from someone other than the person: the
|
/// Why a step isn't run for a turn whose message came from someone other than the person: the
|
||||||
/// browsers (theirs are logged in as the person) and the sent book. None: it may run.
|
/// browsers (theirs are logged in as the person) and the sent book. None: it may run.
|
||||||
|
/// What a 支線 isn't let do in a step (its app actions are refused on the window's side,
|
||||||
|
/// appctl::changes_settings): add or switch AnyBot's browser profiles — the choice is every
|
||||||
|
/// bot's, kept on this computer. Listing them is fine.
|
||||||
|
fn branch_refusal(job: &Job, name: &str, args: &str) -> Option<&'static str> {
|
||||||
|
let v = tools::args_of(args);
|
||||||
|
let changes = name == "browser_profiles" && (!v["name"].as_str().unwrap_or("").trim().is_empty() || !matches!(v["action"].as_str().unwrap_or("").trim(), "" | "list"));
|
||||||
|
(job.home != 0 && changes).then_some(crate::appctl::BRANCH_NO_SETTINGS)
|
||||||
|
}
|
||||||
|
|
||||||
fn untrusted_refusal(job: &Job, name: &str) -> Option<&'static str> {
|
fn untrusted_refusal(job: &Job, name: &str) -> Option<&'static str> {
|
||||||
// (The browser ability: every browser action, the vault's fills, the sent book.)
|
// (The browser ability: every browser action, the vault's fills, the sent book.)
|
||||||
(job.untrusted && crate::profile::ability_of(name) == Some("browser")).then_some(UNTRUSTED_BROWSER)
|
(job.untrusted && crate::profile::ability_of(name) == Some("browser")).then_some(UNTRUSTED_BROWSER)
|
||||||
|
|
@ -4525,7 +4534,7 @@ echo '<meta charset=utf-8><title>done</title>送出了' > done.html; (setsid pyt
|
||||||
assert_eq!(names.last(), Some(&"OnComputer"));
|
assert_eq!(names.last(), Some(&"OnComputer"));
|
||||||
assert_eq!(names.iter().collect::<std::collections::HashSet<_>>().len(), names.len(), "{names:?}");
|
assert_eq!(names.iter().collect::<std::collections::HashSet<_>>().len(), names.len(), "{names:?}");
|
||||||
let pos = |n: &str| names.iter().position(|x| *x == n).unwrap();
|
let pos = |n: &str| names.iter().position(|x| *x == n).unwrap();
|
||||||
assert!(pos("Lacking") < pos("AppTool") && pos("Untrusted") < pos("SentLog") && pos("Untrusted") > pos("WaitAfterSend"));
|
assert!(pos("Lacking") < pos("AppTool") && pos("Untrusted") < pos("SentLog") && pos("Untrusted") > pos("WaitAfterSend") && pos("BranchLimits") < pos("InBotsBrowser"));
|
||||||
let which = |job: &Job, name: &str, args: serde_json::Value| -> &'static str {
|
let which = |job: &Job, name: &str, args: serde_json::Value| -> &'static str {
|
||||||
let (mut history, mut grants, mut browsers) = (vec![], vec![], UsedBrowsers::new("t", 1, false));
|
let (mut history, mut grants, mut browsers) = (vec![], vec![], UsedBrowsers::new("t", 1, false));
|
||||||
let (mut b1, mut b2, mut b3, mut b4, mut changes, mut replay, mut plan_go) = (false, false, false, false, 0u32, None, None);
|
let (mut b1, mut b2, mut b3, mut b4, mut changes, mut replay, mut plan_go) = (false, false, false, false, 0u32, None, None);
|
||||||
|
|
@ -4554,6 +4563,12 @@ echo '<meta charset=utf-8><title>done</title>送出了' > done.html; (setsid pyt
|
||||||
assert_eq!(which(&job, "shell", serde_json::json!({"command": "ls"})), "OnComputer");
|
assert_eq!(which(&job, "shell", serde_json::json!({"command": "ls"})), "OnComputer");
|
||||||
let stranger = Job { untrusted: true, ..test_job() };
|
let stranger = Job { untrusted: true, ..test_job() };
|
||||||
assert_eq!(which(&stranger, "browser_open", serde_json::json!({"url": "https://example.com"})), "Untrusted");
|
assert_eq!(which(&stranger, "browser_open", serde_json::json!({"url": "https://example.com"})), "Untrusted");
|
||||||
|
// A 支線 lists the browser's profiles but doesn't add or switch them (every bot's choice).
|
||||||
|
let branch = Job { home: 7, ..test_job() };
|
||||||
|
assert_eq!(which(&branch, "browser_profiles", serde_json::json!({"name": "工作"})), "BranchLimits");
|
||||||
|
assert_eq!(which(&branch, "browser_profiles", serde_json::json!({"action": "use", "name": ""})), "BranchLimits");
|
||||||
|
assert_eq!(which(&branch, "browser_profiles", serde_json::json!({})), "InBotsBrowser");
|
||||||
|
assert_eq!(which(&job, "browser_profiles", serde_json::json!({"name": "工作"})), "InBotsBrowser");
|
||||||
assert_eq!(which(&stranger, "web_fetch", serde_json::json!({"url": "https://example.com"})), "InBotsBrowser");
|
assert_eq!(which(&stranger, "web_fetch", serde_json::json!({"url": "https://example.com"})), "InBotsBrowser");
|
||||||
let lacking = Job { lacks: vec!["admin".into()], ..test_job() };
|
let lacking = Job { lacks: vec!["admin".into()], ..test_job() };
|
||||||
assert_eq!(which(&lacking, "create_bot", serde_json::json!({})), "Lacking");
|
assert_eq!(which(&lacking, "create_bot", serde_json::json!({})), "Lacking");
|
||||||
|
|
|
||||||
|
|
@ -164,7 +164,7 @@ pub(super) trait TurnTool: Sync {
|
||||||
|
|
||||||
/// In the order they are asked: the first that takes a call runs it (OnComputer takes all).
|
/// In the order they are asked: the first that takes a call runs it (OnComputer takes all).
|
||||||
pub(super) static TOOLS: &[&dyn TurnTool] = &[
|
pub(super) static TOOLS: &[&dyn TurnTool] = &[
|
||||||
&BadAction, &Lacking, &SkillLimit, &ReplaySkill, &FeatureMap, &LookImage, &AppTool, &DemoStep, &WaitAfterSend, &Untrusted, &SentLog, &InBotsBrowser, &Handoff, &KeptResult, &PlanSubmit, &PlanUpdate, &AskCard, &ShowCard, &React, &SendFile, &OpenForPerson, &Phone, &PublishSite, &VaultList, &VaultFill, &ConnectorFind, &Connector, &OnComputer,
|
&BadAction, &Lacking, &SkillLimit, &ReplaySkill, &FeatureMap, &LookImage, &AppTool, &DemoStep, &WaitAfterSend, &Untrusted, &BranchLimits, &SentLog, &InBotsBrowser, &Handoff, &KeptResult, &PlanSubmit, &PlanUpdate, &AskCard, &ShowCard, &React, &SendFile, &OpenForPerson, &Phone, &PublishSite, &VaultList, &VaultFill, &ConnectorFind, &Connector, &OnComputer,
|
||||||
];
|
];
|
||||||
|
|
||||||
/// The tool that runs this step.
|
/// The tool that runs this step.
|
||||||
|
|
@ -473,6 +473,26 @@ impl TurnTool for Untrusted {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 支線: a step that would change what every bot uses (adding or switching a browser profile) —
|
||||||
|
/// refused, as its app actions are.
|
||||||
|
pub(super) struct BranchLimits;
|
||||||
|
|
||||||
|
impl TurnTool for BranchLimits {
|
||||||
|
fn name(&self) -> &'static str {
|
||||||
|
"BranchLimits"
|
||||||
|
}
|
||||||
|
|
||||||
|
fn takes(&self, s: &Step<'_>) -> bool {
|
||||||
|
branch_refusal(s.job, &s.call.name, &s.call.args).is_some()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run(&self, s: &mut Step<'_>) -> Flow {
|
||||||
|
let Some(why) = branch_refusal(s.job, &s.call.name, &s.call.args) else { return Flow::Next };
|
||||||
|
s.finish(why, ToolStatus::Denied, None);
|
||||||
|
Flow::Next
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// 已送帳本: what this brain saw go out, by account — read here, not on a page.
|
/// 已送帳本: what this brain saw go out, by account — read here, not on a page.
|
||||||
pub(super) struct SentLog;
|
pub(super) struct SentLog;
|
||||||
|
|
||||||
|
|
|
||||||
17
src/app.rs
17
src/app.rs
|
|
@ -7355,7 +7355,7 @@ fn system_prompt(b: &Bot, st: &State, computers: &[tools::Target], default_compu
|
||||||
}
|
}
|
||||||
// 支線: a copy of the bot doing one more thing alongside its main line.
|
// 支線: a copy of the bot doing one more thing alongside its main line.
|
||||||
if b.branch_of != 0 {
|
if b.branch_of != 0 {
|
||||||
s.push_str("\n\n你現在是一條支線:使用者用 /btw 開的分身,帶著同一段對話和記憶,跟主線(你的本尊)同時做對話最後交代的那件事。只做那件事,不要接手或重做主線正在做的事。做完用一段話寫清楚結果,它會原封不動送回主線的聊天。要使用者核准的步驟一樣會問他。在「Bot 的電腦」上你有自己的暫時螢幕和瀏覽器(登入從主線的瀏覽器複製過來,支線結束就關掉),不會跟主線搶,但看不到主線開著的網頁,要用就自己打開。在使用者的電腦上,同一個螢幕主線或別的 Bot 正在用時,那一步會被擋下:先做不用螢幕的部分、改用別台電腦,或晚點再試。不能再開支線,也不能改設定(自己的、別的 Bot 的、AnyBot 的都不行)。");
|
s.push_str("\n\n你現在是一條支線:使用者用 /btw 開的分身,帶著同一段對話和記憶,跟主線(你的本尊)同時做對話最後交代的那件事。只做那件事,不要接手或重做主線正在做的事。做完用一段話寫清楚結果,它會原封不動送回主線的聊天。要使用者核准的步驟一樣會問他。在「Bot 的電腦」上你有自己的暫時螢幕和瀏覽器(登入從主線的瀏覽器複製過來,支線結束就關掉),不會跟主線搶,但看不到主線開著的網頁,要用就自己打開。在使用者的電腦上,同一個螢幕主線或別的 Bot 正在用時,那一步會被擋下:先做不用螢幕的部分、改用別台電腦,或晚點再試。不能再開支線,也不能動大家共用的東西:改任何 Bot 或 AnyBot 的設定、建立 Bot、建立或整理群組、刪除或安裝技能、換掉技能庫裡已經有的技能(存新的可以)、改連接器或 hook、新增或切換瀏覽器設定檔,都會被擋下;需要做這些,就在結果裡寫給主線。");
|
||||||
}
|
}
|
||||||
// 個人檔案: what it is good at and what it leaves to others; then who the others are.
|
// 個人檔案: what it is good at and what it leaves to others; then who the others are.
|
||||||
// (Its soul — the 指示 — comes last, where it weighs most.)
|
// (Its soul — the 指示 — comes last, where it weighs most.)
|
||||||
|
|
@ -9062,9 +9062,22 @@ mod tests {
|
||||||
let m = app.state.bot(main).unwrap();
|
let m = app.state.bot(main).unwrap();
|
||||||
assert_eq!(m.name, name);
|
assert_eq!(m.name, name);
|
||||||
assert!(m.branches[0].log.iter().any(|l| l.starts_with('✗') && l.contains(appctl::label("update_bot"))), "{:?}", m.branches[0].log);
|
assert!(m.branches[0].log.iter().any(|l| l.starts_with('✗') && l.contains(appctl::label("update_bot"))), "{:?}", m.branches[0].log);
|
||||||
for (tool, args, refused) in [("update_settings", r#"{"theme":"dark"}"#, true), ("teach_skill", r#"{"bot":"x","skill":"y"}"#, true), (crate::mcp::MANAGE_TOOL, r#"{"action":"add","name":"x"}"#, true), (crate::mcp::MANAGE_TOOL, r#"{"action":"list"}"#, false), (crate::hooks::MANAGE_TOOL, r#"{"action":"remove"}"#, true), (crate::chatgpt::TOOL, r#"{"action":"logout"}"#, false), ("create_routine", "{}", false), ("remember", "{}", false)] {
|
let refused_ones = ["update_settings", "teach_skill", "create_bot", "create_group", "move_to_group", "rename_group", "delete_group", "delete_skill", "skill_install"];
|
||||||
|
for tool in refused_ones {
|
||||||
|
assert!(appctl::changes_settings(tool, r#"{"url":"builtin:pptx"}"#), "{tool}");
|
||||||
|
}
|
||||||
|
for (tool, args, refused) in [(crate::mcp::MANAGE_TOOL, r#"{"action":"add","name":"x"}"#, true), (crate::mcp::MANAGE_TOOL, r#"{"action":" Remove "}"#, true), (crate::mcp::MANAGE_TOOL, r#"{"action":"list"}"#, false), (crate::mcp::MANAGE_TOOL, r#"{"action":"reconnect"}"#, false), (crate::hooks::MANAGE_TOOL, r#"{"action":"remove"}"#, true), (crate::hooks::MANAGE_TOOL, r#"{"action":"list"}"#, false), (crate::chatgpt::TOOL, r#"{"action":"logout"}"#, false), ("create_routine", "{}", false), ("remember", "{}", false), ("save_skill", "{}", false), ("skillify", "{}", false)] {
|
||||||
assert_eq!(appctl::changes_settings(tool, args), refused, "{tool} {args}");
|
assert_eq!(appctl::changes_settings(tool, args), refused, "{tool} {args}");
|
||||||
}
|
}
|
||||||
|
// A new skill from a 支線 is the main bot's; one already in the library stays as it was.
|
||||||
|
app.state.skills.push(crate::memory::Skill { name: "週報(測試)".into(), instructions: "原本的做法".into(), ..Default::default() });
|
||||||
|
let mut br = app.state.bot(main).unwrap().clone();
|
||||||
|
br.id = 9200;
|
||||||
|
br.branch_of = main;
|
||||||
|
app.state.branch_bots.push(br);
|
||||||
|
let out = appctl::apply(&mut app.state, 9200, "save_skill", &serde_json::json!({"name": "週報(測試)", "instructions": "支線改的做法"}).to_string());
|
||||||
|
assert!(!out.ok && out.text.contains("支線不能換掉"), "{}", out.text);
|
||||||
|
assert_eq!(app.state.skills.iter().find(|k| k.name == "週報(測試)").map(|k| k.instructions.as_str()), Some("原本的做法"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Closing AnyBot ends a working 支線 and one still waiting with 「AnyBot 關掉了…」; 「被停止了」
|
/// Closing AnyBot ends a working 支線 and one still waiting with 「AnyBot 關掉了…」; 「被停止了」
|
||||||
|
|
|
||||||
|
|
@ -1248,6 +1248,9 @@ impl App {
|
||||||
let owner = role == "owner";
|
let owner = role == "owner";
|
||||||
let bot = b["bot"].as_u64().unwrap_or(0);
|
let bot = b["bot"].as_u64().unwrap_or(0);
|
||||||
let s = |k: &str| b[k].as_str().unwrap_or("").trim().to_string();
|
let s = |k: &str| b[k].as_str().unwrap_or("").trim().to_string();
|
||||||
|
// A setting's name, exactly as sent: 「direct_mode 」 isn't direct_mode. (Trimmed, it slipped
|
||||||
|
// past the direct connection's guard, which reads names exactly — remote::lan_guard.)
|
||||||
|
let name_of = |k: &str| b[k].as_str().unwrap_or("").to_string();
|
||||||
let fail = |e: &str| json!({"error": e});
|
let fail = |e: &str| json!({"error": e});
|
||||||
let done = |t: &str| json!({"ok": true, "text": t});
|
let done = |t: &str| json!({"ok": true, "text": t});
|
||||||
let owner_only = || json!({"error": "這件事只有這台 AnyBot 的擁有者能做"});
|
let owner_only = || json!({"error": "這件事只有這台 AnyBot 的擁有者能做"});
|
||||||
|
|
@ -1384,7 +1387,7 @@ impl App {
|
||||||
return fail("找不到這個 Bot");
|
return fail("找不到這個 Bot");
|
||||||
}
|
}
|
||||||
let v = &b["value"];
|
let v = &b["value"];
|
||||||
let key = s("key");
|
let key = name_of("key");
|
||||||
if matches!(key.as_str(), "tools" | "allow_remove" | "strengths" | "not_for" | "abilities" | "skills" | "may_use") && !owner {
|
if matches!(key.as_str(), "tools" | "allow_remove" | "strengths" | "not_for" | "abilities" | "skills" | "may_use") && !owner {
|
||||||
return owner_only();
|
return owner_only();
|
||||||
}
|
}
|
||||||
|
|
@ -1547,7 +1550,8 @@ impl App {
|
||||||
return owner_only();
|
return owner_only();
|
||||||
}
|
}
|
||||||
let v = &b["value"];
|
let v = &b["value"];
|
||||||
match s("key").as_str() {
|
let key = name_of("key");
|
||||||
|
match key.as_str() {
|
||||||
"direct_mode" => {
|
"direct_mode" => {
|
||||||
if v.as_bool().unwrap_or(false) {
|
if v.as_bool().unwrap_or(false) {
|
||||||
self.enable_direct_mode()
|
self.enable_direct_mode()
|
||||||
|
|
@ -1559,8 +1563,13 @@ impl App {
|
||||||
"notify" => self.state.notify = v.as_bool().unwrap_or(true),
|
"notify" => self.state.notify = v.as_bool().unwrap_or(true),
|
||||||
"rule_add" | "rule_remove" => {
|
"rule_add" | "rule_remove" => {
|
||||||
let text = v.as_str().unwrap_or("").trim().to_string();
|
let text = v.as_str().unwrap_or("").trim().to_string();
|
||||||
let list = if s("list") == "ask" { &mut self.state.review_ask_rules } else { &mut self.state.review_allow_rules };
|
// (Any list but 「ask」 used to be the allow list.)
|
||||||
if s("key") == "rule_add" {
|
let list = match name_of("list").as_str() {
|
||||||
|
"ask" => &mut self.state.review_ask_rules,
|
||||||
|
"allow" => &mut self.state.review_allow_rules,
|
||||||
|
_ => return fail("不認得這個規則清單"),
|
||||||
|
};
|
||||||
|
if key == "rule_add" {
|
||||||
if text.is_empty() {
|
if text.is_empty() {
|
||||||
return fail("規則是空的");
|
return fail("規則是空的");
|
||||||
}
|
}
|
||||||
|
|
@ -1726,7 +1735,7 @@ impl App {
|
||||||
}
|
}
|
||||||
// 設定 › 電腦's buttons for Bot 的電腦.
|
// 設定 › 電腦's buttons for Bot 的電腦.
|
||||||
"box" => {
|
"box" => {
|
||||||
let op = s("op");
|
let op = name_of("op");
|
||||||
if matches!(op.as_str(), "update" | "reset" | "runtime" | "auto_update") && !owner {
|
if matches!(op.as_str(), "update" | "reset" | "runtime" | "auto_update") && !owner {
|
||||||
return owner_only();
|
return owner_only();
|
||||||
}
|
}
|
||||||
|
|
@ -2033,6 +2042,73 @@ mod phone_act_tests {
|
||||||
assert!(main_rx.try_recv().is_err() && app.approvals.contains_key(&main.id), "the main bot's card still waits");
|
assert!(main_rx.try_recv().is_err() && app.approvals.contains_key(&main.id), "the main bot's card still waits");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// An act from a direct connection: remote::lan_guard first (asked about the bot as the
|
||||||
|
/// route asks), then phone_act — as remote.rs does it.
|
||||||
|
fn over_lan(ctx: &egui::Context, app: &mut App, action: &str, body: serde_json::Value) -> Result<serde_json::Value, crate::remote::Guard> {
|
||||||
|
let detail = app.phone_act(ctx, "detail", &json!({"bot": body["bot"]}), "owner");
|
||||||
|
match crate::remote::lan_guard(action, &body, || detail, "runc") {
|
||||||
|
crate::remote::Guard::Keeps => Ok(app.phone_act(ctx, action, &body, "owner")),
|
||||||
|
other => Err(other),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A direct connection only tightens, however a setting's name is spelled: 「direct_mode 」,
|
||||||
|
/// 「 rule_add」, 「abilities 」 got past the guard (it read the name exactly) and were done
|
||||||
|
/// anyway (phone_act trimmed it). Each loosening, padded, cased or with a wide space, leaves
|
||||||
|
/// every guard as it was; the tightenings still go through.
|
||||||
|
#[test]
|
||||||
|
fn a_direct_connection_cannot_loosen_by_spelling_a_setting_differently() {
|
||||||
|
let (ctx, mut app) = demo();
|
||||||
|
let b = app.state.bots[0].id;
|
||||||
|
app.state.direct_mode = false;
|
||||||
|
app.state.auto_review = false;
|
||||||
|
app.state.review_ask_rules = vec!["付款前先問我".into()];
|
||||||
|
app.state.review_allow_rules = vec![];
|
||||||
|
{
|
||||||
|
let x = app.state.bot_mut(b).unwrap();
|
||||||
|
x.abilities = Some(vec!["web".into()]);
|
||||||
|
x.tools_enabled = false;
|
||||||
|
x.team = false;
|
||||||
|
x.allow_rules = vec!["rm".into()];
|
||||||
|
}
|
||||||
|
let guards = |app: &App| {
|
||||||
|
let x = app.state.bot(b).unwrap();
|
||||||
|
format!("{} {} {:?} {:?} {:?} {} {} {:?}", app.state.direct_mode, app.state.auto_review, app.state.review_ask_rules, app.state.review_allow_rules, x.abilities, x.tools_enabled, x.team, x.allow_rules)
|
||||||
|
};
|
||||||
|
let before = guards(&app);
|
||||||
|
let every = crate::profile::ABILITIES.iter().map(|a| a.0).collect::<Vec<_>>();
|
||||||
|
let loosen: Vec<(&str, &str, serde_json::Value)> = vec![
|
||||||
|
("setting", "key", json!({"key": "direct_mode", "value": true})),
|
||||||
|
("setting", "key", json!({"key": "auto_review", "value": true})),
|
||||||
|
("setting", "key", json!({"key": "rule_add", "list": "allow", "value": "全部直接做"})),
|
||||||
|
("setting", "list", json!({"key": "rule_add", "list": "allow", "value": "全部直接做"})),
|
||||||
|
("setting", "key", json!({"key": "rule_remove", "list": "ask", "value": "付款前先問我"})),
|
||||||
|
("setting", "list", json!({"key": "rule_remove", "list": "ask", "value": "付款前先問我"})),
|
||||||
|
("bot", "key", json!({"bot": b, "key": "abilities", "value": every})),
|
||||||
|
("bot", "key", json!({"bot": b, "key": "tools", "value": true})),
|
||||||
|
("bot", "key", json!({"bot": b, "key": "team", "value": true})),
|
||||||
|
];
|
||||||
|
for (action, field, body) in loosen {
|
||||||
|
assert!(over_lan(&ctx, &mut app, action, body.clone()).is_err(), "as sent: {body}");
|
||||||
|
let name = body[field].as_str().unwrap().to_string();
|
||||||
|
for spelled in [format!("{name} "), format!(" {name}"), format!("\t{name}"), format!("{name}\u{3000}"), format!("{name}\u{a0}"), name.to_uppercase()] {
|
||||||
|
let mut odd = body.clone();
|
||||||
|
odd[field] = json!(spelled);
|
||||||
|
let _ = over_lan(&ctx, &mut app, action, odd.clone());
|
||||||
|
assert_eq!(guards(&app), before, "{odd}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Tightening still works from there: an ask rule in, an allow rule out, tools off.
|
||||||
|
assert_eq!(over_lan(&ctx, &mut app, "setting", json!({"key": "rule_add", "list": "ask", "value": "寄信前先問我"})).unwrap()["ok"], true);
|
||||||
|
assert_eq!(over_lan(&ctx, &mut app, "bot", json!({"bot": b, "key": "allow_remove", "value": "rm"})).unwrap()["ok"], true);
|
||||||
|
assert_eq!(over_lan(&ctx, &mut app, "bot", json!({"bot": b, "key": "abilities", "value": []})).unwrap()["ok"], true);
|
||||||
|
assert!(app.state.review_ask_rules.contains(&"寄信前先問我".to_string()) && app.state.bot(b).unwrap().allow_rules.is_empty());
|
||||||
|
assert_eq!(app.state.bot(b).unwrap().abilities, Some(vec![]));
|
||||||
|
// An unknown list is said so, not taken as the allow list.
|
||||||
|
assert!(app.phone_act(&ctx, "setting", &json!({"key": "rule_add", "list": "Ask", "value": "x"}), "owner")["error"].is_string());
|
||||||
|
assert!(app.state.review_allow_rules.is_empty());
|
||||||
|
}
|
||||||
|
|
||||||
/// A ChatGPT card says what it asks — here a 支線 signing out — not the tool's name (it read
|
/// A ChatGPT card says what it asks — here a 支線 signing out — not the tool's name (it read
|
||||||
/// 「支線:…想要ChatGPT 方案登入」 for a logout).
|
/// 「支線:…想要ChatGPT 方案登入」 for a logout).
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
||||||
|
|
@ -206,20 +206,35 @@ pub fn describe(name: &str, args: &str) -> String {
|
||||||
/// What a 支線 is told when it tries to change a setting.
|
/// What a 支線 is told when it tries to change a setting.
|
||||||
pub const BRANCH_NO_SETTINGS: &str = "支線改不了設定:回到主線再請它改。";
|
pub const BRANCH_NO_SETTINGS: &str = "支線改不了設定:回到主線再請它改。";
|
||||||
|
|
||||||
/// Calls that change a bot's or AnyBot's settings: a bot's name, instructions, model, abilities
|
/// The app actions a 支線 is refused, at once and with no card (BRANCH_NO_SETTINGS) — it does its
|
||||||
/// or skills (its own or another's), the app's settings, connectors, hooks. A 支線 does its one
|
/// one thing and changes nothing app-wide (an update_bot from one renamed the main bot once its
|
||||||
/// thing and changes none of them — an update_bot from one renamed the main bot once the card
|
/// card was allowed):
|
||||||
/// was allowed. (Looking — list — changes nothing; signing in to an account isn't a setting.)
|
/// - any bot's settings: update_bot, update_my_profile, teach_skill;
|
||||||
|
/// - AnyBot's settings: update_settings;
|
||||||
|
/// - the bots and the sidebar: create_bot, create_group, move_to_group, rename_group,
|
||||||
|
/// delete_group;
|
||||||
|
/// - the skill library: delete_skill, skill_install (the built-in ones too);
|
||||||
|
/// - connectors and hooks, except looking (manage_connectors list, reconnect, signing in or out;
|
||||||
|
/// manage_hooks list) — any other action, however spelled, counts as a change.
|
||||||
|
///
|
||||||
|
/// Elsewhere: save_skill and skillify may add a skill (the main bot's) but not replace one
|
||||||
|
/// already in the library (apply); browser profiles may be listed but not added or switched
|
||||||
|
/// (agent::branch_refusal). Signing in or out of ChatGPT isn't a setting: it asks on a card.
|
||||||
pub fn changes_settings(name: &str, args: &str) -> bool {
|
pub fn changes_settings(name: &str, args: &str) -> bool {
|
||||||
let action = crate::tools::args_of(args)["action"].as_str().unwrap_or("").trim().to_string();
|
let action = crate::tools::args_of(args)["action"].as_str().unwrap_or("").trim().to_lowercase();
|
||||||
match name {
|
match name {
|
||||||
"update_bot" | "update_settings" | "update_my_profile" | "teach_skill" => true,
|
"update_bot" | "update_settings" | "update_my_profile" | "teach_skill" | "create_bot" | "create_group" | "move_to_group" | "rename_group" | "delete_group" | "delete_skill" | "skill_install" => true,
|
||||||
crate::mcp::MANAGE_TOOL => matches!(action.as_str(), "add" | "update" | "remove"),
|
crate::mcp::MANAGE_TOOL => !matches!(action.as_str(), "list" | "reconnect" | "login" | "logout"),
|
||||||
crate::hooks::MANAGE_TOOL => matches!(action.as_str(), "add" | "remove"),
|
crate::hooks::MANAGE_TOOL => action != "list",
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A 支線 adds skills but doesn't replace one already in the library.
|
||||||
|
fn branch_replaces_skill(state: &State, bot_id: u64, name: &str) -> Option<String> {
|
||||||
|
(state.bot(bot_id).is_some_and(|b| b.branch_of != 0) && state.skills.iter().any(|k| k.name == name)).then(|| format!("支線不能換掉技能庫裡已經有的「{name}」:換個名字存,或回到主線再改。"))
|
||||||
|
}
|
||||||
|
|
||||||
/// App actions that need a yes from the person first (the original confirms deletions:
|
/// App actions that need a yes from the person first (the original confirms deletions:
|
||||||
/// "這會刪除例行任務並停止其後續執行。此操作無法復原。", VAgxC4).
|
/// "這會刪除例行任務並停止其後續執行。此操作無法復原。", VAgxC4).
|
||||||
pub fn needs_approval(name: &str, args: &str, state: &State) -> Option<String> {
|
pub fn needs_approval(name: &str, args: &str, state: &State) -> Option<String> {
|
||||||
|
|
@ -433,7 +448,8 @@ pub fn wake_message(r: &Routine) -> Message {
|
||||||
|
|
||||||
pub fn apply(state: &mut State, bot_id: u64, name: &str, args: &str) -> Outcome {
|
pub fn apply(state: &mut State, bot_id: u64, name: &str, args: &str) -> Outcome {
|
||||||
// 支線: what it keeps, makes and sets up is its main bot's (memories, pages, routines, the
|
// 支線: what it keeps, makes and sets up is its main bot's (memories, pages, routines, the
|
||||||
// work it hands over); it goes when it is done.
|
// work it hands over); it goes when it is done. (`asker`: the 支線 itself.)
|
||||||
|
let asker = bot_id;
|
||||||
let bot_id = state.home_of(bot_id);
|
let bot_id = state.home_of(bot_id);
|
||||||
let v: Value = match serde_json::from_str(if args.trim().is_empty() { "{}" } else { args }) {
|
let v: Value = match serde_json::from_str(if args.trim().is_empty() { "{}" } else { args }) {
|
||||||
Ok(v) => v,
|
Ok(v) => v,
|
||||||
|
|
@ -707,6 +723,10 @@ pub fn apply(state: &mut State, bot_id: u64, name: &str, args: &str) -> Outcome
|
||||||
if name.is_empty() || instructions.trim().is_empty() {
|
if name.is_empty() || instructions.trim().is_empty() {
|
||||||
return err("技能要有名稱和做法".into());
|
return err("技能要有名稱和做法".into());
|
||||||
}
|
}
|
||||||
|
// (Before its folder is written: that would already replace the skill's files.)
|
||||||
|
if let Some(why) = branch_replaces_skill(state, asker, &name) {
|
||||||
|
return err(why);
|
||||||
|
}
|
||||||
let mut extra: Vec<(String, Vec<u8>)> = vec![];
|
let mut extra: Vec<(String, Vec<u8>)> = vec![];
|
||||||
for f in v["files"].as_array().into_iter().flatten() {
|
for f in v["files"].as_array().into_iter().flatten() {
|
||||||
if let (Some(p), Some(c)) = (f["path"].as_str(), f["content"].as_str()) {
|
if let (Some(p), Some(c)) = (f["path"].as_str(), f["content"].as_str()) {
|
||||||
|
|
@ -788,6 +808,9 @@ pub fn apply(state: &mut State, bot_id: u64, name: &str, args: &str) -> Outcome
|
||||||
Some(sk) => {
|
Some(sk) => {
|
||||||
let n = sk.steps.len();
|
let n = sk.steps.len();
|
||||||
let name = sk.name.clone();
|
let name = sk.name.clone();
|
||||||
|
if let Some(why) = branch_replaces_skill(state, asker, &name) {
|
||||||
|
return err(why);
|
||||||
|
}
|
||||||
crate::memory::upsert_skill(&mut state.skills, sk);
|
crate::memory::upsert_skill(&mut state.skills, sk);
|
||||||
let who = learned(state, bot_id, &name);
|
let who = learned(state, bot_id, &name);
|
||||||
ok(format!("已把「{prompt}」那一回合存成技能「{name}」({n} 步可重播),{who}"))
|
ok(format!("已把「{prompt}」那一回合存成技能「{name}」({n} 步可重播),{who}"))
|
||||||
|
|
|
||||||
|
|
@ -321,6 +321,11 @@ pub fn current() -> String {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_current(name: &str) -> Result<String, String> {
|
pub fn set_current(name: &str) -> Result<String, String> {
|
||||||
|
// Bot 的電腦 has the one profile; the choice kept here is this computer's, and a step there
|
||||||
|
// reset it to 「預設」 (resolve answers 「預設」 inside the box).
|
||||||
|
if using_box() {
|
||||||
|
return Err(BOX_ONE_PROFILE.into());
|
||||||
|
}
|
||||||
let name = resolve(Some(name))?;
|
let name = resolve(Some(name))?;
|
||||||
std::fs::write(current_file(), &name).map_err(|e| format!("存不了設定檔選擇:{e}"))?;
|
std::fs::write(current_file(), &name).map_err(|e| format!("存不了設定檔選擇:{e}"))?;
|
||||||
Ok(name)
|
Ok(name)
|
||||||
|
|
@ -383,6 +388,9 @@ pub fn check_name(name: &str) -> Result<String, String> {
|
||||||
|
|
||||||
/// Make a new empty profile (its own folder, so its own logins).
|
/// Make a new empty profile (its own folder, so its own logins).
|
||||||
pub fn add(name: &str) -> Result<String, String> {
|
pub fn add(name: &str) -> Result<String, String> {
|
||||||
|
if using_box() {
|
||||||
|
return Err(BOX_ONE_PROFILE.into());
|
||||||
|
}
|
||||||
let n = check_name(name)?;
|
let n = check_name(name)?;
|
||||||
if let Some(have) = match_profile(&profiles(), &n) {
|
if let Some(have) = match_profile(&profiles(), &n) {
|
||||||
return Ok(have);
|
return Ok(have);
|
||||||
|
|
@ -807,7 +815,11 @@ pub fn open(url: &str, profile: Option<&str>) -> Result<String, String> {
|
||||||
return Err("安全規則禁止開啟雲端中繼資料(169.254.169.254)或系統內部管理端點。".into());
|
return Err("安全規則禁止開啟雲端中繼資料(169.254.169.254)或系統內部管理端點。".into());
|
||||||
}
|
}
|
||||||
let prof = resolve(profile)?;
|
let prof = resolve(profile)?;
|
||||||
let _ = set_current(&prof);
|
// (The person's own browsers are used for this step, never made the one every later step
|
||||||
|
// uses: that is the person's choice, in Settings.)
|
||||||
|
if !is_persons(&prof) {
|
||||||
|
let _ = set_current(&prof);
|
||||||
|
}
|
||||||
let (name, port, fresh) = ensure(&prof, Some(url))?;
|
let (name, port, fresh) = ensure(&prof, Some(url))?;
|
||||||
if !fresh {
|
if !fresh {
|
||||||
let kind = kind_of(Some(&prof));
|
let kind = kind_of(Some(&prof));
|
||||||
|
|
@ -861,26 +873,67 @@ pub fn show(profile: &str) -> Result<(), String> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// What Bot 的電腦's browser has: one profile, its logins on that computer.
|
||||||
|
const BOX_ONE_PROFILE: &str = "Bot 的電腦上的瀏覽器只有一個設定檔(預設),登入留在那台電腦上:不能新增或切換設定檔。要用別的設定檔,要在使用者的電腦上用 AnyBot 瀏覽器。";
|
||||||
|
|
||||||
|
/// The person's own browsers among the choices — their Firefox profiles, their everyday
|
||||||
|
/// browser: they carry the person's logins.
|
||||||
|
fn is_persons(name: &str) -> bool {
|
||||||
|
name.ends_with(FIREFOX_MARK) || name == PERSON_PROFILE
|
||||||
|
}
|
||||||
|
|
||||||
|
/// AnyBot's own profile of exactly this name (case aside: it is a folder).
|
||||||
|
fn own_profile(own: &[String], name: &str) -> Option<String> {
|
||||||
|
let w = name.trim().to_lowercase();
|
||||||
|
own.iter().find(|p| !w.is_empty() && p.to_lowercase() == w).cloned()
|
||||||
|
}
|
||||||
|
|
||||||
/// What a browser_profiles call does. The one `browser` tool's own `action` is 「profiles」, so
|
/// What a browser_profiles call does. The one `browser` tool's own `action` is 「profiles」, so
|
||||||
/// a call from the model carries no list/add/use of its own: a name alone means "work in that
|
/// a call from the model carries no list/add/use of its own: a name alone means "work in that
|
||||||
/// one" — switch to it when it is there (`all`: the choices now), add it first when it isn't.
|
/// one" — AnyBot's own profile of that name (`own`) is switched to, any other name is a new,
|
||||||
/// (Every call with a name used to list the profiles and change nothing.)
|
/// empty one. (Every call with a name used to list the profiles and change nothing; a loose match
|
||||||
fn profiles_action<'a>(action: &'a str, name: &str, all: &[String]) -> &'a str {
|
/// then would have switched 「阿金」 to the person's own 「阿金(Firefox)」.)
|
||||||
|
fn profiles_action<'a>(action: &'a str, name: &str, own: &[String]) -> &'a str {
|
||||||
match action.trim() {
|
match action.trim() {
|
||||||
"" if name.trim().is_empty() => "list",
|
"" if name.trim().is_empty() => "list",
|
||||||
"" if match_profile(all, name).is_some() => "use",
|
"" if own_profile(own, name).is_some() => "use",
|
||||||
"" => "add",
|
"" => "add",
|
||||||
a => a,
|
a => a,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A name that is the person's own browser — exactly a choice of theirs, or their browser's
|
||||||
|
/// other names: the bot doesn't switch to it. Switching is for every later step and every bot,
|
||||||
|
/// with the person's logins; the person does it in Settings (one tap) — refused rather than
|
||||||
|
/// asked on a card, which this tool has no way to show.
|
||||||
|
fn persons_choice(name: &str, all: &[String]) -> Option<String> {
|
||||||
|
let w = name.trim().to_lowercase();
|
||||||
|
if PERSON_ALIASES.contains(&w.as_str()) {
|
||||||
|
return Some(PERSON_PROFILE.to_string());
|
||||||
|
}
|
||||||
|
all.iter().find(|c| is_persons(c) && c.to_lowercase() == w).cloned()
|
||||||
|
}
|
||||||
|
|
||||||
/// The browser_profiles tool: list, add or switch profiles.
|
/// The browser_profiles tool: list, add or switch profiles.
|
||||||
pub fn profiles_tool(action: &str, name: &str) -> Result<String, String> {
|
pub fn profiles_tool(action: &str, name: &str) -> Result<String, String> {
|
||||||
let list_text = || {
|
let list_text = || {
|
||||||
let cur = current();
|
let cur = current();
|
||||||
choices().iter().map(|p| if *p == cur { format!("{p}(使用中)") } else { p.clone() }).collect::<Vec<_>>().join("、")
|
choices().iter().map(|p| if *p == cur { format!("{p}(使用中)") } else { p.clone() }).collect::<Vec<_>>().join("、")
|
||||||
};
|
};
|
||||||
match profiles_action(action, name, &choices()) {
|
if using_box() {
|
||||||
|
return match profiles_action(action, name, &[]) {
|
||||||
|
"list" => Ok("Bot 的電腦上的 AnyBot 瀏覽器只有一個設定檔:預設(使用中)。".into()),
|
||||||
|
_ => Err(BOX_ONE_PROFILE.into()),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
let own = profiles();
|
||||||
|
let act = profiles_action(action, name, &own);
|
||||||
|
if act != "list" {
|
||||||
|
if let Some(p) = persons_choice(name, &choices()) {
|
||||||
|
return Err(format!("「{p}」是使用者自己的瀏覽器(帶著他的登入):Bot 不能自己換過去,換了之後每一步、每個 Bot 都會用他的帳號。請使用者在 設定 › 電腦 ›「AnyBot 瀏覽器設定檔」自己切換。"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
match act {
|
||||||
"list" => Ok(format!(
|
"list" => Ok(format!(
|
||||||
"AnyBot 瀏覽器的設定檔:{}。每個設定檔有自己的登入。{}{}",
|
"AnyBot 瀏覽器的設定檔:{}。每個設定檔有自己的登入。{}{}",
|
||||||
list_text(),
|
list_text(),
|
||||||
|
|
@ -893,9 +946,9 @@ pub fn profiles_tool(action: &str, name: &str) -> Result<String, String> {
|
||||||
Ok(format!("已新增並切換到設定檔「{n}」(全新的,還沒登入任何網站)。用 browser 的 open 打開網站後,請使用者在那個視窗登入一次。現在:{}", list_text()))
|
Ok(format!("已新增並切換到設定檔「{n}」(全新的,還沒登入任何網站)。用 browser 的 open 打開網站後,請使用者在那個視窗登入一次。現在:{}", list_text()))
|
||||||
}
|
}
|
||||||
"use" | "switch" => {
|
"use" | "switch" => {
|
||||||
let n = set_current(name)?;
|
let n = own_profile(&own, name).ok_or_else(|| format!("AnyBot 瀏覽器沒有叫「{}」的設定檔。現有:{}。", name.trim(), own.join("、")))?;
|
||||||
let note = if n == PERSON_PROFILE { "(使用者平常的瀏覽器:請使用者在那裡切到想要的 Chrome 設定檔)" } else { "" };
|
let n = set_current(&n)?;
|
||||||
Ok(format!("已切換到「{n}」{note},之後 browser 的 open、read 都用它。現在:{}", list_text()))
|
Ok(format!("已切換到「{n}」,之後 browser 的 open、read 都用它。現在:{}", list_text()))
|
||||||
}
|
}
|
||||||
other => Err(format!("不懂「{other}」:不帶 name 是列出設定檔,帶 name 是換到那個設定檔(沒有就先新增)")),
|
other => Err(format!("不懂「{other}」:不帶 name 是列出設定檔,帶 name 是換到那個設定檔(沒有就先新增)")),
|
||||||
}
|
}
|
||||||
|
|
@ -1033,29 +1086,53 @@ mod tests {
|
||||||
assert!(check_name(PERSON_PROFILE).is_err());
|
assert!(check_name(PERSON_PROFILE).is_err());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The model's `browser` call has 「profiles」 as its own action: a name in it switches to that
|
/// The model's `browser` call has 「profiles」 as its own action: a name in it switches to
|
||||||
/// profile, or adds it first — it used to list them and change nothing.
|
/// AnyBot's own profile of exactly that name, or adds a new one — it used to list them and
|
||||||
|
/// change nothing. A near name (「阿金」 beside the person's 「阿金(Firefox)」) is a new
|
||||||
|
/// profile, and the person's own browsers are never switched to by the bot.
|
||||||
#[test]
|
#[test]
|
||||||
fn a_profile_named_by_the_model_is_switched_to_or_added() {
|
fn a_profile_named_by_the_model_is_switched_to_or_added() {
|
||||||
let asked = |args: &str, all: &[String]| {
|
let asked = |args: &str, own: &[String]| {
|
||||||
let mut c = crate::model::ToolCall { id: "c".into(), name: crate::browser::TOOL.into(), args: args.into(), status: crate::model::ToolStatus::Done };
|
let mut c = crate::model::ToolCall { id: "c".into(), name: crate::browser::TOOL.into(), args: args.into(), status: crate::model::ToolStatus::Done };
|
||||||
crate::browser::expand_call(&mut c);
|
crate::browser::expand_call(&mut c);
|
||||||
assert_eq!(c.name, "browser_profiles");
|
assert_eq!(c.name, "browser_profiles");
|
||||||
let v = crate::tools::args_of(&c.args);
|
let v = crate::tools::args_of(&c.args);
|
||||||
profiles_action(v["action"].as_str().unwrap_or(""), v["name"].as_str().unwrap_or(""), all).to_string()
|
profiles_action(v["action"].as_str().unwrap_or(""), v["name"].as_str().unwrap_or(""), own).to_string()
|
||||||
};
|
};
|
||||||
let all = vec![DEFAULT_PROFILE.to_string(), "工作".to_string(), PERSON_PROFILE.to_string()];
|
let own = vec![DEFAULT_PROFILE.to_string(), "工作".to_string()];
|
||||||
assert_eq!(asked(r#"{"action":"profiles"}"#, &all), "list");
|
assert_eq!(asked(r#"{"action":"profiles"}"#, &own), "list");
|
||||||
assert_eq!(asked(r#"{"action":"profiles","name":" "}"#, &all), "list");
|
assert_eq!(asked(r#"{"action":"profiles","name":" "}"#, &own), "list");
|
||||||
assert_eq!(asked(r#"{"action":"profiles","name":"私人"}"#, &all), "add");
|
assert_eq!(asked(r#"{"action":"profiles","name":"私人"}"#, &own), "add");
|
||||||
assert_eq!(asked(r#"{"action":"profiles","name":"工作"}"#, &all), "use");
|
assert_eq!(asked(r#"{"action":"profiles","name":"工作"}"#, &own), "use");
|
||||||
assert_eq!(asked(r#"{"action":"profiles","name":"我的 Chrome"}"#, &all), "use");
|
// The person's own browsers, by their exact name or their browser's other names; a near
|
||||||
|
// name is a new profile of AnyBot's, even with every choice in view.
|
||||||
|
let all = vec![DEFAULT_PROFILE.to_string(), "工作".to_string(), format!("阿金{FIREFOX_MARK}"), PERSON_PROFILE.to_string()];
|
||||||
|
assert_eq!(asked(r#"{"action":"profiles","name":"阿金"}"#, &all), "add");
|
||||||
|
assert_eq!(asked(r#"{"action":"profiles","name":"我的 Chrome"}"#, &all), "add");
|
||||||
|
assert_eq!(persons_choice("阿金", &all), None);
|
||||||
|
assert_eq!(persons_choice(&format!("阿金{FIREFOX_MARK}"), &all).as_deref(), Some(format!("阿金{FIREFOX_MARK}").as_str()));
|
||||||
|
assert_eq!(persons_choice("我的 Chrome", &all).as_deref(), Some(PERSON_PROFILE));
|
||||||
|
assert_eq!(persons_choice(PERSON_PROFILE, &all).as_deref(), Some(PERSON_PROFILE));
|
||||||
|
assert_eq!(persons_choice("工作", &all), None);
|
||||||
// AnyBot's own callers still say which.
|
// AnyBot's own callers still say which.
|
||||||
assert_eq!(profiles_action("add", "私人", &all), "add");
|
assert_eq!(profiles_action("add", "私人", &own), "add");
|
||||||
assert_eq!(crate::web::describe("browser_profiles", r#"{"name":"私人"}"#), "切換到「私人」");
|
assert_eq!(crate::web::describe("browser_profiles", r#"{"name":"私人"}"#), "切換到「私人」");
|
||||||
assert_eq!(crate::web::describe("browser_profiles", "{}"), "列出設定檔");
|
assert_eq!(crate::web::describe("browser_profiles", "{}"), "列出設定檔");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Bot 的電腦's browser has one profile: adding or switching there is refused with that, and
|
||||||
|
/// nothing is written to this computer's choice (a switch there wrote 「預設」 over it, and the
|
||||||
|
/// bot was told 「已新增並切換到…」).
|
||||||
|
#[test]
|
||||||
|
fn the_box_browser_has_one_profile_and_leaves_this_computers_choice() {
|
||||||
|
assert_eq!(in_box(|| profiles_tool("", "工作")), Err(BOX_ONE_PROFILE.to_string()));
|
||||||
|
assert_eq!(in_box(|| profiles_tool("use", DEFAULT_PROFILE)), Err(BOX_ONE_PROFILE.to_string()));
|
||||||
|
assert!(in_box(|| profiles_tool("", "")).unwrap().contains("只有一個設定檔"));
|
||||||
|
assert_eq!(in_box(|| set_current("工作")), Err(BOX_ONE_PROFILE.to_string()));
|
||||||
|
assert_eq!(in_box(|| add("工作")), Err(BOX_ONE_PROFILE.to_string()));
|
||||||
|
assert!(!using_box());
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn profile_names_are_checked() {
|
fn profile_names_are_checked() {
|
||||||
assert_eq!(check_name(" 工作 ").unwrap(), "工作");
|
assert_eq!(check_name(" 工作 ").unwrap(), "工作");
|
||||||
|
|
|
||||||
|
|
@ -387,7 +387,6 @@ pub fn replay_of(name: &str) -> Replay {
|
||||||
"computer_use_check_permissions",
|
"computer_use_check_permissions",
|
||||||
"browser_read",
|
"browser_read",
|
||||||
"browser_screenshot",
|
"browser_screenshot",
|
||||||
"browser_profiles",
|
|
||||||
"browser_wait",
|
"browser_wait",
|
||||||
"browser_tabs",
|
"browser_tabs",
|
||||||
"browser_sent_log",
|
"browser_sent_log",
|
||||||
|
|
@ -707,7 +706,8 @@ mod tests {
|
||||||
fn looking_may_run_again_and_reaching_out_never() {
|
fn looking_may_run_again_and_reaching_out_never() {
|
||||||
assert_eq!(replay_of("computer_use_screenshot"), Replay::Safe);
|
assert_eq!(replay_of("computer_use_screenshot"), Replay::Safe);
|
||||||
assert_eq!(replay_of("read_file"), Replay::Safe);
|
assert_eq!(replay_of("read_file"), Replay::Safe);
|
||||||
for t in ["send_sms", "post_to_x", "publish_site", "browser_fill_card", "mac_send_mail", "shell", "edit_file", "computer_use_click", "computer_use_typing", "mcp__github__create_issue"] {
|
// (browser_profiles adds and switches profiles: it was listed as only looking.)
|
||||||
|
for t in ["send_sms", "post_to_x", "publish_site", "browser_fill_card", "mac_send_mail", "shell", "edit_file", "computer_use_click", "computer_use_typing", "mcp__github__create_issue", "browser_profiles"] {
|
||||||
assert_eq!(replay_of(t), Replay::Never, "{t}");
|
assert_eq!(replay_of(t), Replay::Never, "{t}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
179
src/remote.rs
179
src/remote.rs
|
|
@ -695,9 +695,13 @@ pub fn handle(req: Req, via_relay: bool) -> Resp {
|
||||||
if *action == "mcp" && !body["rename"].is_null() {
|
if *action == "mcp" && !body["rename"].is_null() {
|
||||||
return Resp::error(403, "連接器的名稱只能在電腦上的 AnyBot 改");
|
return Resp::error(403, "連接器的名稱只能在電腦上的 AnyBot 改");
|
||||||
}
|
}
|
||||||
let bot_now = || hub().ask_sync_for(SyncKind::Phone { action: "detail".into(), body: json!({"bot": body["bot"]}), role: role.clone() }, 20).unwrap_or(Value::Null);
|
if !via_relay {
|
||||||
if !via_relay && loosens_guard(action, &body, bot_now) {
|
let bot_now = || hub().ask_sync_for(SyncKind::Phone { action: "detail".into(), body: json!({"bot": body["bot"]}), role: role.clone() }, 20).unwrap_or(Value::Null);
|
||||||
return Resp::error(403, LOOSEN_REFUSED);
|
match lan_guard(action, &body, bot_now, &crate::cloudbox::box_runtime()) {
|
||||||
|
Guard::Keeps => {}
|
||||||
|
Guard::Loosens => return Resp::error(403, LOOSEN_REFUSED),
|
||||||
|
Guard::Unknown => return Resp::error(400, "不認得這個設定"),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// ChatGPT 方案 from the phone: the owner's; over the network, so not on the app's thread.
|
// ChatGPT 方案 from the phone: the owner's; over the network, so not on the app's thread.
|
||||||
if *action == "chatgpt" {
|
if *action == "chatgpt" {
|
||||||
|
|
@ -934,31 +938,70 @@ fn picks_of(b: &Value) -> Option<Vec<String>> {
|
||||||
/// connection is https; it signs in with the phone password alone).
|
/// connection is https; it signs in with the phone password alone).
|
||||||
pub const LOOSEN_REFUSED: &str = "這會放寬 Bot 能做的事:同一個網路直接連的裝置只能收緊、不能放寬。請在電腦上的 AnyBot 改,或用帳號連線。";
|
pub const LOOSEN_REFUSED: &str = "這會放寬 Bot 能做的事:同一個網路直接連的裝置只能收緊、不能放寬。請在電腦上的 AnyBot 改,或用帳號連線。";
|
||||||
|
|
||||||
|
/// What a phone act does to the bots' guards, asked of every act over a direct connection.
|
||||||
|
#[derive(Debug, PartialEq)]
|
||||||
|
pub(crate) enum Guard {
|
||||||
|
/// Changes no guard, or makes one stricter: done.
|
||||||
|
Keeps,
|
||||||
|
/// Lets a bot do more without asking, or lets more in: refused (LOOSEN_REFUSED).
|
||||||
|
Loosens,
|
||||||
|
/// A setting whose name isn't exactly one AnyBot knows (「direct_mode 」, 「Rule_add」…): refused
|
||||||
|
/// rather than guessed — the app's side reads names exactly too, so nothing passes here that
|
||||||
|
/// does something there.
|
||||||
|
Unknown,
|
||||||
|
}
|
||||||
|
|
||||||
/// 團隊角色: what each role may do. "member" chats and attaches files; "admin" also approves,
|
/// 團隊角色: what each role may do. "member" chats and attaches files; "admin" also approves,
|
||||||
/// stops, starts new chats and uses the screens; only "device" (another AnyBot of the owner's
|
/// stops, starts new chats and uses the screens; only "device" (another AnyBot of the owner's
|
||||||
/// account) may run tools here.
|
/// account) may run tools here.
|
||||||
/// A phone action carried out on the app's thread (where the state is), with its answer.
|
/// A phone action carried out on the app's thread (where the state is), with its answer.
|
||||||
/// Whether a phone action takes a guard away: turning 直接操作 on, adding an allow rule, adding
|
/// Which way a phone act moves the guards (`remote_ui.rs` `phone_act` does it, reading the same
|
||||||
/// a connector (a new tool the bots may call), ticking on an ability or a computer. For those the
|
/// names exactly). Looser: 直接操作 or 自動審核 on, an 「無需詢問直接允許」 rule added or an
|
||||||
/// phone sends the whole ticked list: only ticking one that is off now (`now`: the bot's detail,
|
/// 「一律詢問」 one removed, a connector added or switched back on, a messaging channel switched
|
||||||
/// asked only then) loosens anything — unticking one is tighter (it used to be refused too).
|
/// back on, a bot's computer tools on, a bot shared with the team, an ability or a computer
|
||||||
fn loosens_guard(action: &str, body: &Value, now: impl FnOnce() -> Value) -> bool {
|
/// ticked on (the phone sends the whole ticked list: only ticking one that is off now — `now`,
|
||||||
|
/// the bot's detail, asked only then — loosens), Bot 的電腦 taken from 強隔離 (gVisor) to
|
||||||
|
/// 標準 (`runtime`: the box's now). The rest — the other way round for each of those, and what
|
||||||
|
/// changes no guard (names, looks, models, keys, skills, routines, memories, pages) — keeps.
|
||||||
|
/// (Cards are answered, 一律允許 included, through api/bots/…/answer: that is the card in front of
|
||||||
|
/// the person, not a setting.)
|
||||||
|
pub(crate) fn lan_guard(action: &str, body: &Value, now: impl FnOnce() -> Value, runtime: &str) -> Guard {
|
||||||
|
let on = |v: &Value| v.as_bool() == Some(true);
|
||||||
|
let looser = |b: bool| if b { Guard::Loosens } else { Guard::Keeps };
|
||||||
|
let key = body["key"].as_str().unwrap_or("");
|
||||||
match action {
|
match action {
|
||||||
"setting" => match body["key"].as_str().unwrap_or("") {
|
"setting" => match key {
|
||||||
"direct_mode" => body["value"].as_bool().unwrap_or(false),
|
// (As phone_act reads them: a missing value is off.)
|
||||||
"rule_add" => body["list"].as_str() != Some("ask"),
|
"direct_mode" | "auto_review" => looser(on(&body["value"])),
|
||||||
_ => false,
|
"notify" => Guard::Keeps,
|
||||||
|
"rule_add" | "rule_remove" => match body["list"].as_str().unwrap_or("") {
|
||||||
|
"allow" => looser(key == "rule_add"),
|
||||||
|
"ask" => looser(key == "rule_remove"),
|
||||||
|
_ => Guard::Unknown,
|
||||||
|
},
|
||||||
|
_ => Guard::Unknown,
|
||||||
},
|
},
|
||||||
"mcp" => body["add"].is_object(),
|
"bot" => match key {
|
||||||
"bot" => match body["key"].as_str().unwrap_or("") {
|
"abilities" | "may_use" => {
|
||||||
key @ ("abilities" | "may_use") => {
|
|
||||||
let now = now();
|
let now = now();
|
||||||
let on: Vec<&str> = now[key].as_array().into_iter().flatten().filter(|x| x["on"] == true).filter_map(|x| x["key"].as_str()).collect();
|
let ticked_now: Vec<&str> = now[key].as_array().into_iter().flatten().filter(|x| x["on"] == true).filter_map(|x| x["key"].as_str()).collect();
|
||||||
body["value"].as_array().into_iter().flatten().any(|t| !t.as_str().is_some_and(|t| on.contains(&t)))
|
looser(body["value"].as_array().into_iter().flatten().any(|t| !t.as_str().is_some_and(|t| ticked_now.contains(&t))))
|
||||||
}
|
}
|
||||||
_ => false,
|
// (phone_act: a missing value turns the tools on.)
|
||||||
|
"tools" => looser(body["value"].as_bool().unwrap_or(true)),
|
||||||
|
"team" => looser(on(&body["value"])),
|
||||||
|
"allow_remove" | "skills" | "pinned" | "pin_at" | "folder" | "primary" | "members" | "strengths" | "not_for" | "unread" | "shape" | "color" | "context" | "thinking" | "step_model" => Guard::Keeps,
|
||||||
|
_ => Guard::Unknown,
|
||||||
},
|
},
|
||||||
_ => false,
|
// (Renaming is refused before this; reconnecting connects only what is on.)
|
||||||
|
"mcp" => looser(body["add"].is_object() || (!on(&body["reconnect"]) && !on(&body["remove"]) && on(&body["enabled"]))),
|
||||||
|
"channel" => looser(!on(&body["remove"]) && on(&body["enabled"])),
|
||||||
|
"box" => match body["op"].as_str().unwrap_or("") {
|
||||||
|
"runtime" => looser(runtime == "runsc" && body["value"].as_str() != Some("runsc")),
|
||||||
|
"wake" | "snapshot" | "disk" | "update" | "reset" | "auto_update" => Guard::Keeps,
|
||||||
|
_ => Guard::Unknown,
|
||||||
|
},
|
||||||
|
_ => Guard::Keeps,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2964,6 +3007,84 @@ mod tests {
|
||||||
assert_eq!(to_brain(&s, "GET", "/x", &[], &[], 10).unwrap_err(), "找不到這個 Bot");
|
assert_eq!(to_brain(&s, "GET", "/x", &[], &[], 10).unwrap_err(), "找不到這個 Bot");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Every setting the phone can send, which way it moves the guards over a direct connection:
|
||||||
|
/// each loosening is refused, each tightening (and what changes no guard) goes through, and a
|
||||||
|
/// name that isn't exactly one AnyBot knows is refused, not guessed.
|
||||||
|
#[test]
|
||||||
|
fn a_direct_connection_only_tightens() {
|
||||||
|
let unasked = || -> Value { panic!("the bot is asked about only for its abilities and computers") };
|
||||||
|
let g = |action: &str, body: Value| lan_guard(action, &body, unasked, "runc");
|
||||||
|
let loosens = [
|
||||||
|
("setting", json!({"key": "direct_mode", "value": true})),
|
||||||
|
("setting", json!({"key": "auto_review", "value": true})),
|
||||||
|
("setting", json!({"key": "rule_add", "list": "allow", "value": "x"})),
|
||||||
|
("setting", json!({"key": "rule_remove", "list": "ask", "value": "x"})),
|
||||||
|
("bot", json!({"bot": 1, "key": "tools", "value": true})),
|
||||||
|
("bot", json!({"bot": 1, "key": "tools"})),
|
||||||
|
("bot", json!({"bot": 1, "key": "team", "value": true})),
|
||||||
|
("mcp", json!({"add": {"url": "https://x"}})),
|
||||||
|
("mcp", json!({"name": "x", "enabled": true})),
|
||||||
|
("channel", json!({"id": 1, "enabled": true})),
|
||||||
|
];
|
||||||
|
for (a, b) in loosens {
|
||||||
|
assert_eq!(g(a, b.clone()), Guard::Loosens, "{a} {b}");
|
||||||
|
}
|
||||||
|
let keeps = [
|
||||||
|
("setting", json!({"key": "direct_mode", "value": false})),
|
||||||
|
("setting", json!({"key": "auto_review", "value": false})),
|
||||||
|
("setting", json!({"key": "notify", "value": true})),
|
||||||
|
("setting", json!({"key": "rule_add", "list": "ask", "value": "x"})),
|
||||||
|
("setting", json!({"key": "rule_remove", "list": "allow", "value": "x"})),
|
||||||
|
("bot", json!({"bot": 1, "key": "tools", "value": false})),
|
||||||
|
("bot", json!({"bot": 1, "key": "team", "value": false})),
|
||||||
|
("bot", json!({"bot": 1, "key": "allow_remove", "value": "rm"})),
|
||||||
|
("bot", json!({"bot": 1, "key": "shape", "value": "heart"})),
|
||||||
|
("bot", json!({"bot": 1, "key": "skills", "value": []})),
|
||||||
|
("mcp", json!({"name": "x", "enabled": false})),
|
||||||
|
("mcp", json!({"name": "x", "remove": true, "enabled": true})),
|
||||||
|
("mcp", json!({"name": "x", "reconnect": true})),
|
||||||
|
("channel", json!({"id": 1, "enabled": false})),
|
||||||
|
("channel", json!({"id": 1, "remove": true, "enabled": true})),
|
||||||
|
("box", json!({"op": "runtime", "value": "runsc"})),
|
||||||
|
("box", json!({"op": "wake"})),
|
||||||
|
("app", json!({"name": "update_settings", "args": {"theme": "dark"}})),
|
||||||
|
("provider", json!({"provider": "Xai", "key": "k"})),
|
||||||
|
];
|
||||||
|
for (a, b) in keeps {
|
||||||
|
assert_eq!(g(a, b.clone()), Guard::Keeps, "{a} {b}");
|
||||||
|
}
|
||||||
|
// 強隔離 to 標準 is looser; already 標準, nothing changes.
|
||||||
|
assert_eq!(lan_guard("box", &json!({"op": "runtime", "value": ""}), unasked, "runsc"), Guard::Loosens);
|
||||||
|
assert_eq!(lan_guard("box", &json!({"op": "runtime", "value": " runsc"}), unasked, "runsc"), Guard::Loosens);
|
||||||
|
assert_eq!(lan_guard("box", &json!({"op": "runtime", "value": ""}), unasked, "runc"), Guard::Keeps);
|
||||||
|
// Names exactly as AnyBot spells them, or not at all (phone_act trimmed 「direct_mode 」
|
||||||
|
// after the guard had read it as something else).
|
||||||
|
for k in ["direct_mode ", " direct_mode", "Direct_mode", "direct_mode\u{3000}", "direct_mode\u{a0}", "\tdirect_mode", "rule_add ", "auto_review\n"] {
|
||||||
|
assert_eq!(g("setting", json!({"key": k, "list": "allow", "value": true})), Guard::Unknown, "{k:?}");
|
||||||
|
}
|
||||||
|
for l in ["allow ", " ask", "Allow", "ASK", "ask\u{3000}", ""] {
|
||||||
|
assert_eq!(g("setting", json!({"key": "rule_add", "list": l, "value": "x"})), Guard::Unknown, "{l:?}");
|
||||||
|
}
|
||||||
|
for k in ["abilities ", " may_use", "Tools", "team\u{a0}"] {
|
||||||
|
assert_eq!(lan_guard("bot", &json!({"bot": 1, "key": k, "value": ["web"]}), || Value::Null, "runc"), Guard::Unknown, "{k:?}");
|
||||||
|
}
|
||||||
|
assert_eq!(g("box", json!({"op": "runtime "})), Guard::Unknown);
|
||||||
|
// Abilities and computers: unticking one is tighter (it used to be refused too); ticking
|
||||||
|
// one that is off now, or one the bot doesn't have, is looser.
|
||||||
|
let detail = || json!({"abilities": [{"key": "web", "on": true}, {"key": "files", "on": true}, {"key": "admin", "on": false}], "may_use": [{"key": "Bot 的電腦", "on": true}, {"key": "伺服器", "on": false}]});
|
||||||
|
let bot = |key: &str, ticked: Value, now: &dyn Fn() -> Value| lan_guard("bot", &json!({"bot": 1, "key": key, "value": ticked}), now, "runc");
|
||||||
|
assert_eq!(bot("abilities", json!(["web"]), &detail), Guard::Keeps);
|
||||||
|
assert_eq!(bot("abilities", json!(["web", "files"]), &detail), Guard::Keeps);
|
||||||
|
assert_eq!(bot("abilities", json!(["web", "files", "admin"]), &detail), Guard::Loosens);
|
||||||
|
assert_eq!(bot("abilities", json!(["web", "made-up"]), &detail), Guard::Loosens);
|
||||||
|
assert_eq!(bot("abilities", json!(["web "]), &detail), Guard::Loosens);
|
||||||
|
assert_eq!(bot("may_use", json!(["Bot 的電腦"]), &detail), Guard::Keeps);
|
||||||
|
assert_eq!(bot("may_use", json!(["Bot 的電腦", "伺服器"]), &detail), Guard::Loosens);
|
||||||
|
// The bot couldn't be asked: nothing counts as on.
|
||||||
|
assert_eq!(bot("abilities", json!(["web"]), &|| Value::Null), Guard::Loosens);
|
||||||
|
assert!(!LOOSEN_REFUSED.contains("加密") && LOOSEN_REFUSED.contains("只能收緊、不能放寬"));
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn roles_gate_the_sync_and_hands_apis() {
|
fn roles_gate_the_sync_and_hands_apis() {
|
||||||
// 大腦 sync (mirror) and 裝置連結 (device) are separate doors on the hands machine:
|
// 大腦 sync (mirror) and 裝置連結 (device) are separate doors on the hands machine:
|
||||||
|
|
@ -2978,26 +3099,6 @@ mod tests {
|
||||||
assert!(!role_allows("admin", "GET", &["api", "sync"]));
|
assert!(!role_allows("admin", "GET", &["api", "sync"]));
|
||||||
// A role the relay didn't name is nobody's.
|
// A role the relay didn't name is nobody's.
|
||||||
assert!(!role_allows("none", "GET", &["api", "state"]));
|
assert!(!role_allows("none", "GET", &["api", "state"]));
|
||||||
// 區網 can't switch a guard off; turning one on, or an ask rule, is fine.
|
|
||||||
let unasked = || -> Value { panic!("the bot is asked about only for its abilities and computers") };
|
|
||||||
assert!(loosens_guard("setting", &json!({"key": "direct_mode", "value": true}), unasked));
|
|
||||||
assert!(!loosens_guard("setting", &json!({"key": "direct_mode", "value": false}), unasked));
|
|
||||||
assert!(loosens_guard("setting", &json!({"key": "rule_add", "list": "allow", "value": "x"}), unasked));
|
|
||||||
assert!(!loosens_guard("setting", &json!({"key": "rule_add", "list": "ask", "value": "x"}), unasked));
|
|
||||||
assert!(loosens_guard("mcp", &json!({"add": {"url": "https://x"}}), unasked));
|
|
||||||
assert!(!loosens_guard("bot", &json!({"key": "shape", "value": "heart"}), unasked));
|
|
||||||
// Abilities and computers: unticking one is tighter (it used to be refused too); ticking
|
|
||||||
// one that is off now, or one the bot doesn't have, is looser.
|
|
||||||
let detail = || json!({"abilities": [{"key": "web", "on": true}, {"key": "files", "on": true}, {"key": "admin", "on": false}], "may_use": [{"key": "Bot 的電腦", "on": true}, {"key": "伺服器", "on": false}]});
|
|
||||||
assert!(!loosens_guard("bot", &json!({"key": "abilities", "value": ["web"]}), detail));
|
|
||||||
assert!(!loosens_guard("bot", &json!({"key": "abilities", "value": ["web", "files"]}), detail));
|
|
||||||
assert!(loosens_guard("bot", &json!({"key": "abilities", "value": ["web", "files", "admin"]}), detail));
|
|
||||||
assert!(loosens_guard("bot", &json!({"key": "abilities", "value": ["web", "made-up"]}), detail));
|
|
||||||
assert!(!loosens_guard("bot", &json!({"key": "may_use", "value": ["Bot 的電腦"]}), detail));
|
|
||||||
assert!(loosens_guard("bot", &json!({"key": "may_use", "value": ["Bot 的電腦", "伺服器"]}), detail));
|
|
||||||
// The bot couldn't be asked: nothing counts as on.
|
|
||||||
assert!(loosens_guard("bot", &json!({"key": "abilities", "value": ["web"]}), || Value::Null));
|
|
||||||
assert!(!LOOSEN_REFUSED.contains("加密"));
|
|
||||||
assert!(role_allows("member", "POST", &["api", "bots", "1", "send"]));
|
assert!(role_allows("member", "POST", &["api", "bots", "1", "send"]));
|
||||||
assert!(!role_allows("member", "POST", &["api", "bots", "1", "stop"]));
|
assert!(!role_allows("member", "POST", &["api", "bots", "1", "stop"]));
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue