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 应用服务器 |
--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,再重新配对。