Skip to content

feat(editor): Remote-SSH 跨ホストの attach 対応 + up 時のターミナル自動表示 (PLAN31_3)#70

Merged
takemi-ohama merged 11 commits into
mainfrom
feature/PLAN31_3-remote-ssh-attach-and-terminal
Jun 14, 2026
Merged

feat(editor): Remote-SSH 跨ホストの attach 対応 + up 時のターミナル自動表示 (PLAN31_3)#70
takemi-ohama merged 11 commits into
mainfrom
feature/PLAN31_3-remote-ssh-attach-and-terminal

Conversation

@takemi-ohama

Copy link
Copy Markdown
Contributor

Pull Request

概要

devbase up 後の VS Code 自動オープン (PLAN31_3) を、Windows VS Code → Remote-SSH(Mac) → Mac の Docker 上コンテナ という跨ホスト構成で動作するように修正します。あわせて、フォルダを開いた時に統合ターミナルを自動表示する機能を追加します。

実機検証の結果、attached-container+...@ssh-remote+<host> というネスト authority は実際にサポートされており動作することが判明しました(VS Code 1.124.2 / Dev Containers 0.459.1)。当初プラン §2.3 の「ネスト未サポート」は誤りで、本 PR で訂正しています。フラット URI のままだと委譲先クライアント(Windows)のローカル Docker を見に行きコンテナが見つからず「コンテナーにアタッチできません。すでに存在しません」となっていました。

関連 Issue

  • 元 issue: issues/PLAN31_3_up-open-editor.md(第3項)

変更点

  • (b) Remote-SSH ネスト URI 対応
    • opener.build_attach_uri(ssh_host, docker_context)attached-container+{containerName[,settings.context]}@ssh-remote+<host> を生成(docker ルックアップを ssh 先=コンテナのある側で行わせる)
    • resolve_editor_ssh_hostDEVBASE_EDITOR_SSH_HOST)/ resolve_docker_context(既定 docker context showDEVBASE_EDITOR_DOCKER_CONTEXT で上書き)
    • SSH 検出時のみネスト、非 SSH(ローカル/WSL/同一ホスト)は従来のフラット URI を維持
    • ※ ssh ホスト別名(手元 ~/.ssh/config の Host 名)は VS Code が ssh 先端末 env に渡さない(SSH_CONNECTION は IP のみ)ため自動取得不可。明示設定が前提
  • (d) up 時にターミナル自動表示用 tasks.json を配置(既定 ON)
    • _maybe_place_terminal_task が開く dev コンテナの /work/$GIT_REPO/.vscode/tasks.json(folderOpen) を docker exec -i で配置(既存があればスキップ)
    • DEVBASE_OPEN_TERMINAL(既定 ON)/ CLI --open-terminal --no-open-terminal
    • VS Code 公式に起動時ターミナル設定は無く folderOpen が唯一の方法(hideOnStartup は復元セッション制御のみ)。自動実行は Workspace Trust と task.allowAutomaticTasks(共に user スコープ専用・devbase 制御外)に依存し初回承認クリックが要る
  • (a) ドキュメント実態修正
    • issues/PLAN31_3_up-open-editor.md §2.3/§2.4/§8 を訂正(ネスト authority 実サポート・要 DEVBASE_EDITOR_SSH_HOST・実機検証済み)
    • docs/user/environment-variables.md に新 env 3 件(DEVBASE_EDITOR_SSH_HOST / DEVBASE_EDITOR_DOCKER_CONTEXT / DEVBASE_OPEN_TERMINAL)+跨ホスト節を追記
  • lib/devbase/env/keys.py に新キー登録、テスト追加

動作確認

  • uv run --group dev pytest 全 793 passed / 1 skipped
  • 跨ホスト構成(Win→Remote-SSH(mac2)→Mac)で手動採取した正解 URI と同形式(@ssh-remote+mac2 + settings.context=desktop-linux)を生成することを確認
  • レビュアー: $DEVBASE_ROOT/envDEVBASE_EDITOR_SSH_HOST=mac2 を設定し devbase up で自動アタッチ+ターミナル自動表示を実機確認
  • 同一ホスト構成(Mac ローカル)で従来どおりフラット URI で開くことを確認
  • CI が green である

補足

  • 自動オープンの既定は OFF(DEVBASE_OPEN_EDITOR)、ターミナル配置の既定は ON(DEVBASE_OPEN_TERMINAL)と既定が逆である点に注意。
  • Workspace Trust / task.allowAutomaticTasks はクライアント側 user 設定のため devbase からは制御できず、初回のみ承認クリックが必要(docs に明記)。

Windows VS Code → Remote-SSH(Mac) → Mac の Docker 上コンテナ、という構成で
devbase up の自動オープンが「コンテナが存在しません」で失敗する問題を修正。
実機検証の結果、ネスト authority attached-container+...@ssh-remote+<host> は
実際にサポートされており、これを使うと docker ルックアップが ssh 先(コンテナの
ある側)で行われ解決できる(PLAN31_3 §2.3/§2.4 の当初想定を訂正)。

- build_attach_uri に ssh_host / docker_context を追加しネスト URI を生成
- DEVBASE_EDITOR_SSH_HOST(明示) / DEVBASE_EDITOR_DOCKER_CONTEXT(既定 docker context show)
  ※ ssh ホスト別名は VS Code が ssh 先端末 env に渡さず自動取得不可のため明示必須
- DEVBASE_OPEN_TERMINAL(既定 ON): up 時に folderOpen タスク .vscode/tasks.json を
  docker exec で配置し、フォルダを開くと統合ターミナルを自動表示(既存はスキップ)
- CLI: --open-terminal / --no-open-terminal を追加
- docs / PLAN31_3 を実態へ更新、テスト追加

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

@takemi-ohama takemi-ohama left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 cross-review | round 1 | codex | APPROVE

修正必須の指摘はありません。

@takemi-ohama takemi-ohama left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 cross-review | round 1 | gemini | APPROVE

提供された設計仕様 (PLAN31_3) およびドキュメントと実装に乖離はなく、跨ホスト構成のネスト URI 解決や、統合ターミナルの自動表示用タスク配置 (folderOpen) が堅牢かつ冪等に実装されています。新規環境変数や CLI オプションの反映、例外のハンドリングを含め、全体として非常に完成度が高く問題は見当たりません。マージして問題ありません。

跨ホスト Remote-SSH attach に必要な ssh-remote authority ラベル(例 mac2)を、
ssh 先 ~/.vscode-server の File History (entries.json の resource URI に残る
ssh-remote%2B<host>) から自動検出するようにし、DEVBASE_EDITOR_SSH_HOST の明示を
不要にした(明示は上書きとして残す)。

- IP / user@IP でのネスト attach は不可と実機確認(既存 ExecServer の authority と
  一致が必須、"Parent authority found without ExecServer")。別名一致のみ有効
- resolve_editor_ssh_host: 明示 → ~/.vscode-server 自動検出 → None(フラット) の三段
- 複数 ssh-remote ホストは最新 mtime の entries.json を優先
- docs / PLAN31_3 を自動検出方式へ更新、テスト追加

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

@takemi-ohama takemi-ohama left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 cross-review | round 2 | gemini | REQUEST_CHANGES

devbase up 実行時のエディタ自動起動処理において、パフォーマンスに関する懸念が見つかりました。不要なファイル I/O を避けるための最適化をお願いします。

Comment thread lib/devbase/editor/opener.py Outdated

@takemi-ohama takemi-ohama left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 cross-review | round 2 | codex | APPROVE

修正必須の指摘はありません。

_detect_ssh_host_from_vscode が全 entries.json を読んでいたのを、mtime 降順で
新しいファイルから順に読み最初の ssh-remote 一致で即 return する実装へ変更。
History が巨大でも全読み込みを避け devbase up の遅延を防ぐ (gemini 指摘 / major)。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

@takemi-ohama takemi-ohama left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 cross-review | round 3 | codex | APPROVE

指摘事項はありません。

@takemi-ohama takemi-ohama left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 cross-review | round 3 | gemini | REQUEST_CHANGES

エディタの互換性に関して 1 点修正提案があります。code-insiderscursor 利用時にもクロスホストの自動検出が機能するよう、探索対象ディレクトリの拡充をお願いします。

Comment thread lib/devbase/editor/opener.py Outdated
DEVBASE_EDITOR=cursor / code-insiders 等でも跨ホスト自動検出が効くよう、
~/.vscode-server に加え ~/.cursor-server / ~/.vscode-server-insiders /
~/.vscodium-server / ~/.windsurf-server を横断し、全 entries.json から最新
mtime のホストを採用する (_detect_ssh_host_from_dirs)。gemini 指摘 / major。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

@takemi-ohama takemi-ohama left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 cross-review | round 4 | gemini | APPROVE

パフォーマンス観点で 1 点のみマイナーな提案を記載します。

Comment thread lib/devbase/editor/opener.py Outdated
無マッチ時に全 entries.json を read するのを避けるため、mtime 降順で新しい方から
最大 200 件のみ内容を読む (該当ホストは直近接続のファイルに載るため安全)。gemini 指摘 / minor。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

@takemi-ohama takemi-ohama left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 cross-review | round 5 | gemini | APPROVE

エッジケースへの配慮(VS Code の History からのヒューリスティックな検出など)が細かくテストされており素晴らしいです。skip 判定時の軽微な最適化を1点のみ提案しています。

Comment thread lib/devbase/editor/opener.py
skip 判定 (非TTY/CI・code 不在等) でも resolve_container_name(docker compose ps) や
resolve_docker_context(docker context show) を呼んでいたのを、skip を先に return して
無駄な外部コマンド実行を回避。gemini 指摘 / minor。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

@takemi-ohama takemi-ohama left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 cross-review | round 6 | codex | APPROVE

修正必須の新規指摘はありません。

@takemi-ohama takemi-ohama left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 cross-review | round 6 | gemini | REQUEST_CHANGES

DEVBASE_EDITOR_SSH_HOSTDEVBASE_EDITOR_DOCKER_CONTEXT について、環境変数に空文字列を指定して自動推測やコマンド実行を明示的に無効化(オプトアウト)できる仕組みが欠けているため、修正を提案します。

Comment thread lib/devbase/editor/opener.py Outdated
env が空文字 ("") の場合を「明示的オプトアウト」として扱い、ssh host は自動推測を
スキップしてフラット URI 強制、docker context は settings.context を付けない。
判定を `is not None` に変更 (定義されていれば値を尊重し、空なら None)。gemini 指摘 / major。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

@takemi-ohama takemi-ohama left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 cross-review | round 7 | codex | APPROVE

修正必須の新規指摘はありません。

@takemi-ohama takemi-ohama left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 cross-review | round 7 | gemini | APPROVE

パフォーマンス改善に関するインラインコメントを 1 件提案しています。

Comment thread lib/devbase/commands/container.py Outdated
_maybe_place_terminal_task が解決した実コンテナ名を返し、_maybe_open_editor →
open_editor へ container_name として渡して resolve_container_name(docker compose ps)
の重複呼び出しを除去。gemini 指摘 / minor。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

@takemi-ohama takemi-ohama left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 cross-review | round 8 | gemini | APPROVE

特に修正を提案する点はありません。

@takemi-ohama takemi-ohama left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 cross-review | round 8 | codex | REQUEST_CHANGES

インラインの修正点を対応してください。

Comment thread lib/devbase/editor/opener.py Outdated
build_folder_open_tasks_json を type:shell + ${env:SHELL} から type:process +
/bin/sh -lc 'exec "${SHELL:-/bin/sh}"' へ変更。SHELL 未設定コンテナで command が
空になりタスクが即失敗する問題を修正。codex 指摘 / major。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

@takemi-ohama takemi-ohama left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 cross-review | round 9 | codex | REQUEST_CHANGES

plain SSH 経路で Remote-SSH 用の自動検出が混ざるため、提示されるコマンドの正確性を修正してください。

Comment thread lib/devbase/editor/opener.py Outdated

@takemi-ohama takemi-ohama left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 cross-review | round 9 | gemini | APPROVE

統合ターミナル表示の自動化と跨ホスト環境でのネスト URI 対応について、意図通り実装されていることを確認しました。いくつかのリファクタリング・パフォーマンス改善の余地をインラインで提案します。

Comment thread lib/devbase/commands/container.py Outdated
Comment thread lib/devbase/editor/opener.py Outdated
- plain SSH (VS Code 外) は既存 ExecServer 不在でネスト URI が動かないため、自動検出は
  in_vscode の時だけ有効化 (resolve_editor_ssh_host に auto_detect 引数追加)。plain SSH は
  明示設定時のみネスト URI を採用。codex 指摘 / major
- open_index の env フォールバック+範囲チェックを _resolve_open_index に集約 (重複排除)。gemini / minor
- ssh host 自動検出の History 走査を os.walk → os.scandir (固定深さ 1 階層) に変更。gemini / minor

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

@takemi-ohama takemi-ohama left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 cross-review | round 10 | gemini | APPROVE

現在の実装およびテストにおいて問題点はありません。安全にマージ可能な状態です。

冒頭 docstring が「ネスト authority は公式未サポート」と旧設計のまま残り実装・PLAN・
docs と矛盾していたのを、attached-container+...@ssh-remote+<host> 実サポート + 自動検出 +
plain SSH degrade の現設計へ更新。codex 指摘 (round 4/5/10 で line 13 が diff 外のため
inline 投稿 422 となり取りこぼしていた件) / minor。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

@takemi-ohama takemi-ohama left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 cross-review | round 11 | codex | APPROVE

新規の修正提案はありません。

@takemi-ohama takemi-ohama left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 cross-review | round 11 | gemini | APPROVE

PR 全体の実装およびテストを確認しました。指摘事項はありません。

@takemi-ohama takemi-ohama merged commit 03dbb04 into main Jun 14, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant