Skip to content

Conversation

@amisevsk
Copy link
Contributor

Description

This PR adds dynamic completions for ModelKit references where applicable:

  • kit info: If the --remote flag is not specified, generate ModelKit reference completions
  • kit inspect: Same as kit info
  • kit push: Generate completions for ModelKit references, supporting both the one-arg and two-arg (kit push [SOURCE] [TARGET]) format
  • kit remove: Generate completions if the --all flag is not specified
  • kit tag: Generate completions for the first argument only; ignore the second argument
  • kit unpack: Generate completions. Since we can't tell if the intended ModelKit is present locally (since we can unpack from a remote without pulling first), these may be less useful.

For ModelKit completions, we generate completions in two steps:

  • If the to-be-completed reference does not contain a colon (:), suggest repositories for completion, ignoring tags.
    • This is done to keep the list of potential completions small
    • If a completion is accepted, we include a colon, allowing for quickly continuing completion to tags
    • If there's only one tag in a repository, we complete the full reference
  • Otherwise, include tags for the currently referenced repository.

Additionally, completion based on digests is supported as well. If a ModelKit reference includes an @ symbol (as used with @sha256:...), we suggest digests based on what's in the repo.

We also do not suggest filepath completions for commands that do not work on the local directory -- e.g. for kit pack we support autocompleting local directories, but we suppress those completions for kit push.

Finally, this PR adds flag completions for flags that take on a limited set of values:

  • --progress: Complete to none, plain, or fancy
  • --log-level: Complete to one of the log level options

Linked issues

Closes #79
Supercedes #934

@amisevsk amisevsk requested review from Copilot and gorkem September 16, 2025 17:57
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds dynamic shell completions for ModelKit references across multiple CLI commands. The completions intelligently suggest local ModelKit repositories and tags based on the current input context, supporting both repository-only completions (with colon suffix) and full repository:tag completions.

Key changes:

  • Implements a new completion system that generates ModelKit reference suggestions based on local repositories
  • Adds completion logic that handles repository names, tags, and digest-based references
  • Integrates completions into commands like kit info, kit inspect, kit push, kit remove, kit tag, and kit unpack

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
pkg/lib/completion/modelkits.go New completion module with logic for generating ModelKit reference completions
pkg/cmd/unpack/cmd.go Adds ModelKit completion support for the unpack command
pkg/cmd/tag/cmd.go Adds ModelKit completion for the first argument of tag command
pkg/cmd/remove/cmd.go Adds conditional ModelKit completion when --all flag is not present
pkg/cmd/push/cmd.go Adds ModelKit completion support for push command arguments
pkg/cmd/pack/cmd.go Sets default completion directive to enable file completions
pkg/cmd/inspect/cmd.go Adds conditional ModelKit completion when --remote flag is not present
pkg/cmd/info/cmd.go Adds conditional ModelKit completion when --remote flag is not present
cmd/root.go Adds flag completions for --log-level and --progress options

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Example: examples,
RunE: runCommand(opts),
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
if slices.Contains(args, "--all") || slices.Contains(args, "--remote") {
Copy link

Copilot AI Sep 16, 2025

Choose a reason for hiding this comment

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

The slices.Contains(args, "--all") check is incorrect. The args parameter contains positional arguments, not flags. Flags should be checked using cmd.Flags().Changed() or similar methods.

Suggested change
if slices.Contains(args, "--all") || slices.Contains(args, "--remote") {
if cmd.Flags().Changed("all") || cmd.Flags().Changed("remote") {

Copilot uses AI. Check for mistakes.
Copy link
Member

Choose a reason for hiding this comment

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

Looks like copilot caught the issue I see.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, that's a good catch; don't know why I didn't test this directly.

Long: longDesc,
Example: example,
RunE: runCommand(opts),
Args: cobra.RangeArgs(1, 2),
Copy link

Copilot AI Sep 16, 2025

Choose a reason for hiding this comment

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

The Args field is being set twice - once at line 109 and once removed at line 117. This duplication could cause confusion. Consider keeping the Args assignment in one location.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

@amisevsk amisevsk Sep 16, 2025

Choose a reason for hiding this comment

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

Does Copilot not understand that once a line of code is removed, it is no longer run as part of the program?

return completion.GetLocalModelKitsCompletion(cmd.Context(), toComplete), cobra.ShellCompDirectiveNoFileComp | cobra.ShellCompDirectiveNoSpace
},
}

Copy link

Copilot AI Sep 16, 2025

Choose a reason for hiding this comment

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

The Args field is being set twice - once at line 109 and once removed at line 117. This duplication could cause confusion. Consider keeping the Args assignment in one location.

Copilot uses AI. Check for mistakes.
Copy link
Member

@gorkem gorkem left a comment

Choose a reason for hiding this comment

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

I bumped to the issue with kit info --remote which copilot actually flagged. The rest seems to work well.

Add completions for locally-stored ModelKits to commands where it makes
sense. This allows completing ModelKit references in e.g. push commands.

The list of ModelKits is generated at run time based on local storage.
For commands that work both locally and remotely, we only generate
completions when the user could be referring to a local ModelKit.

Signed-off-by: Angel Misevski <amisevsk@gmail.com>
* Add flag completions for flags that take one of a few values (e.g.
  --log-level, --progress)
* Remove filesystem completions for most commands, as they don't care
  about local disk; for commands that do, make sure we print them as
  usual.

Signed-off-by: Angel Misevski <amisevsk@gmail.com>
@amisevsk amisevsk merged commit 83174bf into kitops-ml:main Sep 16, 2025
8 checks passed
@amisevsk amisevsk deleted the completions branch September 16, 2025 22:03
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.

Support shell completions for commands

2 participants