Skip to content

Conversation

@matifali
Copy link
Member

@matifali matifali commented Oct 4, 2025

Adds CompletionHandler to the ssh command that dynamically suggests workspace and agent targets based on the user's running workspaces.

Features:

  • Suggests workspace name for single-agent workspaces
  • Suggests agent.workspace format for all agents in multi-agent workspaces
  • Only shows running workspaces (matches immediate availability)
  • Alphabetically sorted completions for better UX

Tests cover single-agent, multi-agent, and network error scenarios.

Amp-Thread-ID: https://ampcode.com/threads/T-d137d343-53f3-4ece-be5a-584249bbd9e8

closes #20158

Demo:

completiondemo.mov

Adds CompletionHandler to the ssh command that dynamically suggests
workspace and agent targets based on the user's running workspaces.

Features:
- Suggests workspace name for single-agent workspaces
- Suggests agent.workspace format for all agents in multi-agent workspaces
- Only shows running workspaces (matches immediate availability)
- Alphabetically sorted completions for better UX
- Graceful error handling (returns error strings for debugging)

Tests cover single-agent, multi-agent, and network error scenarios.

Amp-Thread-ID: https://ampcode.com/threads/T-d137d343-53f3-4ece-be5a-584249bbd9e8
Co-authored-by: Amp <amp@ampcode.com>
Verify that multi-agent workspaces do not suggest the bare workspace
name (only agent.workspace format should be suggested).

Amp-Thread-ID: https://ampcode.com/threads/T-d137d343-53f3-4ece-be5a-584249bbd9e8
Co-authored-by: Amp <amp@ampcode.com>
@matifali matifali changed the title cli: add dynamic completions for ssh command feat(cli): add dynamic completions for ssh command Oct 4, 2025
@matifali matifali requested a review from ethanndickson October 6, 2025 12:39
Copy link
Member

@code-asher code-asher left a comment

Choose a reason for hiding this comment

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

This is really cool, been hoping we could get this since the wildcard switch 😎

Do you know how this is supposed to work in practice? I tried coder completion and it generates a bashrc that says Setup Bash to use the function for completions for '' which seems weird (the empty string) and neither ssh <tab> nor coder ssh <tab> are showing my workspaces. I tried manually sourcing the bashrc but it looks like the call to complete is giving an error.

The code looks good here, so I wonder if it is a problem with Serpent.

Edit: sorry, I see this is in draft, I got overly excited.

@github-actions github-actions bot added the stale This issue is like stale bread. label Oct 16, 2025
@github-actions github-actions bot closed this Oct 19, 2025
@ethanndickson
Copy link
Member

ethanndickson commented Oct 24, 2025

The code looks good here, so I wonder if it is a problem with Serpent.

It was indeed, fixed in #20448. Thanks for discovering!

@ethanndickson ethanndickson reopened this Oct 24, 2025
@ethanndickson ethanndickson removed the stale This issue is like stale bread. label Oct 24, 2025
@matifali
Copy link
Member Author

matifali commented Oct 24, 2025

@ethanndickson, mind me assigning this to you if you are interested in taking this to completion?
Can also close and redo.

@ethanndickson
Copy link
Member

Yep, will do!

@matifali matifali assigned ethanndickson and unassigned matifali Oct 24, 2025
Owner: codersdk.Me,
})
if err != nil {
return []string{}
Copy link
Member

@ethanndickson ethanndickson Oct 24, 2025

Choose a reason for hiding this comment

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

Returning an error string here doesn't seem very idiomatic - shells will just autocomplete the error which seems kinda gross. If the user runs coder ls they'll see what the issue is.

@ethanndickson ethanndickson marked this pull request as ready for review October 24, 2025 09:01
Copy link
Member

@code-asher code-asher left a comment

Choose a reason for hiding this comment

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

Awesome!! coder ssh <tab> completes wonderfully now.

@ethanndickson ethanndickson merged commit 9780d02 into main Oct 27, 2025
29 checks passed
@ethanndickson ethanndickson deleted the cli/ssh-dynamic-completions branch October 27, 2025 00:13
@github-actions github-actions bot locked and limited conversation to collaborators Oct 27, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add tab completions to coder ssh

4 participants