Skip to content

feat(ssh): add-and-connect fallback row for launcher search misses - #869

Open
zher52 wants to merge 25 commits into
Kuddev:mainfrom
zher52:feat/palette-add-ssh-host
Open

zher52 wants to merge 25 commits into
Kuddev:mainfrom
zher52:feat/palette-add-ssh-host

Conversation

@zher52

@zher52 zher52 commented Nov 4, 2026

Copy link
Copy Markdown

Result / 用户结果

Refs #864.

When the Shell/SSH launcher (Cmd/Ctrl+K) or the command palette finds no match and the typed query looks like a host address (contains @ or .), one fallback row appears: "添加并连接 {destination}". Enter opens a workspace-owned overlay — no navigation to Settings — prefilled from the typed text; "保存并连接" persists the host and immediately opens a connected tab, closing the overlay. Esc/backdrop cancels without touching the host library.

Because the connection goes through add_ssh_terminal, everything downstream behaves exactly like a built-in connection: tab naming, the remote file drawer (ready_ssh_destination), host recording (saved_hosts) and the connection pool.

Design / 设计边界

  • One injection point covers both surfaces: the fallback row is appended in filtered_palette_rows when filtering yields no rows (launcher and command palette share that projection). The row predicate is deliberately loose (@ or ., host segment ≥ 3 chars) because address validity is decided by save-time validation, not by the row.
  • The overlay's field order, wording and authentication segmented row mirror the Settings editor's basic form (name optional → address+port row with the same address hint and a composed-destination preview → username → divider → 身份验证 with the same SegmentedRow in the same mode order). Divergence on purpose: no group/tags/notes block and no private-key file picker. Selecting "密钥" shows guidance; saving a public-key profile is rejected (KeysNeedAdvancedEditor) because an empty key list cannot connect. Complex configuration (proxy, jump, keys, icon, organization) stays with the full editor, reachable via "更多设置", which carries the composed destination into the Settings editor prefilled.
  • Persistence reuses the existing authorities — validate_ssh_destination, join_destination_*, SshProfiles::save, ssh_credentials::store_password — writing the same ssh_profiles.json; no second format, dependency, cross-layer interface or thread-model change. Persistence is split from connecting (persist_quick_add) so failures keep the overlay open with the reason.
  • A name left empty stays empty: the host list and tab fall back to the address instead of an auto "主机 N", matching manual ssh and ~/.ssh/config hosts. Manual adds in Settings keep the existing auto-label behavior.
  • The palette action enum moves to workspace/palette_action.rs: the workspace root file sits at its line budget (2575/2575 before this change) and the row actions belong beside the palette projection that renders them. editor_input/editor_field/editor_hint are reused from the settings editor module (visibility widened to pub(in crate::gpui_shell)), so the two forms share one rendering authority.
  • New UI text uses typed message ids (hosts.add_and_connect, hosts.quick_add_*) with identical en-US/zh-CN placeholder sets.

Evidence / 验证依据

Pinned Rust toolchain, macOS ARM, against origin/main after merging 937b7ae6:

  • cargo test --locked -p nebula --bin pebrel --features gpui-test-support,gpui_platform/runtime_shaders:
    • ssh_quick_add::tests — 3 passed: destination composition + port range + authority rejection; temp-file persistence asserting no auto label, Auto auth, and the public-key guard not overwriting a stored profile; prefill split.
    • workspace::palette + shell_picker + launcher_menu — 11 passed (regression: row projection, launcher chips, menu dispatch).
  • i18n contract (tools/i18n-contract): 24 passed, 1 ignored (existing manual benchmark).
  • python3 scripts/check_architecture.py --base origin/main passes; no budget raised (workspace.rs 2575→2554 by the extraction).
  • cargo fmt --all -- --check, git diff --check clean. cargo check --locked -p nebula --bin pebrel --features gpui-shell passes.

Not run locally: native Windows/Linux keyboard acceptance, screenshots, multi-DPI visual checks. No hot-path allocation or platform-wide performance claim is made.

Required Review / 必须确认

  • I followed CONTRIBUTING.md, docs/architecture.md, and docs/project-constraints.md.
  • I split responsibilities, not arbitrary line ranges; no duplicate behavior authority was added.
  • python3 scripts/check_architecture.py --base <PR-base-commit> passes; budgets were not inflated to fit the change.
  • Tests cover success and failure; platform/feature coverage limitations are stated.
  • New messages use typed i18n IDs and matching placeholders; untranslated content has an explicit fallback.
  • Governance changes include a counterexample, corrected contract, tests, and a maintainer-reviewed decision. Not applicable: this PR does not change governance.

When the Shell/SSH launcher or the command palette finds no match and
the query looks like a host address, offer one "Add and connect" row.
It opens a workspace overlay instead of navigating to Settings; the
form's field order, wording and authentication segmented row mirror the
Settings editor's basic form, and "More settings" hands the composed
destination to the full editor.

Persistence reuses the existing authorities (validate_ssh_destination,
SshProfiles::save, the credential store) and then connects through
add_ssh_terminal, so tab naming, the remote file drawer and host
recording behave like any built-in connection. The overlay cannot
collect private-key files, so a public-key profile is rejected with
guidance instead of being written in a state that cannot connect.

The palette action enum moves to workspace/palette_action.rs: the
workspace root file sits at its line budget and the row actions belong
beside the palette projection that renders them.

Refs Kuddev#864.
@zher52
zher52 requested a review from Kuddev as a code owner November 4, 2026 01:25

@Kuddev Kuddev left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

The quick-add form can replace an existing host without going through its editor. For example, save deploy@box.example with a private key and a jump host, start quick-add for a different address, then edit the form to deploy@box.example and save. The search miss only opens the form; saving never rechecks the final destination. persist_quick_add constructs a new profile with empty keys and default connection options; SshProfiles::upsert replaces the existing profile for that exact destination. This discards the route, key paths, label and icon, then tries to connect using the replacement.

Please resolve duplicates against the final validated destination at save time. Reuse the saved profile for connecting or open it explicitly for editing. Add a regression that starts with a populated profile and asserts that it survives a quick-add collision. Also cover password storage failure: currently the profile file has already changed when the form reports the save error.

Saving a quick-add whose final validated destination already has a stored
profile used to replace it wholesale (empty keys, default connection
options), discarding private keys, jump route, label and icon, and then
connected with the degraded replacement. Save now resolves duplicates
first: an existing profile is reused untouched and the connect path picks
it up by destination. Credentials are also written before the profile
file, so a keychain failure leaves the host library exactly as it was
instead of reporting an error over a half-written save.
@zher52

zher52 commented Nov 12, 2026

Copy link
Copy Markdown
Author

All three points are addressed on head 19da736 (branch also merged current main first):

  1. Duplicates are resolved against the final validated destination at save time. persist_quick_add now loads the host library and checks SshProfiles::contains_destination on the composed destination before writing anything. On a collision the saved profile is reused untouched — private keys, jump route, label, icon and its credentials stay exactly as the editor wrote them — and the returned destination lets add_ssh_terminal connect through the stored configuration. Quick-add never replaces an existing profile anymore; changing keys/label/icon still goes through "More settings".

  2. Collision regression added. quick_add_collision_reuses_the_saved_profile_untouched seeds the library with a populated profile (private key, jump host, label, icon), drives a save whose form was edited onto that destination with a password typed in, and asserts the file survives byte-for-byte while an injected credential recorder observes zero calls.

  3. Password storage failure covered, ordering fixed. The credential write now happens before profiles.save(), so a keychain failure leaves the host library exactly as it was — the form reports the error over an untouched file instead of a half-written save. quick_add_password_failure_leaves_the_host_library_untouched injects a failing store and asserts the profile file is never created. persist_quick_add_with takes the credential write as a parameter (the same closure-injection pattern as the platform::credentials tests), so these tests never touch the real keychain.

The decision and the rejected partial-success-message alternative are recorded in architecture/notes/nebula_app/gpui_shell/workspace/2026-11-13-quick-add-collision-reuse.md. Locally the 5 quick-add tests and 38 ssh_profiles tests pass; cargo fmt --all -- --check and scripts/check_architecture.py --base origin/main are clean.

@Kuddev Kuddev left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

复核了 19da7363。在 Linux 用真实的主机库落盘和本版快捷保存逻辑测试,已有目标能原样复用,凭据没有写入。但两个窗口同时新建同一目标时,后保存失败的一方仍能覆盖另一方的密码。

我用临时主机库和注入的内存凭据库固定了顺序:A 读取主机库,B 保存同一目标及其密码,A 写密码后才调用 profiles.save。实际结果是 A 收到 Host profiles changed,主机库保留 B 的配置,凭据却已被 A 覆盖。独立的文件快照校验只保护主机库。请让主机重复检查、凭据写入和主机库提交遵循同一保存事务,补上这个交错顺序以及主机库写入失败后的凭据结果。测试用假的凭据存储即可。

当前 lint 还报 ssh_quick_add.rs 的格式差异,原生矩阵因此未启动。请按项目固定工具链跑 cargo fmt --all -- --check 后更新。

Two windows quick-adding the same destination could interleave as A loads
the library, B saves profile and password, A writes its password, then
A's commit fails on the changed file: the library kept B's profile while
A had already overwritten B's credential. The duplicate check, the
credential write and the library commit now run under the same OS-handle
lifetime lease (SshProfiles::save_leased), so another window's save is
rejected as lease-busy and retried on a fresh snapshot instead. When the
commit itself fails, the credential is rolled back to its pre-transaction
state: the prior password is restored, or the just-typed one is deleted.

The credential seam is extended to the full transaction (CredentialOp),
and the interleaving plus both rollback outcomes are pinned by tests.
Test coverage also moved to the sibling ssh_quick_add/tests.rs module,
and the note records the superseded credential-ordering decision.

The stray rustfmt drift that kept the lint job red came from the local
default toolchain (1.99.1) formatting two set_value calls differently
than the pinned 1.97.1; cargo +1.97.1 fmt is clean now.
@zher52

zher52 commented Nov 12, 2026

Copy link
Copy Markdown
Author

Both points are addressed on head 140d95c (branch also merged current main first):

  1. The save is now one leased transaction. The duplicate check, the credential write and the library commit all run while holding the same atomic_file lifetime lease, so another window's save can no longer slip between them — it is rejected as lease-busy and retries on a fresh snapshot, which then lands on the collision-reuse path. SshProfiles::save_leased is the new commit-under-the-lease entry; the public save() still acquires the lease itself, so the settings editor and import/export paths are unchanged. Your fixed interleaving is covered from both sides:

    • quick_add_transaction_rejects_a_window_save_in_the_middle fires window B's API save from inside A's credential write; the save is rejected with the busy error, and A's profile and password are the only survivors.
    • quick_add_commit_failure_rolls_the_password_back drives your exact sequence with a lease-bypassing writer: the commit fails on the changed file and the credential outcome is pinned — with no prior password the just-typed one is deleted, with a prior one it is restored. If the rollback itself fails, the form reports both errors.

    The fake in-memory credential store keeps every test off the real keychain, and the superseded credential-ordering decision plus the rejected commit-first alternative are recorded in the note.

  2. Format is fixed with the pinned toolchain. Root cause: my local rustup resolved to the default 1.99.1 despite rust-toolchain.toml, and rustfmt 1.99 formats the two set_value calls in quick_add_collision_reuses_the_saved_profile_untouched differently than 1.97.1 — exactly the drift the lint job reported, so the previous round's "fmt clean" claim was checked against the wrong toolchain. cargo +1.97.1 fmt --all -- --check is clean now; the native matrix should start again.

Locally: 7 quick-add tests and 38 ssh_profiles tests pass; cargo fmt --all -- --check and scripts/check_architecture.py --base origin/main are clean.

@Kuddev Kuddev left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

复核了 140d95c6。快捷添加持有租约时,另一窗口通过 SshProfiles::save 提交会收到 WouldBlock,上轮的主机库并发写入已被挡住。

保存失败的回滚 仍会删除没有修改过的凭据。wants_password 为 false 时跳过读取和写入,prior 却同样是 None,提交失败后就会调用 Forget。我在 Linux 用当前提交的保存函数、真实临时主机库和内存凭据夹具实测:在已存在锁文件、但目录禁止新建文件的情况下,自动认证与密码留空两种保存均报权限错误,且都删掉了该目标原有的测试密码;填写新密码的对照则正确恢复旧值。

请在本次凭据写入成功后才执行凭据回滚,区分「本次没写」和「写入前没有旧值」。回归可预置一条已有凭据,让主机库提交失败,确认自动认证和空密码不会调用删除接口。

The commit-failure rollback keyed on prior alone: a save that never
writes a password (auto auth, or password auth with the field left
empty) shares the prior=None shape with wrote-and-nothing-existed, so a
failed commit called the delete path on a credential this transaction
never touched — an existing password for the destination was wiped.
Reproduced on Linux with a pre-seeded credential, an existing lock file
and a read-only directory: both no-write saves errored on the commit and
deleted the pre-existing password.

The transaction now records whether it wrote a password at all; the
restore/delete path only runs for a written one, and a no-write save
reports the commit error with the credential untouched. Regression
covers auto auth and empty-password saves through the same injection;
the note records the narrowed rollback scope.
@zher52

zher52 commented Nov 13, 2026

Copy link
Copy Markdown
Author

Fixed on head 5e6a130: the rollback is now keyed on what this transaction wrote, not on prior alone. written_password is None when no password was written (auto auth, or password auth with the field left empty) and a failing commit reports the commit error with the credential untouched; only an actual write runs the restore (prior existed) or delete (nothing existed) path — your lock-file-plus-read-only-directory repro is exactly what the regression uses, for both no-write cases, asserting zero credential operations and the pre-seeded password surviving. The typed-password paths keep their existing coverage, and the note records the narrowed rollback scope.

…cfg budget

The unix-only injection carried a platform cfg attribute, and the
platform-cfg budget outside platform/ only ever shrinks (459 -> 460
failed CI lint). Gate on the runtime OS constant instead, following the
existing workspace test pattern, and go through the chmod binary for
the read-only directory so the file compiles on every platform while
the injection still only runs on Unix.

@Kuddev Kuddev left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

复核了 9e69edb0。上次的凭据回滚问题已修复:在主机库写入失败时,自动认证、密码留空和填写新密码三种路径都保留了原凭据。

用这个提交构建并运行 Linux GPUI 后,确认启动器回车能打开预填表单,保存能创建一个 SSH 标签并发起连接。仍有一处键盘操作回归:在表单里按 Esc 后,表单会关闭,主机库没有写入;但焦点没有回到终端,接着输入的命令不执行,必须先点一下终端。

请在取消表单时把焦点交回活动窗格,并补一个键盘回归:打开「添加并连接」→ Esc → 直接输入命令,确认终端收到输入。也请检查「取消」按钮和点击遮罩这两条关闭路径。

Esc closed the overlay and left the host library untouched, but focus
stayed with the dismissed overlay: the next typed command went nowhere
until the user clicked the terminal first. The three cancel paths (Esc,
the Cancel button, clicking the overlay mask) now funnel through
cancel_ssh_quick_add, which hands focus back to the active pane via the
workspace's focus_active. Save-and-connect and More-settings keep the
old close_ssh_quick_add — the tab or settings page they open takes
focus over itself, and the deferred refocus must not compete with it.

The keyboard regression builds a real workspace over the terminal test
fixture (a missing-shell pane with the test session) and pins the full
chain: open the overlay from a focused terminal, Esc, focus is back on
the terminal, then typing reaches the session as Msg::Input bytes.
@zher52

zher52 commented Nov 13, 2026

Copy link
Copy Markdown
Author

Fixed on head f1a7e3b (the branch also merged current main first — the command-manager groups and i18n changes came in cleanly):

  1. All three cancel paths restore focus. Esc, the Cancel button and clicking the overlay mask now funnel through a new cancel_ssh_quick_add: it dismisses the overlay and hands focus back to the active pane via the workspace's existing focus_active (the same deferred refocus the other overlays use). Save-and-connect and More-settings deliberately keep the old close_ssh_quick_add — the tab or settings page they open takes focus over itself, and a deferred refocus would compete with that.

  2. The keyboard regression is in. quick_add_cancel_returns_focus_and_the_next_command_reaches_the_terminal builds a real workspace over the terminal test fixture (one pane whose shell executable does not exist, with the test session installed) and pins the chain literally: open the overlay while the terminal is focused (focus moves into the form), press Esc, focus is asserted back on the terminal, then typing echo hi is asserted to reach the session as Msg::Input bytes — the terminal provably receives the next command with no mouse click. The other two cancel paths share the same cancel_ssh_quick_add seam, so they match by construction.

Local: 9 quick-add tests green including this regression; pinned-toolchain fmt, platform-cfg budget and the architecture gate clean.

…host

# Conflicts:
#	architecture/notes/pebrel_app/gpui_shell/workspace/2026-11-03-launcher-add-and-connect-ssh.md
#	architecture/notes/pebrel_app/gpui_shell/workspace/2026-11-13-quick-add-collision-reuse.md
#	pebrel_app/src/gpui_shell/workspace/palette_action.rs
#	pebrel_app/src/gpui_shell/workspace/ssh_quick_add.rs
#	pebrel_app/src/gpui_shell/workspace/ssh_quick_add/tests.rs
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.

2 participants