Skip to content

feat(cli): selectively import hosts from ~/.ssh/config (--host-import)#32

Merged
jamiesun merged 1 commit into
mainfrom
jamiesun-project-review-suggestions
Jul 16, 2026
Merged

feat(cli): selectively import hosts from ~/.ssh/config (--host-import)#32
jamiesun merged 1 commit into
mainfrom
jamiesun-project-review-suggestions

Conversation

@jamiesun

Copy link
Copy Markdown
Contributor

Summary

Adds selective host import from the OpenSSH client config, so existing ~/.ssh/config users can onboard hosts into ~/.sshx/settings.json without retyping them — and without blind bulk-import pollution.

  • sshx --host-import — interactive: lists importable entries (resolved user@host:port, key, ignored options) plus every skipped entry with its reason, then select by number, name, or all
  • sshx --host-import=<name1,name2> — non-interactive, all-or-nothing (deterministic for scripts/agents)
  • --ssh-config=<path> — choose a different source file (default ~/.ssh/config)
  • Covered by --dry-run plan preview (would_write_local_state) and the local audit trail

Pollution guards

The importer always skips and reports:

  • wildcard/negated patterns (Host *, web-?, !pattern) — rules, not hosts
  • aliases already present in settings
  • duplicate host:port pairs (against settings or earlier entries in the same file)
  • Host * defaults — never merged into imported entries
  • unsupported options (ProxyJump, ForwardAgent, …) — surfaced as ignored:, never silently dropped
  • IdentityFile values containing % tokens (noted)
  • Match blocks are skipped; Include directives are reported but not followed

Implementation

  • internal/app/sshconfig.go — minimal ssh_config parser + import planning (pure functions, no new dependencies, keeps go.mod at Go 1.24)
  • internal/app/host_manager.gohandleHostImport + interactive/named selection
  • Wired into flags, usage, dry-run effects, and audit would_write_local_state
  • 14 new test cases (sshconfig_test.go); make check and golangci-lint run pass clean

Docs

README (EN/CN), docs/host-management.md (EN/ZH), usage text, CHANGELOG, AGENT.md architecture map.

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>
@jamiesun
jamiesun merged commit 9462355 into main Jul 16, 2026
6 checks passed
@jamiesun
jamiesun deleted the jamiesun-project-review-suggestions branch July 16, 2026 07:31
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