Skip to content

Allow to use cagent binary as a docker cli plugin docker-agent. No functional change for cagent command.#1748

Merged
dgageot merged 3 commits intodocker:mainfrom
gtardif:agent_cli_plugin
Feb 16, 2026
Merged

Allow to use cagent binary as a docker cli plugin docker-agent. No functional change for cagent command.#1748
dgageot merged 3 commits intodocker:mainfrom
gtardif:agent_cli_plugin

Conversation

@gtardif
Copy link
Collaborator

@gtardif gtardif commented Feb 16, 2026

  • Added task for local docker cli plugin deployment: task deploy-local
  • ./bin/cagent (or .exe on windows) works exactly as before
  • we can now use docker agent as a replacement for the cagent command, with no other changes:
    docker agent run ...
 docker agent --help
Usage:  docker agent [OPTIONS] COMMAND

create or run AI agents

Examples:
  docker agent run ./agent.yaml
  docker agent run agentcatalog/pirate
...

@gtardif gtardif requested a review from a team as a code owner February 16, 2026 10:43
Copy link

@docker-agent docker-agent bot left a comment

Choose a reason for hiding this comment

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

Review Summary

🔍 Found 1 high-severity and 1 medium-severity issue in the added code.

Critical Issue

  • Line 41: The condition len(os.Args) >= 0 is always true and can cause a panic if os.Args is empty. Should be len(os.Args) > 0.

Additional Issue

  • Line 164: The context passed to Execute() is not propagated to plugin.Run(), so context cancellation won't work in plugin mode.

Please review the inline comments for details.

cmd/root/root.go Outdated
if runtime.GOOS == "windows" {
cliPluginBinary += ".exe"
}
return len(os.Args) >= 0 && strings.HasSuffix(os.Args[0], cliPluginBinary)
Copy link

Choose a reason for hiding this comment

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

🔴 HIGH SEVERITY: Logic error - always true condition can cause panic

The condition len(os.Args) >= 0 is always true since slice length cannot be negative. More critically, if os.Args is empty (length 0), accessing os.Args[0] will cause a panic (index out of range).

Fix: Change the condition to len(os.Args) > 0 to ensure os.Args[0] is accessible:

return len(os.Args) > 0 && strings.HasSuffix(os.Args[0], cliPluginBinary)

While os.Args is typically guaranteed to have at least one element in normal execution, it can be empty in test scenarios or if manipulated, making this a real risk.

if strings.HasPrefix(err.Error(), "unknown command ") || strings.HasPrefix(err.Error(), "accepts ") {
_ = rootCmd.Usage()
if isCliPLugin() {
plugin.Run(func(dockerCli command.Cli) *cobra.Command {
Copy link

Choose a reason for hiding this comment

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

⚠️ MEDIUM SEVERITY: Context not propagated to plugin.Run()

The ctx parameter passed to Execute() is not used in the plugin path. In the non-plugin path (line 186), rootCmd.ExecuteContext(ctx) properly propagates the context. However, in the plugin path, the context is never passed to or used by plugin.Run().

Impact: Context cancellation, timeouts, and other context-based operations won't work when running as a CLI plugin. This creates inconsistent behavior between plugin and non-plugin execution modes.

Suggested fix: Consider calling rootCmd.SetContext(ctx) before passing it to the plugin callback, or investigate if the Docker CLI plugin framework provides a way to pass context.

… functional change if using `cagent` command.

Signed-off-by: Guillaume Tardif <guillaume.tardif@gmail.com>
Signed-off-by: Guillaume Tardif <guillaume.tardif@gmail.com>
@gtardif gtardif force-pushed the agent_cli_plugin branch 3 times, most recently from 086fa66 to 0fb4d74 Compare February 16, 2026 13:32
Signed-off-by: Guillaume Tardif <guillaume.tardif@gmail.com>
@dgageot dgageot merged commit e2f8679 into docker:main Feb 16, 2026
5 checks passed
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.

2 participants