From 2d90e5decd08f0aa9a8130bd24fcd66f1c88d7c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=80=A7=E9=A9=8A?= Date: Fri, 20 Nov 2026 13:38:58 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BA=A4=E4=BB=98=E7=A2=BA=E8=AA=8D?= =?UTF-8?q?=E2=80=94=E2=80=94Bot=20=E5=82=B3=E7=9A=84=E6=AA=94=E6=A1=88?= =?UTF-8?q?=E8=A8=98=E4=B8=8B=E5=9C=A8=E5=93=AA=E5=8F=B0=E8=A3=9D=E7=BD=AE?= =?UTF-8?q?=E9=A1=AF=E7=A4=BA=E3=80=81=E9=BB=9E=E9=96=8B=E6=B2=92=EF=BC=8C?= =?UTF-8?q?=E6=B2=92=E9=A1=AF=E7=A4=BA=E5=87=BA=E4=BE=86=E5=8F=AB=E9=86=92?= =?UTF-8?q?=20Bot=20=E4=B8=80=E6=AC=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 起因:Bot 產了一張圖、send_file 回報成功、Bot 一直說「已完成」,但圖一直沒出現在使用者 的聊天裡,系統完全不知道。「完成」改成:你看得到、能用,而且系統知道你收到了。 - 附件有身分:attach::store/store_bytes 給每個附件一個編號(舊資料讀得進來,沒有回報的 附件寫出來跟以前一字不差);螢幕電腦把路徑換成本機副本時編號不變,回報一律用編號。 - 三層狀態記在大腦那則附件上:已在聊天 → 已在某台裝置顯示 → 點開了,或「顯示失敗」加 原因;每筆記哪台裝置和時間,同一台同一種只記第一次,最多 12 筆。記號和「已顯示/已 點開」只看擁有者自己的裝置;團隊成員、管理員的裝置只記下(最多 4 筆)、不叫醒。 - 誰回報: - 手機:POST api/bots//seen(團隊成員也可以)。圖片真的載入、在畫面裡、頁面在前面 才算顯示;預覽真的畫出來(文字、表格、圖、PDF 的頁、能播的錄音影片)或存到手機才算 點開;大腦回 404/422/500 或圖片再抓一次還是解不開算失敗;斷線、408、429、502–504 算網路問題、不算。不排隊,每次開頁面每個附件每種只報一次。 - 大腦自己的視窗(「這台電腦」):卡片在畫面裡停留 0.8 秒、視窗在前面才算顯示(聊天剛 打開時從頂端畫的那一格、「回到最新訊息」捲過去的不算);點開算點開;檔案不見了算失敗。 - 螢幕電腦:api/sync/act 的 seen(大腦用它的名字記,另開執行緒送、不擋其他訊息);抓大腦 檔案被回 404 算失敗(以前完全不報),網路斷了不算。 - 裝置名稱、原因都由大腦從固定的字選,頁面送來的字不會原樣進到 Bot 那裡。 - 同步:remote_signature、msg_sig、聊天存檔的 chat_mark 都算進回報;message_json 對 Bot 傳 的附件輸出 id、delivery、seen。 - 畫面:Bot 傳來的附件下面一個灰色小記號——✓ 已在聊天、✓✓ 已在某台裝置顯示、點開過的 ✓✓ 是強調色;手機點記號跳出清單、電腦版滑過看清單(每台裝置、時間、顯示/點開/失敗和 原因)。使用者自己附的檔案沒有記號。失敗不另外跳字;手機上解不開的圖也顯示原本的 「這張圖讀不到」(以前是一塊空白)。 - Bot 知道:send_file 的結果改成「已放進聊天(…附件 <編號>)…不要說使用者已經看到」;之後 的回合結果後面帶一行〔交付狀態:…〕(日期寫死,不會每天變);系統提示加一句以那個狀態 為準、使用者問收到沒照它回答。 - 叫醒:擁有者的裝置回報顯示失敗、而且還沒有擁有者的裝置顯示過,叫醒那個 Bot 一次(新的 「[交付]」標籤,視窗和手機的 WAKE_TAGS 一起改),只寫附件編號和副檔名、哪台、為什麼 (不寫檔名:檔名可能來自外面,這則訊息帶著擁有者的信任開一輪),請它換方式交付。只在 「傳出這個檔案的那一輪是擁有者開的」時叫醒:訊息管道的人、團隊成員、別的 Bot 要的檔案、 群組聊天、給使用者看畫面的截圖、支線帶回的檔案都只記下。擁有者上次說話之後最多兩次; Bot 在忙、叫醒在排隊時別台顯示了就取消。 - docs/feature-map/deliver.md 新增子功能 deliver-confirm、使用者怎麼到、三條 verify-anybot 步驟、陷阱;FEATURES.md 同步。verify-anybot 的假模型照規則回答時多記 tool_results(這個 請求裡每個工具結果的結尾),用來證明 Bot 讀到〔交付狀態〕。 合進主線(接在手機、螢幕電腦「沒網路照樣能用」之後) - 手機頁面:apiOnce 用主線那行(已經帶 e.status、e.unsure);離開聊天先存一份、回到聊天看 畫面裡的附件,兩個都留。螢幕電腦:兩邊新增的測試都留,離線那輪的測試附件補上新欄位。 - 合併後跑 deliver.md 時發現(以前就有、離線那輪重畫變多後才明顯):手機聊天每次重畫, 圖片都先退回檔名再載入、長高,「停在最新訊息」只在重畫那一刻判斷,幾張圖之後最新那則 被推到畫面外、也就永遠不算「顯示」。改成:已經讀到的圖重畫時直接沿用;停在底部時, 內容在畫完之後變高(圖片載入)也跟著停在底部,往上捲在讀的不動;比螢幕高的問題卡留在 它的問題那裡,不被拉到底。FEATURES.md 同步。 已驗證: cargo test 全綠(主程式 767,含 featuremap::、layout_audit::、tool_specs_are_locked、 approval_decisions_are_characterized;新增 attach、deliver_ui 6 條、remote、mirror_ui、 remote_ui、app 的 group_history 與系統提示、layout_audit 的記號滑過清單);verify-anybot deliver.md 全部步驟照貼從頭跑過(傳檔預覽、機密不傳、伺服器上打不開、沒登入沒有發佈、 交付確認顯示/點開/Bot 讀到狀態、顯示失敗叫醒一次且重開後仍是一次),另手動驗過刪掉大腦 副本後手機記「大腦上找不到這個檔案」、已點開的不叫醒;十輪乾淨脈絡獨立審查,最後一輪無 P0/P1。 合進主線後:cargo test 774 通過;verify-approval-routing --replay 跟合併前一樣(AllSurfaces 通過、 replay 10 個都過,「改過了」的 5 段在 HEAD 就是如此);verify-anybot 在新的 scratch 上把 deliver.md、phone.md、cards.md 全部步驟各從頭跑過都通過(含「沒網路也打得開」「斷線又回來」、 問題卡一題一題走);另外實跑:往上捲在讀時,新傳來的圖不會把畫面拉回底部。合併的部分另做 一輪乾淨脈絡獨立審查:沒有 P0/P1,兩條 P2(高的問題卡被拉到底、重畫先用原檔)已修,一條 P2(超過 40 張圖時錯誤處理掛得晚,不會誤報)留著。 未驗證: 真的 iPhone/Android(Safari 的 IntersectionObserver、主畫面 App)——要實機;螢幕電腦 連大腦的真實路徑——要另一台登入同帳號的 AnyBot;桌面視窗的記號與 0.8 秒停留——要開視窗 (ABV_ALLOW_WINDOW,要使用者同意),只有行程內繪圖測試;團隊成員、管理員經帳號伺服器 回報——要帳號伺服器與第二個帳號。 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Uirha5JgTkqJjkgMtrEXrn --- .claude/skills/verify-anybot/SKILL.md | 2 +- .../verify-anybot/scripts/fake-model.mjs | 7 +- FEATURES.md | 6 + docs/feature-map/deliver.md | 20 +- mobile/index.html | 155 +++++++-- src/agent.rs | 2 +- src/agent/steps.rs | 4 +- src/app.rs | 53 ++- src/app/chat_ui.rs | 17 +- src/app/deliver_ui.rs | 314 ++++++++++++++++++ src/app/files_ui.rs | 6 +- src/app/layout_audit.rs | 47 +++ src/app/mirror_ui.rs | 77 ++++- src/app/remote_ui.rs | 21 +- src/attach.rs | 212 +++++++++++- src/memory.rs | 2 +- src/model.rs | 4 + src/remote.rs | 91 ++++- 18 files changed, 978 insertions(+), 62 deletions(-) create mode 100644 src/app/deliver_ui.rs diff --git a/.claude/skills/verify-anybot/SKILL.md b/.claude/skills/verify-anybot/SKILL.md index 516f9b1..1e0c1e9 100644 --- a/.claude/skills/verify-anybot/SKILL.md +++ b/.claude/skills/verify-anybot/SKILL.md @@ -139,7 +139,7 @@ $CTL serve # 用完再開回來 - 指定答案:`$CTL model-reply <比對的字> <回答>` 之後,system 或最後一則使用者訊息含那段字的請求都回那個答案(後加的先比對;`--clear` 全拿掉)。給 AnyBot 自己的子任務用:目標評審(system 開頭「你是驗收員」)、自動審核(「你是動作審核員」)…。回答裡的 `[[call 工具 {JSON}]]` 照叫——不管這一輪有沒有那個工具,用來看 AnyBot 怎麼擋——最後一則是工具結果時改回其餘的字,例如 `$CTL model-reply 你是驗收員 '[[call read_file {"path":"hello.txt"}]] {"verdict":"met","reason":"…"}'`。 -每個請求一行記在 `model-requests.jsonl`(種類、工具數、system 開頭、最後一則、回了什麼;前一則的結尾 `prev`(例如回答後面帶的「(使用者對這則回應:👍)」);照規則回的另外記整則使用者訊息 `user_full` 和工具結果 `tool_result`):用來證明訊息真的到了模型那一層、帶了哪些工具、評審讀到什麼。`$CTL model ''` 照 jq 印出來(也存成證據)。要核准又不會動到任何電腦的工具:`update_bot`(「修改 Bot 自己」每次都問)。 +每個請求一行記在 `model-requests.jsonl`(種類、工具數、system 開頭、最後一則、回了什麼;前一則的結尾 `prev`(例如回答後面帶的「(使用者對這則回應:👍)」);照規則回的另外記整則使用者訊息 `user_full`、工具結果 `tool_result`,和這個請求裡每個工具結果的結尾 `tool_results`(例如附件後面的〔交付狀態〕)):用來證明訊息真的到了模型那一層、帶了哪些工具、評審讀到什麼。`$CTL model ''` 照 jq 印出來(也存成證據)。要核准又不會動到任何電腦的工具:`update_bot`(「修改 Bot 自己」每次都問)。 ### 桌面視窗(只寫在這裡,不在使用者正在用的 Mac 上跑) diff --git a/.claude/skills/verify-anybot/scripts/fake-model.mjs b/.claude/skills/verify-anybot/scripts/fake-model.mjs index 19e9856..e0b4c60 100755 --- a/.claude/skills/verify-anybot/scripts/fake-model.mjs +++ b/.claude/skills/verify-anybot/scripts/fake-model.mjs @@ -12,7 +12,7 @@ // reply 裡的 [[call 工具 {JSON}]]:最後一則不是工具結果時照叫(不管這一輪有沒有那個工具,用來看 // AnyBot 怎麼擋),是工具結果時回 reply 去掉 [[call]] 的字。檔案每個請求重讀,後加的規則先比對。 // 每個請求寫一行到 --log(JSONL):時間、種類、工具數、system 開頭、最後一則、前一則的結尾(prev)、回了什麼;照規則回的 -// 另外記整則使用者訊息(user_full)。只聽 127.0.0.1。 +// 另外記整則使用者訊息(user_full)和這個請求裡每個工具結果的結尾(tool_results)。只聽 127.0.0.1。 // // 用法:node fake-model.mjs --port 0 --log requests.jsonl --port-file model.port [--rules rules.json] @@ -63,7 +63,10 @@ function decide(body) { if (rule) { const reply = String(rule.reply ?? ""); const m = last.role !== "tool" ? reply.match(CALL) : null; - const ruled = { ...info, kind: "rule", rule: rule.match, user_full: userText.slice(0, 8000), ...(last.role === "tool" ? { tool_result: textOf(last.content).slice(0, 400) } : {}) }; + // (tool_results: the end of every step's result the model read in this request — what AnyBot + // put after one, e.g. a file's 〔交付狀態〕, shows here.) + const results = msgs.filter((x) => x.role === "tool").slice(-6).map((x) => textOf(x.content).slice(-240)); + const ruled = { ...info, kind: "rule", rule: rule.match, user_full: userText.slice(0, 8000), tool_results: results, ...(last.role === "tool" ? { tool_result: textOf(last.content).slice(0, 400) } : {}) }; if (m) { try { return { info: ruled, call: { name: m[1], args: m[2] ? JSON.parse(m[2]) : {} } }; } catch (e) { return { info: { ...ruled, kind: "bad-directive" }, text: `FAKE-MODEL:規則裡 [[call]] 的 JSON 看不懂(${e.message})` }; } } diff --git a/FEATURES.md b/FEATURES.md index f2487f9..6c2dc58 100644 --- a/FEATURES.md +++ b/FEATURES.md @@ -2545,6 +2545,12 @@ computer_use_screenshot、click、mouse_move、mouse_button(按住/放開) - 圖片:直接顯示。 - PDF、Word:顯示文字。 - 程式碼、文字:等寬字。 + - **交付確認**:「完成」的定義是你看得到、能用,而且系統知道你收到了。Bot 傳來的檔案(`send_file`、給你看畫面的截圖)各有一個編號,每台裝置回報它做了什麼,記在大腦那則附件上(每台每種只記第一次,最多 12 筆): + - 已在聊天(附件存在就是)→ 已在某台裝置顯示 → 你點開了;或「顯示失敗」加原因(大腦上找不到檔案、這台裝置讀不出來、大腦讀檔出錯)。 + - 誰回報:大腦自己的視窗(「這台電腦」:卡片在畫面裡、視窗在前面算顯示,點開算點開,檔案不見了算失敗);螢幕電腦(用它的名字,經 `api/sync/act` 的 `seen`;抓大腦檔案被回「找不到」算失敗,網路斷了不算);手機(自己帶 iPhone/iPad/Android/瀏覽器,團隊成員是「名字 的 iPhone」:圖片真的載入而且在畫面裡、頁面在前面算顯示,檔案卡片在畫面裡算顯示,預覽真的畫出來(文字、表格、圖、PDF 的頁、能播的錄音影片)或存到手機算點開,大腦回錯誤或圖片再抓一次還是解不開算失敗,502–504 和斷線算網路問題、不算;`POST api/bots//seen`,每次開頁面每個附件每種只報一次,網路斷了不排隊)。 + - 畫面:Bot 傳來的附件下面只多一個灰色小記號——✓ 已在聊天、✓✓ 已在某台裝置顯示、點開過的 ✓✓ 是強調色。失敗不另外跳字(手機的「這張圖讀不到」照舊)。電腦版滑過記號、手機點記號,列出每台裝置、什麼時候、顯示/點開/失敗和原因。你自己附的檔案沒有記號。手機聊天停在最新訊息時,圖片載入、內容變高也一直停在底部(往上捲在讀的不會被拉回來),新傳來的圖真的出現在畫面上;重畫時已經讀到的圖直接沿用,不會閃回檔名再長高。 + - Bot 知道:`send_file` 的結果只說「已放進聊天」,下一輪起結果後面帶一行〔交付狀態:…〕;系統提示要它不要說你已經看到,你問「收到了嗎」照那個狀態回答。 + - 有裝置回報顯示失敗、而且還沒有任何裝置顯示過,大腦叫醒那個 Bot 一次(團隊成員、管理員的裝置只記下、不叫醒,最多佔 4 筆;群組聊天、給你看畫面的截圖、團隊成員、訊息管道的人或別的 Bot 要的檔案都只記下、不叫醒;Bot 還在忙、叫醒在排隊時別台顯示了就取消)(「[交付]」開頭:附件編號和副檔名、哪台、為什麼;不寫檔名——檔名可能來自外面,這則訊息帶著你的信任開一輪),請它換方式交付(換格式、縮小、`send_to_device`)。你上次說話之後最多叫醒兩次。你只是還沒打開 App 不算失敗,不催。支線、交辦帶回主聊天的檔案只有記號,不叫醒、主 Bot 也讀不到狀態;管理員要的檔案和你的一樣會叫醒。 - 卡片(天氣、機票等)照舊顯示在回答下面。 - 深色主題改成原版量到的顏色:聊天背景 #131313、側欄 #101010、卡片 #1F1F1F。 diff --git a/docs/feature-map/deliver.md b/docs/feature-map/deliver.md index b03fe85..96e1c70 100644 --- a/docs/feature-map/deliver.md +++ b/docs/feature-map/deliver.md @@ -1,22 +1,27 @@ # 交出結果:傳檔、打開、發佈網站 -Bot 做好的東西用三種方式交給使用者:放進聊天變成檔案卡片、直接在使用者的螢幕上打開,或發佈成公開網站。傳到帳號裡另一台裝置是 `send_to_device`,見 [computers](computers.md)。 +Bot 做好的東西用三種方式交給使用者:放進聊天變成檔案卡片、直接在使用者的螢幕上打開,或發佈成公開網站。傳進聊天的檔案,系統記下它在哪台裝置顯示過、使用者點開沒有(交付確認)。傳到帳號裡另一台裝置是 `send_to_device`,見 [computers](computers.md)。 ## 子功能 - `deliver-send` 傳檔:`send_file` 把檔案放進聊天變成檔案卡片,點一下預覽、可以下載。 +- `deliver-confirm` 交付確認:Bot 傳來的檔案(`send_file`、給使用者看畫面的截圖)各有編號;每台裝置回報它做了什麼,記在大腦那則附件上:已在聊天 → 已在某台裝置顯示 → 使用者點開了,或「顯示失敗」加原因。每台每種只記第一次,最多 12 筆;記號和「已顯示/已點開」只看使用者自己的裝置。 + - 誰回報:大腦自己的視窗(「這台電腦」:卡片在畫面裡、視窗在前面算顯示,點開算點開,檔案不見了算失敗);螢幕電腦(用它的名字,抓大腦的檔案被說找不到算失敗);手機(iPhone、iPad、Android 或「瀏覽器」,團隊成員是「名字 的 iPhone」:圖片真的載入而且在畫面裡算顯示,檔案卡片在畫面裡算顯示,預覽真的畫出來(文字、表格、圖、PDF 的頁、能播的錄音影片)或存到手機算點開,大腦回錯誤或圖片解不開算失敗)。網路斷了不算失敗,使用者還沒打開 App 也不算。 + - Bot 讀得到:`send_file` 的結果只說「已放進聊天」,之後的回合結果後面帶一行〔交付狀態:…〕。 + - 有裝置顯示失敗、而且還沒有任何裝置顯示過,Bot 被叫醒一次(團隊成員、管理員的裝置只記下、不叫醒,最多佔 4 筆;群組聊天、給使用者看畫面的截圖、團隊成員或訊息管道的人要的檔案都只記下、不叫醒)(「[交付]」開頭:附件編號和副檔名、哪台、為什麼;不寫檔名),換方式再交付;使用者上次說話之後最多兩次。 - `deliver-open` 打開給使用者看:`open_for_person` 在使用者的螢幕上打開檔案或網址。 - `deliver-publish` 發佈網站:`publish_site` 把一個 .html 檔或有 index.html 的資料夾發佈成公開網站,回傳網址,同一個名字再發佈就取代。 ## 使用者怎麼到 - `send_file` 的檔案卡片在回覆裡,點一下預覽(「下載檔案」「用其他 App 打開」);右側面板「資料庫」也列出這個對話裡的檔案。 +- 交付確認:Bot 傳來的附件下面一個灰色小記號——✓ 已在聊天、✓✓ 已在某台裝置顯示、點開過的 ✓✓ 是強調色;滑過記號列出每台裝置、時間、顯示/點開/失敗和原因。使用者自己附的檔案沒有記號。 - `publish_site` 要先在 設定 › 一般 ›「手機與帳號」登入帳號才有([account](account.md))。 -- 手機:聊天裡的檔案卡片,點了在 App 裡預覽、右上角存到手機;聊天右上「⋯」›「對話詳細資訊」›「資料庫」([phone](phone.md))。 +- 手機:聊天裡的檔案卡片,點了在 App 裡預覽、右上角存到手機;聊天右上「⋯」›「對話詳細資訊」›「資料庫」([phone](phone.md))。附件下面同樣的記號,點一下跳出清單。 ## 怎麼操作(verify-anybot) -- Bot:交結果用 `send_file`,不要只說檔案在哪;要使用者馬上看到用 `open_for_person`;要公開網址用 `publish_site`(path,name 只用英文字母、數字和 -)。`open_for_person`、`publish_site` 屬於「檔案與指令」能力,`send_file` 每個 Bot 都有。 +- Bot:交結果用 `send_file`,不要只說檔案在哪;傳了不等於使用者已收到:以結果後面的〔交付狀態〕為準,使用者問收到沒照它回答;被「[交付]」叫醒時換格式、縮小或用 `send_to_device` 再交一次;要使用者馬上看到用 `open_for_person`;要公開網址用 `publish_site`(path,name 只用英文字母、數字和 -)。`open_for_person`、`publish_site` 屬於「檔案與指令」能力,`send_file` 每個 Bot 都有。 前提: @@ -28,8 +33,11 @@ Bot 做好的東西用三種方式交給使用者:放進聊天變成檔案卡 - **伺服器上打不開**(covers `deliver-open`):請 Bot 打開 report.md,再打開一個網址。指令:`$CTL phone send '打開 [[call open_for_person {"path":"report.md"}]]' && $CTL phone wait-text '改用 send_file' --in '#msgs' && $CTL phone send '打開網址 [[call open_for_person {"path":"https://example.com/"}]]' && $CTL phone wait-text '不知道使用者現在在用哪台電腦' --in '#msgs' && $CTL api GET /api/bots/1 --jq '[.messages[].tools[]? | select(.name == "open_for_person") | .status]'`。看到:「AnyBot 在伺服器上,檔案沒辦法直接在使用者的螢幕打開。改用 send_file…」;網址是「不知道使用者現在在用哪台電腦,沒辦法打開給他看。把網址直接寫在回覆裡。」;兩步都是 failed。 - **沒登入就沒有發佈**(covers `deliver-publish`):指令:`$CTL phone send '發佈 [[call publish_site {"path":"report.md","name":"report"}]]' && $CTL phone wait-text '這一輪沒有 publish_site 這個工具' --in '#msgs' && $CTL model 'select(.want) | .want'`。看到:Bot 拿到的工具裡沒有 `publish_site`(假模型列出它有的);模型那層記下想要的是 publish_site。 - **打開在螢幕上、真的發佈**(covers `deliver-open`、`deliver-publish`):指令:走不到——打開要「這台電腦」或使用者正在用的帳號裡的電腦,發佈要帳號伺服器(`relay/`)。看到:最接近的真路是上面兩步的拒絕,和自動測試裡在這台電腦上傳檔、打開(工作資料夾外先問、程式或指令檔不打開、機密檔案不傳)。 +- **交付確認:顯示、點開、Bot 照狀態回答**(covers `deliver-confirm`):Bot 在自己的電腦畫一張 PNG 傳過來,看記號,點開,再問 Bot 收到沒。指令:`$CTL phone send '畫 [[call shell {"command":"printf iVBORw0KGgoAAAANSUhEUgAAAKAAAABkCAIAAACO1KzYAAABDUlEQVR42u3cMQ0AIAxE0QpDCUoQgU504KHDDc1L2C/5b22os1f7vdt/djO7JTRgoQELDRgwYLuA7QK2Cxiw0ICFBiw0YLuA7QK2Cxiw0ICFBiw0YMBRYLFm7wIGLDRgoQEDBmwXsF3AdgEDFhqw0ICFBmwXsF3AdgEDFhqw0ICFBgw4CyyWq0qhAQsNGDBgu4DtArYLGLDQgIUGLDRgu4DtArYLGLDQgIUGLDRgwIDt+ifLrqtKu4ABCw1YaMBCA7YL2C5gu4ABCw1YaMBCA7YL2C5gu4ABCw1YaMBC+ycLkqtKu4DtArYLGLDQgIUGLDRgu4DtArYLGLDQgIUGLDRgwIDtArYLGLDQo3c/yQl3/IVNoK0AAAAASUVORK5CYII= | base64 -d > photo.png"}]]' && $CTL phone wait-text '(完成,沒有輸出)' --in '#msgs' && $CTL phone send '傳給我 [[call send_file {"path":"photo.png"}]]' && $CTL phone wait '.attimg[data-name="photo.png"] + .dlv.shown' && $CTL phone shot deliver-shown && $CTL phone click '.attimg[data-name="photo.png"]' && $CTL phone wait '#filebody img' && $CTL phone click '[data-back]' && $CTL phone wait '.attimg[data-name="photo.png"] + .dlv.opened' && $CTL phone click '.attimg[data-name="photo.png"] + .dlv' && $CTL phone wait-text 點開了 --in '#sheet-in' && $CTL phone shot deliver-sheet && $CTL phone click '#sheet' && $CTL api GET /api/bots/1 --jq '[.messages[].attachments[]? | select(.name=="photo.png") | {delivery, seen: [.seen[] | {device, kind}]}]' && $CTL model-reply 那張圖收到了嗎 '照交付狀態回答' && $CTL phone send '那張圖收到了嗎' && $CTL phone wait-text 照交付狀態回答 --in '#msgs' && $CTL model 'select(.rule=="那張圖收到了嗎") | .tool_results'`。看到:圖片下面灰色 ✓✓;點開預覽、返回後 ✓✓ 變強調色;點記號跳出「已點開」,列「iPhone 顯示了」「iPhone 點開了」和時間;API 的 delivery 是 opened、seen 是 iPhone 的 shown、opened;模型讀到的 send_file 結果是「已把「photo.png」放進聊天(…附件 …)。…不要說使用者已經看到。」後面接〔交付狀態:「photo.png」已被點開——iPhone顯示了(…);iPhone點開了(…)〕。 +- **交付確認:顯示失敗叫醒一次**(covers `deliver-confirm`):Bot 傳一個壞掉的 .png。指令:`$CTL phone send '寫 [[call shell {"command":"printf not-a-picture > broken.png"}]]' && $CTL phone wait '.step.done' --text broken.png && $CTL phone send '傳 [[call send_file {"path":"broken.png"}]]' && $CTL phone wait-text 這張圖讀不到 --in '.attimg[data-name="broken.png"]' && $CTL phone wait-text '交付沒顯示' --in '#msgs' && $CTL phone click '.attimg[data-name="broken.png"] + .dlv' && $CTL phone wait-text 沒顯示出來 --in '#sheet-in' && $CTL phone shot deliver-failed && $CTL phone click '#sheet' && $CTL api GET /api/bots/1 --jq '{broken: [.messages[].attachments[]? | select(.name=="broken.png") | .seen], wakes: [.messages[] | select(.wake) | .text]}' && $CTL restart && $CTL phone open --listed && $CTL phone wait '.row[data-bot="1"]' && $CTL phone click '.row[data-bot="1"]' && $CTL phone wait-text 這張圖讀不到 --in '.attimg[data-name="broken.png"]' && $CTL api GET /api/bots/1 --jq '[.messages[] | select(.wake)] | length'`。看到:壞圖顯示「這張圖讀不到」,下面只有一個 ✓;聊天多一則標「交付沒顯示」的訊息:「你傳的附件 …(.png)沒有在iPhone上顯示出來:這台裝置讀不出這個檔案(格式壞了或不支援)。…換個方式再交付一次…」,Bot 接著回答;清單是「已放進聊天」、紅字「iPhone 沒顯示出來:…」;重開 AnyBot、重新打開聊天後,失敗還記著、叫醒還是 1 次。 +- **交付確認:螢幕電腦、大腦自己的視窗**(covers `deliver-confirm`):指令:走不到——螢幕電腦要另一台登入同帳號的 AnyBot;大腦視窗要開視窗(`ABV_ALLOW_WINDOW=1 $CTL desktop-shot`,要使用者同意)。看到:最接近的真路是自動測試:螢幕電腦換成本機副本時編號不變、回報經 `api/sync/act` 只送一次;視窗裡記號滑過列出裝置;這台電腦的回報只記一次。 - **桌面的預覽**(covers `deliver-send`):指令:要開視窗——`$CTL stop && ABV_ALLOW_WINDOW=1 $CTL desktop-shot deliver-preview ANYBOT_SHOT_VIEW=fileview`。看到:示範的試算表在預覽裡打開,上面有「下載檔案」「用其他 App 打開」。 -- 自動測試:`cargo test tools::`、`cargo test preview::`、`cargo test app::files_ui::`、`cargo test agent::`(`a_file_leaves_a_computer_only_past_the_questions_of_reading_it`)。 +- 自動測試:`cargo test tools::`、`cargo test preview::`、`cargo test app::files_ui::`、`cargo test agent::`(`a_file_leaves_a_computer_only_past_the_questions_of_reading_it`)、`cargo test attach::`、`cargo test app::deliver_ui::`、`cargo test a_phone_tells_what_it_did_with_a_file`、`cargo test a_files_delivery_is_published`、`cargo test a_screen_keeps_the_files_id_and_tells_the_brain`、`cargo test the_bot_reads_how_its_file_stands`、`cargo test a_handed_files_mark_tells_where_it_was_seen`。 ## 陷阱 @@ -38,4 +46,8 @@ Bot 做好的東西用三種方式交給使用者:放進聊天變成檔案卡 - SSH 電腦上的檔案不能直接 `send_file`、`open_for_person` 或 `publish_site`;帳號裡其他電腦的檔案可以 `send_file`(最多 20 MB),但不能打開或發佈。先複製到 Bot 自己的電腦。 - `publish_site`:任何知道網址的人都看得到。每個網站名字第一次會問(工作資料夾外的每次都問);最多 500 個檔案、25 MB;點開頭的檔案、node_modules、機密檔案、指到資料夾外的連結會略過;一定要有 index.html。 - 「在這台電腦上執行」設成永不允許(或被管理員鎖住)時,這台的檔案也不能傳出去、打開或發佈。 +- 支線、交辦帶回主聊天的檔案只有記號,不叫醒、主 Bot 也讀不到〔交付狀態〕;管理員要的檔案和擁有者的一樣會叫醒(管理員的裝置只記下)。 +- 交付確認只看得到「有沒有在畫面上出現、有沒有點開」,看不到使用者有沒有真的看懂;`send_to_device`、`open_for_person`、`publish_site` 沒有交付確認。比這個功能早傳的檔案沒有編號,也沒有記號。 +- (驗證)手機頁面存在手機上(Service Worker):重新建置、`$CTL restart` 之後,`$CTL phone open --listed` 可能還是舊頁面;要新頁面用重新整理(`$CTL phone js 'location.reload(), 1'`)。 +- (驗證)1×1 的小圖在聊天裡幾乎看不到,`wait` 會說沒出現:用上面那張 160×100 的。 - (驗證)scratch 只有 Bot 自己的電腦:私密檔案的規則在那裡只擋傳出去(寫 .env 照樣成功),不能拿來證明「不能讀」。 diff --git a/mobile/index.html b/mobile/index.html index 3a4e8e6..389a600 100644 --- a/mobile/index.html +++ b/mobile/index.html @@ -246,6 +246,11 @@ details.dt>.dt-in{padding-left:var(--sp-4);margin-top:var(--sp-2)} .attimg{max-width:min(78%,320px);margin:4px 0;border-radius:var(--r-l);overflow:hidden;box-shadow:inset 0 0 0 .5px var(--line)} .attimg img{display:block;width:100%;max-height:320px;object-fit:cover} .attimg .wait{padding:20px;font-size:var(--fs-caption);color:var(--text3)} +/* 交付確認: one quiet mark under a file the bot handed over (✓ in the chat, ✓✓ shown on a device, accent once opened). */ +.dlv{display:inline-flex;align-items:center;background:none;border:0;padding:2px 6px;margin:-2px 0 0;min-height:24px;color:var(--text3)} +.dlv .ic+.ic{margin-left:-7px}.dlv.opened{color:var(--accent)} +.dlv-list{padding:0 16px 12px}.dlv-list .r{display:flex;gap:8px;align-items:baseline;padding:8px 0;border-top:.5px solid var(--line);font-size:var(--fs-small)} +.dlv-list .r b{font-weight:600}.dlv-list .r .w{color:var(--text3);margin-left:auto;white-space:nowrap}.dlv-list .r.failed span{color:var(--danger)} .plink{cursor:pointer;color:var(--accent-ink);text-decoration:underline;text-decoration-color:color-mix(in srgb,var(--accent-ink) 40%,transparent)} /* empty chat */ .intro{display:flex;flex-direction:column;align-items:center;text-align:center;padding:36px 16px 10px;gap:6px} @@ -1058,6 +1063,8 @@ function show(v) { document.querySelectorAll(".view").forEach((x) => x.classList.toggle("on", x.id === "v-" + v)); S.view = v; if (v !== "screen") stopFrames(); if (v !== "list") stopListTimer(); if (was === "chat" && v !== "chat") keepNow(); + // 交付確認: back in the chat (from a preview), what is in view now counts as shown. + if (v === "chat" && was !== "chat") setTimeout(() => document.querySelectorAll("#msgs [data-att]").forEach(seenCheck), 0); // A new screen slides in (forward from the right, back from the left); redrawing the same one doesn't. const el = $("v-" + v), dir = S.dir; S.dir = ""; if (el && dir && was && was !== v) { el.classList.remove("in-fwd", "in-back"); void el.offsetWidth; el.classList.add(dir); el.addEventListener("animationend", () => el.classList.remove(dir), {once: true}); } @@ -1661,7 +1668,7 @@ function openChat(id) { if (bubble === "bot" && ob.color && ob.color_key !== "black") { chat.style.setProperty("--bot", ob.color); chat.style.setProperty("--bot-ink", "var(--on-color)"); } else { chat.style.removeProperty("--bot"); chat.style.removeProperty("--bot-ink"); } chatHead(); renderChips(); renderQuote(); - renderMsgs(); $("scroller").scrollTop = $("scroller").scrollHeight; + renderMsgs(); $("scroller").scrollTop = $("scroller").scrollHeight; atEnd = true; loadChat(true); renderDock(); api(base() + `api/bots/${id}/read`, {json: {}}).catch(() => {}); } @@ -1715,8 +1722,80 @@ function thinkHtml(m) { } function attHtml(a) { if (!a.path) return `
${ic(a.image ? "image" : "file", 16)}${esc(a.name)}
`; - if (a.image) return `
${FILES[a.path] ? `${esc(a.name)}` : `
${ic("image", 14)} ${esc(a.name)}
`}
`; - return `${ic("file", 18)}
${esc(a.name)}
${esc(a.kind || "檔案")}${a.bytes ? " · " + kb(a.bytes) : ""} · 點一下開啟
`; + const att = a.id ? ` data-att="${esc(a.id)}" data-bot="${S.open}"` : ""; + // (A picture already fetched is drawn from its copy: a redraw doesn't drop every picture to its + // name and grow the chat again under the newest message.) + const got = BLOBS["img:" + a.path] || FILES[a.path]; + if (a.image) return `
${got ? `${esc(a.name)}` : `
${ic("image", 14)} ${esc(a.name)}
`}
`; + return `${ic("file", 18)}
${esc(a.name)}
${esc(a.kind || "檔案")}${a.bytes ? " · " + kb(a.bytes) : ""} · 點一下開啟
`; +} +// 交付確認: the mark under a file the bot handed over; tapping it lists the devices (dlvSheet). +const DLV_TITLE = {chat: "已放進聊天", shown: "已在裝置上顯示", opened: "已點開"}; +function dlvMark(a) { + if (!a.id || !a.path) return ""; + const d = DLV_TITLE[a.delivery] ? a.delivery : "chat"; + return ``; +} +function dlvSheet(id) { + const a = S.msgs.flatMap((m) => m.role === "user" ? [] : m.attachments || []).find((x) => x.id === id); + if (!a) return; + const d = DLV_TITLE[a.delivery] ? a.delivery : "chat"; + const what = {shown: "顯示了", opened: "點開了", failed: "沒顯示出來"}; + const rows = (a.seen || []).map((x) => `
${esc(x.device)}${esc(what[x.kind] || "")}${x.why ? ":" + esc(x.why) : ""}${x.at ? esc(dayLabel(x.at) + " " + clock(x.at)) : ""}
`).join(""); + sheet(DLV_TITLE[d], [], `
${esc(a.name)}
${rows || `
還沒有裝置回報顯示
`}
`); +} +// The device this page names for itself in 交付確認. +function deviceLabel() { + const ua = navigator.userAgent || ""; + if (/iPad/.test(ua) || (/Macintosh/.test(ua) && navigator.maxTouchPoints > 1)) return "iPad"; + if (/iPhone|iPod/.test(ua)) return "iPhone"; + if (/Android/.test(ua)) return "Android"; + return /Mobi/.test(ua) ? "手機" : "瀏覽器"; +} +// What this page did with a file the bot handed over, told once each while the page is open +// (not queued: one lost on a bad line is tried again only when it is drawn again). +const SEEN_TOLD = new Set(); +function seenTell(att, kind, why, bot) { + const k = att + ":" + kind; + if (!att || !bot || SEEN_TOLD.has(k)) return; + SEEN_TOLD.add(k); + api(base() + `api/bots/${bot}/seen`, {json: {att, kind, why: why || "", device: deviceLabel()}, timeout: 15000}).catch((e) => { if (e.transient) SEEN_TOLD.delete(k); }); +} +// Shown: drawn (a picture loaded), in view, the page in front. +function seenCheck(el) { + if (!el.dataset.att || document.hidden || S.view !== "chat" || !el.isConnected) return; + const r = el.getBoundingClientRect(); + if (r.bottom <= 0 || r.top >= innerHeight || !r.width) return; + if (el.classList.contains("attimg")) { const img = el.querySelector("img"); if (!img || !img.complete || !img.naturalWidth) return; } + seenTell(el.dataset.att, "shown", "", +el.dataset.bot); +} +const seenObs = "IntersectionObserver" in window ? new IntersectionObserver((es) => es.forEach((e) => { if (e.isIntersecting) seenCheck(e.target); }), {threshold: 0.2}) : null; +function seenWatch() { + if (!seenObs) return; + seenObs.disconnect(); + document.querySelectorAll("#msgs [data-att]").forEach((el) => seenObs.observe(el)); +} +document.addEventListener("visibilitychange", () => { if (!document.hidden) document.querySelectorAll("#msgs [data-att]").forEach(seenCheck); }); +// A picture in the chat: shown once it has loaded in view; one the phone can't decode failed. +function seenImg(el) { + const img = el.querySelector("img"); + if (!img || !el.dataset.att) return; + img.onload = () => seenCheck(el); + img.onerror = () => { + // (Its kept copy let go while it loaded — many pictures in one chat: not the picture's fault.) + if (BLOBS["img:" + el.dataset.file] !== img.src) { el.innerHTML = ""; loadFiles(); return; } + el.innerHTML = `
這張圖讀不到
`; + // (Once more first: a picture whose kept copy was let go while it loaded isn't unreadable.) + if (!SEEN_RETRIED.has(el.dataset.att)) { SEEN_RETRIED.add(el.dataset.att); delete BLOBS["img:" + el.dataset.file]; loadFiles(); return; } + seenTell(el.dataset.att, "failed", "unreadable", +el.dataset.bot); + }; + if (img.complete && img.naturalWidth) seenCheck(el); +} +// Couldn't be fetched: the brain said no (not a line that is down — that is nobody's failure). +const SEEN_RETRIED = new Set(); +function seenFail(att, e, bot) { + if (!att || !e || e.transient || !e.status || e.status === 429) return; + seenTell(att, "failed", e.status === 404 ? "missing" : e.status === 422 ? "unreadable" : "error", bot); } const kb = (n) => n >= 1048576 ? (n / 1048576).toFixed(1) + " MB" : Math.max(1, Math.round(n / 1024)) + " KB"; function safeHttpUrl(u) { @@ -1854,7 +1933,7 @@ function renderMsgs() { const who = m.author ? `
${esc(m.author)}
` : ""; const think = m.thinking ? thinkHtml(m) : ""; const bub = m.text ? `
${pageMd(m.text, 0)}
` : ""; - const atts = (m.attachments || []).map(attHtml).join(""); + const atts = (m.attachments || []).map((a) => attHtml(a) + dlvMark(a)).join(""); const meta = end && m.text ? `
${m.at ? esc(clock(m.at)) : ""}${owner() && m === lastBot && t === lastTurn ? `` : ""}
` : ""; h += `
${who}${think}${bub}${steps ? `
${steps}
` : ""}${extra}${atts}${reacts}${meta}
`; }); @@ -1883,11 +1962,13 @@ function renderMsgs() { $("msgs").innerHTML = h; renderSendBtn(); loadFiles(); + seenWatch(); } // Taps in the chat: steps, folds, summaries, copy, regenerate, resend, reactions, suggestions, pages. $("msgs").addEventListener("click", async (e) => { // The end of a drag that selected words is not a tap: nothing folds, opens or goes. if (!e.target.closest("button,a") && selIn(e.target)) return; + const dv = e.target.closest("[data-dlv]"); if (dv) { dlvSheet(dv.dataset.dlv); return; } const st = e.target.closest(".step .h"); if (st) { const k = st.parentElement.dataset.step; S.openSteps[k] = !S.openSteps[k]; st.parentElement.classList.toggle("open"); return; } const f = e.target.closest(".fold"); if (f) { S.unfold[f.dataset.turn] = true; renderMsgs(); return; } @@ -2142,7 +2223,7 @@ const COMMANDS = [{name: "goal", description: "設一個目標,一直做到達 /** What woke the bot, from the tag its message starts with (app::chat_ui::wake_tag on the * desktop): [tag, icon, label], and the words after it. 監看's tag carries the command's number, so * its words stay whole. (Every wake used to say 例行任務 — a 監看's lines, a colleague's message.) */ -const WAKE_TAGS = [["[目標]", "target", "目標"], ["[例行任務]", "alarm-clock", "例行任務"], ["[觸發]", "zap", "觸發"], ["[訊息管道]", "message", "訊息管道"], ["[來自 Bot]", "bot", "來自其他 Bot"], ["⏰ ", "alarm-clock", "例行任務"], ["⚡ ", "zap", "觸發"], ["💬 ", "message", "訊息管道"], ["📨 ", "bot", "來自其他 Bot"]]; +const WAKE_TAGS = [["[目標]", "target", "目標"], ["[例行任務]", "alarm-clock", "例行任務"], ["[觸發]", "zap", "觸發"], ["[訊息管道]", "message", "訊息管道"], ["[來自 Bot]", "bot", "來自其他 Bot"], ["[交付]", "circle-alert", "交付沒顯示"], ["⏰ ", "alarm-clock", "例行任務"], ["⚡ ", "zap", "觸發"], ["💬 ", "message", "訊息管道"], ["📨 ", "bot", "來自其他 Bot"]]; function wakeTag(text) { const t = String(text || ""); for (const [tag, icon, label] of WAKE_TAGS) if (t.startsWith(tag)) return {icon, label, body: t.slice(tag.length)}; @@ -2430,7 +2511,12 @@ function threads(b) { try { await api(base() + `api/bots/${b.id}/restore`, {json: {index: t.index}}); toast("已回到那段對話"); S.unfold = {}; setTimeout(() => loadChat(true), 700); } catch (e) { toast(e.message); } }}))); } -$("scroller").addEventListener("scroll", () => { const sc = $("scroller"); $("b-down").classList.toggle("on", sc.scrollHeight - sc.scrollTop - sc.clientHeight > 400); }); +// At the newest message, it stays in view while what is above it grows after being drawn (a +// picture that loads, a preview); scrolled up to read, nothing moves. (A question card taller +// than the screen is left where renderQuestion put it: its question, not its buttons.) +let atEnd = true; +$("scroller").addEventListener("scroll", () => { const sc = $("scroller"), left = sc.scrollHeight - sc.scrollTop - sc.clientHeight; atEnd = left < 140; $("b-down").classList.toggle("on", left > 400); }); +if ("ResizeObserver" in window) new ResizeObserver(() => { const sc = $("scroller"); if (atEnd && S.view === "chat" && $("askq").offsetHeight <= sc.clientHeight && sc.scrollHeight - sc.scrollTop - sc.clientHeight > 1) sc.scrollTop = sc.scrollHeight; }).observe($("msgs")); $("b-down").onclick = () => { const sc = $("scroller"); sc.scrollTo({top: sc.scrollHeight, behavior: "smooth"}); };