本文へスキップ

コンパニオン

このページは、エージェントが英語版から翻訳し、確認しました。Zhehan が読めるのは英語と中国語です。校正へのご協力をお待ちしています。 校正に協力する 翻訳の問題を報告する

コンパニオンとは、SwB サーバーに接続するデバイスです。接続すると、エージェントがそのデバイスの機能を使えます。

macOS のコンパニオンは、更新ガイドに従って更新してください。

セットアップ用プロンプトをコピーする

Claude で開くChatGPT で開く
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.

Ask if I want the companion to start automatically. Use the foreground commands by default. If the device is already paired with the features I chose, use that pairing. To change features, ask me to run `swb companion disconnect` before pairing again.

For a new pairing, get a pairing code. If you can create a private file on my device, use an owner session. Call `companion_code` from that 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.

For SwB on this device, use its local address, such as `http://127.0.0.1:8870`. Use this command for a new foreground pairing. Include my SwB address and selected options. Before release, use `swb companion connect` from a source install.

```sh
uvx swb.one companion connect https://swb.example.com
```

For a new foreground pairing, ask me to run the pairing command on my device. Ask me to enter the code at the hidden prompt. Ask me to leave the command running. The foreground uses Python directly. For an existing foreground pairing, ask me to start the companion with `swb companion run` if needed. Use the same way of running `swb` as for pairing.

If I choose the background service, install SwB with `uv tool install swb.one` For a source build, use the installed source build. Follow the background section of the guide for my operating system. On macOS, the SwB release automatically installs and verifies the signed SwB Companion app when setting up the service. `launchd` uses that app to start the service.

For a new pairing with the service, use `swb companion connect https://swb.example.com --no-run` with my SwB address and selected options. Ask me to enter the code at the hidden prompt. For an existing pairing, reuse the device key. Ask me to stop any foreground run. Ask me to run `swb companion service install` with the installed `swb`. Check the connection with `swb companion status`.

Wait for me to confirm the companion is running. 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

入力内容を隠すプロンプトに、ペアリングコードを入力してください。コードは 1 回だけ使えて、10 分で期限が切れます。監査ログには、コードを作った人が記録されます。

デバイスは、専用のキーを非公開のファイルに保存します。

機能を選ぶ

有効にする機能ごとに、--cap オプションを 1 つずつ追加してください。

オプション機能
--cap notifyデバイスにデスクトップ通知を表示します
--cap drop~/SwB Drop フォルダーで、1 つ 10 MiB までのファイルを共有します
--cap mcp --mcp NAME=COMMANDデバイス上の MCP サーバーのツールをエージェントが使えるようにします
--cap herdrHerdr
--cap codexCodex app server
--cap opencodeOpenCode server
--cap dshDeepSeek Harness
--cap hooksステータスフック

Linux では、通知に notify-send を使います。Debian と Ubuntu では、libnotify-bin パッケージでインストールしてください。

MCP サーバーごとに --mcp オプションを 1 つずつ追加してください。プログラムの場合は --mcp 'NAME=COMMAND' を使います。NAME をサーバーの名前に置き換えてください。COMMAND をプログラムの起動コマンドに置き換えてください。デバイス上の HTTP サーバーの場合は、--mcp notes=http://127.0.0.1:8000/mcp のようにローカルアドレスを使ってください。

エージェントは companion_list で、ペアリング済みの各デバイスとその操作を確認します。操作の実行には companion_invoke を使います。

SwB は、コンパニオンが引き続き提供する機能の利用許可を保持します。新しい機能にはオーナーの承認が必要です。

companion_list か switchboard_status で、承認待ちの機能を確認してください。オーナーのセッションで companion_grant を使い、選んだ ID の機能を承認してください。

コンパニオンのテキスト結果の上限は 1 MiB です。Drop のファイルデータは structuredContent.result.content_b64 から読み取ってください。

ローカルセッション

ローカルセッションとは、デバイス上でコーディングエージェントが開いている会話です。SwB は、そのセッションの状態を local:session:<companion>:<harness>:<session> というアドレスとともに一覧表示します。

機能の表にある、お使いのコーディングエージェントのリンクを使ってください。ペアリングの前にエージェントを設定してください。ペアリング後は、コンパニオンを動かし続けてください。オーナーとしてサインインしたエージェントに、targets(block="local") の呼び出しを頼んでください。セッションのアドレスが表示されることを確認してください。

SwB は、各メッセージを開いているセッションに届けようとします。送信者がエージェントのメールボックスを使える場合は、メッセージをそのメールボックスに入れます。回答は同じ会話に返ってきます。

targets に表示されるセッションのアドレスを使ってください。そのアドレスのリソースを visibility_list で探してください。visibility_set でそのリソースを共有してください。

コマンドと対応エージェントについては、ローカルセッションをご覧ください。

動かし続ける

ペアリングするとコンパニオンが起動します。もう一度起動するときは swb companion run を使います。ローカルのデバイス ID と機能は swb companion status で確認できます。

uvx でペアリングした場合は、swb の代わりに uvx swb.one を使ってください。フォアグラウンドでは、Python がコンパニオンを直接実行します。

SwB への接続は、毎回デバイスの側から始めます。

バックグラウンドで実行する

コンパニオンを自動で起動するには、バックグラウンドサービスをインストールしてください。uv tool install swb.one で SwB をインストールしてください。

新たにペアリングするときは、ペアリング用のオプションに --no-run を追加してください。そのオプションを指定して swb companion connect を実行してください。コマンドはペアリングを終えると終了します。ターミナルでコンパニオンが動作中の場合は、サービスをインストールする前に停止してください。サービスを操作するときは、インストールした swb を使ってください。

swb companion service install

Linux では、systemd --user がユーザーのアカウントでサービスを実行します。起動時にサービスを開始し、ログアウト後も実行を続けるには、loginctl enable-linger "$USER" を実行してください。

macOS では、デスクトップにログインしてからサービスをインストールしてください。SwB の正式版では、署名済みの SwB Companion アプリが ~/Applications に自動でインストールされます。インストール時に署名も検証されます。launchd はこのアプリを使ってサービスを起動します。

Windows では、サインイン時にタスク スケジューラがサービスを起動します。

ローカルのツールに必要な変数は、サービスの管理ツールで設定してください。

swb companion service start でサービスを開始してください。swb companion service status でサービスの状態を確認してください。swb companion service logs でログを確認してください。

swb companion status でコンパニオンの実行状態、接続状態、SwB のアドレスを確認してください。

すぐにサービスを停止するには、swb companion service stop を使ってください。自動起動の設定を削除するには、swb companion service uninstall を使ってください。デバイスのキーは保持されます。

接続を解除する

デバイスのキーを削除するときは、そのデバイスで swb companion disconnect を実行してください。コンソールでキーを取り消すときは、Settings の Connections を開いてください。そのデバイスの Disconnect を選択してください。

動作中のコンパニオンは、取り消しを検出するとローカルのキーを削除します。デバイスにキーが残っている場合は、再びペアリングする前に swb companion disconnect を実行してください。

このページの内容