tmux-status-debug について
tmux-opencode-integrated の状態検出を保守する開発者向けのデバッグスキルです。tmux ペインの確認、状態パターンのテスト、テストやビルドの更新方法を扱います。
主な機能
- 01エージェントのペイン確認と内容取得
- 02ペイン出力に対するパターンテスト
- 03状態判定の優先順位の把握
- 04パターン更新とテスト実行
活用シーン
- 01エージェント状態アイコンの誤表示調査
- 02未一致の端末パターンの診断
- 03新しい状態表示の追加と検証
インストール
コマンドをコピーしてターミナルで実行します。
$
npx skills add https:/ / github.com/ edmundmiller/ dotfiles --skill tmux-status-debugインストール後、Claude Code で/tmux-status-debugを入力して読み込まれたか確認します。
詳細
tmux-opencode-integrated のステータス検出をデバッグする
使用するタイミング
- ステータスアイコンに誤った状態が表示される場合(例:エージェントが IDLE なのに ERROR と表示される)
- エージェント検出用のパターンを追加する場合
- 実際のペイン内容に対するパターンマッチングをテストする場合
クイックコマンド
すべてのエージェントのペインを一覧表示する
tmux list-panes -a -F "#{session_name}:#{window_name}.#{pane_index} #{pane_current_command}" | grep -E "opencode|claude|amp"
ペインの内容を取得する(生データ)
tmux capture-pane -t "main:1" -p -S -30 | tail -40
制御文字を表示して取得する
tmux capture-pane -t "main:1" -p -S -30 | cat -v | tail -40
ペインにパターンが存在するか確認する
tmux capture-pane -t "main:1" -p -S -20 | grep -o "pattern"
デバッグスクリプト
/tmp/debug_status.py を作成し、libtmux を含む Nix の Python で実行します。
import sys
sys.path.insert(0, "/Users/emiller/.config/dotfiles/packages/tmux-opencode-integrated/scripts")
import smart_name
import re
import libtmux
server = libtmux.Server()
for session in server.sessions:
for window in session.windows:
for pane in window.panes:
program = smart_name.get_pane_program(pane)
if program in smart_name.AGENT_PROGRAMS:
print(f"\n=== {program} in {session.name}:{window.name} ===")
try:
cmd_output = pane.cmd("capture-pane", "-p", "-S", "-20").stdout
if isinstance(cmd_output, list):
content = "\n".join(cmd_output)
else:
content = str(cmd_output)
cleaned = smart_name.strip_ansi_and_control(content)
print(f"Last 300 chars (cleaned):\n{cleaned[-300:]}")
print(f"\n--- Status: {smart_name.get_opencode_status(pane)} ---")
except Exception as e:
print(f"Error: {e}")
libtmux を含む Nix の Python を探す
# Build the package and get the store path
nix build .#tmux-opencode-integrated --no-link --print-out-paths
# Check wrapper to find Python path
head -10 /nix/store/<hash>-tmux-opencode-integrated-*/share/tmux-plugins/tmux-opencode-integrated/scripts/smart-name.sh
# Run debug script with that Python
/nix/store/<python-hash>-python3-*-env/bin/python3 /tmp/debug_status.py
パターンのテスト
サンプルコンテンツに対してパターンをテストします。
import re
content = """ctrl+t variants tab agents ctrl+p commands • OpenCode 1.1.30"""
patterns = [
(r"OpenCode \d+\.\d+\.\d+", "IDLE - version"),
(r"ctrl\+p commands", "IDLE - status bar"),
(r"esc interrupt", "BUSY - can interrupt"),
(r"Esc to cancel", "BUSY - can cancel"),
(r"■■■", "BUSY - progress bar"),
]
for pattern, desc in patterns:
if re.search(pattern, content, re.IGNORECASE):
print(f"✓ {desc}: {pattern}")
ステータスの優先順位
順序が重要です。最初に一致したものが採用されます。
- ERROR - トレースバック、パニック、FATAL ERROR、API エラー
- WAITING - Allow once?、Permission required、yes/no/skip のプロンプト
- BUSY - Thinking...、スピナー、ツールの実行中、esc による中断
- IDLE - 入力プロンプト、コンテキスト表示、OpenCode のバージョン、ctrl+p コマンド
- UNKNOWN - 一致するパターンがない場合(フォールバック)
新しいパターンの追加
- 上記のデバッグスクリプトを使って、実際のペイン内容を取得します
- 状態を示す固有のテキストを特定します
smart_name.pyの該当するリストにパターンを追加しますtests/test_smart_name.pyにテストケースを追加します- テストを実行します:
uvx pytest tests/test_smart_name.py -v - 再ビルドします:
nix build .#tmux-opencode-integrated
よくある問題
「No module named 'libtmux'」
使用している Python が違います。このパッケージでラップされた Nix の Python を使用してください。
パターンが一致しない
ターミナルの制御文字が干渉している可能性があります。strip_ansi_and_control() 関数で処理されるはずですが、cat -v で生の内容を確認してください。
ERROR と表示されるべきでないのに、ステータスが ERROR と表示される
以前の出力にエラーのような文字列が含まれていないか確認してください。検出では、ペイン内容の最後の 20 行を確認します。
コメント
Markdown 対応