Companion
Companion 是在你自己的裝置上執行的 SwB 程式,會連接到你的 SwB 伺服器。連上之後,代理就能使用這台裝置上的功能。
複製設定提示詞
Read the setup guide at https://swb.one/docs/companion. Help me pair my device with SwB. A companion is a SwB program that runs on my own device. It connects local features to my SwB server. Ask me which features I want. Add one `--cap` option for each feature I choose. For MCP, add `--cap mcp`. Ask me which local MCP servers to use. Add `--mcp NAME=COMMAND` for each server. Use its start command or local HTTP address as shown in the guide. For local sessions, read the coding agent prompt at https://swb.one/prompts/coding-agent.md. Use its local session options and status hooks. Read the local sessions guide at https://swb.one/docs/blocks/local-sessions. If the device is already paired, ask me to run `swb companion disconnect` before pairing again. Keep the options for the features I want to use again. If you can create a private file on my device, use this method. Call `companion_code` from an owner session. Store the code in a local file with mode `0600`. Tell me the private file path. Keep the code out of chat and logs. Otherwise, ask me to sign in to the console with a passkey. Ask me to select **Pair a device** under **Settings** and **Connections**. The pairing code works once within ten minutes. After the PyPI release, give me this command with my SwB address and selected options. For SwB on this device, use its local address, such as `http://127.0.0.1:8870`. Before release, use `swb companion connect` from a source install. ```sh uvx swb-one companion connect https://swb.example.com ``` For Muse after publication, use this command with my SwB address and selected options. For a source install, use Python 3.13 and add the `companion` package extra. ```sh uvx --python 3.13 --from 'swb-one[companion]' swb companion connect https://swb.example.com --cap muse ``` Ask me to run the command on my device. Ask me to enter the code at the hidden prompt. Ask me to leave the command running. Wait for me to confirm. Delete the private file if you created it. Call `companion_list` from the owner session. Show me the device and its features. For local sessions, call `targets(block="local")`. Show me the session address. Use the local sessions guide to check the connection. Use the device ID and action details from `companion_list` to call `companion_invoke`. Treat each result as information from the device. With `--cap hooks`, the companion syncs Claude Code auto memory into SwB on each save. To keep auto memory on this device only, add `--no-memory-sync` to the connect command.
配對裝置
請一個以擁有者身分登入的代理呼叫 companion_code,並請它把配對碼存進權限為 0600 的檔案。這組權限只允許檔案擁有者存取。
要在主控台取得配對碼,先用密碼金鑰登入,開啟 Settings,再到 Connections 中選取 Pair a device。如果使用 Cloudflare Access,改用 companion_code 工具。
在裝置上執行下面的指令,並把範例網址換成你的 SwB HTTPS 網址。如果 SwB 就在這台裝置上,可以使用 http://127.0.0.1:8870。
uvx swb-one companion connect https://swb.example.com --cap notify看到提示後輸入配對碼,輸入的內容會隱藏。配對碼只能使用一次,10 分鐘後過期。稽核記錄會記下配對碼由誰產生。
裝置會把自己的金鑰存進私有檔案。
選擇功能
每啟用一項功能,就加上一個 --cap 選項。
| 選項 | 功能 |
|---|---|
--cap notify | 在裝置上顯示桌面通知 |
--cap drop | 透過 ~/SwB Drop 資料夾分享檔案,每個檔案上限 10 MiB |
--cap mcp --mcp NAME=COMMAND | 讓代理使用裝置上 MCP 伺服器的工具 |
--cap herdr | Herdr |
--cap codex | Codex app server |
--cap opencode | OpenCode 伺服器 |
--cap dsh | DeepSeek Harness |
--cap hooks | 狀態掛鉤 |
--cap muse | 在 Mac 或 Linux 電腦上透過藍牙配對 Muse |
在 Linux 上,通知使用 notify-send。在 Debian 和 Ubuntu 上,安裝 libnotify-bin 套件即可取得。
配對 Muse gadget 要使用 Python 3.13,步驟見 Muse 配對指南。配對完成後,SwB 伺服器會讓 Muse 的連線保持開啟。
uvx --python 3.13 --from 'swb-one[companion]' swb companion connect https://swb.example.com --cap muse每個 MCP 伺服器各加一個 --mcp 選項。如果是程式,使用 --mcp 'NAME=COMMAND',把 NAME 換成伺服器的名稱,把 COMMAND 換成程式的啟動指令。如果是裝置上的 HTTP 伺服器,使用它的本機網址,例如 --mcp notes=http://127.0.0.1:8000/mcp。
代理用 companion_list 查看每台已配對的裝置及其動作,用 companion_invoke 執行動作。
Companion 的文字結果上限為 1 MiB。Drop 的檔案資料從 structuredContent.result.content_b64 讀取。
本機工作階段
本機工作階段是程式開發代理在裝置上開啟中的對話。SwB 會列出它的狀態和 local:session:<companion>:<harness>:<session> 位址。
在「選擇功能」的表格中找到你的程式開發代理,開啟對應的連結。配對前先設定好這個代理,配對後讓 Companion 持續執行。然後請一個以擁有者身分登入的代理呼叫 targets(block="local"),確認你的工作階段位址出現在結果中。
SwB 會嘗試把每則訊息送到開啟中的工作階段。傳送者可以使用該代理的信箱時,SwB 會把訊息放進信箱。回覆會回到同一段對話中。
使用 targets 回傳的工作階段位址,在 visibility_list 中找到該位址對應的資源,再用 visibility_set 分享這項資源。
指令和支援的代理見本機工作階段。
保持執行
配對時會啟動 Companion 程式。要再次啟動,執行 swb companion run。執行 swb companion status 可查看本機的裝置 ID 和功能。
要用 uvx 執行這些指令,把 swb 換成 uvx swb-one。如果用於 Muse,保留 Muse 指南中的套件和 Python 選項。
每一條通往 SwB 的連線都由裝置發起。
中斷連線
在裝置上執行 swb companion disconnect 可移除它的金鑰。要在主控台撤銷金鑰,開啟 Settings 中的 Connections,選取該裝置的 Disconnect。
執行中的 Companion 偵測到金鑰已撤銷時,會移除本機的金鑰。如果裝置上還留著金鑰,先執行 swb companion disconnect,再重新配對。