Rex
Rex 是 Superlogical 的終端機應用程式。Rex 伺服器讓工作階段持續執行。
SwB 可將工作傳送到開啟的 Rex 窗格中的代理。窗格是 Rex 終端機中的一塊區域。
複製設定提示詞
Read the setup guide at https://swb.one/docs/setup/rex.
Help me connect an agent in Rex to SwB.
Rex is a terminal app from Superlogical.
A pane is one terminal area in Rex.
SwB carries messages and stores shared memory.
Use a SwB client with owner access for setup.
Call `connect(what="rex")`.
Alternatively, run this command in my SwB folder.
```sh
swb connect rex
```
## Agent in the Rex pane
The agent that runs in the Rex pane connects with `connect(what="coding-agent")`.
Call it from the owner client.
Alternatively, run `swb connect coding-agent` in my SwB folder.
Keep the existing key if the agent already has one.
If SwB returns a pairing code, redeem it in a private terminal within ten minutes.
Use `POST /connect`.
Send `{"code":"<pairing code>"}` in the request body.
Send a `User-Agent` header that names the app on each HTTP request to SwB.
Read the response in memory.
Add a server named `swb` in the settings of the agent.
Use `mcp_url` as the Streamable HTTP address.
Streamable HTTP lets the app call SwB tools over the network.
Use the returned `key` in the `Authorization: Bearer <key>` header.
Store the key in the agent's private settings.
Keep credentials private.
For its settings format, use the matching entry in the [coding agent guide](https://swb.one/docs/setup/coding-agent).
For Claude Code or Codex, add the matching status hooks from the SwB checkout.
A status hook runs a command when an agent reports a change.
Use `channel/hooks/hooks.json` for Claude Code or `integrations/codex/hooks.json` for Codex.
The hook reads `REX_BLOCK`, which Rex sets in each pane.
Open a new Rex pane after you save the hooks.
## Companion
A companion is a SwB program that connects this device to my SwB server.
Install the `swb` command with `pipx install swb.one`.
Run the companion on the device that runs Rex.
Use Rex 0.1.0-preview.25 or later.
Check it with `rex version --json`, which must report API revision 24 or later.
Replace the example address with my SwB address.
```sh
swb companion connect https://swb.example.com --cap rex --cap hooks
```
Use `companion_code` from the owner client.
Enter the code at the hidden prompt.
Leave the companion running.
The companion finds `rex` on the command search path or in `REX_BIN_DIR`.
Rex sets `REX_BIN_DIR` in its own terminals.
To list panes on other Rex hosts, set `SWB_REX_HOSTS` to host labels from `rex hosts`, separated by commas.
A host is a computer that runs a Rex server.
Status hooks run where the agent runs, so a reply comes from a pane on the companion's own device.
Run a companion on the other host for replies there.
## Check the connection
Run `swb companion status` on the device.
If it prints that Rex is unavailable or needs an update, fix Rex and run it again.
Call `targets(block="local")` from the owner client.
Find the target `local:session:<companion>:rex:<block uuid>` for the pane that runs the agent.
The block uuid is the block ID without the `block:` part.
Send a test message to that target.
SwB pastes the message into the pane and presses Enter.
SwB delivers it to a pane that runs a known agent, such as Claude Code, Codex, or Antigravity CLI.
Read the answer with `result` and the conversation from `send`.
Call `inbox` from the paired client.
Call `swb_guide(trigger="setup")` from the same client.
Call `memory_summary` from the paired client.
Read the session's `AGENTS.md`.
Select facts to share.
Keep credentials and private details on the device.
Use `memory_sync` with `source="agents-md"`.
Give each fact a stable `source_key`.
Use the project slug for project memory.把提示詞貼給以 SwB 擁有者身分登入的代理。代理會呼叫 connect(what="rex") 取得設定指南。
Rex 窗格中的代理用 connect(what="coding-agent") 連接。依照終端機代理的說明,為這個代理加入 SwB 和狀態掛鉤。把金鑰保存在私人設定中。
在執行 Rex 的裝置上啟動 Companion。使用 Rex 0.1.0-preview.25 或更新版本。
swb companion connect https://swb.example.com --cap rex --cap hooks配對裝置。出現提示時,輸入裝置的一次性配對碼。
請具有擁有者權限的代理呼叫 targets(block="local")。找出格式為 local:session:<companion>:rex:<block uuid> 的目標。傳送測試訊息到這個目標。用 result 讀取回覆。
參考
裝置上 Rex 伺服器的每個終端機窗格都是一個目標。區塊 ID 是 Rex 給窗格的穩定 ID。目標使用區塊 ID 中 block: 後面的部分。
SwB 把訊息貼到窗格中,再按下 Enter 鍵。SwB 會把訊息交給執行已知代理的窗格,例如 Claude Code、Codex 或 Antigravity CLI。對於執行 shell 或其他程式的窗格,SwB 會把訊息保存在信箱中。
回覆使用狀態掛鉤。Claude Code 用 channel/hooks/hooks.json,Codex 用 integrations/codex/hooks.json。掛鉤會讀取 Rex 在每個窗格中設定的 REX_BLOCK。在狀態掛鉤回報之前,工作階段狀態顯示為 unknown。
Companion 在指令搜尋路徑或 REX_BIN_DIR 中尋找 rex。Rex 會在自己的終端機中設定 REX_BIN_DIR。rex version --json 必須回報 API 修訂號 24 或更新。缺少 rex 時,swb companion status 會顯示 Rex is unavailable on this device. Rex 版本較舊時,會顯示 Update Rex to API revision 24 or later to use it with SwB.
如果要同時列出其他 Rex 主機上的窗格,把 SWB_REX_HOSTS 設為 rex hosts 中的主機標籤,用逗號分隔。主機是執行 Rex 伺服器的電腦。狀態掛鉤在代理執行的位置運作。回覆來自 Companion 所在裝置上的窗格。如果要在另一台主機上取得回覆,請在那台主機上執行 Companion。

