diff --git a/.env.example b/.env.example
index be2f9ef..9b5fd8c 100644
--- a/.env.example
+++ b/.env.example
@@ -27,6 +27,12 @@ LAZYBOY_COMPUTER_DRIVER=cua
# Linux only (optional): point this at the host's LXCFS root to make htop/free
# report the per-Agent cgroup quota. Leave the default empty directory on macOS.
LAZYBOY_LXCFS_ROOT=./data/lxcfs
+# 群組聊天「誰該回應」:沒被 @ 的時候,由一次短短的模型問從成員的工作內容與簡介裡
+# 挑出最多三個人回覆。留空(預設)=沿用空間的預設模型,多數人不用理這行;
+# 想省 token 就填一個便宜快速的 model id(要跟空間預設來自同一家 provider)。
+# 挑不到人、模型不能用、或超過 1.2 秒,一律由主持人(群組第一位成員)收場。
+LAZYBOY_ROUTER_MODEL=
+
# 任務長度政策:不再用固定輪數掐掉任務。正常任務一路做到驗證完成,只有
# 真的鬼打牆(同一個動作重複、同一個錯誤一直失敗、很久沒有新的成功)才會被
# 提示、接著暫停等你決定;最後兩個是防迴圈失控烧 token 的保險絲,不是額度。
diff --git a/README.md b/README.md
index 45e189a..bb43f0a 100644
--- a/README.md
+++ b/README.md
@@ -14,7 +14,7 @@ A self-hosted AI agent workspace. Assign tasks in text or voice, watch the deskt
-
+
LazyBoy gives each agent its own Linux desktop in Docker — browser, terminal, and files. You can run several agents, put them in a group, turn a demonstration into a skill, and schedule it to run again.
@@ -24,8 +24,10 @@ This is an early `0.1.0` release with desktop and phone browser UIs. You bring y
- **A lasting workspace**: each agent has its own chats, run history, and optional long-term memory.
- **A real computer**: open pages, use the terminal, organize files, drive the GUI — and watch it live.
+- **Attachments in chat**: send files or images along with the message; the agent can open them on its own desktop, and inbox copies expire on their own.
- **Take over any time**: sign in, pass a check, or nudge things by hand on the same desktop, then hand it back.
-- **Several agents and groups**: shared Team computers or private dedicated desktops.
+- **Saved logins**: keep site credentials in the agent's encrypted vault, so it can fill them in at a login wall without the password ever passing through the model.
+- **Several agents and groups**: shared Team computers or private dedicated desktops; `@name` decides who answers, so a message wakes the one agent it is for instead of all of them.
- **Teach by demo, then schedule**: turn a walkthrough into a skill; use cron for repeat work.
- **Your models and tools**: xAI, OpenCode Go, OpenAI-compatible endpoints, MCP, and file skills.
- **Voice calls**: after you enable a voice provider, you can talk to the agent on a call.
@@ -69,7 +71,7 @@ For resource limits, environment variables, HTTPS, and in-container sudo, see [O
## On a phone
-Desktop and phone share the same web UI. After you deploy on a host the phone can reach, open that URL in the phone browser. `127.0.0.1` is the phone itself — it will not reach another machine.
+Desktop and phone share the same web UI. The API listens on `127.0.0.1` by default, so set `LAZYBOY_BIND_IP=0.0.0.0` (or one network card's address) in `.env` and recreate the api container before a phone on your network can reach it; off-loopback the login token has to be at least 32 characters. Then open that address in the phone browser — `127.0.0.1` there is the phone itself and will not reach another machine.
Tap outside the chat sidebar to collapse it. On the remote desktop you can switch between tap-to-click and trackpad, and use the toolbar for keyboard, right-click, or drag. Put the service behind HTTPS before you expose it; see [Operations](./docs/operations.md#安全模型).
@@ -79,7 +81,7 @@ Tap outside the chat sidebar to collapse it. On the remote desktop you can switc
- **Backend**: Rust 2024, Axum, Tokio
- **Data**: PostgreSQL, pgvector, SQLx
- **Desktop**: Docker, Debian, XFCE, Chromium, Xvfb
-- **Computer control**: CDP, AT-SPI, X11
+- **Computer control**: Cua Driver over X11, AT-SPI, and Chromium
- **Extensions**: MCP, file skills, demonstration playbooks
Flow diagrams, handoff, component roles, and the computer lifecycle live in **[Architecture](./docs/architecture.md)**. The older **[interactive diagram](./docs/workflow.html)** is still there — download it and open it in a browser.
@@ -108,30 +110,59 @@ Open [http://127.0.0.1:5173](http://127.0.0.1:5173). Tests and the tree layout a
The guides below are currently in Traditional Chinese.
-| Doc | Contents |
-| --- | --- |
-| [Architecture](./docs/architecture.md) | Task flow, system architecture, computer lifecycle |
-| [Interactive diagram](./docs/workflow.html) | Zoomable, searchable HTML chart; download and open |
-| [Operations](./docs/operations.md) | Resources, env vars, security, site checks, sudo |
-| [Agent experience](./docs/agent-experience.md) | Turn limits, persistent terminal, live chat |
+| Doc | Contents |
+| -------------------------------------------------------- | ---------------------------------------------------- |
+| [Architecture](./docs/architecture.md) | Task flow, system architecture, computer lifecycle |
+| [Interactive diagram](./docs/workflow.html) | Zoomable, searchable HTML chart; download and open |
+| [Operations](./docs/operations.md) | Resources, env vars, security, site checks, sudo |
+| [Agent experience](./docs/agent-experience.md) | Turn limits, persistent terminal, live chat |
| [hermes-agent review](./docs/hermes-agent-cua-review.md) | Cua harness smoothness: comparison with hermes-agent |
-| [Development](./docs/development.md) | Local dev, checks and tests, directory layout |
-| [Env example](./.env.example) | Environment variables and defaults |
+| [Development](./docs/development.md) | Local dev, checks and tests, directory layout |
+| [Env example](./.env.example) | Environment variables and defaults |
## Data
Chats, memory, browser profiles, and encrypted credentials stay on your host. When you use an external model, the prompts, tool results, and screenshots the task needs may still be sent to that provider.
+## Acknowledgements
+
+LazyBoy is mostly other people's software, carefully assembled. The projects we lean on hardest:
+
+**Special thanks**
+
+- **[Cua](https://github.com/trycua/cua)** — the Linux desktop driver behind every click, keystroke, and screenshot. We rebuild `cua-driver-rs` v0.23.2 from source with two small patches kept in this repo: one lets the agent cursor wear the bot's own colour, the other swaps the embedded Latin-only badge font for [jf open Huninn](https://github.com/justfont/open-huninn-font) so Chinese renders. Neither patch touches input handling or permissions.
+- **[hermes-agent](https://github.com/NousResearch/hermes-agent)** — not a dependency, but the reference we kept returning to while tuning how smooth an agent's desktop should feel. The comparison is written up in the [hermes-agent review](./docs/hermes-agent-cua-review.md).
+
+**Agents and retrieval** — [rig](https://github.com/0xPlaygrounds/rig) · [rmcp](https://github.com/modelcontextprotocol/rust-sdk) · [fastembed-rs](https://github.com/Anush008/fastembed-rs) and [ONNX Runtime](https://github.com/microsoft/onnxruntime), running [paraphrase-multilingual-MiniLM-L12-v2](https://huggingface.co/sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2)
+
+**Rust** — Tokio · Axum · tower-http · SQLx · reqwest · rustls · Bollard · tracing · aes-gcm and hmac from [RustCrypto](https://github.com/RustCrypto) · cap-std · cron · chrono · uuid · thiserror · dotenvy
+
+**Web** — React · Vite · TypeScript · [noVNC](https://github.com/novnc/noVNC) · react-markdown with [remark-gfm](https://github.com/remarkjs/remark-gfm) and [remark-breaks](https://github.com/remarkjs/remark-breaks) · [Blobatar](https://github.com/Alain00/blobatar) avatars · [react-useanimations](https://github.com/useAnimations/react-useanimations) icons
+
+**Data** — [PostgreSQL](https://www.postgresql.org) · [pgvector](https://github.com/pgvector/pgvector)
+
+**The desktop inside each container** — [Docker](https://www.docker.com) · [Debian](https://www.debian.org) · [XFCE](https://www.xfce.org) · [Chromium](https://www.chromium.org) · [Xvfb](https://www.x.org) · Thunar · [x11vnc](https://github.com/LibVNC/x11vnc) · [websockify](https://github.com/novnc/websockify) · [AT-SPI2](https://gitlab.gnome.org/GNOME/at-spi2-core) · [gosu](https://github.com/tianon/gosu) · [LXCFS](https://github.com/lxc/lxcfs) · git · zsh with [Powerlevel10k](https://github.com/romkatv/powerlevel10k) · htop
+
+**Type and theme** — [jf open Huninn](https://github.com/justfont/open-huninn-font) (SIL OFL) in the UI and on the agent badge · [Noto CJK](https://github.com/notofonts/noto-cjk), DejaVu, and Liberation as fallbacks · [MesloLGS NF](https://github.com/romkatv/powerlevel10k-media) in the terminal · [Arc Dark](https://github.com/horst3180/arc-theme) and [Papirus](https://github.com/PapirusDevelopmentTeam/papirus-icon-theme) for the look of the room
+
+Every version above is pinned in `Cargo.lock`, `apps/web/package.json`, and `image/computer/Dockerfile`. LazyBoy is Apache-2.0; each project keeps its own license. Thanks also to the maintainers whose names never make it into a README, and to everyone who files a good bug report.
+
---
+
+
+**LazyBoy is free and open source.** If it hands you back an afternoon, a coffee is the nicest way to say so.
+
+
+
+
+
+
+
**Daniel Wang**
-[igs170911@gmail.com](mailto:igs170911@gmail.com)
-
-
-
-[Apache License 2.0](./LICENSE)
+[igs170911@gmail.com](mailto:igs170911@gmail.com) · [Apache License 2.0](./LICENSE)
diff --git a/README.zh-TW.md b/README.zh-TW.md
index b79e244..4054d5f 100644
--- a/README.zh-TW.md
+++ b/README.zh-TW.md
@@ -14,7 +14,7 @@
-
+
LazyBoy 讓 Agent 在 Docker 裡使用自己的 Linux 桌面,操作瀏覽器、終端與檔案。你可以建立不同的 Agent、在群組中協作,把示範整理成技能,再安排定時執行。
@@ -24,8 +24,10 @@ LazyBoy 讓 Agent 在 Docker 裡使用自己的 Linux 桌面,操作瀏覽器
- **持續的工作空間**:每個 Agent 有自己的對話、工作紀錄與可設定的長期記憶。
- **真的能操作電腦**:開網頁、使用終端、整理檔案、操作圖形介面,過程可即時觀看。
+- **附件直接丟進對話**:訊息可帶檔案或圖片,Agent 能在自己的桌面開啟,放在收件匣的複本會自動到期清除。
- **隨時人工接管**:在同一個桌面完成登入、驗證或手動調整,再交回 Agent。
-- **多 Agent 與群組**:支援 Team 共用電腦與 Private 獨立電腦模式。
+- **登入帳密進保險庫**:帳密加密存在 Agent 自己的保險庫,遇到登入頁由它填寫,密碼不會經過模型。
+- **多 Agent 與群組**:支援 Team 共用電腦與 Private 獨立電腦模式;群組裡 @誰就由誰回,沒點名時只叫醒工作內容相關的那個,不會全部出動。
- **示範教學與排程**:把操作示範整理成技能,使用 cron 安排重複工作。
- **自選模型與工具**:支援 xAI、OpenCode Go、OpenAI 相容端點,以及 MCP 與檔案技能。
- **語音通話**:設定語音服務後,可以透過通話與 Agent 互動。
@@ -69,7 +71,7 @@ make down # 停止服務,保留 PostgreSQL 資料
## 在手機上使用
-手機與桌面使用同一個 Web 介面。將服務部署在可連線的主機後,用手機瀏覽器開啟該服務的網址即可;`127.0.0.1` 只代表手機本身,不能拿來連另一台電腦。
+手機與桌面使用同一個 Web 介面。API 預設只綁 `127.0.0.1`,請在 `.env` 設定 `LAZYBOY_BIND_IP=0.0.0.0`(或指定網卡位址)並重建 api 容器,區網裡的手機才連得到;綁非 loopback 時登入 token 需至少 32 字元。接著用手機瀏覽器開啟該位址——手機上的 `127.0.0.1` 只代表手機本身,不能拿來連另一台電腦。
聊天側欄可點外側空白處收合。操作遠端桌面時,可切換直接點選與觸控板模式,使用工具列叫出鍵盤、按右鍵或拖曳。對外提供服務時請設定 HTTPS,詳見 [部署指南](./docs/operations.md#安全模型)。
@@ -79,7 +81,7 @@ make down # 停止服務,保留 PostgreSQL 資料
- **後端**:Rust 2024、Axum、Tokio
- **資料**:PostgreSQL、pgvector、SQLx
- **桌面**:Docker、Debian、XFCE、Chromium、Xvfb
-- **電腦控制**:CDP、AT-SPI、X11
+- **電腦控制**:Cua Driver(X11、AT-SPI、Chromium)
- **擴充**:MCP、檔案技能、示範 playbook
流程圖、控制權交接、元件職責與電腦生命週期狀態機,集中在 **[架構與流程](./docs/architecture.md)**。原有的 **[互動流程圖](./docs/workflow.html)** 也保留;下載後用瀏覽器開啟即可操作。
@@ -112,6 +114,7 @@ npm run dev
| [互動流程圖](./docs/workflow.html) | 可縮放、搜尋的 HTML 圖表;下載後開啟 |
| [部署與操作](./docs/operations.md) | 資源、環境變數、安全設定、網站驗證、sudo |
| [AI 使用體驗](./docs/agent-experience.md) | 輪次政策、持久終端機、聊天即時推送 |
+| [hermes-agent 比較](./docs/hermes-agent-cua-review.md) | Cua 操作流暢度:與 hermes-agent 對照 |
| [開發指南](./docs/development.md) | 本機開發、檢查與測試、目錄結構 |
| [設定範例](./.env.example) | 環境變數與預設值 |
@@ -119,16 +122,45 @@ npm run dev
對話、記憶、瀏覽器設定檔與加密憑證保存在自架主機。使用外部模型時,任務所需的提示詞、工具結果與截圖仍可能傳送給該模型供應商。
+## 特別感謝
+
+LazyBoy 站在許多開源專案的肩上,下面是我們用到最多、也最想致謝的專案。
+
+**首要致謝**
+
+- **[Cua](https://github.com/trycua/cua)**:每一次點擊、鍵盤輸入與截圖,都由它的 Linux 桌面驅動完成。我們從原始碼重建 `cua-driver-rs` v0.23.2,並在本專案內維護兩處小修補:一處讓 Agent 游標套用機器人自己的顏色,另一處把內嵌的純英文徽章字型換成 [jf open Huninn](https://github.com/justfont/open-huninn-font),讓中文能正確顯示。兩處修補都不碰輸入處理與權限邏輯。
+- **[hermes-agent](https://github.com/NousResearch/hermes-agent)**:它不是相依套件,卻是我們調整操作流暢度時一再回頭參照的對象。對照分析見 [hermes-agent 比較](./docs/hermes-agent-cua-review.md)。
+
+**Agent 與記憶檢索**:[rig](https://github.com/0xPlaygrounds/rig) · [rmcp](https://github.com/modelcontextprotocol/rust-sdk) · [fastembed-rs](https://github.com/Anush008/fastembed-rs) 與 [ONNX Runtime](https://github.com/microsoft/onnxruntime),嵌入模型為 [paraphrase-multilingual-MiniLM-L12-v2](https://huggingface.co/sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2)
+
+**Rust**:Tokio · Axum · tower-http · SQLx · reqwest · rustls · Bollard · tracing · [RustCrypto](https://github.com/RustCrypto) 的 aes-gcm 與 hmac · cap-std · cron · chrono · uuid · thiserror · dotenvy
+
+**前端**:React · Vite · TypeScript · [noVNC](https://github.com/novnc/noVNC) · react-markdown 搭配 [remark-gfm](https://github.com/remarkjs/remark-gfm) 與 [remark-breaks](https://github.com/remarkjs/remark-breaks) · [Blobatar](https://github.com/Alain00/blobatar) 頭像 · [react-useanimations](https://github.com/useAnimations/react-useanimations) 圖示
+
+**資料**:[PostgreSQL](https://www.postgresql.org) · [pgvector](https://github.com/pgvector/pgvector)
+
+**容器裡的桌面**:[Docker](https://www.docker.com) · [Debian](https://www.debian.org) · [XFCE](https://www.xfce.org) · [Chromium](https://www.chromium.org) · [Xvfb](https://www.x.org) · Thunar · [x11vnc](https://github.com/LibVNC/x11vnc) · [websockify](https://github.com/novnc/websockify) · [AT-SPI2](https://gitlab.gnome.org/GNOME/at-spi2-core) · [gosu](https://github.com/tianon/gosu) · [LXCFS](https://github.com/lxc/lxcfs) · git · 搭配 [Powerlevel10k](https://github.com/romkatv/powerlevel10k) 的 zsh · htop
+
+**字型與佈景主題**:介面與 Agent 徽章使用 [jf open Huninn](https://github.com/justfont/open-huninn-font)(SIL OFL)· 備援字型為 [Noto CJK](https://github.com/notofonts/noto-cjk)、DejaVu 與 Liberation · 終端機使用 [MesloLGS NF](https://github.com/romkatv/powerlevel10k-media) · 外觀採用 [Arc Dark](https://github.com/horst3180/arc-theme) 與 [Papirus](https://github.com/PapirusDevelopmentTeam/papirus-icon-theme)
+
+以上版本都釘選在 `Cargo.lock`、`apps/web/package.json` 與 `image/computer/Dockerfile`。LazyBoy 以 Apache-2.0 釋出,上述每個專案保留各自的授權條款。也謝謝那些名字從不出現在 README 裡的維護者,以及每一位認真回報問題的使用者。
+
---
+
+
+**LazyBoy 是免費的開源專案。** 如果它幫你省下一個下午,一杯咖啡是最好的回禮。
+
+
+
+
+
+
+
**danielwang**
-[igs170911@gmail.com](mailto:igs170911@gmail.com)
-
-
-
-[Apache License 2.0](./LICENSE)
+[igs170911@gmail.com](mailto:igs170911@gmail.com) · [Apache License 2.0](./LICENSE)
diff --git a/a.md b/a.md
deleted file mode 100644
index 0e0baa0..0000000
--- a/a.md
+++ /dev/null
@@ -1,2210 +0,0 @@
-# LazyBoy → Cua Driver Migration Plan
-
-> 2026-09-07 檢查:Phase 1 規格尚未全部勾完(生產預設仍是 legacy;takeover/錄製端到端未另開測)。opt-in Cua 已可在現有桌面容器使用,驗收見 [docs/cua-review.md](docs/cua-review.md)。本文件仍是目標規格,不能視為完成證明。
-
-> **Purpose:** This document is an implementation specification for a coding agent.
->
-> Repository: `https://code.30cm.net/daniel.w/lazyBoy`
->
-> Cua: `https://github.com/trycua/cua`
->
-> Cua docs: `https://cua.ai/docs`
->
-> **Main principle:** Do **NOT** rewrite LazyBoy into Cua. Keep LazyBoy as the agent/workspace/product layer and replace the low-level computer-control implementation with Cua Driver incrementally.
-
----
-
-## 0. Agent Instructions
-
-You are modifying **LazyBoy**, a self-hosted AI agent workspace.
-
-The goal is to migrate the low-level GUI/browser computer-control implementation from custom CDP / AT-SPI / X11 code to **Cua Driver**, without breaking LazyBoy's existing product architecture.
-
-### Non-negotiable rules
-
-1. **Do not perform a Big Bang rewrite.**
-2. **Do not remove the legacy computer-control implementation in the first PR.**
-3. Keep LazyBoy's current public Agent tool schema stable unless absolutely necessary.
-4. Keep:
- - `computer_observe`
- - `computer_act`
- - `browser`
- - `shell`
- - file tools
- - takeover flow
- - memory
- - schedule
- - vault
- - skills/playbooks
-5. Cua must initially be an **implementation detail behind LazyBoy abstractions**.
-6. Do not expose all Cua MCP tools directly to the LLM.
-7. Do not replace `DockerSandbox`, `Supervisor`, noVNC, or persistent bot homes during Phase 1.
-8. Add a feature flag / backend selector so legacy behavior can be restored immediately.
-9. Every migrated action must have observable verification.
-10. Do not guess Cua API/tool names from this document.
-
-### Cua API freshness rule
-
-Cua changes quickly.
-
-Before implementing anything:
-
-```bash
-cua-driver --version
-cua-driver doctor
-cua-driver list-tools
-```
-
-For every Cua tool you plan to call:
-
-```bash
-cua-driver describe
-```
-
-Use the schema reported by the installed Cua Driver version as the source of truth.
-
-Do not hard-code assumptions from old blog posts, old examples, or this document when the installed version differs.
-
----
-
-# 1. Current LazyBoy Architecture
-
-The current architecture is approximately:
-
-```text
-User
- │
- ▼
-React Web UI
- │
- ▼
-crates/api
- │
- ├── Agent loop
- ├── Sessions / Runs
- ├── Memory
- ├── Schedule
- ├── Vault
- ├── Skills
- ├── MCP
- └── Tool definitions
- │
- ▼
-SandboxProvider
- │
- ▼
-crates/sandbox
- │
- ▼
-DockerSandbox
- │
- ▼
-crates/supervisor
- │
- ▼
-Linux Desktop Container
- │
- ├── XFCE
- ├── Chromium
- ├── Xvfb
- ├── x11vnc
- ├── websockify
- └── controld
- │
- ├── CDP
- ├── AT-SPI
- ├── X11
- └── screenshots
-```
-
-Relevant current components:
-
-```text
-apps/web
-crates/api
-crates/contracts
-crates/control
-crates/controld
-crates/harness
-crates/sandbox
-crates/supervisor
-```
-
-The existing `SandboxProvider` abstraction is an important migration seam and should be preserved.
-
-Current methods include approximately:
-
-```rust
-async fn provision(...)
-async fn prepare(...)
-async fn capabilities(...)
-async fn ensure_screen(...)
-async fn reconnect(...)
-async fn suspend(...)
-async fn resume(...)
-async fn execute(...)
-async fn observe(...)
-async fn act(...)
-async fn connect_screen(...)
-async fn list_files(...)
-async fn read_file(...)
-async fn write_file(...)
-async fn stop(...)
-async fn destroy(...)
-```
-
-Do not collapse this abstraction.
-
----
-
-# 2. Target Architecture
-
-Phase 1 target:
-
-```text
- LazyBoy Web
- │
- ▼
- LazyBoy API
- │
- LazyBoy Agent Loop
- │
- ┌────────────────┼────────────────┐
- │ │ │
- ▼ ▼ ▼
- Memory Skills Schedule
- │
- ▼
- LazyBoy Tool Layer
- │
- computer / browser / shell
- │
- ▼
- ComputerController
- abstraction
- │ │
- ┌───────────┘ └────────────┐
- ▼ ▼
- LegacyController CuaController
- │ │
- CDP / AT-SPI / X11 Cua Driver
- │
- ┌──────────────┼──────────────┐
- ▼ ▼ ▼
- X11 AT-SPI Browser
- │
- ▼
- Existing Desktop
- Container
-```
-
-### Important
-
-Cua is initially used as the **computer-control backend**.
-
-It is **not** the Agent runtime.
-
-It is **not** the memory system.
-
-It is **not** the scheduler.
-
-It is **not** the user-facing product.
-
-It is **not** the first-phase sandbox lifecycle owner.
-
----
-
-# 3. What Must Stay in LazyBoy
-
-The following are LazyBoy product responsibilities and must remain owned by LazyBoy.
-
-## Keep unchanged unless required
-
-### Frontend
-
-```text
-apps/web
-```
-
-Keep:
-
-- Chat UI
-- remote desktop
-- noVNC
-- mobile controls
-- takeover UI
-- bot management
-- session UI
-
-### API / Agent layer
-
-```text
-crates/api
-```
-
-Keep:
-
-- Agent loop
-- model interaction
-- run management
-- session management
-- tool policy
-- takeover workflow
-- credential flow
-- memory
-- schedules
-- skills
-- MCP integrations
-
-### Harness
-
-```text
-crates/harness
-```
-
-Keep model-provider support.
-
-Cua Driver must not decide which model LazyBoy uses.
-
-### Supervisor
-
-```text
-crates/supervisor
-```
-
-Phase 1: keep current behavior.
-
-Keep:
-
-- Docker lifecycle
-- pause/resume
-- resource limits
-- persisted bot homes
-- screen lifecycle
-
-### Sandbox
-
-```text
-crates/sandbox
-```
-
-Phase 1: keep `DockerSandbox`.
-
-Do **not** replace it with Cua Sandbox yet.
-
----
-
-# 4. What Cua Should Replace
-
-The long-term goal is to reduce LazyBoy-owned OS automation.
-
-Current files that are candidates for replacement or simplification:
-
-```text
-crates/control/src/a11y.py
-crates/control/src/a11y.rs
-
-crates/control/src/cdp.py
-crates/control/src/cdp.rs
-
-crates/control/src/x11.rs
-crates/control/src/screen.rs
-crates/control/src/overlay.rs
-```
-
-Do not delete them during the initial migration.
-
-Instead place them behind a legacy backend.
-
-The responsibilities that should gradually move to Cua:
-
-- screenshots
-- application/window enumeration
-- accessibility tree
-- native UI element actions
-- pointer input
-- keyboard input
-- scrolling
-- browser state
-- browser semantic actions
-- window-scoped control
-- recording / trajectory capture
-
----
-
-# 5. Do NOT Expose Raw Cua to the LLM
-
-LazyBoy currently has a relatively compact Agent-facing tool surface.
-
-Preserve this.
-
-Preferred model:
-
-```text
-LLM
- │
- ▼
-LazyBoy tools
- │
- ├── computer_observe
- ├── computer_act
- ├── browser
- ├── shell
- ├── file tools
- └── request_takeover
- │
- ▼
-LazyBoy policy / safety / vault / state
- │
- ▼
-Cua adapter
- │
- ▼
-Cua Driver
-```
-
-Avoid this:
-
-```text
-LLM
- │
- ▼
-50+ raw Cua tools
- │
- ▼
-OS
-```
-
-Reasons:
-
-- larger tool schemas consume context
-- LazyBoy loses policy control
-- LazyBoy loses stable abstraction
-- Cua version changes would leak into prompts
-- takeover behavior becomes harder to control
-- credential handling becomes harder to constrain
-- Agent behavior becomes coupled to Cua implementation details
-
-Cua should initially behave like a device driver.
-
----
-
-# 6. Introduce a ComputerController Abstraction
-
-Create a low-level computer-control abstraction separate from sandbox lifecycle.
-
-Suggested location:
-
-```text
-crates/control/src/controller.rs
-```
-
-Possible interface:
-
-```rust
-#[async_trait::async_trait]
-pub trait ComputerController: Send + Sync {
- async fn health(&self, ctx: &ControlContext)
- -> Result;
-
- async fn observe(
- &self,
- request: ObserveRequest,
- ctx: &ControlContext,
- ) -> Result;
-
- async fn act(
- &self,
- request: ActionRequest,
- ctx: &ControlContext,
- ) -> Result;
-
- async fn browser(
- &self,
- request: BrowserRequest,
- ctx: &ControlContext,
- ) -> Result;
-
- async fn start_recording(
- &self,
- request: RecordingRequest,
- ctx: &ControlContext,
- ) -> Result;
-
- async fn stop_recording(
- &self,
- ctx: &ControlContext,
- ) -> Result;
-}
-```
-
-Names may be adjusted to match existing LazyBoy contracts.
-
-Do not introduce unnecessary abstractions if equivalent types already exist.
-
----
-
-# 7. Backend Implementations
-
-Implement:
-
-```text
-LegacyController
-CuaController
-```
-
-Suggested layout:
-
-```text
-crates/control/src/
-├── controller.rs
-├── legacy/
-│ ├── mod.rs
-│ ├── a11y.rs
-│ ├── cdp.rs
-│ ├── x11.rs
-│ └── screen.rs
-└── cua/
- ├── mod.rs
- ├── client.rs
- ├── translate.rs
- ├── observe.rs
- ├── actions.rs
- ├── browser.rs
- └── recording.rs
-```
-
-Do not spend the first PR moving all old files if it creates noisy diffs.
-
-It is acceptable to initially keep existing file locations and only add:
-
-```text
-controller.rs
-cua.rs
-```
-
-Refactor structure after behavior is stable.
-
----
-
-# 8. Backend Configuration
-
-Add a configuration value:
-
-```bash
-LAZYBOY_COMPUTER_DRIVER=legacy
-```
-
-or:
-
-```bash
-LAZYBOY_COMPUTER_DRIVER=cua
-```
-
-Default during initial rollout:
-
-```bash
-LAZYBOY_COMPUTER_DRIVER=legacy
-```
-
-After Cua passes production-equivalent validation, the default may become:
-
-```bash
-LAZYBOY_COMPUTER_DRIVER=cua
-```
-
-Do not remove the legacy option until Cua has passed the migration acceptance suite.
-
-If configuration already has a typed settings system, add this there instead of reading environment variables throughout the code.
-
-Suggested enum:
-
-```rust
-pub enum ComputerDriver {
- Legacy,
- Cua,
-}
-```
-
----
-
-# 9. Recommended Cua Integration Mode
-
-LazyBoy is an application with built-in computer-use.
-
-Preferred order for experimentation:
-
-## POC
-
-Use the Cua Driver CLI / daemon boundary first if it allows fast validation.
-
-Examples:
-
-```bash
-cua-driver call ''
-```
-
-or a controlled local process interface.
-
-This proves Cua works inside the existing Linux desktop container.
-
-## Production integration
-
-Prefer a typed/stable integration boundary.
-
-Evaluate, based on the installed Cua release:
-
-1. direct in-process SDK if suitable for LazyBoy's process model
-2. private worker / daemon
-3. CLI JSON calls as fallback
-
-Do not choose MCP merely because Agent frameworks often use MCP.
-
-LazyBoy is embedding computer use inside a product. The internal integration does not have to look like the Agent-facing integration.
-
-### Rust note
-
-Cua Driver's core runtime is Rust-based, but public application SDK support may differ by release.
-
-Do not write custom unsafe bindings unless there is a strong reason.
-
-Prefer an officially supported application integration surface.
-
----
-
-# 10. Phase 0 — Discovery / Compatibility Check
-
-Before changing LazyBoy behavior, create a short engineering report.
-
-The coding agent must verify the actual runtime environment.
-
-Inside a real LazyBoy desktop container:
-
-```bash
-echo "$DISPLAY"
-ps aux
-env | sort
-```
-
-Confirm:
-
-- X11 display exists
-- XFCE session exists
-- AT-SPI bus is available
-- Chromium exists
-- Cua Driver can start
-- Cua Driver can capture the current display
-- Cua Driver can enumerate apps/windows
-- Cua Driver can operate in Xvfb
-- Cua Driver can access Chromium in this environment
-
-Install Cua Driver using the current official installation method.
-
-Then run:
-
-```bash
-cua-driver --version
-cua-driver doctor
-cua-driver list-tools
-```
-
-Save results in:
-
-```text
-docs/cua-compatibility.md
-```
-
-Include:
-
-- installed Cua version
-- Linux distribution
-- display server
-- Cua doctor output summary
-- supported Cua tools relevant to LazyBoy
-- missing dependencies
-- known limitations
-
-### Stop condition
-
-If Cua cannot reliably control the existing `XFCE + Xvfb` environment, do **not** proceed with architecture replacement.
-
-Instead document the blocker first.
-
----
-
-# 11. Phase 1 — Five-Action POC
-
-Do not begin by migrating the whole control crate.
-
-First prove these five capabilities inside the existing LazyBoy desktop:
-
-1. screenshot
-2. accessibility/window observation
-3. click native GUI element
-4. type text
-5. browser semantic action
-
-Optional sixth:
-
-6. scroll
-
-Create a standalone POC path.
-
-Example:
-
-```text
-scripts/cua-smoke-test.sh
-```
-
-or:
-
-```text
-crates/control/examples/cua_smoke.rs
-```
-
-### POC flow
-
-Suggested test:
-
-```text
-1. Open a native/simple XFCE application.
-2. Observe window state.
-3. Click an accessible element.
-4. Type text.
-5. Launch/use Chromium.
-6. Navigate to example.com.
-7. Read browser state.
-8. Trigger a semantic browser interaction if available.
-9. Capture final screenshot.
-```
-
-### POC success criteria
-
-All five core actions succeed 10 consecutive times without:
-
-- wrong window actions
-- stale element actions
-- focus corruption
-- unexplained timeouts
-- leaving Cua processes behind
-- breaking noVNC control
-
-Do not migrate production paths until this passes.
-
----
-
-# 12. Phase 2 — Migrate `computer_observe`
-
-First production migration target:
-
-```text
-computer_observe
-```
-
-Current LazyBoy observation must remain compatible with the Agent.
-
-Do not change the Agent prompt contract unless required.
-
-Cua result must be translated into:
-
-```rust
-ComputerObservation
-```
-
-Preserve existing concepts where possible:
-
-- screenshot/image
-- dimensions
-- cursor
-- active window
-- UI elements
-
-### Translation layer
-
-Implement:
-
-```text
-Cua state
- ↓
-CuaObservationAdapter
- ↓
-LazyBoy ComputerObservation
-```
-
-Do not expose Cua-native short-lived element identifiers directly as permanent LazyBoy identifiers.
-
-Element references may only be valid for a specific observation.
-
-Treat each observation as a snapshot.
-
-### Observation ID
-
-Strongly consider adding or preserving an observation/snapshot identifier.
-
-Example:
-
-```rust
-pub struct ComputerObservation {
- pub observation_id: String,
- ...
-}
-```
-
-If changing the contract is too invasive, keep this internal first.
-
-This will later help detect stale actions.
-
----
-
-# 13. Phase 3 — Migrate `computer_act`
-
-Preserve the existing LazyBoy `ComputerAction` DSL.
-
-Current behavior such as:
-
-- click
-- move
-- pointer down/up
-- hover
-- drag
-- type
-- keyboard
-- wait
-- semantic references
-
-should remain Agent-facing LazyBoy concepts.
-
-Create a translator:
-
-```text
-LazyBoy ComputerAction
- │
- ▼
- CuaActionTranslator
- │
- ▼
- Cua Driver
-```
-
-Example conceptual mapping:
-
-```text
-LazyBoy click(element)
- → semantic Cua action when possible
-
-LazyBoy click(x, y)
- → pixel Cua action
-
-LazyBoy type(text)
- → Cua text input
-
-LazyBoy key(...)
- → Cua key action
-
-LazyBoy scroll(...)
- → Cua scroll
-```
-
-Exact tool names MUST come from:
-
-```bash
-cua-driver list-tools
-cua-driver describe ...
-```
-
-### Preserve semantic-first behavior
-
-Prefer:
-
-```text
-Accessibility / browser semantic action
-```
-
-over:
-
-```text
-screen coordinate
-```
-
-Coordinate action should be fallback, not default.
-
----
-
-# 14. Preserve LazyBoy Action Safety Logic
-
-Do not delete useful behavior from:
-
-```text
-crates/control/src/actions.rs
-```
-
-Existing logic includes concepts such as:
-
-- action batch limits
-- coordinate validation
-- element lookup
-- stale click prevention
-- browser semantic-routing preference
-- double-click expansion
-- drag normalization
-
-These should become policy/translation logic above Cua.
-
-Desired layering:
-
-```text
-Agent request
- │
- ▼
-LazyBoy validation
- │
- ▼
-LazyBoy action policy
- │
- ▼
-Cua translation
- │
- ▼
-Cua Driver
-```
-
-Cua is not a replacement for LazyBoy product policy.
-
----
-
-# 15. Stale Element Handling
-
-This is critical.
-
-Do not assume:
-
-```text
-element 12
-```
-
-from one Cua observation refers to the same UI element later.
-
-The migration must treat element references as snapshot-scoped.
-
-Preferred flow:
-
-```text
-observe
- ↓
-snapshot A
- ↓
-Agent selects element
- ↓
-act against snapshot A
- ↓
-UI changes
- ↓
-observe again
- ↓
-snapshot B
-```
-
-If the UI changed materially, do not retry an old semantic reference blindly.
-
-### Retry rule
-
-When an action fails:
-
-1. re-observe
-2. re-resolve the target
-3. retry with bounded count
-
-Never loop the same stale action indefinitely.
-
----
-
-# 16. Phase 4 — Migrate Browser Control
-
-LazyBoy currently separates browser actions from generic computer actions.
-
-Keep that separation for the Agent.
-
-Agent-facing:
-
-```text
-browser
-```
-
-Internal:
-
-```text
-LazyBoy BrowserRequest
- │
- ▼
-Cua Browser Adapter
- │
- ▼
-Cua Driver browser tools
-```
-
-Cua browser control should replace custom CDP behavior gradually.
-
-### Important
-
-Preserve the current policy:
-
-```text
-When semantic browser state is available,
-prefer browser semantic actions over pixel clicking Chromium.
-```
-
-Do not make browser automation less reliable during migration.
-
-### Test cases
-
-At minimum test:
-
-- navigate URL
-- inspect page
-- click semantic element
-- type into input
-- scroll
-- multiple tabs if LazyBoy currently depends on them
-- file picker transition
-- page refresh
-- browser restart
-- authenticated persistent profile
-
----
-
-# 17. Browser Profile Compatibility
-
-LazyBoy persists browser profiles per computer/bot.
-
-This is product-critical.
-
-Do not let Cua silently replace LazyBoy's profile with an ephemeral managed browser unless explicitly intended.
-
-Verify:
-
-- existing Chromium profile path remains usable
-- cookies survive container pause/resume
-- login sessions survive LazyBoy restart behavior as expected
-- takeover user and Agent see the same session
-- Cua attaches to the correct browser/window
-
-If Cua requires an explicit browser preparation/attach step, integrate that into LazyBoy lifecycle.
-
-Do not auto-create a separate profile that breaks existing saved logins.
-
----
-
-# 18. Phase 5 — Recording Integration
-
-LazyBoy has an important feature:
-
-```text
-Human demonstration
- ↓
-record context/actions
- ↓
-model generates playbook
- ↓
-future run resolves current UI
-```
-
-Preserve this architecture.
-
-Do **not** downgrade it into raw coordinate replay.
-
-Cua recording should be used as richer source data.
-
-Target:
-
-```text
-Human / Agent demonstration
- │
- ▼
- Cua trajectory
- │
- ├── before state
- ├── action
- ├── after state
- ├── screenshots
- └── optional video
- │
- ▼
- LazyBoy Skill Compiler
- │
- ▼
- Semantic Playbook
-```
-
-Cua trajectory is evidence.
-
-LazyBoy skill/playbook is the reusable automation.
-
-### Do not do
-
-```text
-record x=312,y=441
-replay x=312,y=441 forever
-```
-
-### Do
-
-Store semantic intent when possible:
-
-```text
-Click the "Sign in" button
-```
-
-Then resolve it on the current screen during replay.
-
----
-
-# 19. Takeover Must Keep Working
-
-User takeover is a core LazyBoy feature.
-
-Migration acceptance requires:
-
-```text
-Agent running
- ↓
-request_takeover
- ↓
-Agent stops issuing input
- ↓
-User controls noVNC desktop
- ↓
-User releases takeover
- ↓
-Agent re-observes
- ↓
-Agent resumes from current state
-```
-
-### Required rule
-
-After takeover ends:
-
-**Always perform a fresh observation before the Agent performs another UI action.**
-
-Never reuse pre-takeover element references.
-
----
-
-# 20. Credential / Vault Boundary
-
-Cua must not get broad access to LazyBoy secrets by default.
-
-Keep credential policy in LazyBoy.
-
-Preferred flow:
-
-```text
-Agent wants login
- │
- ▼
-LazyBoy checks:
-- allowed domain
-- saved credential exists
-- HTTPS / policy
- │
- ▼
-LazyBoy authorizes injection
- │
- ▼
-Cua performs allowed typing/action
-```
-
-Do not make the Cua integration read the entire Vault.
-
-Secrets should not appear:
-
-- in command-line arguments
-- in logs
-- in Cua debug output
-- in trajectory metadata
-- in screenshots longer than unavoidable
-- in error messages
-
-Audit recording behavior around passwords.
-
-If recording is active, ensure sensitive typing can be masked or recording paused.
-
----
-
-# 21. `controld` Migration Strategy
-
-Do not delete `crates/controld` during Phase 1.
-
-It is a useful compatibility boundary.
-
-Current conceptual API:
-
-```text
-POST /observe
-POST /act
-```
-
-Recommended first migration:
-
-```text
-POST /observe
- ↓
-selected ComputerController
- ↓
-CuaController or LegacyController
-```
-
-```text
-POST /act
- ↓
-LazyBoy validation
- ↓
-selected ComputerController
- ↓
-CuaController or LegacyController
-```
-
-This keeps:
-
-```text
-API
-SandboxProvider
-Supervisor
-```
-
-largely unchanged.
-
-Later, if Cua integration makes `controld` unnecessary, remove it in a dedicated architectural PR.
-
-Do not mix that cleanup into the initial migration.
-
----
-
-# 22. Docker Image Changes
-
-Add Cua dependencies to the LazyBoy desktop image.
-
-The coding agent must locate the actual Dockerfile(s) used for desktop computers.
-
-Do not assume the path.
-
-Changes may include:
-
-- Cua Driver install
-- required X11 packages
-- AT-SPI dependencies
-- ffmpeg if recording/video is enabled
-- runtime directories
-- permissions
-- PATH configuration
-
-Run:
-
-```bash
-cua-driver doctor
-```
-
-inside the built desktop container as part of the smoke test.
-
-### Image versioning
-
-Pin a known-working Cua version for reproducible builds.
-
-Do not install uncontrolled nightly builds in the default production image.
-
-Optionally allow:
-
-```bash
-LAZYBOY_CUA_CHANNEL=stable
-LAZYBOY_CUA_VERSION=
-```
-
-or equivalent build args.
-
----
-
-# 23. Cua Process Lifecycle
-
-Do not start one uncontrolled global Cua process for every LazyBoy computer unless architecture requires it.
-
-Determine which process should own:
-
-- display connection
-- accessibility session
-- browser connection
-- recordings
-- Cua lifecycle
-
-For LazyBoy's existing architecture, the safest initial design is usually:
-
-```text
-one desktop container
- │
- ├── XFCE/Xvfb
- ├── Chromium
- ├── noVNC
- ├── LazyBoy controld
- └── Cua runtime/driver
-```
-
-The driver should only see/control that computer's desktop session.
-
-### Isolation
-
-Bot A must never control Bot B's display.
-
-Tests must explicitly verify isolation.
-
----
-
-# 24. Health Checks
-
-Add a Cua health check.
-
-Possible information:
-
-```rust
-pub struct ControllerHealth {
- pub backend: String,
- pub version: Option,
- pub healthy: bool,
- pub degraded: bool,
- pub details: Vec,
-}
-```
-
-Surface useful failures:
-
-- driver not installed
-- X11 unavailable
-- AT-SPI unavailable
-- screenshot unavailable
-- browser unavailable
-- incompatible Cua version
-
-Do not return generic:
-
-```text
-computer failed
-```
-
-when a meaningful diagnosis is available.
-
----
-
-# 25. Fallback Behavior
-
-During migration:
-
-```text
-LAZYBOY_COMPUTER_DRIVER=legacy
-```
-
-must work.
-
-For `cua` mode, avoid silent fallback for individual actions unless explicitly designed.
-
-Bad:
-
-```text
-Cua click failed
-→ silently xdotool click
-```
-
-This makes failures impossible to debug.
-
-Preferred:
-
-```text
-Cua action failed
-→ return classified error
-→ Agent re-observes / retries / requests takeover
-```
-
-A feature-flag-level fallback is acceptable.
-
-An invisible per-action fallback is not.
-
----
-
-# 26. Logging / Observability
-
-Add structured logs around Cua calls.
-
-Include:
-
-- operation ID
-- run ID
-- bot ID
-- screen ID
-- backend
-- Cua tool
-- duration
-- success/failure
-- action route if Cua reports it
-- observation ID if available
-
-Never log secret text.
-
-For typing actions:
-
-```text
-text=""
-length=12
-```
-
-not:
-
-```text
-text="actual-password"
-```
-
----
-
-# 27. Metrics
-
-If LazyBoy has metrics infrastructure, add:
-
-```text
-computer_action_total
-computer_action_failed_total
-computer_observe_duration_ms
-computer_action_duration_ms
-computer_browser_action_duration_ms
-computer_stale_reference_total
-computer_takeover_total
-cua_driver_restart_total
-```
-
-Useful labels:
-
-```text
-backend
-action_type
-route
-result
-```
-
-Avoid high-cardinality IDs such as `run_id` as metric labels.
-
----
-
-# 28. Testing Strategy
-
-## Unit tests
-
-Test translation only.
-
-Examples:
-
-```text
-LazyBoy click semantic ref → expected Cua request
-
-LazyBoy coordinate click → expected Cua request
-
-LazyBoy type → expected Cua request
-
-Cua observation → LazyBoy ComputerObservation
-
-unsupported Cua response → classified error
-```
-
-Use fake/mocked Cua responses.
-
----
-
-## Contract tests
-
-The Agent-facing tool results should remain equivalent between:
-
-```text
-LegacyController
-CuaController
-```
-
-for common scenarios.
-
-Test:
-
-- observation shape
-- action result shape
-- error behavior
-- browser results
-- takeover interaction
-
----
-
-## Integration tests
-
-Run against a real desktop container.
-
-Test native GUI:
-
-```text
-open app
-observe
-click
-type
-verify application state
-```
-
-Do not validate only that Cua returned `"ok"`.
-
-Validate independent application state.
-
----
-
-## Browser E2E
-
-Use a deterministic local test page rather than an external website.
-
-Create fixtures for:
-
-- button
-- input
-- checkbox
-- select
-- scroll area
-- delayed DOM update
-- modal
-- new tab
-- canvas fallback if needed
-
-Verify actual DOM/application state.
-
----
-
-# 29. Migration Acceptance Suite
-
-Cua backend is not considered ready until all of the following pass.
-
-## Desktop
-
-- [ ] screenshot works
-- [ ] window enumeration works
-- [ ] active window works
-- [ ] accessibility elements work
-- [ ] semantic click works
-- [ ] coordinate click works
-- [ ] type text works
-- [ ] hotkey works
-- [ ] scroll works
-- [ ] drag works if supported
-- [ ] desktop stays usable through noVNC
-
-## Browser
-
-- [ ] attach to correct Chromium
-- [ ] use persistent LazyBoy profile
-- [ ] navigate
-- [ ] observe DOM/browser state
-- [ ] semantic click
-- [ ] type
-- [ ] scroll
-- [ ] refresh
-- [ ] profile survives pause/resume
-- [ ] same browser is visible to human takeover
-
-## Lifecycle
-
-- [ ] fresh container
-- [ ] existing persisted container
-- [ ] pause
-- [ ] resume
-- [ ] stop
-- [ ] restart
-- [ ] concurrent bots
-- [ ] no cross-bot control
-
-## Agent flow
-
-- [ ] `computer_observe`
-- [ ] `computer_act`
-- [ ] `browser`
-- [ ] `shell`
-- [ ] takeover
-- [ ] resume after takeover
-- [ ] skill recording
-- [ ] scheduled run
-
----
-
-# 30. Performance Benchmark
-
-Before defaulting to Cua, compare against legacy.
-
-Create a benchmark report:
-
-```text
-docs/cua-benchmark.md
-```
-
-Measure:
-
-| Scenario | Legacy | Cua | Winner |
-| -------------------- | -----: | --: | ------ |
-| screenshot | | | |
-| observe desktop | | | |
-| native click | | | |
-| type text | | | |
-| browser snapshot | | | |
-| browser click | | | |
-| 20-step browser task | | | |
-
-Also measure:
-
-- tool-call count
-- bytes returned to model
-- screenshot count
-- total model-visible observation size
-- end-to-end task completion time
-- failure rate
-
-The goal is not only faster pointer execution.
-
-The real goal is:
-
-```text
-fewer Agent turns
-+
-less context
-+
-higher task success rate
-```
-
----
-
-# 31. Rollout Plan
-
-## Step A
-
-Add:
-
-```text
-ComputerController
-LegacyController
-```
-
-No behavior change.
-
-All tests must pass.
-
----
-
-## Step B
-
-Add Cua smoke test.
-
-No production traffic.
-
----
-
-## Step C
-
-Implement:
-
-```text
-CuaController.observe
-```
-
-Feature flagged.
-
----
-
-## Step D
-
-Implement simple actions:
-
-```text
-click
-type
-keyboard
-scroll
-```
-
----
-
-## Step E
-
-Migrate browser state/actions.
-
----
-
-## Step F
-
-Add recording integration.
-
----
-
-## Step G
-
-Run acceptance suite and benchmark.
-
----
-
-## Step H
-
-Change default:
-
-```text
-legacy
-→
-cua
-```
-
-but keep legacy rollback.
-
----
-
-## Step I
-
-After stable operation, delete obsolete low-level code in separate PRs.
-
-Possible deletion candidates:
-
-```text
-a11y.py
-a11y.rs
-cdp.py
-cdp.rs
-x11.rs
-screen implementation portions
-```
-
-Only delete code proven unused.
-
----
-
-# 32. Suggested PR Sequence
-
-Keep PRs small.
-
-### PR 1
-
-```text
-refactor(control): introduce pluggable ComputerController
-```
-
-- add interface
-- wrap legacy
-- no behavior change
-- tests
-
-### PR 2
-
-```text
-build(desktop): install and validate Cua Driver
-```
-
-- image changes
-- doctor
-- smoke test
-- compatibility doc
-
-### PR 3
-
-```text
-feat(control): add Cua observation backend
-```
-
-### PR 4
-
-```text
-feat(control): route computer actions through Cua
-```
-
-### PR 5
-
-```text
-feat(browser): add Cua browser adapter
-```
-
-### PR 6
-
-```text
-feat(skills): ingest Cua trajectories for demonstrations
-```
-
-### PR 7
-
-```text
-test(control): add Cua acceptance and benchmark suite
-```
-
-### PR 8
-
-```text
-chore(control): make Cua the default backend
-```
-
-### Later
-
-```text
-chore(control): remove obsolete legacy OS automation
-```
-
----
-
-# 33. Error Model
-
-Map Cua failures to typed LazyBoy errors.
-
-Suggested categories:
-
-```rust
-pub enum ControlError {
- DriverUnavailable,
- DriverUnhealthy,
- DisplayUnavailable,
- AccessibilityUnavailable,
- BrowserUnavailable,
- TargetNotFound,
- StaleReference,
- PermissionDenied,
- Timeout,
- Unsupported,
- Busy,
- InvalidAction,
- Internal(String),
-}
-```
-
-Do not expose Cua raw errors directly to the Agent when a stable LazyBoy error can represent them.
-
-Log the raw cause internally.
-
----
-
-# 34. Retry Policy
-
-Do not blindly retry UI actions.
-
-Recommended:
-
-### Observation failure
-
-Retry a small bounded number if transport/runtime error appears transient.
-
-### Semantic target not found
-
-```text
-re-observe
-→ re-resolve
-→ retry once
-```
-
-### Stale target
-
-```text
-re-observe
-→ never retry original snapshot ref directly
-```
-
-### Pixel miss
-
-Do not repeat the same click indefinitely.
-
-Preserve LazyBoy's stale-click protection concept.
-
-### Driver crash
-
-Restart driver/runtime if safe, then require a fresh observation.
-
----
-
-# 35. Screenshot Policy
-
-Avoid sending screenshots to the model when structured UI state is sufficient.
-
-Prefer:
-
-```text
-semantic / accessibility observation
-```
-
-Use screenshots when:
-
-- layout matters
-- semantic state is incomplete
-- canvas/WebGL is involved
-- visual verification is needed
-
-This reduces:
-
-- latency
-- model context
-- vision token cost
-- accidental secret exposure
-
----
-
-# 36. Cua Permission Policy
-
-If the chosen Cua deployment mode supports permission policies, use allow-list behavior.
-
-LazyBoy only needs a subset of Cua capabilities.
-
-Allow only required operations.
-
-Example conceptual set:
-
-```text
-health/doctor-like observation
-window/app listing
-screenshot
-window state
-click
-type
-key
-scroll
-browser state
-browser click
-browser type
-browser navigation
-recording
-```
-
-Do not allow unrelated capabilities automatically.
-
-Use actual current Cua tool names from the installed version.
-
----
-
-# 37. Security Requirements
-
-- Cua must not access the host Docker socket from Agent desktops.
-- Each bot must remain isolated.
-- Keep LazyBoy supervisor on internal network.
-- Keep `controld` localhost/internal where applicable.
-- Do not expose Cua daemon ports publicly.
-- Do not log passwords/tokens.
-- Verify trajectory storage permissions.
-- Verify screenshots are covered by LazyBoy retention policy.
-- Do not allow an Agent to change Cua policies.
-- Do not let the Agent select another bot's display/session.
-- Cua executable/version should be controlled by LazyBoy image/build process.
-
----
-
-# 38. Multi-Screen Considerations
-
-LazyBoy already has screen concepts:
-
-```text
-screen_lease_id
-screen_id
-screen_slot
-display
-```
-
-Do not discard these.
-
-Cua must be bound to the LazyBoy-selected display/screen.
-
-Verify multi-screen behavior before enabling Cua for multi-screen bots.
-
-If Cua does not safely support LazyBoy's current multi-screen semantics:
-
-- support one screen first
-- return explicit capability information
-- do not fake support
-
----
-
-# 39. Cua Capability Mapping
-
-LazyBoy should expose backend capabilities.
-
-Suggested internal structure:
-
-```rust
-pub struct ComputerCapabilities {
- pub multi_screen: bool,
- pub semantic_desktop: bool,
- pub semantic_browser: bool,
- pub pixel_actions: bool,
- pub recording: bool,
- pub background_input: bool,
-}
-```
-
-Only add fields if needed and compatible with existing contract evolution.
-
-Use capability checks instead of OS-name conditionals where possible.
-
-Bad:
-
-```rust
-if linux {
- ...
-}
-```
-
-Better:
-
-```rust
-if capabilities.semantic_browser {
- ...
-}
-```
-
----
-
-# 40. Future Phase — Cua Sandbox
-
-Do **not** implement this during the Driver migration.
-
-Later, LazyBoy may support:
-
-```text
-SandboxProvider
- │
- ├── LazyBoyDocker
- └── CuaSandbox
-```
-
-Possible future computer types:
-
-```text
-Lightweight Linux
-Linux VM
-Windows VM
-macOS VM
-Cloud Computer
-```
-
-This should be a separate project after Cua Driver migration is stable.
-
-The current `SandboxProvider` abstraction should make this possible.
-
----
-
-# 41. Future Phase — Windows / macOS
-
-One strategic reason for Cua is avoiding custom implementations for:
-
-```text
-Linux AT-SPI/X11
-Windows UIA/input/capture
-macOS AX/input/capture
-```
-
-Do not add Windows/macOS support during the initial Linux migration.
-
-First ensure the LazyBoy control contract is OS-neutral.
-
-Then add backend capabilities and sandbox providers later.
-
----
-
-# 42. Definition of Done — Phase 1
-
-Phase 1 is complete when:
-
-1. LazyBoy can run with:
-
-```bash
-LAZYBOY_COMPUTER_DRIVER=legacy
-```
-
-and:
-
-```bash
-LAZYBOY_COMPUTER_DRIVER=cua
-```
-
-2. Existing Agent tool schemas remain compatible.
-
-3. Cua works in the existing LazyBoy Linux desktop container.
-
-4. `computer_observe` works through Cua.
-
-5. `computer_act` core actions work through Cua.
-
-6. Browser semantic operations work through Cua.
-
-7. noVNC human takeover still works.
-
-8. Persistent Chromium sessions still work.
-
-9. Docker pause/resume still works.
-
-10. Multi-bot isolation is verified.
-
-11. Legacy backend remains available for rollback.
-
-12. No secret is exposed in logs or recording metadata.
-
-13. Acceptance tests pass.
-
-14. Benchmark results are documented.
-
----
-
-# 43. First Task for the Coding Agent
-
-Do this first and nothing larger:
-
-## Task
-
-Create a branch:
-
-```text
-feat/cua-driver-poc
-```
-
-Then:
-
-1. inspect current LazyBoy computer-control flow
-2. identify actual desktop Dockerfile/image entrypoint
-3. install a pinned stable Cua Driver in that image
-4. make no Agent-facing schema changes
-5. create a Cua smoke test that runs inside a LazyBoy desktop
-6. verify:
- - `cua-driver --version`
- - `cua-driver doctor`
- - screenshot
- - window/accessibility observation
- - native click
- - typing
- - Chromium/browser state
-7. write results to:
-
-```text
-docs/cua-compatibility.md
-```
-
-8. stop after the POC
-9. do not delete any legacy control code
-10. report blockers before starting the controller refactor
-
-### Expected output
-
-The first PR should answer only:
-
-> "Can Cua Driver reliably control the existing LazyBoy XFCE + Xvfb desktop container?"
-
-If the answer is yes, proceed to the next PR.
-
----
-
-# 44. Second Task After POC Passes
-
-Create:
-
-```text
-ComputerController
-```
-
-with:
-
-```text
-LegacyController
-CuaController
-```
-
-Initially make all production requests use:
-
-```text
-LegacyController
-```
-
-Then route only test/flagged traffic to:
-
-```text
-CuaController
-```
-
-Do not migrate browser and recording in the same PR.
-
----
-
-# 45. Architecture Decision
-
-The intended ownership after migration is:
-
-| Concern | Owner |
-| ----------------------------------- | ------- |
-| Product UI | LazyBoy |
-| Agent loop | LazyBoy |
-| Model provider | LazyBoy |
-| Memory | LazyBoy |
-| Schedules | LazyBoy |
-| Vault | LazyBoy |
-| Takeover | LazyBoy |
-| Skills/playbooks | LazyBoy |
-| Sandbox lifecycle (Phase 1) | LazyBoy |
-| Docker resources | LazyBoy |
-| Remote desktop/noVNC | LazyBoy |
-| Computer observation | Cua |
-| Native UI control | Cua |
-| Pointer/keyboard | Cua |
-| Browser semantic control | Cua |
-| OS-specific accessibility | Cua |
-| Trajectory capture | Cua |
-| Workflow abstraction from recording | LazyBoy |
-
-This is the central design decision.
-
-Do not invert it.
-
----
-
-# 46. Final Principle
-
-LazyBoy's competitive/product value is:
-
-```text
-Agent workspace
-Multi-agent
-Persistent computers
-Human takeover
-Memory
-Schedules
-Vault
-Skills
-Demo → reusable workflow
-Web/mobile UX
-Model choice
-```
-
-The goal of using Cua is to stop spending LazyBoy engineering effort on:
-
-```text
-X11 automation
-AT-SPI edge cases
-CDP plumbing
-screen capture
-OS-specific input
-window enumeration
-cross-platform UI automation
-```
-
-Build LazyBoy **on top of** Cua.
-
-Do not turn LazyBoy **into** Cua.
-
----
-
-# References
-
-LazyBoy:
-
-- https://code.30cm.net/daniel.w/lazyBoy
-- https://code.30cm.net/daniel.w/lazyBoy/src/branch/main/docs/architecture.md
-- https://code.30cm.net/daniel.w/lazyBoy/src/branch/main/crates/control
-- https://code.30cm.net/daniel.w/lazyBoy/src/branch/main/crates/control/src/sandbox.rs
-- https://code.30cm.net/daniel.w/lazyBoy/src/branch/main/crates/control/src/actions.rs
-- https://code.30cm.net/daniel.w/lazyBoy/src/branch/main/crates/sandbox
-
-Cua:
-
-- https://github.com/trycua/cua
-- https://cua.ai/docs
-- https://cua.ai/docs/how-to-guides/driver/install
-- https://cua.ai/docs/concepts/choose-a-cua-driver-integration
-- https://cua.ai/docs/how-to-guides/driver/connect-your-agent
-- https://cua.ai/docs/reference/cua-driver/cli-reference
-- https://cua.ai/docs/reference/cua-driver/mcp-tools
-- https://cua.ai/docs/how-to-guides/driver/record-and-render-a-trajectory
-- https://cua.ai/docs/how-to-guides/driver/restrict-tool-access
diff --git a/apps/web/src/App.tsx b/apps/web/src/App.tsx
index fadaa74..bdba7f1 100644
--- a/apps/web/src/App.tsx
+++ b/apps/web/src/App.tsx
@@ -1,4 +1,4 @@
-import { FormEvent, KeyboardEvent as ReactKeyboardEvent, useCallback, useEffect, useMemo, useRef, useState } from "react";
+import { FormEvent, Fragment, KeyboardEvent as ReactKeyboardEvent, useCallback, useEffect, useMemo, useRef, useState } from "react";
import { BotIcon, Brain, ChevronDown, ChevronsRight, CircleHelp, ClipboardPaste, Computer, Download, Ellipsis, Info, LogOut, Megaphone, Paperclip, Pencil, Pin, Plug, Plus, RefreshCw, Settings, Smartphone, Sparkle, Square, Upload, Users, X } from "./animated-icons";
import UseAnimations from "./use-animations";
import loading from "react-useanimations/lib/loading";
@@ -17,6 +17,8 @@ import searchToX from "react-useanimations/lib/searchToX";
import { api, ApiError } from "./api";
import { createCoalescer, subscribeToSession } from "./live";
import { applyReplyEvent, type ReplyDrafts } from "./reply-stream";
+import { acceptMention, mentionChoices, mentionToken } from "./mentions";
+import { clockTime, dayLabel, sameDay } from "./chat-time";
import { HANDOFF_MS, VEIL_FADE_MS, handoffRemaining, keepScreenUrl, nextVeil, viewOnlyFor, viewerPath, type Veil } from "./handoff";
import { Avatar, AvatarLookProvider, AvatarStack, BLOBATAR_BACKGROUNDS, BLOBATAR_EXPRESSIONS, BLOBATAR_SHAPES, DEFAULT_LOOK, persistBlobatarShape, readAvatarLooks, resolveBlobatarShape, writeAvatarLook, type AvatarBackground, type AvatarExpression, type AvatarLook } from "./avatar";
import { dateLocale, getLocale, listJoin, setLocale, t, useLocale, type MessageKey } from "./i18n";
@@ -55,10 +57,17 @@ type WorkspacePrefs={name:string;showHidden:boolean};
function isDefaultWorkspaceName(name?:string|null){return !name||name==="Local workspace"||name==="本機工作區"}
function readWorkspace():WorkspacePrefs{try{const raw=localStorage.getItem(WORKSPACE_STORE);if(!raw)return{name:t("localWorkspace"),showHidden:false};const value=JSON.parse(raw) as {name?:string;showHidden?:boolean};const name=value.name?.trim();return{name:isDefaultWorkspaceName(name)?t("localWorkspace"):name||t("localWorkspace"),showHidden:Boolean(value.showHidden)}}catch{return{name:t("localWorkspace"),showHidden:false}}}
+// A message shows only its clock time; the day it belongs to is written once,
+// in the divider above the first message of that day, the way chat apps do.
function MessageTime({value}:{value:string}){
const date=new Date(value);
if(!Number.isFinite(date.getTime()))return null;
- return {date.toLocaleString(dateLocale(),{month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:false})} ;
+ return {clockTime(date,dateLocale())} ;
+}
+function DayDivider({value}:{value:string}){
+ const date=new Date(value);
+ if(!Number.isFinite(date.getTime()))return null;
+ return {dayLabel(date,new Date(),dateLocale(),{today:t("today"),yesterday:t("yesterday")})}
;
}
function WorkspaceAvatar({name}:{name:string}){const parts=name.trim().split(/\s+/).filter(Boolean);const initials=(parts.length>1?parts.map(part=>part[0]).join(""):parts[0]?.slice(0,2)||"LB").slice(0,2).toUpperCase();return {initials} }
function modeLabel(mode:ComputerMode){return mode==="team"?t("sharedComputer"):t("privateComputer")}
@@ -217,6 +226,20 @@ export function App(){
const [slashIndex,setSlashIndex]=useState(0);
const [slashDismissed,setSlashDismissed]=useState(false);
useEffect(()=>{setSlashIndex(0);setSlashDismissed(false)},[draft]);
+ // Who answers a group message is decided by the server; here it is only
+ // typed. The `@` list opens on `@`, closes on the first space, and remembers
+ // nothing, because choosing who should talk must never feel like setup.
+ const [mentionIndex,setMentionIndex]=useState(0);
+ const [mentionDismissed,setMentionDismissed]=useState(false);
+ const [caretAt,setCaretAt]=useState(0);
+ const composerRef=useRef(null);
+ const [hostMenuOpen,setHostMenuOpen]=useState(false);
+ useEffect(()=>{setMentionIndex(0);setMentionDismissed(false);setHostMenuOpen(false)},[draft,activeRoomId]);
+ useEffect(()=>{setCaretAt(current=>current>draft.length?draft.length:current)},[draft]);
+ const mentionQuery=activeRoom&&!mentionDismissed?mentionToken(draft,caretAt):null;
+ const mentionList=mentionQuery===null||!activeRoom?[]:mentionChoices(mentionQuery,activeRoom.members,t("everyoneMention"));
+ const roomHostId=activeRoom?activeRoom.hostBotId||activeRoom.members[0]?.id||null:null;
+ const roomHost=activeRoom?.members.find(member=>member.id===roomHostId)||null;
const slashToken=draft.trimStart().split(/\s/,1)[0].slice(1).toLowerCase();
const slashSuggestions=!slashDismissed&&/^\/[^\s]*$/.test(draft.trimStart())
? [{name:"goal",description:t("goalCommandHint"),kind:t("slashMode")},...fileSkills.map(skill=>({...skill,kind:t("slashFileSkill")}))].filter(skill=>!slashToken||skill.name.startsWith(slashToken)).slice(0,8)
@@ -290,7 +313,12 @@ export function App(){
useEffect(()=>{if(!handingOff)return;handoffAtRef.current=Date.now();const timer=setTimeout(()=>{expectedHolderRef.current=null;setHandingOff(false)},HANDOFF_MS);return()=>clearTimeout(timer)},[handingOff]);
useEffect(()=>{const frame=desktopFrameRef.current;if(!frame?.contentWindow||!screenUrl)return;frame.contentWindow.postMessage({type:"lazyboy-view-only",viewOnly:!desktopInteractive},location.origin)},[desktopInteractive,screenUrl,desktopReady]);
useEffect(()=>{const listener=(event:MessageEvent)=>{if(event.origin!==location.origin||event.source!==desktopFrameRef.current?.contentWindow||event.data?.type!=="lazyboy-request-control"||!paneBotId)return;if(computer.sharedInput){pushViewOnly(!desktopInteractive);return}void setControl("user")};window.addEventListener("message",listener);return()=>window.removeEventListener("message",listener)},[paneBotId,computer.sharedInput,desktopInteractive]);
- useEffect(()=>{const close=(event:MouseEvent)=>{const target=event.target;if(target instanceof Element&&target.closest(".create-menu-wrap,.account-wrap,.session-picker,.context-menu,.plus-menu-wrap"))return;setContext(null);setRoomContext(null);setSessionMenuOpen(false);setAccountOpen(false);setCreateMenuOpen(false);setPlusOpen(false)};window.addEventListener("click",close);return()=>window.removeEventListener("click",close)},[]);
+ async function setRoomHost(botId:string){
+ setHostMenuOpen(false);
+ if(!activeRoom||botId===roomHostId)return;
+ try{await api(`/api/rooms/${activeRoom.id}`,{method:"PATCH",body:JSON.stringify({hostBotId:botId})});await loadBots()}catch(error){setError(localizeError(error instanceof Error?error.message:t("operationFailed")))}
+ }
+ useEffect(()=>{const close=(event:MouseEvent)=>{const target=event.target;if(target instanceof Element&&target.closest(".create-menu-wrap,.account-wrap,.session-picker,.context-menu,.plus-menu-wrap,.host-chip-wrap"))return;setContext(null);setRoomContext(null);setSessionMenuOpen(false);setAccountOpen(false);setCreateMenuOpen(false);setPlusOpen(false);setHostMenuOpen(false)};window.addEventListener("click",close);return()=>window.removeEventListener("click",close)},[]);
useEffect(()=>{const onKey=(event:KeyboardEvent)=>{if(event.key!=="Escape")return;setAccountOpen(false);setAccountDialog(null);setCreateMenuOpen(false);setPlusOpen(false);setTeachOpen(false);setEditingSkillId(null);setSessionMenuOpen(false);setContext(null);setRoomContext(null)};window.addEventListener("keydown",onKey);return()=>window.removeEventListener("keydown",onKey)},[]);
useEffect(()=>{setWorkspaceName(name=>isDefaultWorkspaceName(name)?t("localWorkspace"):name)},[locale]);
useEffect(()=>{localStorage.setItem(WORKSPACE_STORE,JSON.stringify({name:workspaceName,showHidden}))},[workspaceName,showHidden]);
@@ -365,7 +393,8 @@ export function App(){
})}finally{sendingRef.current=false;setSendingMessage(false)}
}
- function composerKeyDown(event:ReactKeyboardEvent){if(event.nativeEvent.isComposing||event.key==="Process")return;if(slashSuggestions.length){if(event.key==="Escape"){event.preventDefault();setSlashDismissed(true);return}if(event.key==="ArrowDown"||event.key==="ArrowUp"){event.preventDefault();setSlashIndex(index=>(index+(event.key==="ArrowDown"?1:slashSuggestions.length-1))%slashSuggestions.length);return}if(event.key==="Tab"||(event.key==="Enter"&&!event.shiftKey)){event.preventDefault();setDraft(`/${slashSuggestions[slashIndex%slashSuggestions.length].name} `);return}}const history=sentHistoryRef.current;if(event.key==="ArrowUp"&&history.length>0&&(!event.currentTarget.value.includes("\n")||event.currentTarget.selectionStart===0)){event.preventDefault();if(historyIndexRef.current===null){historyDraftRef.current=draft;historyIndexRef.current=history.length-1}else historyIndexRef.current=Math.max(0,historyIndexRef.current-1);setDraft(history[historyIndexRef.current]);return}if(event.key==="ArrowDown"&&historyIndexRef.current!==null&&(!event.currentTarget.value.includes("\n")||event.currentTarget.selectionEnd===event.currentTarget.value.length)){event.preventDefault();if(historyIndexRef.currentcomposerRef.current?.focus())}
+ function composerKeyDown(event:ReactKeyboardEvent){if(event.nativeEvent.isComposing||event.key==="Process")return;if(mentionList.length){if(event.key==="Escape"){event.preventDefault();setMentionDismissed(true);return}if(event.key==="ArrowDown"||event.key==="ArrowUp"){event.preventDefault();setMentionIndex(index=>(index+(event.key==="ArrowDown"?1:mentionList.length-1))%mentionList.length);return}if(event.key==="Tab"||(event.key==="Enter"&&!event.shiftKey)){event.preventDefault();pickMention(mentionList[mentionIndex%mentionList.length]);return}}if(slashSuggestions.length){if(event.key==="Escape"){event.preventDefault();setSlashDismissed(true);return}if(event.key==="ArrowDown"||event.key==="ArrowUp"){event.preventDefault();setSlashIndex(index=>(index+(event.key==="ArrowDown"?1:slashSuggestions.length-1))%slashSuggestions.length);return}if(event.key==="Tab"||(event.key==="Enter"&&!event.shiftKey)){event.preventDefault();setDraft(`/${slashSuggestions[slashIndex%slashSuggestions.length].name} `);return}}const history=sentHistoryRef.current;if(event.key==="ArrowUp"&&history.length>0&&(!event.currentTarget.value.includes("\n")||event.currentTarget.selectionStart===0)){event.preventDefault();if(historyIndexRef.current===null){historyDraftRef.current=draft;historyIndexRef.current=history.length-1}else historyIndexRef.current=Math.max(0,historyIndexRef.current-1);setDraft(history[historyIndexRef.current]);return}if(event.key==="ArrowDown"&&historyIndexRef.current!==null&&(!event.currentTarget.value.includes("\n")||event.currentTarget.selectionEnd===event.currentTarget.value.length)){event.preventDefault();if(historyIndexRef.current(sessionsPath,{method:"POST",body:JSON.stringify({title:t("newConversation")})});writeSessionStore(sessionStoreKey,session.id);const next=await api(sessionsPath);setSessions(next);setActiveSessionId(session.id);setMessages([])}catch(e){setError(e instanceof Error?localizeError(e.message):t("operationFailed"))}finally{setBusy(false)}}
// A run that stopped to ask keeps its harness state, so the answer is just a
@@ -525,14 +554,14 @@ export function App(){
- setMobileNav(v=>!v)}> {activeRoom?<>member.id)}/>{activeRoom.name} {setSessionMenuOpen(false);setSessionToDelete(id)}} onClear={()=>{setSessionMenuOpen(false);setClearOpen(true)}}/> {topTools}>:active?<>{active.name} {setSessionMenuOpen(false);setSessionToDelete(id)}} onClear={()=>{setSessionMenuOpen(false);setClearOpen(true)}}/> {topTools}>:<>{t("chooseBot")} {topTools}>}
+ setMobileNav(v=>!v)}> {activeRoom?<>member.id)}/>{activeRoom.name} event.stopPropagation()}>setHostMenuOpen(v=>!v)}>{roomHost?roomHost.name:t("hostBadge")} {hostMenuOpen&&{t("hostMenuLabel")} {activeRoom.members.map(member=>
void setRoomHost(member.id)}>{member.name} {member.id===roomHostId&&{t("hostBadge")} } )}
} {setSessionMenuOpen(false);setSessionToDelete(id)}} onClear={()=>{setSessionMenuOpen(false);setClearOpen(true)}}/> {topTools}>:active?<>{active.name} {setSessionMenuOpen(false);setSessionToDelete(id)}} onClear={()=>{setSessionMenuOpen(false);setClearOpen(true)}}/> {topTools}>:<>{t("chooseBot")} {topTools}>}
{callOpen&&voiceSettings?.enabled&&active&&activeSessionId&&!activeRoomId?setCallOpen(false)} onTakeOver={()=>{setRightPart("computer");setRightCollapsed(false);setComputerOpen(true);if(active&&!computer.sharedInput)void setControl("user",active.id)}}/>:null}
- {(activeRoom||active)&&messages.length===0?
{activeRoom?
:
}{activeRoom?t("startRoomDiscussion",{name:activeRoom.name}):t("startBotWork",{name:active!.name})} {activeRoom?t("roomWillReply",{names:listJoin(activeRoom.members.map(member=>member.name))}):active!.description||t("botWelcome")}
:messages.map(message=>{const spoken=message.role!=="user"&&Boolean(activeRoom);const speakerName=message.speakerName||(spoken?paneBot?.name:undefined);const speakerShape=(message.speakerShape||paneBot?.avatarShape||"blob") as AvatarShape;const files=messageFiles(message.blocks);const chips=chipBlocks(message.blocks);const hideBody=isAutoAttachCaption(message.body,files)||isAutoScheduleCaption(message.body,chips);return
{spoken&&
}{spoken&&
{speakerName} }{files.length>0&&
{files.map(file=>)}
}{chips.map((chip,index)=>chip.kind==="error"?
{errorTitle(chip.code)}
{errorActions(chip.code).map(next=>next==="retry"?void retryRun(chip.runId)}>{retriedRuns[chip.runId||""]?t("errorRetried"):t("errorRetry")} :next==="screen"?void openLoginScreen()}>{t("loginOpenScreen")} :openAccount("model")}>{t("errorOpenSettings")} )}
:chip.kind==="resume"?
{resumeTitle(chip.reason)}
{(chip.limit||0)>0?
{t("resumeProgress",{turns:chip.turns||0,limit:chip.limit||0})}
:null}{resumedChips[message.id]||(message.seq??0)
void continueRun(message.id)}>{t("resumeContinue")} setResumedChips(current=>({...current,[message.id]:true}))}>{t("resumeStop")} }
:chip.kind==="login"?
{t("loginNeedsYou")}
{chip.site||message.body}
{chip.why?
{t("loginWhy",{why:chip.why})}
:null}
void openLoginScreen()}>{t("loginOpenScreen")} :chip.kind==="schedule"?
{t("scheduleChip")}
{chip.name} {scheduleWhen(chip.cron,chip.human)} :
{t("scheduleRunChip")}
{chip.name} {scheduleWhen(chip.cron,chip.human)} )}{!hideBody&&(message.role==="assistant"?
{message.body}
{message.body.trim()?
:null}{message.runId&& {t("messageRunDetails")} } :
{message.body} )}{!hideBody&&message.body.trim()&&
void rememberMessage(message)}> }
})}{pausedForUser&&paneBot&&{computer.sharedInput?t("sharedNeedsUser",{name:paneBot.name}):computer.controlHolder==="user"?t("pausedUserControl",{name:paneBot.name}):t("pausedNeedsUser",{name:paneBot.name})}{(computer.queuedRuns||0)>0&&<> {t("queuedMessages",{count:computer.queuedRuns||0})}>} {computer.sharedInput||computer.controlHolder==="user"?void setControl("none",paneBot.id)}>{computer.sharedInput?t("doneContinue"):t("releaseAndContinue")} :void setControl("user",paneBot.id)}>{t("takeOverNow")} }
}{teaching&&active&& {t("teachingLive",{goal:teaching.goal})}{t("teachingHint")}{teaching.eventCount>0&&<> · {t("teachingCaptured",{count:teaching.eventCount})}>} void stopTeaching()}>{t("finishDemo")} void cancelTeaching()}>{t("cancel")}
}{drafting&&{t("distilling",{goal:drafting.goal})}
}{skillDraft&&active&&void saveSkill(skillDraft,name,playbook)} onTest={(name,playbook)=>void testSkill(skillDraft,name,playbook)} onDiscard={()=>void discardSkill(skillDraft)} onEdit={()=>setEditingSkillId(skillDraft.id)} onExport={(name,playbook)=>downloadSkill(name,skillDraft.goal,playbook)}/>}{Object.values(replyDrafts).filter(reply=>reply.text&&(!reply.messageId||!messages.some(message=>message.id===reply.messageId))).map(reply=>{const speaker=bots.find(bot=>bot.id===reply.botId);return {activeRoom&&speaker&&<>
{speaker.name} >}
})}
+ {(activeRoom||active)&&messages.length===0?
{activeRoom?
:
}{activeRoom?t("startRoomDiscussion",{name:activeRoom.name}):t("startBotWork",{name:active!.name})} {activeRoom?t("roomWillReply",{names:listJoin(activeRoom.members.map(member=>member.name))}):active!.description||t("botWelcome")}
:messages.map((message,index)=>{const spoken=message.role!=="user"&&Boolean(activeRoom);const speakerName=message.speakerName||(spoken?paneBot?.name:undefined);const speakerShape=(message.speakerShape||paneBot?.avatarShape||"blob") as AvatarShape;const files=messageFiles(message.blocks);const chips=chipBlocks(message.blocks);const hideBody=isAutoAttachCaption(message.body,files)||isAutoScheduleCaption(message.body,chips);const previous=index>0?messages[index-1]:null;const newDay=!previous||!sameDay(previous.createdAt,message.createdAt);return
{newDay&&}{spoken&&
}{spoken&&
{speakerName} }{files.length>0&&
{files.map(file=>)}
}{chips.map((chip,index)=>chip.kind==="error"?
{errorTitle(chip.code)}
{errorActions(chip.code).map(next=>next==="retry"?void retryRun(chip.runId)}>{retriedRuns[chip.runId||""]?t("errorRetried"):t("errorRetry")} :next==="screen"?void openLoginScreen()}>{t("loginOpenScreen")} :openAccount("model")}>{t("errorOpenSettings")} )}
:chip.kind==="resume"?
{resumeTitle(chip.reason)}
{(chip.limit||0)>0?
{t("resumeProgress",{turns:chip.turns||0,limit:chip.limit||0})}
:null}{resumedChips[message.id]||(message.seq??0)
void continueRun(message.id)}>{t("resumeContinue")} setResumedChips(current=>({...current,[message.id]:true}))}>{t("resumeStop")} }
:chip.kind==="login"?{t("loginNeedsYou")}
{chip.site||message.body}
{chip.why?
{t("loginWhy",{why:chip.why})}
:null}
void openLoginScreen()}>{t("loginOpenScreen")} :chip.kind==="schedule"?{t("scheduleChip")}
{chip.name} {scheduleWhen(chip.cron,chip.human)} :{t("scheduleRunChip")}
{chip.name} {scheduleWhen(chip.cron,chip.human)} )}{!hideBody&&(message.role==="assistant"?{message.body}
{message.body.trim()?
:null}{message.runId&& {t("messageRunDetails")} } :{message.body} )}{!hideBody&&message.body.trim()&&void rememberMessage(message)}> }{message.replyBots&&message.replyBots.length>0&&{message.role==="user"?t("routedTo",{names:listJoin(message.replyBots.map(reply=>reply.name))}):t("handedTo",{name:message.replyBots[0].name})}
} })}{pausedForUser&&paneBot&&{computer.sharedInput?t("sharedNeedsUser",{name:paneBot.name}):computer.controlHolder==="user"?t("pausedUserControl",{name:paneBot.name}):t("pausedNeedsUser",{name:paneBot.name})}{(computer.queuedRuns||0)>0&&<> {t("queuedMessages",{count:computer.queuedRuns||0})}>} {computer.sharedInput||computer.controlHolder==="user"?void setControl("none",paneBot.id)}>{computer.sharedInput?t("doneContinue"):t("releaseAndContinue")} :void setControl("user",paneBot.id)}>{t("takeOverNow")} }
}{teaching&&active&& {t("teachingLive",{goal:teaching.goal})}{t("teachingHint")}{teaching.eventCount>0&&<> · {t("teachingCaptured",{count:teaching.eventCount})}>} void stopTeaching()}>{t("finishDemo")} void cancelTeaching()}>{t("cancel")}
}{drafting&&{t("distilling",{goal:drafting.goal})}
}{skillDraft&&active&&void saveSkill(skillDraft,name,playbook)} onTest={(name,playbook)=>void testSkill(skillDraft,name,playbook)} onDiscard={()=>void discardSkill(skillDraft)} onEdit={()=>setEditingSkillId(skillDraft.id)} onExport={(name,playbook)=>downloadSkill(name,skillDraft.goal,playbook)}/>}{Object.values(replyDrafts).filter(reply=>reply.text&&(!reply.messageId||!messages.some(message=>message.id===reply.messageId))).map(reply=>{const speaker=bots.find(bot=>bot.id===reply.botId);return {activeRoom&&speaker&&<>
{speaker.name} >}
})}
{error&&
{error} setError(null)}>
}
{otherSessionBusy&&
{t("anotherConversationQueued")}
}
{statusMembers.map(member=>{const step=computer.busyStep&&member.id===computer.botId?computer.busyStep:null;const transition=isTransitionStep(step);const label=t("working",{name:member.name});return
{label} {!transition&&step?{localizeStep(step)} :null}})}
-
+
{event.preventDefault()}} onDrop={event=>{event.preventDefault();if(event.dataTransfer.files.length)addPendingFiles(event.dataTransfer.files)}}>event.stopPropagation()}>
setPlusOpen(v=>!v)}> {plusOpen&&
{setPlusOpen(false);attachRef.current?.click()}}> {t("attachFile")} {setPlusOpen(false);setTeachOpen(true)}}> {t("teachTask")} {setPlusOpen(false);importRef.current?.click()}}> {t("importSkill")} {savedSkills.length>0&&<>
{t("taughtSkills")}{savedSkills.length>5?` · ${savedSkills.length}`:""} {savedSkills.length>=6&&
setSkillQuery(e.target.value)} placeholder={t("searchSkills")} aria-label={t("searchSkills")} onClick={e=>e.stopPropagation()}/>}
{listedSkills.map(skill=>
runSkill(skill)}> {skill.name} downloadSkill(skill.name,skill.goal,skill.playbook)}> {setPlusOpen(false);setEditingSkillId(skill.id)}}> )}{listedSkills.length===0&&
{t("noMatchingSkills")} }
>}
}
{const file=event.target.files?.[0];event.currentTarget.value="";if(file)void importSkillFile(file)}}/> {const files=[...event.target.files||[]];event.currentTarget.value="";if(files.length)addPendingFiles(files)}}/>{pendingFiles.length>0&&{pendingFiles.map(item=>removePendingFile(item.id)}/>)}
}{slashSuggestions.length>0&&{slashSuggestions.map((skill,index)=>{setDraft(`/${skill.name} `);requestAnimationFrame(()=>document.querySelector(".composer textarea")?.focus())}}>/{skill.name} {skill.kind} {skill.description} )}
}{mentionList.length>0&&{mentionList.map((choice,index)=>
pickMention(choice)}>{choice.member&&}@{choice.name} {choice.member?null:{t("mentionEveryoneHint")} } )}
}{setDraft(e.target.value);setCaretAt(e.target.selectionStart??e.target.value.length)}} onSelect={e=>setCaretAt(e.currentTarget.selectionStart)} onKeyDown={composerKeyDown} onPaste={event=>{const files=event.clipboardData?.files;if(files&&files.length){event.preventDefault();addPendingFiles(files)}}} placeholder={teaching?t("teachingComposerHint"):activeSessionId&&chatName?t("messageTo",{name:chatName}):t("chooseConversationFirst")} disabled={!activeSessionId||Boolean(teaching)}/>{sessionBusy?void action(stopChat)}> : }
@@ -925,7 +954,7 @@ function SkillEditDialog({skill,busy,close,save,test,remove,exportFile}:{skill:T
}
function ClipboardDialog({close,paste}:{close:()=>void;paste:(text:string)=>void}){const[text,setText]=useState("");return
{t("pasteToRemoteComputer")} {t("pasteRemoteHelp")}
setText(e.target.value)} placeholder={t("pasteTextPlaceholder")}/>{t("cancel")} paste(text)}>{t("pasteIntoVnc")}
}
function CreateDialog({close,created}:{close:()=>void;created:(bot:Bot)=>void}){const[name,setName]=useState("");const[mode,setMode]=useState("team");const[busy,setBusy]=useState(false);return {e.preventDefault();if(!name.trim())return;setBusy(true);try{created(await api("/api/bots",{method:"POST",body:JSON.stringify({name:name.trim(),computerMode:mode})}))}finally{setBusy(false)}}}>
{t("addBot")} {t("name")} setName(e.target.value)} placeholder={t("botNamePlaceholder")}/> setMode("team")}>{t("sharedComputer")} {t("sharedComputerHint")} setMode("dedicated")}>{t("privateComputer")} {t("privateComputerHint")}
{t("cancel")} {t("create")}
}
-function CreateGroupDialog({bots,close,created}:{bots:Bot[];close:()=>void;created:(room:Room)=>void}){const[name,setName]=useState("");const[selected,setSelected]=useState([]);const[busy,setBusy]=useState(false);const visible=bots.filter(bot=>!bot.hidden);return }
+function CreateGroupDialog({bots,close,created}:{bots:Bot[];close:()=>void;created:(room:Room)=>void}){const[name,setName]=useState("");const[selected,setSelected]=useState([]);const[busy,setBusy]=useState(false);const visible=bots.filter(bot=>!bot.hidden);return }
function RoomContextMenu({context,close,onDelete}:{context:{room:Room;x:number;y:number};close:()=>void;onDelete:()=>void}){return e.stopPropagation()}> {t("deleteGroup")}
}
function ConfirmRoomDelete({room,close,confirm}:{room:Room;close:()=>void;confirm:()=>void}){return {t("deleteNamed",{name:room.name})} {t("deleteGroupDescription")}
{t("cancel")} {t("deleteGroup")}
}
function ConfirmDelete({bot,close,confirm}:{bot:Bot;close:()=>void;confirm:()=>void}){return {t("deleteNamed",{name:bot.name})} {bot.computerMode==="dedicated"?t("deleteDedicatedBotDescription"):t("deleteSharedBotDescription")}
{t("cancel")} {t("delete")}
}
diff --git a/apps/web/src/chat-time.ts b/apps/web/src/chat-time.ts
new file mode 100644
index 0000000..0f1b274
--- /dev/null
+++ b/apps/web/src/chat-time.ts
@@ -0,0 +1,54 @@
+/**
+ * How a chat shows when something was said: the day is written once, as a
+ * divider above the first message of that day, and each message carries only
+ * its clock time. A day is named the way people say it — 今天, 昨天 — and
+ * spelled out only when it is further away.
+ */
+
+export interface DayWords {
+ today: string;
+ yesterday: string;
+}
+
+/** Local calendar day, so two timestamps on the same date compare equal. */
+export function dayKey(value: string | Date): string {
+ const date = value instanceof Date ? value : new Date(value);
+ if (!Number.isFinite(date.getTime())) return "";
+ return `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`;
+}
+
+export function sameDay(a: string | Date, b: string | Date): boolean {
+ const keyA = dayKey(a);
+ return keyA !== "" && keyA === dayKey(b);
+}
+
+/** Whole local days between two moments; negative when `date` is in the future. */
+function daysBefore(date: Date, now: Date): number {
+ const start = (value: Date) => new Date(value.getFullYear(), value.getMonth(), value.getDate()).getTime();
+ return Math.round((start(now) - start(date)) / 86_400_000);
+}
+
+/**
+ * The divider text for a day: 今天 / 昨天, then a weekday for the past week
+ * (people remember "Wednesday" before "the 3rd"), then a short date, and the
+ * year only when it is not this one.
+ */
+export function dayLabel(value: string | Date, now: Date, locale: string, words: DayWords): string {
+ const date = value instanceof Date ? value : new Date(value);
+ if (!Number.isFinite(date.getTime())) return "";
+ const ago = daysBefore(date, now);
+ if (ago === 0) return words.today;
+ if (ago === 1) return words.yesterday;
+ if (ago > 1 && ago < 7) return date.toLocaleDateString(locale, { weekday: "long" });
+ if (date.getFullYear() === now.getFullYear()) {
+ return date.toLocaleDateString(locale, { month: "numeric", day: "numeric", weekday: "short" });
+ }
+ return date.toLocaleDateString(locale, { year: "numeric", month: "numeric", day: "numeric" });
+}
+
+/** The clock time a message shows next to itself; the day lives in the divider. */
+export function clockTime(value: string | Date, locale: string): string {
+ const date = value instanceof Date ? value : new Date(value);
+ if (!Number.isFinite(date.getTime())) return "";
+ return date.toLocaleTimeString(locale, { hour: "2-digit", minute: "2-digit", hour12: false });
+}
diff --git a/apps/web/src/chat.css b/apps/web/src/chat.css
index 7959880..ad3bc17 100644
--- a/apps/web/src/chat.css
+++ b/apps/web/src/chat.css
@@ -77,3 +77,31 @@
.message{padding-bottom:21px}
.message-time{position:absolute;bottom:0;left:0;font-size:11px;line-height:17px;color:var(--muted);font-variant-numeric:tabular-nums}
.message.user .message-time{left:auto;right:28px}
+
+/* The day is said once, centred above the first message of that day, so each
+ message only needs its clock time. */
+.day-divider{display:flex;justify-content:center;width:var(--chat-col);margin:6px auto -4px;user-select:none}
+.day-divider time{padding:3px 11px;border-radius:999px;background:rgba(255,255,255,.06);color:var(--muted);font-size:11px;line-height:16px;letter-spacing:.02em}
+
+/* Who the room sent a message to: one thin line in the space under the bubble,
+ opposite the timestamp, so it reads as a note about the message and never as
+ a second message. */
+.route-note{position:absolute;bottom:0;left:0;max-width:56%;overflow:hidden;color:var(--muted);font-size:11px;line-height:17px;opacity:.78;text-overflow:ellipsis;white-space:nowrap}
+.message.user .route-note{left:0;right:auto}
+.message.assistant .route-note{left:auto;right:28px;text-align:right}
+
+/* The `@` list sits where the slash list sits: only one of them is ever open. */
+.mention-suggestions button{align-items:center;gap:8px}
+.mention-suggestions strong{min-width:0}
+
+/* The host is a name in the top bar, not a page of settings. */
+.host-chip-wrap{position:relative;display:inline-flex;align-items:center}
+.host-chip{display:inline-flex;align-items:center;gap:5px;max-width:150px;padding:3px 9px;border:1px solid var(--border);border-radius:999px;background:transparent;color:var(--muted);font-size:11px;cursor:pointer}
+.host-chip:hover,.host-chip[aria-expanded="true"]{border-color:var(--accent);color:var(--ink)}
+.host-chip span{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
+.host-menu{position:absolute;top:calc(100% + 8px);left:0;z-index:9;display:grid;gap:2px;min-width:190px;padding:8px;border:1px solid var(--border);border-radius:14px;background:var(--menu);box-shadow:0 14px 34px rgba(0,0,0,.35)}
+.host-menu button{display:flex;align-items:center;gap:8px;padding:7px 9px;border:0;border-radius:9px;background:transparent;color:var(--ink);font-size:13px;text-align:left;cursor:pointer}
+.host-menu button:hover,.host-menu button:focus-visible{background:rgba(255,255,255,.08);outline:0}
+.host-menu button span{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
+.host-menu-label{padding:2px 9px 4px;color:var(--muted);font-size:11px}
+.host-flag{margin-left:auto;color:var(--accent);font-size:11px;font-weight:650}
diff --git a/apps/web/src/locales/en.ts b/apps/web/src/locales/en.ts
index 2988f6b..c954e13 100644
--- a/apps/web/src/locales/en.ts
+++ b/apps/web/src/locales/en.ts
@@ -56,7 +56,11 @@ export const en: { [K in keyof typeof zhTW]: string } = {
chooseBot: "Choose a bot",
startRoomDiscussion: "Start a discussion with {name}",
startBotWork: "Start working with {name}",
- roomWillReply: "{names} will all reply.",
+ roomWillReply: "{names} are here. Whoever is @-mentioned answers; otherwise the host, or the best fit, picks it up.",
+ everyoneMention: "everyone", mentionEveryoneHint: "every member answers", mentionList: "Members to mention",
+ routedTo: "{names} will answer this", handedTo: "→ handed to {name}",
+ today: "Today", yesterday: "Yesterday",
+ hostBadge: "Host", hostMenuLabel: "Who hosts", hostHint: "The host answers what nobody is named for. Tap to change it.",
botWelcome: "Send a message and it will get it done on its own computer.",
remembered: "Remembered",
remember: "Remember",
@@ -292,6 +296,7 @@ export const en: { [K in keyof typeof zhTW]: string } = {
privateComputerHint: "A fresh dedicated Docker desktop",
create: "Create",
groupDescription: "A group opens one chat where every selected agent speaks.",
+ groupHostHint: "{name} starts as host — one tap in the top bar swaps it.",
groupName: "Group name",
groupNamePlaceholder: "For example: product research",
chooseBots: "Choose bots (at least two)",
@@ -340,7 +345,7 @@ export const en: { [K in keyof typeof zhTW]: string } = {
helpBotsTitle: "Bots",
helpBots: "Use + at the top left to add a bot. Click the list to chat. Right-click to pin, hide, or delete.",
helpGroupsTitle: "Groups",
- helpGroups: "+ → New group, pick at least two. One message, every agent in the group replies.",
+ helpGroups: "+ → New group, pick at least two. @ a name and that agent answers; unaddressed messages go to the host or the best fit.",
helpComputerTitle: "Computer",
helpComputer: "The Computer tab on the right is this agent’s desktop. Start it, take over mouse and keyboard, or let it drive.",
helpMemoryTitle: "Memory",
diff --git a/apps/web/src/locales/zh-TW.ts b/apps/web/src/locales/zh-TW.ts
index 0ba970c..4d0df98 100644
--- a/apps/web/src/locales/zh-TW.ts
+++ b/apps/web/src/locales/zh-TW.ts
@@ -14,7 +14,11 @@ export const zhTW = {
unreadMessages: "{count} 則未讀訊息", members: "{count} 位成員", hideHiddenItems: "隱藏已隱藏項目", showHiddenItems: "顯示已隱藏項目",
mcpConnected: "{count} 個 MCP 已連線", connectMcpServer: "接入 MCP server",
openOnPhone: "在手機開啟", settings: "設定", about: "關於", helpCenter: "說明中心", sendFeedback: "傳送意見回饋", logout: "登出", workspaceMenu: "工作區選單",
- chooseBot: "選擇一個機器人", startRoomDiscussion: "和 {name} 開始討論", startBotWork: "和 {name} 開始工作", roomWillReply: "{names} 會一起回覆。",
+ chooseBot: "選擇一個機器人", startRoomDiscussion: "和 {name} 開始討論", startBotWork: "和 {name} 開始工作", roomWillReply: "{names} 都在這裡。@誰就由誰回覆,沒點名時由主持人或最合適的 Agent 接手。",
+ everyoneMention: "所有人", mentionEveryoneHint: "每個人都回覆", mentionList: "可點名的成員",
+ routedTo: "本輪由 {names} 回覆", handedTo: "→ 交給 {name}",
+ today: "今天", yesterday: "昨天",
+ hostBadge: "主持人", hostMenuLabel: "由誰主持", hostHint: "沒被點名的時候由主持人回答。點一下換人。",
botWelcome: "傳送訊息,讓它在自己的電腦上完成任務。", remembered: "已記住", remember: "記住", working: "{name} 正在工作…",
copyCode: "複製程式碼", copiedCode: "已複製", copyMessage: "複製", copiedMessage: "已複製",
anotherConversationQueued: "另一則對話正在執行,這則會排隊。",
@@ -93,7 +97,7 @@ export const zhTW = {
hudBooting: "電腦啟動中…", hudWaking: "喚醒中…", hudConnecting: "連線中…", hudHandoff: "換手中…",
pasteToRemoteComputer: "貼到遠端電腦", pasteRemoteHelp: "把外面的文字貼在這裡,再送進 VNC。這個方式在區網 HTTP 也能使用。", pasteTextPlaceholder: "在此貼上文字…", pasteIntoVnc: "貼入 VNC",
botNamePlaceholder: "例如:研究助理", sharedComputerHint: "與其他機器人共用環境", privateComputerHint: "全新的獨立 Docker", create: "建立",
- groupDescription: "拉進群組會開一個對話,選中的 Agent 都會在裡面發言。", groupName: "群組名稱", groupNamePlaceholder: "例如:產品研究", chooseBots: "選擇機器人(至少兩位)", creating: "建立中…", createGroup: "建立群組",
+ groupDescription: "拉進群組會開一個對話,選中的 Agent 都會在裡面發言。", groupHostHint: "第一位({name})先擔任主持人,以後在上方一點就能換。", groupName: "群組名稱", groupNamePlaceholder: "例如:產品研究", chooseBots: "選擇機器人(至少兩位)", creating: "建立中…", createGroup: "建立群組",
deleteGroup: "刪除群組", deleteNamed: "刪除 {name}?", deleteGroupDescription: "群組對話會刪除。裡面的機器人與他們自己的對話、記憶都會保留。", deleteDedicatedBotDescription: "對話、私人電腦與其中的檔案都會永久刪除。", deleteSharedBotDescription: "對話會刪除,但共用電腦與其中的檔案會保留。",
phoneAccessDescription: "同一區網的手機用瀏覽器打開這個網址,再用同一個存取 token 登入。", localAddressWarning: "這是本機位址,手機打不開。請改成這台電腦的區網 IP,例如 http://192.168.x.x:3101。",
close: "關閉", copied: "已複製", copyUrl: "複製網址", workspaceName: "工作區名稱", showHiddenBots: "顯示已隱藏的機器人", collapseRightSidebar: "收合右側欄",
@@ -113,7 +117,7 @@ export const zhTW = {
workspaceModelHint: "先選供應商,再填金鑰與模型。OpenAI 相容需要自己填端點。",
aboutDescription: "本機多 Agent 工作區。每個機器人有自己的 Linux 電腦,也可以拉進群組一起討論,並接入 MCP 工具。",
apiStatus: "API 狀態:{status}", statusNormal: "正常", statusUnavailable: "無法連線", statusChecking: "檢查中…",
- helpBotsTitle: "機器人", helpBots: "左上角 + 新增機器人。點左側列進入對話。右鍵可以釘選、隱藏或刪除。", helpGroupsTitle: "群組", helpGroups: "+ → 新增群組,選至少兩位。傳一句話,裡面的 Agent 都會回。",
+ helpBotsTitle: "機器人", helpBots: "左上角 + 新增機器人。點左側列進入對話。右鍵可以釘選、隱藏或刪除。", helpGroupsTitle: "群組", helpGroups: "+ → 新增群組,選至少兩位。@誰就由誰回;沒點名時,主持人或最合適的 Agent 會接手。",
helpComputerTitle: "電腦", helpComputer: "右側「電腦」是這個 Agent 的獨立桌面。可以啟動、接管滑鼠鍵盤,或讓它自己操作。", helpMemoryTitle: "記憶", helpMemory: "清除對話不會刪長期記憶。可以叫 Agent 記住,或在右側「記憶」手動新增。",
helpMcpTitle: "MCP 外掛", helpMcp: "左下「外掛程式」接入 MCP server。連上的工具會顯示在畫面上,對話時 Agent 可以使用。",
helpSkillsTitle: "技能", helpSkills: "+ → 教它一項任務,示範一次就會整理成技能。示範結束後可以匯出 JSON,或把別人的技能檔匯入,換一個機器人也適用。",
diff --git a/apps/web/src/mentions.ts b/apps/web/src/mentions.ts
new file mode 100644
index 0000000..6e3dc16
--- /dev/null
+++ b/apps/web/src/mentions.ts
@@ -0,0 +1,56 @@
+import type { RoomMember } from "./types";
+
+/** One row of the `@` list. A null `member` is the whole-room escape hatch. */
+export interface MentionChoice {
+ name: string;
+ member: RoomMember | null;
+}
+
+/**
+ * The `@`-token under the caret, or null when the caret is not writing one.
+ * A token ends at a space, so `@小美 幫我看` stops offering the list the moment
+ * the name is finished, and `mail@example.com` never opens it.
+ */
+export function mentionToken(text: string, caret: number): string | null {
+ const end = Math.max(0, Math.min(caret, text.length));
+ const hit = /(?:^|\s)@([^\s@]*)$/.exec(text.slice(0, end));
+ return hit ? hit[1] : null;
+}
+
+/**
+ * Who the token could mean, in room order, capped so the list stays one glance.
+ * `everyone` — the one name that reaches the whole room — leads the list while
+ * the token is empty or could still become it, because typing `@` is where a
+ * person discovers that escape hatch.
+ */
+export function mentionChoices(
+ token: string,
+ members: RoomMember[],
+ everyone: string,
+): MentionChoice[] {
+ const needle = token.trim().toLowerCase();
+ const choices: MentionChoice[] = [];
+ if (everyone.toLowerCase().startsWith(needle)) {
+ choices.push({ name: everyone, member: null });
+ }
+ for (const member of members) {
+ if (member.name.toLowerCase().includes(needle)) choices.push({ name: member.name, member });
+ }
+ return choices.slice(0, 6);
+}
+
+/**
+ * Replace the token being typed with a chosen name and one space, leaving the
+ * rest of the message where it was. The new caret sits after that space, so the
+ * next keystroke continues the sentence instead of reopening the list.
+ */
+export function acceptMention(
+ text: string,
+ caret: number,
+ name: string,
+): { text: string; caret: number } {
+ const end = Math.max(0, Math.min(caret, text.length));
+ const head = text.slice(0, end).replace(/@([^\s@]*)$/, "");
+ const inserted = `${head}@${name} `;
+ return { text: inserted + text.slice(end), caret: inserted.length };
+}
diff --git a/apps/web/src/refinements.css b/apps/web/src/refinements.css
index 1d92596..c8bad2e 100644
--- a/apps/web/src/refinements.css
+++ b/apps/web/src/refinements.css
@@ -620,6 +620,8 @@
.dialog-lead{margin:0;color:var(--muted);line-height:1.5;font-size:13px}
+/* One quiet sentence under a form: what will happen by default, so the human has nothing to configure. */
+.dialog-note{margin:-4px 0 0;color:var(--muted);font-size:12px;line-height:1.5}
@keyframes computer-hud-bob{0%,100%{transform:translateY(0) rotate(-4deg)}50%{transform:translateY(-3px) rotate(5deg)}}
diff --git a/apps/web/src/responsive.css b/apps/web/src/responsive.css
index dddc302..fcf6e88 100644
--- a/apps/web/src/responsive.css
+++ b/apps/web/src/responsive.css
@@ -2,7 +2,7 @@
@media(max-width:700px){.app-shell{display:block}.sidebar{position:fixed;z-index:40;inset:0 auto 0 0;width:min(300px,88vw);transform:translateX(-105%);transition:.2s;box-shadow:20px 0 60px #000}.sidebar.open{transform:none}.chat-panel{height:100%}.mobile-menu{display:inline-flex}.topbar{padding:0 12px}.messages{padding:24px 18px 16px}.composer{left:12px;right:12px}.computer-overlay>header{height:auto;min-height:64px;flex-wrap:wrap;padding:10px}.computer-overlay>header>div:last-child{flex-wrap:wrap;justify-content:flex-end}.overlay-screen{padding:8px}.mode-grid{grid-template-columns:1fr}}
@media(max-width:1200px){.app-shell{grid-template-columns:230px minmax(0,1fr) 330px}}
@media(max-width:1050px){.app-shell{grid-template-columns:250px minmax(0,1fr)}}
-@media(max-width:700px){.chat-panel{--chat-gutter:18px}.app-shell{display:block}.message{width:100%}.message>span,.message>.message-body,.message-stack{max-width:90%}.composer-dock{padding:20px var(--chat-gutter) 16px}.composer{width:var(--chat-col);min-height:60px}.composer-files{padding:2px 4px 8px 8px}.file-card{max-width:100%;height:52px}.file-card-remove{flex-basis:32px;width:32px;height:32px}.message.with-files .msg-attachments{max-width:100%}.messages{padding-bottom:16px}}
+@media(max-width:700px){.chat-panel{--chat-gutter:18px}.app-shell{display:block}.message{width:100%}.day-divider{width:100%}.message>span,.message>.message-body,.message-stack{max-width:90%}.composer-dock{padding:20px var(--chat-gutter) 16px}.composer{width:var(--chat-col);min-height:60px}.composer-files{padding:2px 4px 8px 8px}.file-card{max-width:100%;height:52px}.file-card-remove{flex-basis:32px;width:32px;height:32px}.message.with-files .msg-attachments{max-width:100%}.messages{padding-bottom:16px}}
@media(prefers-reduced-motion:reduce){.avatar.blobatar.thinking:before,.avatar.blobatar.thinking:after,.thinking-dots i{animation:none!important}}
@media(max-width:1200px){.app-shell.right-open{grid-template-columns:230px minmax(0,1fr) 340px}.app-shell.right-collapsed{grid-template-columns:230px minmax(0,1fr) 52px}}
@media(max-width:1050px){
diff --git a/apps/web/src/types.ts b/apps/web/src/types.ts
index f9db9aa..dfef92d 100644
--- a/apps/web/src/types.ts
+++ b/apps/web/src/types.ts
@@ -5,10 +5,10 @@ export type BlobatarShape = "round"|"organic"|"boxy"|"capsule"|"nub"|"cloud"|"dr
export type AvatarShape = BlobatarShape|"blob"|"squircle"|"diamond"|"drop"|"organic-4"|"organic-5"|"organic-6"|"organic-7"|"organic-8"|"organic-9"|"organic-10"|"organic-11"|"cat"|"bunny"|"star"|"heart"|"egg"|"ghost"|"sprout"|"cactus"|"mushroom"|"paw";
export interface Bot { id:string; spaceId:string; name:string; title:string; description:string; avatarColor:string; avatarShape:AvatarShape; tags:string[]; pinned:boolean; hidden:boolean; groupName:string|null; unreadCount:number; lastMessageAt:string|null; instructions:string; threadId:string; computerId:string; computerMode:ComputerMode; memoryEnabled:boolean }
export interface Session { id:string; botId:string; title:string; status:"active"|"archived"; createdAt:string; updatedAt:string; nextMessageSeq:number; historySummary:string; historySummarySeq:number }
-export interface Message { id:string; sessionId?:string; seq?:number; role:string; body:string; blocks?:unknown[]; runId?:string|null; clientNonce?:string|null; createdAt:string; speakerBotId?:string|null; speakerName?:string|null; speakerColor?:string|null; speakerShape?:AvatarShape|null }
+export interface Message { id:string; sessionId?:string; seq?:number; role:string; body:string; blocks?:unknown[]; runId?:string|null; clientNonce?:string|null; createdAt:string; speakerBotId?:string|null; speakerName?:string|null; speakerColor?:string|null; speakerShape?:AvatarShape|null; replyBots?:RoomMember[] }
export interface MessageFile { kind:"image"|"file"; name:string; mimeType?:string; size?:number }
export interface RoomMember { id:string; name:string; avatarColor:string; avatarShape:AvatarShape }
-export interface Room { id:string; name:string; members:RoomMember[]; lastMessageAt:string|null; lastPreview:string|null; unreadCount:number }
+export interface Room { id:string; name:string; members:RoomMember[]; hostBotId?:string|null; lastMessageAt:string|null; lastPreview:string|null; unreadCount:number }
export interface ComputerStatus { botId:string; mode:ComputerMode; state:ComputerState; sharedInput?:boolean; controlHolder:"none"|"bot"|"user"; takeoverRequested:boolean; busyBotName:string|null; busySessionId:string|null; busyRunId:string|null; busyStep?:string|null; usingComputer?:boolean; waitingRunId?:string|null; waitingSessionId?:string|null; queuedRuns?:number; display:string|null; profileMode:string; screenAvailable:boolean }
/** One line of the live trail a run writes while it works. */
export type RunActivityKind = "run"|"model"|"tool"|"retry"|"notice"|"memory";
diff --git a/crates/api/src/main.rs b/crates/api/src/main.rs
index 208de0e..a1b6da3 100644
--- a/crates/api/src/main.rs
+++ b/crates/api/src/main.rs
@@ -10,6 +10,7 @@ mod monitor;
mod retention;
mod rooms;
mod routes;
+mod routing;
mod runs;
mod schedules;
mod screen_proxy;
diff --git a/crates/api/src/memory.rs b/crates/api/src/memory.rs
index 2e6a733..3b42f34 100644
--- a/crates/api/src/memory.rs
+++ b/crates/api/src/memory.rs
@@ -1280,4 +1280,91 @@ mod tests {
.id
);
}
+
+ /// A conversation that holds remembered lines can still be removed: the
+ /// memory survives, pointing at nothing, and the guard keeps rejecting a
+ /// genuine move into another agent's conversation.
+ #[sqlx::test(migrations = "../../migrations")]
+ async fn deleting_a_conversation_keeps_its_memories_and_the_guard(pool: sqlx::PgPool) {
+ sqlx::query("INSERT INTO users(id,name) VALUES ('u','test')")
+ .execute(&pool)
+ .await
+ .unwrap();
+ sqlx::query("INSERT INTO spaces(id,user_id,name) VALUES ('s','u','test')")
+ .execute(&pool)
+ .await
+ .unwrap();
+ for bot in ["a", "b"] {
+ sqlx::query("INSERT INTO bots(id,space_id,user_id,name) VALUES ($1,'s','u',$1)")
+ .bind(bot)
+ .execute(&pool)
+ .await
+ .unwrap();
+ sqlx::query("INSERT INTO threads(id,space_id,user_id,bot_id) VALUES ($1,'s','u',$2)")
+ .bind(format!("thread-{bot}"))
+ .bind(bot)
+ .execute(&pool)
+ .await
+ .unwrap();
+ }
+ sqlx::query(
+ "INSERT INTO runs(id,space_id,user_id,bot_id,thread_id,status,prompt)
+ VALUES ('run-a','s','u','a','thread-a','completed','hi')",
+ )
+ .execute(&pool)
+ .await
+ .unwrap();
+ sqlx::query(
+ "INSERT INTO messages(id,thread_id,seq,role,body,run_id)
+ VALUES ('msg-a','thread-a',1,'user','remember this','run-a')",
+ )
+ .execute(&pool)
+ .await
+ .unwrap();
+ // One saved from the chat (message + session), one by the remember tool
+ // (run + session): both link into the conversation being removed.
+ let from_chat = Uuid::new_v4();
+ let from_tool = Uuid::new_v4();
+ sqlx::query(
+ "INSERT INTO memory_items(id,space_id,user_id,bot_id,session_id,source_run_id,source_message_id,content)
+ VALUES ($1,'s','u','a','thread-a',NULL,'msg-a','saved from chat'),
+ ($2,'s','u','a','thread-a','run-a',NULL,'saved by tool')",
+ )
+ .bind(from_chat)
+ .bind(from_tool)
+ .execute(&pool)
+ .await
+ .unwrap();
+
+ sqlx::query("DELETE FROM threads WHERE id='thread-a'")
+ .execute(&pool)
+ .await
+ .expect("a conversation with remembered lines can be deleted");
+ let left: Vec<(Option, Option, Option)> = sqlx::query_as(
+ "SELECT session_id, source_run_id, source_message_id FROM memory_items
+ WHERE bot_id='a' ORDER BY content",
+ )
+ .fetch_all(&pool)
+ .await
+ .unwrap();
+ assert_eq!(left, vec![(None, None, None), (None, None, None)]);
+
+ // The guard still holds: memory cannot be pointed at another agent's
+ // conversation after the fact.
+ let moved = sqlx::query("UPDATE memory_items SET session_id='thread-b' WHERE id=$1")
+ .bind(from_chat)
+ .execute(&pool)
+ .await;
+ assert!(
+ moved.is_err(),
+ "re-homing into another agent's thread must fail"
+ );
+ let kept: i64 = sqlx::query_scalar(
+ "SELECT count(*) FROM memory_items WHERE bot_id='a' AND session_id IS NULL",
+ )
+ .fetch_one(&pool)
+ .await
+ .unwrap();
+ assert_eq!(kept, 2);
+ }
}
diff --git a/crates/api/src/rooms.rs b/crates/api/src/rooms.rs
index 149f99a..42e3586 100644
--- a/crates/api/src/rooms.rs
+++ b/crates/api/src/rooms.rs
@@ -5,7 +5,7 @@ use axum::http::StatusCode;
use axum::routing::get;
use axum::{Json, Router};
use lazyboy_contracts::{
- CreateRoomInput, CreateSessionInput, Room, RoomMember, RoomStatus, Session,
+ CreateRoomInput, CreateSessionInput, Room, RoomMember, RoomStatus, Session, UpdateRoomInput,
};
use serde_json::{Value, json};
use uuid::Uuid;
@@ -19,7 +19,10 @@ type ApiError = (StatusCode, Json);
pub fn router() -> Router {
Router::new()
.route("/api/rooms", get(list_rooms).post(create_room))
- .route("/api/rooms/{id}", get(get_room).delete(delete_room))
+ .route(
+ "/api/rooms/{id}",
+ get(get_room).patch(update_room).delete(delete_room),
+ )
.route(
"/api/rooms/{id}/sessions",
get(list_sessions).post(create_session),
@@ -64,10 +67,12 @@ async fn members_for(state: &AppState, room_id: &str) -> Result,
Ok(rows.into_iter().map(member_from_row).collect())
}
-/// `room_from_id` projection: id, name, last message time, preview, unread count.
+/// `room_from_id` projection: id, name, host, last message time, preview, unread
+/// count.
type RoomSummaryRow = (
String,
String,
+ Option,
Option>,
Option,
i64,
@@ -79,7 +84,7 @@ async fn room_from_id(
id: &str,
) -> Result, sqlx::Error> {
let row: Option = sqlx::query_as(
- "SELECT r.id, r.name,
+ "SELECT r.id, r.name, r.host_bot_id,
(SELECT MAX(m.created_at) FROM messages m JOIN threads t ON t.id=m.thread_id WHERE t.room_id=r.id),
(SELECT m.body FROM messages m JOIN threads t ON t.id=m.thread_id
WHERE t.room_id=r.id ORDER BY m.created_at DESC, m.seq DESC LIMIT 1),
@@ -96,13 +101,14 @@ async fn room_from_id(
.bind(&actor.user_id)
.fetch_optional(state.pool())
.await?;
- let Some((id, name, last_message_at, last_preview, unread_count)) = row else {
+ let Some((id, name, host_bot_id, last_message_at, last_preview, unread_count)) = row else {
return Ok(None);
};
Ok(Some(Room {
members: members_for(state, &id).await?,
id,
name,
+ host_bot_id,
last_message_at,
last_preview,
unread_count,
@@ -149,6 +155,15 @@ async fn create_room(
Json(json!({"message":"群組需要名稱,並至少兩位機器人"})),
));
}
+ let host_bot_id = input.host_bot_id;
+ if let Some(host) = host_bot_id.as_deref()
+ && !member_ids.iter().any(|member| member.as_str() == host)
+ {
+ return Err((
+ StatusCode::BAD_REQUEST,
+ Json(json!({"message":"主持人必須是群組成員"})),
+ ));
+ }
let mut members = Vec::new();
for bot_id in &member_ids {
let exists: Option<(String, String, String, String)> = sqlx::query_as(
@@ -170,17 +185,20 @@ async fn create_room(
members.push(member_from_row(row));
}
let room_id = Uuid::new_v4().to_string();
- let host_id = members[0].id.clone();
+ // The host is decided once, here: the member the human chose, or simply the
+ // first one. Starting a group needs no other setting.
+ let host_id = host_bot_id.unwrap_or_else(|| members[0].id.clone());
let mut tx = state
.pool()
.begin()
.await
.map_err(|error| internal(error.to_string()))?;
- sqlx::query("INSERT INTO rooms (id,space_id,user_id,name) VALUES ($1,$2,$3,$4)")
+ sqlx::query("INSERT INTO rooms (id,space_id,user_id,name,host_bot_id) VALUES ($1,$2,$3,$4,$5)")
.bind(&room_id)
.bind(&actor.space_id)
.bind(&actor.user_id)
.bind(name)
+ .bind(&host_id)
.execute(&mut *tx)
.await
.map_err(|error| internal(error.to_string()))?;
@@ -213,6 +231,7 @@ async fn create_room(
id: room_id,
name: name.into(),
members,
+ host_bot_id: Some(host_id),
last_message_at: None,
last_preview: None,
unread_count: 0,
@@ -258,6 +277,59 @@ async fn delete_room(
Ok(StatusCode::NO_CONTENT)
}
+/// Change who leads the room. This is the only room setting that exists, and it
+/// is reached by one tap on a member — there is no settings page to open.
+async fn update_room(
+ State(state): State,
+ Path(id): Path,
+ Json(input): Json,
+) -> Result, ApiError> {
+ let actor = actor(&state).await?;
+ let current = room_from_id(&state, &actor, &id)
+ .await
+ .map_err(|error| internal(error.to_string()))?
+ .ok_or_else(|| {
+ (
+ StatusCode::NOT_FOUND,
+ Json(json!({"message":"group not found"})),
+ )
+ })?;
+ let Some(host_bot_id) = input.host_bot_id else {
+ return Ok(Json(current));
+ };
+ if !current
+ .members
+ .iter()
+ .any(|member| member.id == host_bot_id)
+ {
+ return Err((
+ StatusCode::BAD_REQUEST,
+ Json(json!({"message":"主持人必須是群組成員"})),
+ ));
+ }
+ let updated = sqlx::query(
+ "UPDATE rooms SET host_bot_id=$2, updated_at=now()
+ WHERE id=$1 AND space_id=$3 AND user_id=$4",
+ )
+ .bind(&id)
+ .bind(&host_bot_id)
+ .bind(&actor.space_id)
+ .bind(&actor.user_id)
+ .execute(state.pool())
+ .await
+ .map_err(|error| internal(error.to_string()))?;
+ if updated.rows_affected() == 0 {
+ return Err((
+ StatusCode::NOT_FOUND,
+ Json(json!({"message":"group not found"})),
+ ));
+ }
+ room_from_id(&state, &actor, &id)
+ .await
+ .map(|room| Json(room.unwrap_or(current)))
+ .map_err(|error| internal(error.to_string()))
+}
+
async fn list_sessions(
State(state): State,
Path(id): Path,
diff --git a/crates/api/src/routing.rs b/crates/api/src/routing.rs
new file mode 100644
index 0000000..c4be915
--- /dev/null
+++ b/crates/api/src/routing.rs
@@ -0,0 +1,1047 @@
+//! Who is allowed to answer a group message.
+//!
+//! A room used to wake every member for every message, so a group of four paid
+//! for four model calls (and four desktop claims) to get one useful answer. The
+//! audience is now decided once, when the message arrives: an `@name` is law,
+//! and without one a single short model call picks the members whose role fits
+//! the ask. When nothing fits, the host answers — a message is never left with
+//! nobody to read it, because a silently dropped message is worse than one
+//! wasted reply.
+
+use std::time::Duration;
+
+use lazyboy_contracts::ModelProvider;
+use lazyboy_harness::{
+ CredentialChain, DynModel, ResolveModelRequest, connect_model, credential_from_env,
+ resolve_backend,
+};
+use rig_core::completion::message::{AssistantContent, Message, UserContent};
+
+use crate::db::Actor;
+use crate::state::AppState;
+
+/// The picker is a nicety, not a gate: past this the host takes over, so a slow
+/// helper never holds up a chat message.
+const ROUTER_TIMEOUT: Duration = Duration::from_millis(1200);
+/// How many members one unprefixed message may wake.
+const ROUTER_CAP: usize = 3;
+/// Recent lines and role text handed to the picker.
+const ROUTER_HISTORY: i64 = 6;
+const FIELD_CHARS: usize = 100;
+const LINE_CHARS: usize = 200;
+/// `@所有人` and its spellings: everybody, and no model call at all. The web
+/// composer offers the escape hatch in whatever language the screen is in, so
+/// every spelling it can insert has to be understood here too.
+const ALL_KEYWORDS: [&str; 5] = ["所有人", "全部", "all", "everyone", "everybody"];
+
+const PICKER_SYSTEM: &str = "You decide which members of a group chat should answer the newest message.
+
+Reply with names from the roster only, separated by 、, at most three of them. Choose a member when the message falls inside what that member does. Reply NONE when no roster member fits, and add nothing else.
+Never invent a name, never explain your choice, and never answer the message yourself.";
+
+#[derive(Debug, Clone, PartialEq, Eq)]
+pub struct Member {
+ pub id: String,
+ pub name: String,
+ /// What this member says it does (title + description). Picker input only;
+ /// empty is fine.
+ pub role: String,
+}
+
+#[derive(Debug, Clone, Default, PartialEq, Eq)]
+pub struct Mentions {
+ /// `@所有人` appeared.
+ pub all: bool,
+ /// Member ids in the order they were named.
+ pub ids: Vec,
+}
+
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub enum Reason {
+ All,
+ Mention,
+ Routed,
+ Host,
+}
+
+#[derive(Debug, Clone, PartialEq, Eq)]
+pub struct Audience {
+ pub targets: Vec,
+ pub reason: Reason,
+}
+
+/// A room reduced to what routing needs: who leads it and who is in it.
+#[derive(Debug, Clone, PartialEq, Eq)]
+pub struct Room {
+ pub id: String,
+ pub host_id: String,
+ pub members: Vec,
+}
+
+/// Names written as `@名字`, longest name first so a short member cannot steal a
+/// longer member's mention.
+pub fn parse_mentions(text: &str, members: &[Member]) -> Mentions {
+ let mut mentions = Mentions::default();
+ let chars: Vec = text.chars().collect();
+ for (position, ch) in chars.iter().enumerate() {
+ // `mail@example.com` is not a mention: `@` has to open a word.
+ if *ch != '@' || (position > 0 && chars[position - 1].is_alphanumeric()) {
+ continue;
+ }
+ let tail: String = chars[position + 1..].iter().collect();
+ if ALL_KEYWORDS.iter().any(|word| name_hit(&tail, word)) {
+ mentions.all = true;
+ continue;
+ }
+ if let Some(id) = find_names(&tail, members, true).into_iter().next()
+ && !mentions.ids.contains(&id)
+ {
+ mentions.ids.push(id);
+ }
+ }
+ mentions
+}
+
+/// Names of roster members that appear in `text`, in order of appearance.
+/// `anchored` accepts a name only at the very start of `text`, which is what a
+/// mention needs after the `@`.
+fn find_names(text: &str, members: &[Member], anchored: bool) -> Vec {
+ let mut ranked: Vec<&Member> = members
+ .iter()
+ .filter(|member| !member.name.trim().is_empty())
+ .collect();
+ ranked.sort_by_key(|member| std::cmp::Reverse(member.name.chars().count()));
+ let chars: Vec = text.chars().collect();
+ let mut ids: Vec = Vec::new();
+ let mut position = 0usize;
+ while position < chars.len() {
+ let tail: String = chars[position..].iter().collect();
+ if let Some(member) = ranked.iter().find(|member| name_hit(&tail, &member.name))
+ && !ids.contains(&member.id)
+ {
+ ids.push(member.id.clone());
+ }
+ if anchored {
+ break;
+ }
+ position += 1;
+ }
+ ids
+}
+
+/// Does `tail` open with `name`? ASCII names need a word boundary after them so
+/// `@Ali` cannot pick "Alice"; CJK names run together, so the longest match is
+/// already the boundary.
+fn name_hit(tail: &str, name: &str) -> bool {
+ let lowered = tail.to_lowercase();
+ let needle = name.trim().to_lowercase();
+ if needle.is_empty() || !lowered.starts_with(&needle) {
+ return false;
+ }
+ if !needle
+ .chars()
+ .next_back()
+ .is_some_and(|last| last.is_ascii_alphanumeric())
+ {
+ return true;
+ }
+ match lowered.chars().nth(needle.chars().count()) {
+ None => true,
+ Some(next) => !(next.is_ascii_alphanumeric() || next == '-' || next == '_'),
+ }
+}
+
+/// The picker's answer reduced to roster ids. It may write "阿明、小美", a JSON
+/// array, or prose naming people; anything outside the roster is dropped.
+pub fn parse_router_reply(raw: &str, members: &[Member]) -> Vec {
+ let mut picked = find_names(raw, members, false);
+ picked.truncate(ROUTER_CAP);
+ picked
+}
+
+/// Who should run for one message: a name is law, `@所有人` is everybody, and
+/// only an unaddressed message consults the picker.
+pub fn resolve_audience(
+ members: &[Member],
+ mentions: &Mentions,
+ host_id: &str,
+ busy: &[String],
+ routed: &[String],
+) -> Audience {
+ let roster: Vec<&String> = members.iter().map(|member| &member.id).collect();
+ if mentions.all {
+ return Audience {
+ targets: roster.into_iter().cloned().collect(),
+ reason: Reason::All,
+ };
+ }
+ let named: Vec = mentions
+ .ids
+ .iter()
+ .filter(|id| roster.contains(id))
+ .cloned()
+ .collect();
+ if !named.is_empty() {
+ return Audience {
+ targets: named,
+ reason: Reason::Mention,
+ };
+ }
+ let chosen: Vec = routed
+ .iter()
+ .filter(|id| roster.contains(id) && !busy.contains(id))
+ .cloned()
+ .collect();
+ if !chosen.is_empty() {
+ return Audience {
+ targets: chosen,
+ reason: Reason::Routed,
+ };
+ }
+ // Never zero: the host picks up what nobody was chosen for.
+ Audience {
+ targets: vec![host_id.to_string()],
+ reason: Reason::Host,
+ }
+}
+
+/// The room a thread belongs to, or `None` for a one-to-one conversation.
+pub(crate) async fn room_for_thread(
+ state: &AppState,
+ thread_id: &str,
+) -> Result, String> {
+ // The column is nullable and the row may be missing: both read as "not a
+ // room", so the outer `Option` (no row) and the inner one (NULL) are
+ // flattened together. Decoding the column straight into `String` made every
+ // one-to-one message fail with an "unexpected null".
+ let room_id: Option > =
+ sqlx::query_scalar("SELECT room_id FROM threads WHERE id=$1")
+ .bind(thread_id)
+ .fetch_optional(state.pool())
+ .await
+ .map_err(|error| error.to_string())?;
+ let Some(room_id) = room_id.flatten() else {
+ return Ok(None);
+ };
+ let rows: Vec<(String, String, String, String)> = sqlx::query_as(
+ "SELECT b.id, b.name, b.title, b.description
+ FROM room_members m JOIN bots b ON b.id=m.bot_id
+ WHERE m.room_id=$1
+ ORDER BY m.created_at, b.name",
+ )
+ .bind(&room_id)
+ .fetch_all(state.pool())
+ .await
+ .map_err(|error| error.to_string())?;
+ if rows.is_empty() {
+ return Ok(None);
+ }
+ let members: Vec = rows
+ .into_iter()
+ .map(|(id, name, title, description)| Member {
+ role: format!("{title} {description}").trim().to_string(),
+ id,
+ name,
+ })
+ .collect();
+ let host: Option> =
+ sqlx::query_scalar("SELECT host_bot_id FROM rooms WHERE id=$1")
+ .bind(&room_id)
+ .fetch_optional(state.pool())
+ .await
+ .map_err(|error| error.to_string())?;
+ // A deleted host, or a room written before this column existed, falls back
+ // to the first member — who is the one that used to answer anyway.
+ let host_id = host
+ .flatten()
+ .filter(|host| members.iter().any(|member| member.id == *host))
+ .unwrap_or_else(|| members[0].id.clone());
+ Ok(Some(Room {
+ id: room_id,
+ host_id,
+ members,
+ }))
+}
+
+/// Members of `room` that already have a run of their own in flight.
+pub(crate) async fn busy_members(state: &AppState, room: &Room) -> Result, String> {
+ let roster: Vec = room
+ .members
+ .iter()
+ .map(|member| member.id.clone())
+ .collect();
+ let busy: Vec = sqlx::query_scalar(
+ "SELECT DISTINCT bot_id FROM runs
+ WHERE bot_id = ANY($1)
+ AND status IN ('queued','leased','running','waiting_input','waiting_takeover')",
+ )
+ .bind(&roster)
+ .fetch_all(state.pool())
+ .await
+ .map_err(|error| error.to_string())?;
+ Ok(busy)
+}
+
+/// Decide the audience for a message that has not been written yet. The model
+/// call happens outside the message transaction, so a slow picker never holds a
+/// row lock, and every failure path lands on the host.
+pub(crate) async fn audience_for(
+ state: &AppState,
+ actor: &Actor,
+ room: &Room,
+ thread_id: &str,
+ text: &str,
+) -> Audience {
+ let mentions = parse_mentions(text, &room.members);
+ let decided = resolve_audience(&room.members, &mentions, &room.host_id, &[], &[]);
+ if decided.reason != Reason::Host {
+ log(room, thread_id, &decided);
+ return decided;
+ }
+ let busy = busy_members(state, room).await.unwrap_or_default();
+ // Two members need no referee: the host answers, and naming the other one
+ // is free.
+ let routed = if room.members.len() > 2 {
+ pick(state, actor, room, thread_id, text).await
+ } else {
+ Vec::new()
+ };
+ let decided = resolve_audience(&room.members, &mentions, &room.host_id, &busy, &routed);
+ log(room, thread_id, &decided);
+ decided
+}
+
+fn log(room: &Room, thread_id: &str, audience: &Audience) {
+ tracing::info!(
+ room = room.id,
+ thread = thread_id,
+ reason = reason_label(audience.reason),
+ targets = ?audience.targets,
+ "room routing"
+ );
+}
+
+pub fn reason_label(reason: Reason) -> &'static str {
+ match reason {
+ Reason::All => "all",
+ Reason::Mention => "mention",
+ Reason::Routed => "routed",
+ Reason::Host => "host",
+ }
+}
+
+/// One short model call: which names fit this message?
+async fn pick(
+ state: &AppState,
+ actor: &Actor,
+ room: &Room,
+ thread_id: &str,
+ text: &str,
+) -> Vec {
+ let model = match router_model(state, actor).await {
+ Ok(model) => model,
+ Err(error) => {
+ tracing::warn!("room router unavailable: {error}");
+ return Vec::new();
+ }
+ };
+ let prompt = match prompt_for(state, room, thread_id, text).await {
+ Ok(prompt) => prompt,
+ Err(error) => {
+ tracing::warn!("room router prompt: {error}");
+ return Vec::new();
+ }
+ };
+ let attempt = tokio::time::timeout(
+ ROUTER_TIMEOUT,
+ crate::runs::complete_once(
+ &model,
+ Message::User {
+ content: vec![UserContent::text(prompt)],
+ },
+ PICKER_SYSTEM,
+ &[],
+ &[],
+ ),
+ )
+ .await;
+ let raw = match attempt {
+ Ok(Ok(parts)) => parts
+ .into_iter()
+ .filter_map(|part| match part {
+ AssistantContent::Text(text) => Some(text.text),
+ _ => None,
+ })
+ .collect::>()
+ .join(" "),
+ Ok(Err(error)) => {
+ tracing::warn!("room router call: {error}");
+ return Vec::new();
+ }
+ Err(_) => {
+ tracing::warn!("room router timed out; the host answers");
+ return Vec::new();
+ }
+ };
+ parse_router_reply(&raw, &room.members)
+}
+
+async fn prompt_for(
+ state: &AppState,
+ room: &Room,
+ thread_id: &str,
+ text: &str,
+) -> Result {
+ let recent: Vec<(String, String)> = sqlx::query_as(
+ "SELECT COALESCE(b.name, '你') AS speaker, m.body
+ FROM messages m LEFT JOIN bots b ON b.id=m.speaker_bot_id
+ WHERE m.thread_id=$1
+ ORDER BY m.seq DESC LIMIT $2",
+ )
+ .bind(thread_id)
+ .bind(ROUTER_HISTORY)
+ .fetch_all(state.pool())
+ .await
+ .map_err(|error| error.to_string())?;
+ let mut prompt = String::from("Roster (name — what they do):\n");
+ for member in &room.members {
+ prompt.push_str(&format!(
+ "- {} — {}\n",
+ clip(&member.name, FIELD_CHARS),
+ if member.role.is_empty() {
+ "—".to_string()
+ } else {
+ clip(&member.role, FIELD_CHARS)
+ }
+ ));
+ }
+ if !recent.is_empty() {
+ prompt.push_str("\nRecent lines (newest last):\n");
+ for (speaker, body) in recent.iter().rev() {
+ prompt.push_str(&format!(
+ "{}: {}\n",
+ clip(speaker, 40),
+ clip(body, LINE_CHARS)
+ ));
+ }
+ }
+ prompt.push_str("\nNewest message:\n");
+ prompt.push_str(text.trim());
+ prompt.push_str("\n\nNames that should answer:");
+ Ok(prompt)
+}
+
+/// The picker runs on the workspace model unless `LAZYBOY_ROUTER_MODEL` names a
+/// cheaper one; leaving it unset is a valid and common state.
+async fn router_model(state: &AppState, actor: &Actor) -> Result {
+ let space = state
+ .db
+ .get_space(actor)
+ .await
+ .map_err(|error| error.to_string())?
+ .ok_or_else(|| "workspace not found".to_string())?;
+ let provider = space
+ .default_model_provider
+ .parse::()
+ .map_err(|error| error.to_string())?;
+ let override_id = std::env::var("LAZYBOY_ROUTER_MODEL")
+ .ok()
+ .map(|value| value.trim().to_string())
+ .filter(|value| !value.is_empty());
+ let backend = resolve_backend(ResolveModelRequest {
+ provider,
+ model_id: override_id.or(Some(space.default_model_id)),
+ base_url: space.default_model_base_url.clone(),
+ credentials: CredentialChain {
+ bot: None,
+ space: space.default_model_api_key.clone(),
+ env: credential_from_env(provider),
+ },
+ })
+ .map_err(|error| error.to_string())?;
+ connect_model(&backend).map_err(|error| error.to_string())
+}
+
+/// The single hand-off a bot may pass on: a member it names that is neither
+/// itself nor already working. `@所有人` from a bot is ignored on purpose — a
+/// bot must never broadcast the room.
+pub(crate) async fn handoff_target(
+ state: &AppState,
+ run_id: &str,
+ from_bot_id: &str,
+ body: &str,
+) -> Result, String> {
+ let producing: Option<(String, Option, String)> = sqlx::query_as(
+ "SELECT r.thread_id, t.room_id, r.\"trigger\"
+ FROM runs r JOIN threads t ON t.id=r.thread_id WHERE r.id=$1",
+ )
+ .bind(run_id)
+ .fetch_optional(state.pool())
+ .await
+ .map_err(|error| error.to_string())?;
+ let Some((thread_id, Some(_room_id), trigger)) = producing else {
+ return Ok(None);
+ };
+ // One hop, hard stop: a run that exists because of a hand-off cannot start
+ // another one, or two chatty bots would keep the room (and the bill) alive.
+ if trigger == "handoff" {
+ return Ok(None);
+ }
+ let Some(room) = room_for_thread(state, &thread_id).await? else {
+ return Ok(None);
+ };
+ let mentions = parse_mentions(body, &room.members);
+ if mentions.all || mentions.ids.is_empty() {
+ return Ok(None);
+ }
+ let busy = busy_members(state, &room).await.unwrap_or_default();
+ Ok(mentions
+ .ids
+ .into_iter()
+ .find(|id| id != from_bot_id && !busy.contains(id)))
+}
+
+/// Trim to whole characters so a clipped role or line never splits in half.
+fn clip(text: &str, chars: usize) -> String {
+ text.chars().take(chars).collect()
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ fn member(id: &str, name: &str) -> Member {
+ Member {
+ id: id.to_string(),
+ name: name.to_string(),
+ role: String::new(),
+ }
+ }
+
+ fn roster() -> Vec {
+ vec![member("a", "阿明"), member("b", "小美"), member("c", "Dev")]
+ }
+
+ fn ids(values: &[&str]) -> Vec {
+ values.iter().map(|value| value.to_string()).collect()
+ }
+
+ /// Ids in the order they were found. Anything outside the roster is quoted,
+ /// so a failure points at the stranger rather than looking like a member.
+ fn found(picked: &[String], room: &[Member]) -> Vec {
+ picked
+ .iter()
+ .map(|id| {
+ if room.iter().any(|member| member.id == *id) {
+ id.clone()
+ } else {
+ format!("«{id}»")
+ }
+ })
+ .collect()
+ }
+
+ #[test]
+ fn only_a_named_member_is_consulted() {
+ let room = roster();
+ let mentions = parse_mentions("@小美 幫我看這份報表", &room);
+ assert!(!mentions.all);
+ assert_eq!(found(&mentions.ids, &room), ["b"]);
+ }
+
+ #[test]
+ fn the_longest_name_wins_when_members_overlap() {
+ let room = vec![member("a", "阿明"), member("b", "阿明哥")];
+ assert_eq!(
+ found(&parse_mentions("@阿明哥 來一下", &room).ids, &room),
+ ["b"]
+ );
+ assert_eq!(
+ found(&parse_mentions("@阿明 來一下", &room).ids, &room),
+ ["a"]
+ );
+ }
+
+ #[test]
+ fn ascii_names_need_a_word_boundary_after_them() {
+ let room = roster();
+ assert_eq!(
+ found(&parse_mentions("@dev 幫我看", &room).ids, &room),
+ ["c"]
+ );
+ assert_eq!(
+ found(&parse_mentions("@Dev, help", &room).ids, &room),
+ ["c"]
+ );
+ assert!(parse_mentions("@Developer 幫我看", &room).ids.is_empty());
+ }
+
+ #[test]
+ fn punctuation_does_not_eat_a_mention() {
+ let room = roster();
+ assert_eq!(
+ found(&parse_mentions("@小美,@阿明 一起看", &room).ids, &room),
+ ["b", "a"]
+ );
+ assert_eq!(found(&parse_mentions("(@小美)", &room).ids, &room), ["b"]);
+ }
+
+ #[test]
+ fn an_email_address_is_not_a_mention() {
+ let room = roster();
+ let mentions = parse_mentions("寄到 mail@小美 或 report@dev.example 就好", &room);
+ assert!(mentions.ids.is_empty() && !mentions.all);
+ }
+
+ #[test]
+ fn naming_everyone_is_the_escape_hatch() {
+ let room = roster();
+ for text in [
+ "@所有人 結論定了",
+ "@全部 來看",
+ "@all look",
+ "@everyone look",
+ "@everybody, your turn",
+ ] {
+ assert!(parse_mentions(text, &room).all, "{text}");
+ }
+ // `@allison` is somebody's name, not `all`.
+ assert!(!parse_mentions("@allison 來了", &room).all);
+ }
+
+ #[test]
+ fn unknown_names_are_dropped_and_repeats_count_once() {
+ let room = roster();
+ let mentions = parse_mentions("@阿明 和 @路人,@阿明 再說一次", &room);
+ assert_eq!(found(&mentions.ids, &room), ["a"]);
+ }
+
+ #[test]
+ fn the_picker_may_answer_in_names_json_or_prose() {
+ let room = roster();
+ assert_eq!(
+ found(&parse_router_reply("小美、阿明", &room), &room),
+ ["b", "a"]
+ );
+ assert_eq!(
+ found(&parse_router_reply("[\"小美\", \"Dev\"]", &room), &room),
+ ["b", "c"]
+ );
+ assert_eq!(
+ found(&parse_router_reply("我覺得小美可以回答", &room), &room),
+ ["b"]
+ );
+ }
+
+ #[test]
+ fn the_picker_cannot_invent_members_or_a_crowd() {
+ let room = roster();
+ assert!(parse_router_reply("NONE", &room).is_empty());
+ assert!(parse_router_reply("請由 Grace 處理", &room).is_empty());
+ assert!(parse_router_reply("Development work", &room).is_empty());
+ let crowd = vec![
+ member("a", "一"),
+ member("b", "二"),
+ member("c", "三"),
+ member("d", "四"),
+ ];
+ assert_eq!(
+ parse_router_reply("一、二、三、四", &crowd).len(),
+ ROUTER_CAP
+ );
+ }
+
+ #[test]
+ fn a_named_member_answers_even_while_the_picker_skips_busy_ones() {
+ let room = roster();
+ let busy = ids(&["b"]);
+ let mentioned = resolve_audience(
+ &room,
+ &Mentions {
+ all: false,
+ ids: ids(&["b"]),
+ },
+ "a",
+ &busy,
+ &[],
+ );
+ assert_eq!(mentioned.targets, ids(&["b"]));
+ assert_eq!(mentioned.reason, Reason::Mention);
+
+ let routed = resolve_audience(&room, &Mentions::default(), "a", &busy, &ids(&["b", "c"]));
+ assert_eq!(routed.targets, ids(&["c"]));
+ assert_eq!(routed.reason, Reason::Routed);
+ }
+
+ #[test]
+ fn everybody_or_nobody_is_settled_without_the_picker() {
+ let room = roster();
+ let all = resolve_audience(
+ &room,
+ &Mentions {
+ all: true,
+ ids: Vec::new(),
+ },
+ "a",
+ &[],
+ &[],
+ );
+ assert_eq!(all.targets, ids(&["a", "b", "c"]));
+ assert_eq!(all.reason, Reason::All);
+
+ // Nothing fitted, the picker named strangers, or it named only busy
+ // members: the host picks it up rather than the message going unread.
+ let stranded: Vec> = vec![vec![], ids(&["ghost"]), ids(&["b"])];
+ for routed in stranded {
+ let host = resolve_audience(&room, &Mentions::default(), "a", &ids(&["b"]), &routed);
+ assert_eq!(host.targets, ids(&["a"]));
+ assert_eq!(host.reason, Reason::Host);
+ }
+ }
+
+ #[test]
+ fn an_id_that_left_the_room_is_not_an_audience() {
+ let room = roster();
+ let audience = resolve_audience(
+ &room,
+ &Mentions {
+ all: false,
+ ids: ids(&["ghost"]),
+ },
+ "a",
+ &[],
+ &ids(&["c"]),
+ );
+ assert_eq!(audience.targets, ids(&["c"]));
+ assert_eq!(audience.reason, Reason::Routed);
+ }
+
+ #[test]
+ fn clipping_counts_characters_not_bytes() {
+ assert_eq!(clip("群組聊天", 3), "群組聊");
+ }
+}
+
+/// The same decisions with the real tables behind them: how many runs one chat
+/// message is allowed to start, and where a hand-off stops.
+#[cfg(test)]
+mod fan_out {
+ use super::*;
+ use serde_json::json;
+
+ fn app(pool: sqlx::PgPool) -> AppState {
+ AppState {
+ db: crate::db::Db { pool },
+ sandbox: std::sync::Arc::new(lazyboy_sandbox::FakeSandbox::new()),
+ data_dir: String::new(),
+ auth: crate::auth::AuthConfig::from_env(),
+ memory: crate::memory::MemoryService::from_env(),
+ mcp: crate::mcp::McpHub::new(),
+ calls: crate::state::CallRegistry::default(),
+ wakes: crate::state::WakeBus::default(),
+ }
+ }
+
+ /// `members` join one room led by `host`, and share the thread `t`. A
+ /// `group` of one is a direct message, which has no audience to choose.
+ async fn seed(pool: &sqlx::PgPool, members: &[(&str, &str)], host: Option<&str>, group: bool) {
+ sqlx::query("INSERT INTO users (id,name) VALUES ('u','test')")
+ .execute(pool)
+ .await
+ .unwrap();
+ sqlx::query("INSERT INTO spaces (id,user_id,name) VALUES ('s','u','test')")
+ .execute(pool)
+ .await
+ .unwrap();
+ for (id, name) in members {
+ sqlx::query("INSERT INTO bots (id,space_id,user_id,name) VALUES ($1,'s','u',$2)")
+ .bind(id)
+ .bind(name)
+ .execute(pool)
+ .await
+ .unwrap();
+ }
+ if group {
+ sqlx::query(
+ "INSERT INTO rooms (id,space_id,user_id,name,host_bot_id)
+ VALUES ('r','s','u','產品群',$1)",
+ )
+ .bind(host)
+ .execute(pool)
+ .await
+ .unwrap();
+ for (id, _) in members {
+ sqlx::query("INSERT INTO room_members (room_id,bot_id) VALUES ('r',$1)")
+ .bind(id)
+ .execute(pool)
+ .await
+ .unwrap();
+ }
+ }
+ sqlx::query(
+ "INSERT INTO threads (id,space_id,user_id,bot_id,room_id) VALUES ('t','s','u',$1,$2)",
+ )
+ .bind(members[0].0)
+ .bind(group.then_some("r"))
+ .execute(pool)
+ .await
+ .unwrap();
+ }
+
+ async fn start_run(pool: &sqlx::PgPool, id: &str, bot: &str, trigger: &str) {
+ sqlx::query(
+ "INSERT INTO runs (id,space_id,user_id,bot_id,thread_id,status,trigger,prompt)
+ VALUES ($1,'s','u',$2,'t','running',$3,'開始')",
+ )
+ .bind(id)
+ .bind(bot)
+ .bind(trigger)
+ .execute(pool)
+ .await
+ .unwrap();
+ }
+
+ async fn runs_for(pool: &sqlx::PgPool, bot: &str) -> i64 {
+ sqlx::query_scalar("SELECT count(*) FROM runs WHERE bot_id=$1")
+ .bind(bot)
+ .fetch_one(pool)
+ .await
+ .unwrap()
+ }
+
+ /// The audience written next to the newest message of `role`. Empty means
+ /// nothing was recorded, which is what a direct message must do.
+ async fn audience_of(pool: &sqlx::PgPool, role: &str) -> Vec {
+ let stored: Option>> =
+ sqlx::query_scalar("SELECT reply_bot_ids FROM messages WHERE role=$1 LIMIT 1")
+ .bind(role)
+ .fetch_optional(pool)
+ .await
+ .unwrap();
+ stored.flatten().unwrap_or_default()
+ }
+
+ const TRIO: [(&str, &str); 3] = [("a", "阿明"), ("b", "小美"), ("c", "阿強")];
+
+ #[sqlx::test(migrations = "../../migrations")]
+ async fn only_the_member_named_in_the_message_is_woken(pool: sqlx::PgPool) {
+ seed(&pool, &TRIO, Some("a"), true).await;
+ let actor = Actor {
+ user_id: "u".into(),
+ space_id: "s".into(),
+ };
+ crate::runs::send(
+ &app(pool.clone()),
+ &actor,
+ "a",
+ "t",
+ "@小美 幫我看這份",
+ None,
+ &[],
+ &[],
+ )
+ .await
+ .unwrap();
+ assert_eq!(runs_for(&pool, "b").await, 1);
+ assert_eq!(runs_for(&pool, "a").await, 0);
+ assert_eq!(runs_for(&pool, "c").await, 0);
+ assert_eq!(audience_of(&pool, "user").await, ["b"]);
+ }
+
+ #[sqlx::test(migrations = "../../migrations")]
+ async fn a_two_member_room_answers_without_calling_the_picker(pool: sqlx::PgPool) {
+ seed(&pool, &[("a", "阿明"), ("b", "小美")], Some("a"), true).await;
+ let actor = Actor {
+ user_id: "u".into(),
+ space_id: "s".into(),
+ };
+ crate::runs::send(
+ &app(pool.clone()),
+ &actor,
+ "a",
+ "t",
+ "誰幫我看這份",
+ None,
+ &[],
+ &[],
+ )
+ .await
+ .unwrap();
+ assert_eq!(runs_for(&pool, "a").await, 1);
+ assert_eq!(runs_for(&pool, "b").await, 0);
+ assert_eq!(audience_of(&pool, "user").await, ["a"]);
+ }
+
+ #[sqlx::test(migrations = "../../migrations")]
+ async fn a_mention_is_queued_behind_the_work_already_running(pool: sqlx::PgPool) {
+ seed(&pool, &TRIO, Some("a"), true).await;
+ start_run(&pool, "busy", "b", "message").await;
+ let actor = Actor {
+ user_id: "u".into(),
+ space_id: "s".into(),
+ };
+ crate::runs::send(
+ &app(pool.clone()),
+ &actor,
+ "a",
+ "t",
+ "@小美 再看一次",
+ None,
+ &[],
+ &[],
+ )
+ .await
+ .unwrap();
+ assert_eq!(runs_for(&pool, "b").await, 2);
+ }
+
+ #[sqlx::test(migrations = "../../migrations")]
+ async fn a_bot_hands_one_item_over_and_stops_there(pool: sqlx::PgPool) {
+ seed(&pool, &TRIO, Some("a"), true).await;
+ start_run(&pool, "r1", "a", "message").await;
+ let app = app(pool.clone());
+ crate::runs::append_bot_message_with(
+ &app,
+ "t",
+ "r1",
+ "a",
+ "這塊我不熟,@小美 交給妳。",
+ json!([]),
+ )
+ .await
+ .unwrap();
+ let passed: Vec<(String, String)> =
+ sqlx::query_as("SELECT bot_id, \"trigger\" FROM runs WHERE id<>'r1'")
+ .fetch_all(&pool)
+ .await
+ .unwrap();
+ assert_eq!(passed, vec![("b".to_string(), "handoff".to_string())]);
+ assert_eq!(audience_of(&pool, "assistant").await, ["b"]);
+
+ // The hand-off's own reply starts nothing: one hop is the whole budget,
+ // or two chatty bots would keep the room and the bill alive.
+ let handed_run: String = sqlx::query_scalar("SELECT id FROM runs WHERE id<>'r1'")
+ .fetch_one(&pool)
+ .await
+ .unwrap();
+ crate::runs::append_bot_message_with(
+ &app,
+ "t",
+ &handed_run,
+ "b",
+ "@阿強 換妳。",
+ json!([]),
+ )
+ .await
+ .unwrap();
+ let total: i64 = sqlx::query_scalar("SELECT count(*) FROM runs")
+ .fetch_one(&pool)
+ .await
+ .unwrap();
+ assert_eq!(total, 2);
+ }
+
+ #[sqlx::test(migrations = "../../migrations")]
+ async fn a_busy_member_is_not_handed_more_work(pool: sqlx::PgPool) {
+ seed(&pool, &TRIO, Some("a"), true).await;
+ start_run(&pool, "busy", "b", "message").await;
+ start_run(&pool, "r1", "a", "message").await;
+ crate::runs::append_bot_message_with(
+ &app(pool.clone()),
+ "t",
+ "r1",
+ "a",
+ "@小美 或 @阿強,誰有空?",
+ json!([]),
+ )
+ .await
+ .unwrap();
+ let passed: Vec =
+ sqlx::query_scalar("SELECT bot_id FROM runs WHERE \"trigger\"='handoff'")
+ .fetch_all(&pool)
+ .await
+ .unwrap();
+ assert_eq!(passed, vec!["c".to_string()]);
+ }
+
+ #[sqlx::test(migrations = "../../migrations")]
+ async fn a_bot_naming_everyone_hands_over_nothing(pool: sqlx::PgPool) {
+ seed(&pool, &TRIO, Some("a"), true).await;
+ start_run(&pool, "r1", "a", "message").await;
+ crate::runs::append_bot_message_with(
+ &app(pool.clone()),
+ "t",
+ "r1",
+ "a",
+ "@所有人 一起看這份。",
+ json!([]),
+ )
+ .await
+ .unwrap();
+ let total: i64 = sqlx::query_scalar("SELECT count(*) FROM runs")
+ .fetch_one(&pool)
+ .await
+ .unwrap();
+ assert_eq!(total, 1);
+ }
+
+ #[sqlx::test(migrations = "../../migrations")]
+ async fn a_direct_message_never_broadcasts(pool: sqlx::PgPool) {
+ seed(&pool, &[("a", "阿明"), ("b", "小美")], None, false).await;
+ start_run(&pool, "r1", "a", "message").await;
+ crate::runs::append_bot_message_with(
+ &app(pool.clone()),
+ "t",
+ "r1",
+ "a",
+ "@小美 @所有人 一起看。",
+ json!([]),
+ )
+ .await
+ .unwrap();
+ let total: i64 = sqlx::query_scalar("SELECT count(*) FROM runs")
+ .fetch_one(&pool)
+ .await
+ .unwrap();
+ assert_eq!(total, 1);
+ assert!(audience_of(&pool, "assistant").await.is_empty());
+ }
+
+ /// A one-to-one thread has no room to look up; the send must simply reach
+ /// its bot. This once failed before the message was even written, because a
+ /// NULL `room_id` was decoded as if it could not be NULL.
+ #[sqlx::test(migrations = "../../migrations")]
+ async fn a_direct_message_reaches_its_bot_and_records_no_audience(pool: sqlx::PgPool) {
+ seed(&pool, &[("a", "阿明")], None, false).await;
+ let actor = Actor {
+ user_id: "u".into(),
+ space_id: "s".into(),
+ };
+ crate::runs::send(
+ &app(pool.clone()),
+ &actor,
+ "a",
+ "t",
+ "幫我看這份",
+ None,
+ &[],
+ &[],
+ )
+ .await
+ .unwrap();
+ assert_eq!(runs_for(&pool, "a").await, 1);
+ assert!(audience_of(&pool, "user").await.is_empty());
+ }
+
+ /// A room whose host was deleted (or that predates the column) still has a
+ /// host: the first member, as before.
+ #[sqlx::test(migrations = "../../migrations")]
+ async fn a_room_without_a_recorded_host_falls_back_to_its_first_member(pool: sqlx::PgPool) {
+ seed(&pool, &[("a", "阿明"), ("b", "小美")], None, true).await;
+ let room = room_for_thread(&app(pool.clone()), "t")
+ .await
+ .unwrap()
+ .expect("the thread belongs to a room");
+ assert_eq!(room.host_id, "a");
+ }
+}
diff --git a/crates/api/src/runs.rs b/crates/api/src/runs.rs
index 2bea22a..38fa825 100644
--- a/crates/api/src/runs.rs
+++ b/crates/api/src/runs.rs
@@ -106,6 +106,25 @@ pub async fn send(
let stored_body = crate::attachments::caption_for_title(text, &decoded);
let mut stored_blocks = blocks.to_vec();
stored_blocks.extend(crate::attachments::stored_blocks(&decoded));
+ // Who answers is decided before the row lock: an `@name` settles it for
+ // free, and the one model call that sometimes stands in for it must never
+ // hold this thread's transaction open.
+ let room = crate::routing::room_for_thread(state, thread_id).await?;
+ // One run per chosen member — `@name` wins, then the picker's short list,
+ // then the host. A room message keeps this list with it so the chat can say
+ // who is about to talk; a direct message records nothing extra.
+ let mut member_ids: Vec = match room.as_ref() {
+ Some(room) => {
+ crate::routing::audience_for(state, actor, room, thread_id, text)
+ .await
+ .targets
+ }
+ None => vec![bot_id.to_string()],
+ };
+ if member_ids.is_empty() {
+ member_ids.push(bot_id.to_string());
+ }
+ let reply_bot_ids: Option> = room.map(|_| member_ids.clone());
let mut tx = state
.pool()
.begin()
@@ -199,8 +218,8 @@ pub async fn send(
.await
.map_err(|error| error.to_string())?;
sqlx::query(
- "INSERT INTO messages (id,thread_id,seq,role,body,blocks,run_id,client_nonce)
- VALUES ($1,$2,$3,'user',$4,$5,$6,$7)",
+ "INSERT INTO messages (id,thread_id,seq,role,body,blocks,run_id,client_nonce,reply_bot_ids)
+ VALUES ($1,$2,$3,'user',$4,$5,$6,$7,$8)",
)
.bind(&message_id)
.bind(thread_id)
@@ -209,6 +228,7 @@ pub async fn send(
.bind(json!(stored_blocks))
.bind(&run_id)
.bind(client_nonce)
+ .bind(&reply_bot_ids)
.execute(&mut *tx)
.await
.map_err(|error| error.to_string())?;
@@ -220,18 +240,6 @@ pub async fn send(
.await
.map_err(|error| error.to_string())?;
}
- let mut member_ids: Vec = if let Some(room_id) = room_id.as_deref() {
- sqlx::query_scalar("SELECT bot_id FROM room_members WHERE room_id=$1 ORDER BY created_at")
- .bind(room_id)
- .fetch_all(&mut *tx)
- .await
- .map_err(|error| error.to_string())?
- } else {
- vec![bot_id.to_string()]
- };
- if member_ids.is_empty() {
- member_ids.push(bot_id.to_string());
- }
for (index, member_id) in member_ids.iter().enumerate() {
if merged && index == 0 {
continue;
@@ -280,7 +288,15 @@ pub async fn send(
"SELECT EXISTS(SELECT 1 FROM runs WHERE bot_id=$1 AND id<>$2
AND status IN ('queued','leased','running','waiting_input','waiting_takeover'))",
)
- .bind(bot_id)
+ // The question is about the bot that will actually answer, which in a
+ // room is whoever routing put first — not the host the message was
+ // addressed to.
+ .bind(
+ member_ids
+ .first()
+ .cloned()
+ .unwrap_or_else(|| bot_id.to_string()),
+ )
.bind(&run_id)
.fetch_one(&mut *tx)
.await
@@ -860,7 +876,7 @@ async fn execute_run(
.unwrap_or_default();
if !room_mates.is_empty() {
preamble.push_str(&format!(
- "\n\nYou are {} in a group chat with: {}. Reply as yourself only. Other agents' lines are prefixed with [Name]. Do not speak for them.",
+ "\n\nYou are {} in a group chat with: {}. Reply as yourself only. Other agents' lines are prefixed with [Name]. Do not speak for them. The human names who should answer: speak when your name is on the message, stay quiet when it is not. When the piece belongs to someone else, say one short line and name them with @TheirName, which hands this one item over once.",
bot.name,
room_mates.join("、")
));
@@ -2091,6 +2107,15 @@ pub(crate) async fn append_bot_message_with(
if body.trim().is_empty() && !has_blocks {
return Ok(());
}
+ // A bot that names a member may hand this piece over: one hop only, and
+ // never to a member who is already working. The lookup happens before the
+ // transaction so the message write stays short.
+ let handoff = crate::routing::handoff_target(state, run_id, bot_id, body)
+ .await
+ .unwrap_or_else(|error| {
+ tracing::warn!("room hand-off lookup for run {run_id}: {error}");
+ None
+ });
let mut tx = state
.pool()
.begin()
@@ -2106,8 +2131,8 @@ pub(crate) async fn append_bot_message_with(
.map_err(|error| error.to_string())?;
let message_id = Uuid::new_v4().to_string();
sqlx::query(
- "INSERT INTO messages (id,thread_id,seq,role,body,blocks,run_id,speaker_bot_id)
- VALUES ($1,$2,$3,'assistant',$4,$5,$6,$7)",
+ "INSERT INTO messages (id,thread_id,seq,role,body,blocks,run_id,speaker_bot_id,reply_bot_ids)
+ VALUES ($1,$2,$3,'assistant',$4,$5,$6,$7,$8)",
)
.bind(&message_id)
.bind(thread_id)
@@ -2116,9 +2141,37 @@ pub(crate) async fn append_bot_message_with(
.bind(&blocks)
.bind(run_id)
.bind(bot_id)
+ .bind(handoff.clone().map(|target| vec![target]))
.execute(&mut *tx)
.await
.map_err(|error| error.to_string())?;
+ if let Some(target) = handoff.as_ref() {
+ let owner: Option<(String, String, String)> = sqlx::query_as(
+ "SELECT r.space_id, r.user_id, b.name
+ FROM runs r JOIN bots b ON b.id=r.bot_id WHERE r.id=$1",
+ )
+ .bind(run_id)
+ .fetch_optional(&mut *tx)
+ .await
+ .map_err(|error| error.to_string())?;
+ if let Some((space_id, user_id, speaker)) = owner {
+ tracing::info!(run_id, target, "room hand-off queued");
+ sqlx::query(
+ "INSERT INTO runs (id,space_id,bot_id,thread_id,user_id,status,trigger,prompt,checkpoint)
+ VALUES ($1,$2,$3,$4,$5,'queued','handoff',$6,$7)",
+ )
+ .bind(Uuid::new_v4().to_string())
+ .bind(space_id)
+ .bind(target)
+ .bind(thread_id)
+ .bind(user_id)
+ .bind(format!("{speaker} 在群組裡把這件事交給你:\n{body}"))
+ .bind(json!({"handoffFrom": run_id}))
+ .execute(&mut *tx)
+ .await
+ .map_err(|error| error.to_string())?;
+ }
+ }
tx.commit().await.map_err(|error| error.to_string())?;
let _ = crate::sessions::append_event(
state,
diff --git a/crates/api/src/sessions.rs b/crates/api/src/sessions.rs
index 52f6e2f..64d6f35 100644
--- a/crates/api/src/sessions.rs
+++ b/crates/api/src/sessions.rs
@@ -485,6 +485,7 @@ type MessageWithSpeakerRow = (
Option,
Option,
Option,
+ Value,
);
pub async fn messages_for_session(
@@ -494,7 +495,16 @@ pub async fn messages_for_session(
) -> Result, ApiError> {
let rows: Vec = sqlx::query_as(
"SELECT m.id, m.thread_id, m.seq, m.role, m.body, m.blocks, m.run_id,
- m.client_nonce, m.created_at, m.speaker_bot_id, b.name, b.avatar_color, b.avatar_shape
+ m.client_nonce, m.created_at, m.speaker_bot_id, b.name, b.avatar_color, b.avatar_shape,
+ COALESCE((
+ SELECT jsonb_agg(
+ jsonb_build_object('id', r.id, 'name', r.name,
+ 'avatarColor', r.avatar_color,
+ 'avatarShape', r.avatar_shape)
+ ORDER BY picked.ord)
+ FROM unnest(m.reply_bot_ids) WITH ORDINALITY AS picked(bot_id, ord)
+ JOIN bots r ON r.id = picked.bot_id
+ ), '[]'::jsonb) AS reply_bots
FROM messages m
JOIN threads t ON t.id=m.thread_id
LEFT JOIN bots b ON b.id=m.speaker_bot_id
@@ -523,6 +533,8 @@ pub async fn messages_for_session(
speaker_name: row.10,
speaker_color: row.11,
speaker_shape: row.12,
+ // A malformed array must not take the whole transcript with it.
+ reply_bots: serde_json::from_value(row.13).unwrap_or_default(),
})
.collect())
}
diff --git a/crates/contracts/src/room.rs b/crates/contracts/src/room.rs
index 94cb36d..3a018ea 100644
--- a/crates/contracts/src/room.rs
+++ b/crates/contracts/src/room.rs
@@ -16,6 +16,9 @@ pub struct Room {
pub id: String,
pub name: String,
pub members: Vec,
+ /// The member that answers what nobody was named for. `None` means "the
+ /// first member", which is what rooms used before this column resolve to.
+ pub host_bot_id: Option,
pub last_message_at: Option>,
pub last_preview: Option,
pub unread_count: i64,
@@ -26,6 +29,18 @@ pub struct Room {
pub struct CreateRoomInput {
pub name: String,
pub member_ids: Vec,
+ /// Optional from the first version: leaving it out makes the first member
+ /// the host, which is what a group needs by default.
+ #[serde(default)]
+ pub host_bot_id: Option,
+}
+
+#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default)]
+#[serde(rename_all = "camelCase")]
+pub struct UpdateRoomInput {
+ /// Must be one of the room's members.
+ #[serde(default)]
+ pub host_bot_id: Option,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
diff --git a/crates/contracts/src/session.rs b/crates/contracts/src/session.rs
index 2bd2a13..dc043ab 100644
--- a/crates/contracts/src/session.rs
+++ b/crates/contracts/src/session.rs
@@ -2,6 +2,8 @@ use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use serde_json::Value;
+use crate::RoomMember;
+
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Session {
@@ -46,6 +48,10 @@ pub struct SessionMessage {
pub speaker_name: Option,
pub speaker_color: Option,
pub speaker_shape: Option,
+ /// Who the group decided should answer this message, in order. Empty for a
+ /// one-to-one conversation and for messages written before routing existed.
+ #[serde(default)]
+ pub reply_bots: Vec,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
diff --git a/docs/cua-benchmark.md b/docs/cua-benchmark.md
deleted file mode 100644
index 2e1295c..0000000
--- a/docs/cua-benchmark.md
+++ /dev/null
@@ -1,17 +0,0 @@
-# Cua adapter timings (2026-09-07)
-
-Measured on Apple Silicon, `lazyboy/computer:local`, Cua Driver 0.23.2, inside `make cua-smoke` (`--repeat 10`). These are LazyBoy `controld` HTTP calls, not raw `cua-driver` CLI.
-
-| Call | n | median ms | max ms |
-| --- | ---: | ---: | ---: |
-| `GET /controller/health` | 1 | 11 | 11 |
-| `POST /observe` | 30 | 101 | 125 |
-| `POST /act` | 40 | 403 | 744 |
-| `POST /browser` snapshot | 10 | 48 | 51 |
-| `POST /browser` click | 20 | 332 | 337 |
-| `POST /browser` type | 10 | 391 | 399 |
-| `POST /browser` navigate | 10 | 927 | 941 |
-
-`/act` includes native click, batched setvalue+click, focus, and one Cua `drag`. Navigate includes the 800 ms settle in the adapter.
-
-There is no legacy control-plane comparison in this run. Do not treat these numbers as a ship gate against CDP/AT-SPI.
diff --git a/docs/cua-compatibility.md b/docs/cua-compatibility.md
deleted file mode 100644
index 192eafb..0000000
--- a/docs/cua-compatibility.md
+++ /dev/null
@@ -1,159 +0,0 @@
-# Cua Driver compatibility (LazyBoy desktop)
-
-> 歷史紀錄:本文描述 2026-09-07 的雙後端驗證,已非現況。目前只保留 Cua;操作方式見 [operations.md](operations.md),最新驗證狀態見 [cua-migration-progress.md](cua-migration-progress.md)。
-
-This report answers one question, from a real `make cua-smoke` run on 2026-09-07:
-
-> Can Cua Driver reliably control the existing LazyBoy XFCE + Xvfb desktop container?
-
-**Yes, as an opt-in backend.** A disposable `lazyboy/computer:local` desktop on 2026-09-07 (linux/arm64, Cua Driver 0.23.2) passed raw Driver smoke 10/10, the LazyBoy adapter 10/10, dual-display isolation, and Chromium cookie persistence across `docker pause` and `docker restart`. Production still defaults to `legacy`. See [cua-review.md](cua-review.md) and [cua-benchmark.md](cua-benchmark.md).
-
-## Environment
-
-- Image: `lazyboy/computer:local` (`image/computer/Dockerfile`)
-- Distro: Debian bookworm; Driver binary follows `TARGETARCH` (`linux-arm64` or `linux-x86_64`)
-- Display: Xvfb `DISPLAY=:1` at 1280×800, XFCE (`xfwm4` compositor off, `xfce4-panel`, `xfdesktop`)
-- Accessibility: AT-SPI 2 per screen (`at-spi-bus-launcher` + `at-spi2-registryd`)
-- Browser: Debian `chromium` via `lazyboy-browser` (persistent profile, `--remote-debugging-port=9221+display`, `--force-renderer-accessibility`, `--lang=zh-TW`)
-- Cua Driver: **0.23.2** (`cua-driver-rs-v0.23.2`; linux-arm64 SHA256 `be22768a207796a4bc1de50c52f32f9ef680b5e86e58c059e02eec2caba2e7bb`, linux-x86_64 SHA256 `01bf8339ec129cc00f4b4b2c6056ef1a7c5b52df39ff83ad17c9b16818aec500`)
-- Install path: `/usr/local/lib/cua-driver` + `/usr/local/bin/cua-driver` (not under the persisted `/home/lazyboy` bind)
-- Daemon: `cua-driver serve --grant existing-profile --socket /tmp/lazyboy/cua.sock --no-overlay` on the primary display only
-- Telemetry: disabled
-- How to reproduce: `make cua-smoke` (artifacts in `/tmp/lazyboy-cua-smoke-last/`)
-
-## Doctor
-
-`cua-driver doctor --json` exit 0, `ok: true`.
-
-| Probe | Status | Note |
-| --- | --- | --- |
-| binary | ok | `cua-driver 0.23.2 (x86_64-linux)` |
-| install dir | ok | `/usr/local/lib/cua-driver/cua-driver` |
-| telemetry | ok | disabled |
-| display server | ok | X11 `DISPLAY=:1` |
-| X11 connection | ok | connected, visible top-level windows |
-| AT-SPI | **warn** | CLI `doctor` (docker exec) does not always see the XFCE session bus. The **daemon** started from `lazyboy-screen` does: native `get_window_state` + AT-SPI click/type worked 10/10. |
-
-`cua-driver status --socket /tmp/lazyboy/cua.sock`: daemon running, permission mode `standard`. Unix socket rejects uid 0; smoke and future controld calls must run as uid 1000 (`lazyboy`).
-
-## Results (10 consecutive iterations)
-
-Independent application state, not Cua `"ok"`:
-
-| Check | Result |
-| --- | --- |
-| `cua-driver --version` | `cua-driver 0.23.2` |
-| screenshot (`get_desktop_state`) | 10/10 PNG of the XFCE desktop |
-| window / accessibility observation | 10/10 `list_windows` + GTK `get_window_state` |
-| native click | 10/10 GTK `Smoke Click` wrote `/tmp/lazyboy/cua-smoke-clicked` |
-| native type | 10/10 GTK entry + `Smoke Save` wrote `hello-cua` |
-| Chromium attach (existing window/profile) | 10/10 `browser_prepare` `attached_existing_profile` |
-| browser semantic click / type | 10/10 local `http://127.0.0.1:8765/cua-smoke.html`; DOM became `clicked-ok` then `typed:hello-cua` |
-| noVNC `:6080` still up | 10/10 |
-| leftover Cua processes | none (only `cua-driver serve`) |
-
-Same Chromium **pid 334** / **window_id 29360131** across all ten iterations. `browser_prepare` side effects were all false: no isolated profile, no copy, no restart, no extra remote-debugging toggle (LazyBoy already exposes loopback CDP).
-
-Element refs are snapshot-scoped (`p1:1`, `p4:1`, … `p28:1`). Reusing an old ref would be wrong; the smoke re-snapshots every action.
-
-## Relevant tools (0.23.2 `list-tools`)
-
-Observation / native input used by `controld`: `get_desktop_state`, `list_windows`,
-`get_window_state`, `click`, `type_text`, `press_key`, `hotkey`, `scroll`, `drag`,
-`move_cursor`, `set_value`, `bring_to_front`, `get_cursor_position`, `get_screen_size`.
-
-Browser (attach only): `browser_prepare` (`strategy.kind=existing_profile`,
-`allow_launch=false`), `get_browser_state` (`semantic_v2`), `browser_navigate`
-(http/https/about only), `browser_click`, `browser_type`.
-
-Lifecycle / diagnostics: `start_session`, `end_session`, `health_report`. Skill
-teaching also uses `start_recording` / `stop_recording`.
-
-Not used: `mouse_button_down`, `mouse_button_up`, `mouse_drag` (held-button
-background X11 tools). LazyBoy's action DSL has no partial-pointer state, so
-`Pointer{Down}` / `Pointer{Up}` translate to `ControlError::Unsupported` instead
-of a half-pressed button nobody releases. Also unused: isolated `launch_app`
-browsers, Wayland helpers, and the deprecated `get_session_state` /
-`escalate_session` aliases. None of these names may be exposed to the LLM.
-
-## Driver contract rules (enforced in `crates/control/src/cua`)
-
-Each of these was confirmed against a real 0.23.2 daemon, and each one fails
-silently (exit 0) if violated:
-
-1. **Repeat the `session` label on every call.** `CuaClient::call` injects
- `lazyboy-` unless the caller already set one. Without it each CLI
- process gets an ephemeral `cli-` session, so trajectory turns,
- snapshots, and browser binds never line up, and every call also emits a bogus
- `end_session` turn.
-2. **Never send `target: {kind: "desktop", display_id: "primary"}`.** The Linux
- driver rejects it with `invalid_action_target` (exit 0). Omit `target` to use
- the global input route.
-3. **Desktop `scroll` needs a point.** With `scope: "desktop"`, `x`/`y` are
- required (`missing field x`); `dispatch` aims at the pointer and falls back to
- the screen centre. `amount` is clamped to the schema range `1..=50`.
-4. **Only a JSON object proves the tool ran.** A refusal or prose banner that
- arrives with exit 0 is a failure (`decode_stdout`), never an empty success.
-5. **One escalation retry.** `background_unavailable` carries
- `escalation.recommended`; the client retries once with that `delivery_mode`
- and never loops.
-6. **`get_window_state` can be degraded.** AT-SPI intermittently answers with
- `degraded: true` and a root-only tree. Such windows are skipped and the
- observation reports `native_observation_complete: false` rather than failing
- the whole `observe`.
-7. **Nothing is validated for you.** The Linux schemas declare
- `additionalProperties: false` and numeric bounds, but 0.23.2 accepts unknown
- keys and out-of-range values anyway (a bogus key on `list_windows` and
- `scroll amount: 0` both return exit 0 with `effect: unverifiable`), so the
- bounds in `docs/cua-schemas/0.23.2/` are enforced here, by the client.
- `session` is accepted by every tool, including the ones whose own schema
- omits it (`list_windows`, `bring_to_front`, `health_report`,
- `start_recording`), which is what lets rule 1 be applied uniformly.
-8. **Socket peer uid.** `/tmp/lazyboy/cua*.sock` rejects uid 0; `controld` runs as
- the desktop user (uid 1000).
-
-## Integration notes for the next PR
-
-- Call Cua as uid 1000 via `cua-driver call --socket /tmp/lazyboy/cua.sock`. Root is rejected (`reject Unix peer uid 0 for runtime owned by uid 1000`).
-- `get_browser_state` on a live LazyBoy Chromium first returns `browser_consent_required` / `consumer_profile_endpoint_requires_grant`. Then `browser_prepare` with `existing_profile` attaches. Serve must keep `--grant existing-profile`. Never `allow_launch`.
-- Linux Chromium trusted CDP pointer is unavailable; smoke used `browser_click` `input_route=dom_event` and verified the DOM. Production adapter should prefer that route on this platform and treat `browser_input_trust_unavailable` as classified, not a silent xdotool fallback.
-- Extra Team screens are extra Xvfb `DISPLAY`s. This POC only runs a daemon on `:1`. Later: one socket per slot.
-- `browser_navigate` refuses `file://`; local fixtures need `http://127.0.0.1`.
-- `get_window_state` on Linux is `additionalProperties: false` — do not send macOS-only fields such as `include_accessibility_tree`.
-
-## Known limits
-
-- Doctor AT-SPI warn from a non-desktop D-Bus is not a daemon failure.
-- Overlay warnings (`X11 channel rejected command`) appeared in the daemon log with `--no-overlay`; they did not block actions.
-- Debian Chromium + zh-TW UI: existing-profile attach worked because CDP was already open, so Cua did not need the English setup-checkbox path.
-- Multi-screen, pause/resume, takeover, and skill recording were **not** in this POC; later PRs added controller routing, browser attach, takeover re-observe, and dual-source skill recording.
-
-## Conclusion
-
-Cua Driver 0.23.2 **can** control the existing LazyBoy XFCE + Xvfb container: screenshot, window/AT-SPI observation, native click/type, and Chromium semantic click/type, 10/10, without replacing the browser profile or breaking noVNC.
-
-`ComputerController` is in place. Production defaults to `legacy` pending the full acceptance suite and benchmark. Set `LAZYBOY_COMPUTER_DRIVER=cua` only for explicit testing. Set `LAZYBOY_COMPUTER_DRIVER=legacy` on the supervisor (passed into each desktop container) to roll back to CDP/AT-SPI/xdotool. Recreate desktop containers after changing the flag.
-
-With `cua`: `POST /observe`, `POST /act`, and `POST /browser` go through Cua Driver. The Agent-facing `browser` schema is unchanged (`snapshot` / `click` / `type` / `press` / `navigate` / `wait`); Cua attaches with `existing_profile` and maps `semantic_v2` refs (`pN:M`) onto the existing element list. After human takeover ends, the run forces a fresh `computer_observe` and drops pre-handoff ids/refs. Skill teaching starts Cua `start_recording` (no video) plus the existing CDP DOM recorder so a human noVNC demo still yields semantic click/type/navigate events; Cua trajectory turns are ingested as extra evidence and password-labelled typing is masked. `use_saved_login` still fills via CDP stdin so passwords never appear on argv. `cdp.py` / AT-SPI remain for login fill, human browser recording, and the `legacy` rollback.
-
-
-## Review of the current checkout (2026-09-07)
-
-The locally tagged `lazyboy/computer:local` image now installs Cua Driver 0.23.2
-for the build architecture (`cua-driver 0.23.2` on linux/arm64 in this run).
-`make cua-smoke` is the acceptance entry: raw Driver smoke, adapter E2E,
-isolation, and pause/restart persistence. Production defaults remain `legacy`.
-See [the migration audit](cua-review.md).
-
-One upstream caveat about that persistence claim: Chromium writes its cookie
-database on a ~30 s timer and does not flush on `SIGTERM`. A profile survives
-`docker pause` / `docker restart` once that write has landed; stopping a desktop
-seconds after a login can still lose the cookie, and no LazyBoy code controls
-the timer. `scripts/cua-smoke-test.sh` waits for the fixture cookie to reach the
-profile before it restarts, so the check measures profile persistence instead of
-the flush timer.
-
-Image architectures are capped at `linux/amd64` and `linux/arm64` by upstream
-binaries: the Cua Driver ships only `linux-x86_64` / `linux-arm64` and ONNX
-Runtime only `linux-x64` / `linux-aarch64`. See
-[development.md](development.md#映像與-cpu-架構).
diff --git a/docs/cua-migration-progress.md b/docs/cua-migration-progress.md
deleted file mode 100644
index 4cd1956..0000000
--- a/docs/cua-migration-progress.md
+++ /dev/null
@@ -1,58 +0,0 @@
-# Cua-only migration verification
-
-Verified locally on 2026-09-08 (Linux arm64, Cua Driver 0.23.2). Source changes and local acceptance are complete. Production deployment is not part of this verification.
-
-The subsequent named-cursor feature, Chinese badge font, and its separate image
-verification are documented in [Agent cursor on the shared desktop](agent-cursor.md).
-
-## Requirements and evidence
-
-| Requirement | Implementation | Verification |
-| --- | --- | --- |
-| Remove the old control implementation | Cua is the only ComputerDriver. Deleted LegacyController, direct CDP/AT-SPI Python controllers, clipboard.py, process helpers and the tmux shell. Removed xdotool/xclip packages. | Source audit; old backend names rejected; final running image contains neither binary. |
-| See what Cua is doing | Actions foreground the existing browser/native window on the bot's shared display. Shell/file tools use visible named terminals; clipboard operations use a visible GTK editor. | Native/browser/noVNC smoke; terminal and clipboard integration; actual VNC demonstration. |
-| All computer actions through Cua | Browser, native pointer/key/ref actions, launch/focus, shell/file tools, clipboard and saved-login use the Cua controller. Removed blanket browser-pixel blocking so canvas/unsupported controls can use fresh screenshot coordinates through Cua. | Adapter, terminal, clipboard, login and dual-display tests; API tool-path audit found no hidden shell execution in agent computer/file tools. |
-| Time on every conversation record | Every persisted message renders MessageTime, including attachment/chip messages. Date/time includes seconds, ISO datetime and full local-time tooltip. | Real user and assistant error messages inspected at desktop and 500px width; frontend tests/typecheck/build. |
-| Faster/reliable connections | Reuse browser bindings; start VNC before Cua; record the daemon PID; do not inherit startup locks; skip repeated network attachment; reject missing networks before connect and fall back to host ports; recover expired Cua sessions for reads without replaying mutations. | Warm ensure reuses one daemon with an available lock; missing-network fallback leaves no stale attachment; session-expiry observation/browser recovery and mutation refusal pass. |
-
-Infrastructure provisioning/storage/database calls and independent connected-service MCP facilities remain. They are not alternate desktop controllers. Computer, browser, terminal and agent workspace-file interactions use Cua.
-
-## Acceptance results
-
-Final desktop image `lazyboy/computer:cua-work`:
-`sha256:4ad46205023694a26ff06f9e969d7c7e0ac43b98cae97a4483d2ba3379462117`
-
-- `cargo test --workspace`: 204 passed; the environment-dependent login integration is ignored by default and separately passed.
-- `cargo clippy --workspace --all-targets -- -D warnings`: passed.
-- `cargo fmt --all --check` and `git diff --check`: passed.
-- Frontend: 44 tests passed; TypeScript/Vite build passed.
-- `scripts/cua-smoke-test.sh --docker --repeat 1 --image lazyboy/computer:cua-work`: passed on the final image. Covers native/browser/noVNC, terminal persistence/Unicode/interrupt/reset, clipboard Unicode/multiline/copy, two-display isolation, session expiry, and browser-cookie persistence across pause/restart.
-- `COMPUTER_IMAGE=lazyboy/computer:cua-work scripts/cua-login-test.sh`: passed. Uses a trusted local HTTPS fixture in a disposable container and the production field-filling function, checks both exact values and verifies no submission.
-- Manual VNC demonstration switched the target desktop from Chromium to its terminal. Teaching retained 2 window events and 3 screenshots, including the final frame. The target's recording was driven by human-style VNC input, not target-side Cua action calls.
-
-Local measurements are samples, not production benchmarks: boot request 2.358s; warm screen URL request 0.100s; missing-network fallback 0.086s with unchanged Docker network attachments. A full container replacement/restart took 10.419s, including Docker shutdown.
-
-## Driver compatibility fixes
-
-- A zero CLI exit code is insufficient: `effect: refused` is treated as failure along with `status: refused`.
-- Email input can refuse Cua browser typing. Its fallback resolves one uniquely labelled visible native web entry through Cua, clicks the fresh observed bounds, selects all and pastes through Cua. Duplicate labels, browser chrome and zero-size fields are rejected.
-- Native type_text loses Unicode in terminals. Shell commands use ASCII Bash literals encoding UTF-8 bytes; general Unicode/multiline paste uses the Cua-operated clipboard editor. Zsh confirms multiline bracketed paste with another Enter.
-- The GTK helper exposes exact clipboard text through its accessibility label because the pinned driver does not return GTK entry values.
-- Expired driver sessions are revived for observations. Mutations rejected at expiry are not replayed. Expired browser bindings are classified as stale and re-bound for read requests.
-- Browser semantic clicks use `dom_event`; callers still inspect results. Unsupported controls can be operated with Cua coordinates from a fresh screenshot.
-
-## Teaching and environment limits
-
-Cua trajectories record driver invocations, not raw human VNC clicks/keys. Teaching retains window changes and visual keyframes. The start message and model prompt describe that accurately and require review of missing/ambiguous steps. Model failure no longer claims the skill was learned. The local environment has no real model key, so model-generated playbook quality was not tested; recording persistence and missing-key handling were verified.
-
-Local API: `http://127.0.0.1:3111`; supervisor7191. The test bot `1ae00840-ceaf-4197-957d-661df677b015` is running the final image with one Cua daemon. Generated test credentials are in the local .env; no real provider credentials were used. API login sessions are in-memory, so restarting the API requires signing in again (existing behavior).
-
-The disposable Postgres test database uses tmpfs on15434; the pre-existing compose database volume was left intact. The separate old `lazyboy-cua-verify` container is a UI-test viewer, not the final target desktop. Temporary smoke/login containers are removed by their scripts.
-
-## Local evidence files
-
-- `/tmp/lazyboy-workspace-tests.log`, `/tmp/lazyboy-workspace-clippy.log`
-- `/tmp/lazyboy-acceptance-smoke.log`, `/tmp/lazyboy-acceptance-login.log`
-- `/tmp/lazyboy-network-fallback-test.log`, `/tmp/lazyboy-session-recovery-test.log`
-- `/tmp/lazyboy-chat-time.png`, `/tmp/lazyboy-chat-mobile.png`, `/tmp/teach-vnc.png`
-- `/tmp/lazyboy-web-build-final.log`, `/tmp/lazyboy-final-frontend-tests.log`
diff --git a/docs/cua-review.md b/docs/cua-review.md
deleted file mode 100644
index 54aff4f..0000000
--- a/docs/cua-review.md
+++ /dev/null
@@ -1,55 +0,0 @@
-# Cua 遷移檢查(2026-09-07)
-
-> 歷史紀錄:本文描述 2026-09-07 的雙後端驗證,已非現況。目前只保留 Cua;操作方式見 [operations.md](operations.md),最新驗證狀態見 [cua-migration-progress.md](cua-migration-progress.md)。
-
-結論:`a.md` Phase 1 規格尚未全部勾完,但 **opt-in Cua 已可在現有 XFCE + Xvfb 桌面容器使用**。生產預設仍是 `legacy`。
-
-本次在 Apple Silicon(linux/arm64)上以 `lazyboy/computer:local` + Cua Driver **0.23.2** 重跑隔離桌面驗收。
-
-## 現況
-
-| 規格 | 狀態 |
-| --- | --- |
-| 雙後端、Agent schema 不變 | 完成。`LAZYBOY_COMPUTER_DRIVER=legacy`(預設)或 `cua`。 |
-| Docker 安裝 | 完成。Dockerfile 依 `TARGETARCH` 安裝 linux-arm64 / linux-x86_64,checksum 固定。 |
-| `computer_observe` | 完成。截圖 + native AT-SPI 元素(`kind=a11y`、snapshot-scoped `cua:…` handle)+ 視窗列表。 |
-| `computer_act` | 完成。pointer / type / key / scroll / focus / 單次 `drag`;native ref 走 Cua `click` / `set_value`。不支援的動作明確 `Unsupported`,不再偷偷回退 legacy。 |
-| Browser | 完成。`existing_profile` attach、`semantic_v2` refs、navigate 限 http/https/about。 |
-| 多螢幕隔離 | 完成。display `:1` 的 handle 送到 `:2` 會被拒絕;各自點擊只改自己的測試程式。 |
-| pause / restart 後 Chromium cookie | 完成。adapter `--check-persistence` 在 `docker pause` 與 `docker restart` 後都通過。 |
-| noVNC | smoke 確認 `:6080` 仍可連;完整 human takeover 端到端未另開測試。 |
-| 示範錄製 | Cua `start_recording` + 既有 CDP recorder 仍在;未做真人 noVNC 示範驗收。 |
-| Benchmark 文件 | 見 [cua-benchmark.md](cua-benchmark.md)。尚未對 legacy 做對照。 |
-| 預設切到 Cua | **未做。** 完整 DoD(takeover、錄製、生產 metrics)未過前維持 legacy。 |
-
-## 這輪修正
-
-- Native 同一批 `computer_act` 共用一份觀察快照;先前每個動作都把 handle map 拿掉,導致 `wait` 後面的 ref 或連續兩個 ref 被當成過期。
-- 拒絕的過期 ref 不再清掉該螢幕上其他仍有效的 handle。
-- JSON `code != ok` 即使行程成功碼為 0 也當失敗(避免 drag 誤報成功)。
-- CLI JSON 改走 stdin,避免輸入文字出現在 argv。
-- 拖曳改打最小包含該點的視窗(避免點到覆蓋其上的 Chromium),focus 優先精確標題(避免 `LazyBoy Cua Smoke - Chromium` 搶走 GTK 視窗)。
-- GTK 測資把 drawing area 座標轉成螢幕座標。
-- Cua 選到但 binary 不在或 daemon 起不來會明確失敗。
-
-## 驗證(本機 2026-09-07)
-
-- `cargo test --locked -p lazyboy-control`:84 通過。
-- `cargo check --locked -p lazyboy-api -p lazyboy-sandbox -p lazyboy-controld`:通過。
-- `make cua-smoke`(`--repeat 10`):
- - 原始 Driver smoke **10/10**(截圖、視窗、native click/type、Chromium attach、noVNC)
- - LazyBoy adapter **10/10**(GTK click / 中文 setvalue、過期 handle 拒絕、批次 native、drag、Chromium 表單)
- - 雙 display 隔離通過
- - pause/unpause 與 `docker restart` 後 cookie 仍在
-
-## 如何啟用
-
-預設不要改。要在本機明確跑 Cua:
-
-```bash
-make cua-smoke
-# 或
-docker compose -f docker-compose.yml -f docker-compose.cua.yml up -d --build
-```
-
-overlay 把 supervisor 的 `LAZYBOY_COMPUTER_DRIVER` 設成 `cua`,桌面映像標成 `lazyboy/computer:cua`,不會覆寫預設的 `lazyboy/computer:local` legacy 映像。改 flag 後必須重建桌面容器。
diff --git a/docs/development.md b/docs/development.md
index e6192c1..a80ba1a 100644
--- a/docs/development.md
+++ b/docs/development.md
@@ -38,7 +38,6 @@ python3 tests/log-rotation.test.py
# Cua Driver 能否控制現有 XFCE + Xvfb 桌面(會建 computer image)
make cua-smoke
-# 結果摘要見 docs/cua-compatibility.md、docs/cua-review.md
# 生產路徑只使用 Cua;更新後請重建 supervisor 與桌面映像。
# Python 整合測試用 docker compose exec 連進 Postgres,自己建一次性資料庫後清掉
@@ -105,6 +104,31 @@ builder 並註冊 binfmt;主機本身的架構會跳過註冊,否則在特
不推送 registry 時輸出 OCI archive(`nerdctl load -i <檔>` 可載入),因為 Docker 的
`docker` driver 無法匯出 manifest list。
+### README 首頁圖
+
+首頁圖不再手刻假介面:先用 `scripts/capture-hero.mjs` 拍**正在跑的真實介面**,再由
+`docs/hero.html` 套上品牌框輸出 `docs/readme-hero.png`。兩段都只要有任一 Chromium
+(`CHROME=` 指定,否則依序找 PATH 上的 chromium/Chrome 與 Playwright 下載的 chrome)。
+
+```bash
+# 1. 對運行中的 stack 擷取真實畫面(登入 token 讀 .env,可用 LB_TOKEN/LB_URL 覆寫)
+# 群組視圖的右欄是機器人自己的瀏覽器,進圖前先用 --hide 遮掉,再補一張中立的上去;
+# --anchor 會印出被遮區塊在圖上的位置,hero.html 的圖層座標就是從這裡來的。
+node scripts/capture-hero.mjs --out docs/hero/agent.png
+node scripts/capture-hero.mjs --out docs/hero/room.png --pick 測試聊天 \
+ --hide .side-card --anchor .side-card
+node scripts/capture-hero.mjs --out docs/hero/desktop.png --pick 阿狗 --selector .side-card
+
+# 2. 套框輸出 README 用的圖,SHOT= 決定用哪張(預設 room)
+scripts/render-readme-hero.sh
+SHOT=agent scripts/render-readme-hero.sh
+```
+
+`capture-hero.mjs` 直接講 CDP,沒有 npm 相依。預設擷取 1480x650(2 倍圖),正好對應
+`hero.html` 的 1184x520 視窗,不會裁到圖。noVNC 是即時串流,`--settle`(預設 6 秒)是留給
+桌面畫出內容的時間。**發布前務必逐張檢查**:機器人瀏覽器裡留著的帳號、網址與貼文會一起進
+圖,`--hide` 的 selector 沒命中時擷取會直接失敗,不要繞過這個檢查把圖放進 repo。
+
### 專案結構
```text
@@ -122,7 +146,8 @@ LazyBoy/
├── migrations/ SQLx PostgreSQL migrations
├── tests/ Rust 以外的契約與回歸測試
├── scripts/ 環境初始化與執行工具
-├── docs/hero.html README 首頁視覺原稿
+├── docs/hero.html README 首頁框架(品牌+真實截圖)
+├── docs/hero/ README 用的真實截圖原檔
├── docs/workflow.html 可互動產品流程圖
├── docker-compose.yml 正式堆疊
├── clippy.toml Clippy 閾值(要在 repo 根目錄執行才讀得到)
diff --git a/docs/hero.html b/docs/hero.html
index 69c5f29..6a4214b 100644
--- a/docs/hero.html
+++ b/docs/hero.html
@@ -26,332 +26,49 @@
html, body {
margin: 0;
width: 1280px;
- height: 640px;
+ height: 760px;
overflow: hidden;
background: #f3f3f5;
color: #161618;
font-family: Huninn, "jf open 粉圓", "PingFang TC", sans-serif;
}
- .page {
- width: 1280px;
- height: 640px;
- padding: 28px 48px 0;
- position: relative;
- }
- .top {
- display: flex;
- align-items: center;
- justify-content: space-between;
- height: 36px;
- }
- .brand {
- display: flex;
- align-items: center;
- gap: 10px;
- font-size: 20px;
- letter-spacing: .02em;
- }
+ .page { width: 1280px; height: 760px; padding: 30px 48px 0; }
+ .top { display: flex; align-items: center; justify-content: space-between; height: 36px; }
+ .brand { display: flex; align-items: center; gap: 10px; font-size: 20px; letter-spacing: .02em; }
+ .brand svg { width: 26px; height: 26px; }
.pill {
- display: inline-flex;
- align-items: center;
- gap: 8px;
- height: 28px;
- padding: 0 12px;
- border: 1px solid #e4e4e8;
- border-radius: 999px;
- background: #fff;
- color: #5c5c64;
- font-size: 12px;
- }
- .pill b {
- color: #0f766e;
- font-weight: 400;
- }
- .copy {
- text-align: center;
- margin: 22px auto 18px;
- max-width: 760px;
- }
- h1 {
- margin: 0;
- font-size: 42px;
- font-weight: 400;
- letter-spacing: .01em;
- line-height: 1.15;
- }
- .lead {
- margin: 10px 0 0;
- color: #6b6b73;
- font-size: 15px;
- line-height: 1.55;
+ display: inline-flex; align-items: center; gap: 8px; height: 28px; padding: 0 12px;
+ border: 1px solid #e4e4e8; border-radius: 999px; background: #fff; color: #5c5c64; font-size: 12px;
}
+ .pill b { color: #0f766e; font-weight: 400; }
+ .copy { text-align: center; margin: 20px auto 18px; max-width: 820px; }
+ h1 { margin: 0; font-size: 40px; font-weight: 400; letter-spacing: .01em; line-height: 1.15; }
+ .lead { margin: 10px 0 0; color: #6b6b73; font-size: 15px; line-height: 1.55; }
.window {
- width: 1184px;
- height: 470px;
- margin: 0 auto;
- border-radius: 16px 16px 0 0;
- overflow: hidden;
- background: #0d0d0e;
+ width: 1184px; height: 554px; margin: 0 auto;
+ border-radius: 16px 16px 0 0; overflow: hidden; background: #0d0d0e;
box-shadow: 0 24px 70px rgba(16, 16, 20, .28), 0 0 0 1px rgba(0,0,0,.08);
- display: grid;
- grid-template-rows: 36px 1fr;
+ display: grid; grid-template-rows: 34px 1fr;
}
.chrome {
- display: flex;
- align-items: center;
- gap: 7px;
- padding: 0 14px;
- background: #161618;
- border-bottom: 1px solid #202023;
+ display: flex; align-items: center; gap: 7px; padding: 0 14px;
+ background: #161618; border-bottom: 1px solid #202023;
}
.dot { width: 10px; height: 10px; border-radius: 50%; }
.dot.r { background: #ff5f57; }
.dot.y { background: #febc2e; }
.dot.g { background: #28c840; }
- .app {
- display: grid;
- grid-template-columns: 228px 1fr 300px;
- min-height: 0;
- color: #dfdfe2;
- background: #050506;
- }
- .side, .chat, .desk {
- min-width: 0;
- min-height: 0;
- }
- .side {
- background: #0b0b0c;
- border-right: 1px solid #171719;
- padding: 12px 10px;
- display: flex;
- flex-direction: column;
- gap: 8px;
- }
- .ws {
- display: flex;
- align-items: center;
- gap: 8px;
- padding: 4px 6px 8px;
- font-size: 14px;
- }
- .ws i {
- width: 26px; height: 26px;
- display: grid; place-items: center;
- border-radius: 50%;
- background: #151517;
- color: #85858a;
- font-size: 9px;
- font-style: normal;
- letter-spacing: .04em;
- }
- .search {
- height: 34px;
- border: 1px solid #202023;
- border-radius: 12px;
- background: #121214;
- color: #626267;
- display: flex;
- align-items: center;
- padding: 0 10px;
- font-size: 12px;
- gap: 8px;
- }
- .search svg { width: 13px; height: 13px; stroke: currentColor; fill: none; stroke-width: 1.7; }
- .label {
- padding: 8px 8px 2px;
- color: #626267;
- font-size: 10px;
- letter-spacing: .06em;
- }
- .bot {
- display: flex;
- align-items: center;
- gap: 8px;
- padding: 8px;
- border-radius: 12px;
- }
- .bot.on { background: #171719; }
- .bot strong { display: block; font-size: 13px; font-weight: 400; }
- .bot small { display: block; color: #85858a; font-size: 11px; margin-top: 1px; }
- .bot .copy { min-width: 0; flex: 1; }
- .bot .copy strong, .bot .copy small {
- overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
- }
- .time { color: #626267; font-size: 10px; align-self: start; }
- .chat {
- background: #0d0d0e;
- display: grid;
- grid-template-rows: 52px 1fr 118px;
- }
- .topbar {
- display: flex;
- align-items: center;
- gap: 8px;
- padding: 0 16px;
- border-bottom: 1px solid #171719;
- font-size: 15px;
- }
- .grow { flex: 1; }
- .tools {
- display: flex; gap: 2px; padding: 3px;
- border: 1px solid #29292d; border-radius: 11px; background: rgba(18,18,20,.86);
- }
- .tools i {
- width: 26px; height: 26px; border-radius: 8px;
- display: grid; place-items: center;
- font-style: normal;
- }
- .tools i.on { background: #151517; }
- .tools svg { width: 13px; height: 13px; stroke: currentColor; fill: none; stroke-width: 1.7; }
- .tools i.on svg { stroke: #f1f1f2; }
- .tools i:not(.on) svg { stroke: #85858a; }
- .msgs {
- padding: 18px 28px 8px;
- display: flex;
- flex-direction: column;
- gap: 12px;
- }
- .bubble {
- max-width: 78%;
- padding: 10px 14px;
- border-radius: 18px;
- line-height: 1.5;
- font-size: 13px;
- white-space: pre-wrap;
- }
- .me { align-self: flex-end; background: #f1f1ef; color: #1a1a1a; }
- .them { align-self: flex-start; background: #19191c; }
- .dock {
- padding: 8px 22px 16px;
- display: flex;
- flex-direction: column;
- gap: 8px;
- }
- .think {
- display: flex; align-items: center; gap: 8px;
- font-size: 12px;
- }
- .think .lbl {
- background: linear-gradient(90deg, #7a8088 0%, #7a8088 28%, #fff 50%, #7a8088 72%, #7a8088 100%);
- background-size: 220% 100%;
- -webkit-background-clip: text;
- background-clip: text;
- color: transparent;
- }
- .think small { color: #85858a; }
- .composer {
- height: 52px;
- display: flex; align-items: center; gap: 8px;
- border: 1px solid #29292d;
- background: #121214;
- border-radius: 22px;
- padding: 6px 8px;
- }
- .plus, .send {
- width: 34px; height: 34px; border-radius: 50%;
- display: grid; place-items: center;
- }
- .plus { color: #85858a; font-size: 20px; }
- .ph { flex: 1; color: #626267; font-size: 13px; }
- .send { background: #f1f1ef; color: #1b1b1c; font-size: 14px; }
- .desk {
- background: #0a0a0b;
- border-left: 1px solid #171719;
- padding: 10px 12px 12px;
- display: flex;
- flex-direction: column;
- gap: 8px;
- }
- .desk-h {
- display: flex; align-items: center; gap: 8px;
- color: #f1f1f2; font-size: 13px;
- }
- .desk-h .dot-run {
- width: 7px; height: 7px; border-radius: 50%; background: #4ecb71;
- }
- .desk-h small { color: #85858a; margin-left: auto; font-size: 11px; }
- .preview {
- position: relative;
- flex: 1;
- border: 1px solid #29292d;
- border-radius: 12px;
- background: #101012;
- overflow: hidden;
- min-height: 168px;
- }
- .desktop {
- position: absolute; inset: 0;
- background:
- radial-gradient(circle at 20% 0%, #1a2430 0%, transparent 42%),
- linear-gradient(180deg, #15202b, #0d1218);
- }
- .win {
- position: absolute;
- left: 14px; top: 12px; right: 14px; bottom: 28px;
- border-radius: 8px;
- background: #fff;
- overflow: hidden;
- box-shadow: 0 10px 28px rgba(0,0,0,.35);
- display: grid;
- grid-template-rows: 22px 28px 1fr;
- }
- .win-bar { background: #e8e8ea; display: flex; align-items: center; gap: 5px; padding: 0 8px; }
- .win-bar i { width: 7px; height: 7px; border-radius: 50%; background: #c4c4c8; font-style: normal; }
- .addr {
- background: #f4f4f6;
- display: flex; align-items: center;
- padding: 0 10px;
- color: #444; font-size: 10px;
- border-bottom: 1px solid #ececf0;
- }
- .page-body { padding: 12px 14px; color: #222; }
- .page-body h3 { margin: 0 0 6px; font-size: 13px; font-weight: 400; }
- .page-body p { margin: 0; color: #666; font-size: 11px; line-height: 1.45; }
- .progress {
- margin-top: 10px; height: 6px; border-radius: 99px; background: #ececf0; overflow: hidden;
- }
- .progress b { display: block; width: 62%; height: 100%; background: #3ec5a8; }
- .next {
- margin-top: 10px; height: 24px; width: 64px;
- border-radius: 6px; background: #1a1a1c; color: #fff;
- display: grid; place-items: center; font-size: 11px;
- }
- .panel {
- position: absolute; left: 0; right: 0; bottom: 0; height: 22px;
- background: #1b242e; border-top: 1px solid #2a3540;
- }
- .cap {
- display: flex; justify-content: space-between;
- color: #85858a; font-size: 11px;
- }
- .btn {
- height: 28px; padding: 0 10px; border-radius: 8px;
- border: 1px solid #29292d; color: #dfdfe2; display: grid; place-items: center;
- font-size: 12px;
- }
- .btn.cream { background: #f1f1ef; color: #181819; border-color: #f1f1ef; }
- .actions { display: flex; justify-content: flex-end; gap: 6px; }
-
- /* blobatar-ish faces */
- .blob { width: 32px; height: 32px; flex: 0 0 32px; }
- .blob.sm { width: 22px; height: 22px; flex-basis: 22px; }
- .blob.md { width: 28px; height: 28px; flex-basis: 28px; }
- .think-ring { position: relative; }
- .think-ring:after {
- content: "";
- position: absolute; inset: -5px;
- border-radius: 50%;
- background: conic-gradient(from 40deg, transparent 0 8%, #ff4fd8 12%, #7c5cff 18%, transparent 26% 48%, #34d9ff 54%, transparent 62%);
- -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 2px), #000 calc(100% - 1.5px));
- mask: radial-gradient(farthest-side, transparent calc(100% - 2px), #000 calc(100% - 1.5px));
- }
+ /* Real pixels: docs/hero/*.png comes from scripts/capture-hero.mjs. */
+ /* 1184x520 matches the capture ratio (1480x650), so nothing is cropped. */
+ .shot { position: relative; width: 1184px; height: 520px; overflow: hidden; }
+ .shot img { position: absolute; display: block; }
-
+
@@ -360,83 +77,75 @@
LazyBoy
-
Self-hosted a Linux desktop per agent
+
-
Give an agent a real computer
-
Open bots in the browser. They browse, run commands, and learn the flows you demonstrate. Chats and desktops stay on your host. You choose the model.
+
+
-
-
- LB Local workspace
-
- Pinned
-
-
-
-
-
Engineering Page 12, waiting for Next
-
14:08
-
- Agent
-
-
-
Morning digest Runs tomorrow at 9:00
-
-
-
-
Support Remembered the reply tone
-
-
-
-
-
- Engineering
- STAR training ▾
-
-
-
-
-
Finish the STAR course and submit the quiz.
-
Computer is up. Page 12 / 24 — I’ll hit Next when the video ends. I won’t store passwords.
-
-
-
-
-
Working…
-
click Next
-
-
-
-
-
-
+
+