feat(cli): selectively import hosts from ~/.ssh/config (--host-import)#32
Merged
Merged
Conversation
Add --host-import for pollution-free host onboarding from the OpenSSH client config. Interactive mode lists importable entries plus every skipped entry with its reason; --host-import=<name1,name2> imports the named entries non-interactively (all-or-nothing); --ssh-config=<path> selects the source file. Guards against config pollution: wildcard/negated patterns, existing names, duplicate host:port pairs, 'Host *' defaults, unsupported options (reported as ignored), and %-token IdentityFile values are never imported. Match blocks are skipped and Include directives are reported but not followed. Import is covered by --dry-run plan preview and the audit trail (would_write_local_state). Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds selective host import from the OpenSSH client config, so existing
~/.ssh/configusers can onboard hosts into~/.sshx/settings.jsonwithout retyping them — and without blind bulk-import pollution.sshx --host-import— interactive: lists importable entries (resolveduser@host:port, key, ignored options) plus every skipped entry with its reason, then select by number, name, orallsshx --host-import=<name1,name2>— non-interactive, all-or-nothing (deterministic for scripts/agents)--ssh-config=<path>— choose a different source file (default~/.ssh/config)--dry-runplan preview (would_write_local_state) and the local audit trailPollution guards
The importer always skips and reports:
Host *,web-?,!pattern) — rules, not hostshost:portpairs (against settings or earlier entries in the same file)Host *defaults — never merged into imported entriesProxyJump,ForwardAgent, …) — surfaced asignored:, never silently droppedIdentityFilevalues containing%tokens (noted)Matchblocks are skipped;Includedirectives are reported but not followedImplementation
internal/app/sshconfig.go— minimal ssh_config parser + import planning (pure functions, no new dependencies, keepsgo.modat Go 1.24)internal/app/host_manager.go—handleHostImport+ interactive/named selectionwould_write_local_statesshconfig_test.go);make checkandgolangci-lint runpass cleanDocs
README (EN/CN),
docs/host-management.md(EN/ZH), usage text, CHANGELOG, AGENT.md architecture map.