Skip to content

Add docker model code command for AI-powered code editing with aider#40

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/add-docker-model-code-command
Draft

Add docker model code command for AI-powered code editing with aider#40
Copilot wants to merge 2 commits intomainfrom
copilot/add-docker-model-code-command

Conversation

Copy link

Copilot AI commented Oct 18, 2025

Overview

Adds a new docker model code command that integrates AI-powered code editing into Docker Model Runner by running aider in an ephemeral Docker container. This enables developers to edit code with AI assistance while maintaining a clean, isolated environment that talks directly to Docker Model Runner.

Features

Git-like Workflow

The command behaves similarly to git commit, requiring execution from within a Git repository. When no prompt is provided, it opens your configured text editor (EDITOR/VISUAL, defaulting to vim) to compose a detailed prompt:

# Opens editor for prompt composition
docker model code ai/smollm2

# Or provide prompt directly
docker model code ai/smollm2 "Add error handling to the main function"

Ephemeral Container Execution

Uses docker run --rm to run aider in a disposable container with:

  • Repository mounted at /workspace
  • Automatic connection to Docker Model Runner
  • Network configuration adjusted for Docker Desktop vs Engine
  • Clean environment for each execution

Intelligent Environment Detection

Automatically detects and configures the appropriate Model Runner endpoint:

  • Docker Desktop: Uses model-runner.docker.internal DNS
  • Docker Engine: Uses host networking
  • Custom setups: Respects MODEL_RUNNER_HOST environment variable

Usage Examples

# Interactive mode with editor
cd /path/to/your/project
docker model code ai/smollm2

# Direct prompt
docker model code ai/smollm2 "Refactor the database connection code to use a connection pool"

# With OpenAI backend
docker model code --backend openai gpt-4 "Add comprehensive unit tests for the user service"

# Custom aider image
docker model code --aider-image custom/aider:latest ai/smollm2 "Fix bug in authentication"

Implementation Details

The command:

  1. Validates the current directory is a Git repository
  2. Gets prompt from editor or command line
  3. Validates and pulls the specified model if needed
  4. Executes aider in a Docker container with proper environment variables and mounts
  5. Connects aider to Docker Model Runner via OpenAI-compatible API

Files Changed

  • cmd/cli/commands/code.go (276 lines): Main implementation with editor integration, container execution, and URL detection
  • cmd/cli/commands/code_test.go (226 lines): Comprehensive unit tests covering command validation, flags, editor integration, and helper functions
  • cmd/cli/commands/root.go (1 line): Command registration

Testing

  • ✅ All existing tests pass (no regressions)
  • ✅ 8 new unit tests added covering all major functionality
  • ✅ Manual testing confirms git validation, editor integration, and flag handling work correctly
  • ✅ CodeQL security scan: 0 vulnerabilities found

Command Line Interface

Usage:
  model code MODEL [PROMPT] [flags]

Flags:
      --backend string       inference backend to use
      --aider-image string   Docker image to use for aider (default "paulgauthier/aider")
  -h, --help                 help for code

Future Enhancements

This initial implementation provides a solid foundation that could be extended with:

  • Configuration file support for project-specific settings
  • Support for additional code editing tools
  • Advanced networking options for complex setups
  • Git commit integration for automatic change tracking

Closes #[issue-number]

Original prompt

Add command "docker model code MODEL [PROMPT]" that behaves like this. You run it in the root of a github repo and it should behave like the github version. It should execute things in an ephemeral container "docker run --rm". Assume the container has aider installed (should be this container by default paulgauthier/aider) so we can execute "aider . -m" and talks to "Docker Model Runner" by default. It should not bring up the normal "docker model run" prompt, instead it should behave like git, open up a vim text editor or other configured text editor to prompt:

github.com/copilot/agents


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Add docker model code command for GitHub repos Add docker model code command for AI-powered code editing with aider Oct 18, 2025
Copilot AI requested a review from ericcurtin October 18, 2025 17:52
First implemented with aider integration

Signed-off-by: Eric Curtin <eric.curtin@docker.com>
@ericcurtin ericcurtin force-pushed the copilot/add-docker-model-code-command branch from c290d8f to f416c1c Compare October 19, 2025 17:18
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