feat(completion): improve @N<TAB> UX with grouped section menu#67
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR improves the CLI’s @N<TAB> autocompletion experience by enriching exact numeric node matches with endpoint candidates and grouped “next action” suggestions (device/cluster/tool commands), primarily for the custom zsh completion script.
Changes:
- Extend Go completion logic to emit endpoint candidates (e.g.
@N/0,@N/1) and encoded expansion tokens for exact@Nmatches. - Add a root-command snapshot helper to provide target-aware top-level commands for completion expansion.
- Update the zsh completion script to split targets into “Devices” vs “Endpoints” sections and to interpret encoded expansion tokens into grouped menus; adjust
Execute()behavior for cobra completion invocations.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
cli/root.go |
Wires root completion with the new top-level command snapshot; adds a guard around ExtractTargetFromArgs for cobra completion invocations. |
cli/completion/completer.go |
Adds stage-1b exact-match enrichment (endpoints + encoded @N+<cmd> tokens) and updates completion function signatures. |
cli/cluster.go |
Implements topLevelCommandsForCompletion() to snapshot visible root commands and tag target-awareness. |
cli/completion.go |
Updates the generated zsh completion script to add “Devices/Endpoints” sections and parse @N+<cmd> tokens into grouped expansions. |
cli/completion/completer_test.go |
Adds tests covering stage-1b endpoint enrichment and expansion-token emission rules. |
cli/rename.go |
Updates call site for the new TargetCompletionFunc(nil) signature. |
cli/decommission.go |
Updates call site for the new TargetCompletionFunc(nil) signature. |
cli/fabric.go |
Updates call site for the new TargetCompletionFunc(nil) signature. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Typing `matter @1<TAB>` previously offered only sibling nodes that happened to share the @1 prefix. Users had to already know to type space (for device commands) or slash (for endpoints) to see anything useful. This change wires up a four-section completion menu whenever the typed token is an exact numeric node ID: Devices – sibling nodes matching the prefix (@1, @11, ...) Endpoints – node's endpoints (@1/0, @1/1, ...) Device Commands – target-aware commands (tree, rename, ...) Cluster Commands – cluster shorthands (OnOff, LevelControl, ...) Tools – code, help, ... Implementation: • cli/completion/completer.go - Add TopLevelCommand struct and ExpandSeparator constant. - TargetCompletionFunc gains a topLevelCommands func() parameter. - Stage-1b: when toComplete is a bare numeric @n that exactly matches a commissioned node, emit @N/EP endpoint tokens and @n+<cmd> expansion tokens for each target-aware top-level command. - RootCompletionFunc accepts the same parameter and forwards it. • cli/cluster.go - Add topLevelCommandsForCompletion(), which snapshots the visible root cobra commands and labels each as device/cluster/tool. Non- TargetAware commands (commission, discover, fabric, …) are excluded. • cli/root.go - Execute() skips @target extraction for __complete invocations so the target token reaches the completion function instead of being consumed by the normal arg-parsing path. • cli/completion.go (zsh script) - Split legacy target_cmds bucket into device_targets (@n) and endpoint_targets (@N/EP). - Parse @n+<cmd> expansion tokens: look up <cmd> in _matter_group_map, bucket into exp_device/cluster/tool arrays. - Emit expansion groups with compadd -U -p "@n " so the candidate displays as the bare command name but inserts as "@n <cmd>". • cli/completion/completer_test.go - Tests for stage-1b endpoint emission on exact match. - Tests for @n+<cmd> token generation with/without topLevelCommands. - Tests confirming alias-based and non-existent node prefixes do not trigger expansion. Closes #59
- Extract @targets from committed completion args (not toComplete) so cobra can still resolve subcommands like "matter @1/1 OnOff <TAB>". - Gate "@n+<cmd>" expansion tokens behind MATTER_COMPLETION_EXPAND=zsh so bash, fish, and PowerShell completions do not display the literal zsh-specific encoding. - Route ungrouped expansion commands (e.g. "help") to the Tools bucket in the zsh script's case statement instead of silently dropping them. - Clarify that TopLevelCommand.Group is metadata for shell-specific helpers; it is not encoded in the emitted "@n+<name>" token. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Prevents backslash-escaping of spaces in "@n " so completions insert as separate shell words, improving CLI ergonomics.
a4f9156 to
f1de03a
Compare
Stale cross-package staticcheck facts were causing phantom SA5011 diagnostics locally while CI (which starts with no lint cache) passed. Cleaning the cache up-front costs ~10s but makes local results match CI. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.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
Fixes #59 — typing
matter @1<TAB>previously showed nothing useful (or only sibling nodes sharing the@1prefix). Users had to already know to type/for endpoints orfor device commands.This PR wires up a four-section completion menu when the typed token is an exact numeric node ID:
How it works
Go side (
cli/completion/completer.go)TopLevelCommandstruct +ExpandSeparator(+) constant.TargetCompletionFuncgains atopLevelCommands func()parameter. When the typed token is a bare numeric@Nthat exactly matches a commissioned node (stage-1b), it emits:@N/EPendpoint tokens (appear under "Endpoints" in zsh)@N+<cmd>expansion tokens for each target-aware root commandRootCompletionFuncforwards the parameter through.Helper (
cli/cluster.go)topLevelCommandsForCompletion()snapshots the visible root cobra commands and tags each asdevice/cluster/tool. Non-target-aware commands (commission, discover, fabric, use, …) are excluded so the menu stays relevant.Bug fix (
cli/root.go)Execute()was stripping@1fromos.Argsfor__completeinvocations, causing cobra to receive an empty argument list. Fixed with anisCompletionInvocation()guard.Zsh script (
cli/completion.go)target_cmdsintodevice_targets(@n) andendpoint_targets(@N/EP).@N+<cmd>tokens: looks up<cmd>in_matter_group_map, buckets intoexp_device/cluster/toolarrays.compadd -U -p "@N "so the candidate displays as the bare command name but inserts as@N <cmd>on the command line.Test plan
TestTargetCompletionFunc_Stage1b_EndpointsInExactMatch— exact @n emits endpoint tokensTestTargetCompletionFunc_Stage1b_CommandsInExactMatch— expansion tokens emitted only for TargetAware commandsTestTargetCompletionFunc_Stage1b_NamedNoExpansion— alias prefix (@kitchen-light) does NOT trigger expansionTestTargetCompletionFunc_Stage1b_NonExistentNodeNoExpansion— @99 (no match) does NOT trigger expansionmise run test)mise run lintpasses clean🤖 Generated with Claude Code