Skip to content

Commit b82276c

Browse files
committed
draft
1 parent 542f8ec commit b82276c

File tree

9 files changed

+928
-0
lines changed

9 files changed

+928
-0
lines changed

aider-test-template/ main.tf

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
terraform {
2+
required_providers {
3+
coder = {
4+
source = "coder/coder"
5+
version = ">= 2.5"
6+
}
7+
docker = {
8+
source = "kreuzwerker/docker"
9+
version = ">= 3.0"
10+
}
11+
}
12+
}
13+
14+
provider "docker" {}
15+
16+
data "coder_provisioner" "me" {}
17+
data "coder_workspace" "me" {}
18+
data "coder_workspace_owner" "me" {}
19+
20+
# This variable will prompt you for your API key when you create the workspace.
21+
variable "api_key" {
22+
description = "API Key for your AI provider (e.g., OpenAI)."
23+
sensitive = true
24+
default = ""
25+
}
26+
27+
# This parameter is required by the agentapi module to accept the initial user prompt.
28+
data "coder_parameter" "ai_prompt" {
29+
name = "AI Prompt"
30+
description = "Write an initial prompt for Aider to work on."
31+
type = "string"
32+
default = ""
33+
mutable = true
34+
ephemeral = true
35+
}
36+
37+
38+
# Create a persistent volume for the home directory.
39+
resource "docker_volume" "home" {
40+
name = "coder-${data.coder_workspace.me.id}-home"
41+
}
42+
43+
# Create the Docker container for the workspace.
44+
resource "docker_container" "workspace" {
45+
count = data.coder_workspace.me.start_count
46+
image = "codercom/enterprise-base:ubuntu"
47+
name = "coder-${data.coder_workspace.me.id}"
48+
hostname = data.coder_workspace.me.name
49+
entrypoint = ["sh", "-c", replace(coder_agent.main.init_script, "/localhost|127\\.0\\.0\\.1/", "host.docker.internal")]
50+
env = ["CODER_AGENT_TOKEN=${coder_agent.main.token}"]
51+
host {
52+
host = "host.docker.internal"
53+
ip = "host-gateway"
54+
}
55+
volumes {
56+
container_path = "/home/coder"
57+
volume_name = docker_volume.home.name
58+
}
59+
}
60+
61+
resource "coder_agent" "main" {
62+
os = "linux"
63+
arch = data.coder_provisioner.me.arch
64+
# Set the AI provider's API key as an environment variable in the agent.
65+
# This is how the Aider module will access it.
66+
env = {
67+
OPENAI_API_KEY = var.api_key
68+
AIDER_TASK_PROMPT = data.coder_parameter.ai_prompt.value
69+
}
70+
}
71+
72+
# This is the most important part!
73+
# It includes your local Aider module into this template.
74+
module "aider" {
75+
source = "./aider" # Use the local copy of the module
76+
77+
agent_id = coder_agent.main.id
78+
ai_provider = "openai"
79+
ai_model = "4o" # Aider's alias for gpt-4o
80+
ai_api_key = var.api_key
81+
}

aider-test-template/aider/README.md

Lines changed: 315 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,315 @@
1+
---
2+
display_name: Aider
3+
description: Run Aider AI pair programming in your workspace
4+
icon: ../../../../.icons/aider.svg
5+
maintainer_github: coder
6+
verified: true
7+
tags: [agent, ai, aider]
8+
---
9+
10+
# Aider
11+
12+
Run [Aider](https://aider.chat) AI pair programming in your workspace. This module installs Aider and provides a persistent session using screen or tmux.
13+
14+
```tf
15+
module "aider" {
16+
source = "registry.coder.com/coder/aider/coder"
17+
version = "1.1.0"
18+
agent_id = coder_agent.example.id
19+
}
20+
```
21+
22+
## Features
23+
24+
- **Interactive Parameter Selection**: Choose your AI provider, model, and configuration options when creating the workspace
25+
- **Multiple AI Providers**: Supports Anthropic (Claude), OpenAI, DeepSeek, GROQ, and OpenRouter
26+
- **Persistent Sessions**: Uses screen (default) or tmux to keep Aider running in the background
27+
- **Optional Dependencies**: Install Playwright for web page scraping and PortAudio for voice coding
28+
- **Project Integration**: Works with any project directory, including Git repositories
29+
- **Browser UI**: Use Aider in your browser with a modern web interface instead of the terminal
30+
- **Non-Interactive Mode**: Automatically processes tasks when provided via the `task_prompt` variable
31+
32+
## Module Parameters
33+
34+
| Parameter | Description | Type | Default |
35+
| ---------------------------------- | -------------------------------------------------------------------------- | -------- | ------------------- |
36+
| `agent_id` | The ID of a Coder agent (required) | `string` | - |
37+
| `folder` | The folder to run Aider in | `string` | `/home/coder` |
38+
| `install_aider` | Whether to install Aider | `bool` | `true` |
39+
| `aider_version` | The version of Aider to install | `string` | `"latest"` |
40+
| `use_screen` | Whether to use screen for running Aider in the background | `bool` | `true` |
41+
| `use_tmux` | Whether to use tmux instead of screen for running Aider in the background | `bool` | `false` |
42+
| `session_name` | Name for the persistent session (screen or tmux) | `string` | `"aider"` |
43+
| `order` | Position of the app in the UI presentation | `number` | `null` |
44+
| `icon` | The icon to use for the app | `string` | `"/icon/aider.svg"` |
45+
| `experiment_report_tasks` | Whether to enable task reporting | `bool` | `true` |
46+
| `system_prompt` | System prompt for instructing Aider on task reporting and behavior | `string` | See default in code |
47+
| `task_prompt` | Task prompt to use with Aider | `string` | `""` |
48+
| `ai_provider` | AI provider to use with Aider (openai, anthropic, azure, etc.) | `string` | `"anthropic"` |
49+
| `ai_model` | AI model to use (can use Aider's built-in aliases like "sonnet", "4o") | `string` | `"sonnet"` |
50+
| `ai_api_key` | API key for the selected AI provider | `string` | `""` |
51+
| `custom_env_var_name` | Custom environment variable name when using custom provider | `string` | `""` |
52+
| `experiment_pre_install_script` | Custom script to run before installing Aider | `string` | `null` |
53+
| `experiment_post_install_script` | Custom script to run after installing Aider | `string` | `null` |
54+
| `experiment_additional_extensions` | Additional extensions configuration in YAML format to append to the config | `string` | `null` |
55+
56+
> **Note**: `use_screen` and `use_tmux` cannot both be enabled at the same time. By default, `use_screen` is set to `true` and `use_tmux` is set to `false`.
57+
58+
## Usage Examples
59+
60+
### Basic setup with API key
61+
62+
```tf
63+
variable "anthropic_api_key" {
64+
type = string
65+
description = "Anthropic API key"
66+
sensitive = true
67+
}
68+
69+
module "aider" {
70+
count = data.coder_workspace.me.start_count
71+
source = "registry.coder.com/coder/aider/coder"
72+
version = "1.1.0"
73+
agent_id = coder_agent.example.id
74+
ai_api_key = var.anthropic_api_key
75+
}
76+
```
77+
78+
This basic setup will:
79+
80+
- Install Aider in the workspace
81+
- Create a persistent screen session named "aider"
82+
- Configure Aider to use Anthropic Claude 3.7 Sonnet model
83+
- Enable task reporting (configures Aider to report tasks to Coder MCP)
84+
85+
### Using OpenAI with tmux
86+
87+
```tf
88+
variable "openai_api_key" {
89+
type = string
90+
description = "OpenAI API key"
91+
sensitive = true
92+
}
93+
94+
module "aider" {
95+
count = data.coder_workspace.me.start_count
96+
source = "registry.coder.com/coder/aider/coder"
97+
version = "1.1.0"
98+
agent_id = coder_agent.example.id
99+
use_tmux = true
100+
ai_provider = "openai"
101+
ai_model = "4o" # Uses Aider's built-in alias for gpt-4o
102+
ai_api_key = var.openai_api_key
103+
}
104+
```
105+
106+
### Using a custom provider
107+
108+
```tf
109+
variable "custom_api_key" {
110+
type = string
111+
description = "Custom provider API key"
112+
sensitive = true
113+
}
114+
115+
module "aider" {
116+
count = data.coder_workspace.me.start_count
117+
source = "registry.coder.com/coder/aider/coder"
118+
version = "1.1.0"
119+
agent_id = coder_agent.example.id
120+
ai_provider = "custom"
121+
custom_env_var_name = "MY_CUSTOM_API_KEY"
122+
ai_model = "custom-model"
123+
ai_api_key = var.custom_api_key
124+
}
125+
```
126+
127+
### Adding Custom Extensions (Experimental)
128+
129+
You can extend Aider's capabilities by adding custom extensions:
130+
131+
```tf
132+
module "aider" {
133+
count = data.coder_workspace.me.start_count
134+
source = "registry.coder.com/coder/aider/coder"
135+
version = "1.1.0"
136+
agent_id = coder_agent.example.id
137+
ai_api_key = var.anthropic_api_key
138+
139+
experiment_pre_install_script = <<-EOT
140+
pip install some-custom-dependency
141+
EOT
142+
143+
experiment_additional_extensions = <<-EOT
144+
custom-extension:
145+
args: []
146+
cmd: custom-extension-command
147+
description: A custom extension for Aider
148+
enabled: true
149+
envs: {}
150+
name: custom-extension
151+
timeout: 300
152+
type: stdio
153+
EOT
154+
}
155+
```
156+
157+
Note: The indentation in the heredoc is preserved, so you can write the YAML naturally.
158+
159+
## Task Reporting (Experimental)
160+
161+
> This functionality is in early access as of Coder v2.21 and is still evolving.
162+
> For now, we recommend testing it in a demo or staging environment,
163+
> rather than deploying to production
164+
>
165+
> Learn more in [the Coder documentation](https://coder.com/docs/tutorials/ai-agents)
166+
>
167+
> Join our [Discord channel](https://discord.gg/coder) or
168+
> [contact us](https://coder.com/contact) to get help or share feedback.
169+
170+
Your workspace must have either `screen` or `tmux` installed to use this.
171+
172+
Task reporting is **enabled by default** in this module, allowing you to:
173+
174+
- Send an initial prompt to Aider during workspace creation
175+
- Monitor task progress in the Coder UI
176+
- Use the `coder_parameter` resource to collect prompts from users
177+
178+
### Setting up Task Reporting
179+
180+
To use task reporting effectively:
181+
182+
1. Add the Coder Login module to your template
183+
2. Configure the necessary variables to pass the task prompt
184+
3. Optionally add a coder_parameter to collect prompts from users
185+
186+
Here's a complete example:
187+
188+
```tf
189+
module "coder-login" {
190+
count = data.coder_workspace.me.start_count
191+
source = "registry.coder.com/modules/coder-login/coder"
192+
version = "1.0.15"
193+
agent_id = coder_agent.example.id
194+
}
195+
196+
variable "anthropic_api_key" {
197+
type = string
198+
description = "Anthropic API key"
199+
sensitive = true
200+
}
201+
202+
data "coder_parameter" "ai_prompt" {
203+
type = "string"
204+
name = "AI Prompt"
205+
default = ""
206+
description = "Write a prompt for Aider"
207+
mutable = true
208+
ephemeral = true
209+
}
210+
211+
module "aider" {
212+
count = data.coder_workspace.me.start_count
213+
source = "registry.coder.com/coder/aider/coder"
214+
version = "1.1.0"
215+
agent_id = coder_agent.example.id
216+
ai_api_key = var.anthropic_api_key
217+
task_prompt = data.coder_parameter.ai_prompt.value
218+
219+
# Optionally customize the system prompt
220+
system_prompt = <<-EOT
221+
You are a helpful Coding assistant. Aim to autonomously investigate
222+
and solve issues the user gives you and test your work, whenever possible.
223+
Avoid shortcuts like mocking tests. When you get stuck, you can ask the user
224+
but opt for autonomy.
225+
YOU MUST REPORT ALL TASKS TO CODER.
226+
When reporting tasks, you MUST follow these EXACT instructions:
227+
- IMMEDIATELY report status after receiving ANY user message.
228+
- Be granular. If you are investigating with multiple steps, report each step to coder.
229+
Task state MUST be one of the following:
230+
- Use "state": "working" when actively processing WITHOUT needing additional user input.
231+
- Use "state": "complete" only when finished with a task.
232+
- Use "state": "failure" when you need ANY user input, lack sufficient details, or encounter blockers.
233+
Task summaries MUST:
234+
- Include specifics about what you're doing.
235+
- Include clear and actionable steps for the user.
236+
- Be less than 160 characters in length.
237+
EOT
238+
}
239+
```
240+
241+
When a task prompt is provided via the `task_prompt` variable, the module automatically:
242+
243+
1. Combines the system prompt with the task prompt into a single message in the format:
244+
245+
```
246+
SYSTEM PROMPT:
247+
[system_prompt content]
248+
249+
This is your current task: [task_prompt]
250+
```
251+
252+
2. Executes the task during workspace creation using the `--message` and `--yes-always` flags
253+
3. Logs task output to `$HOME/.aider.log` for reference
254+
255+
If you want to disable task reporting, set `experiment_report_tasks = false` in your module configuration.
256+
257+
## Using Aider in Your Workspace
258+
259+
After the workspace starts, Aider will be installed and configured according to your parameters. A persistent session will automatically be started during workspace creation.
260+
261+
### Session Options
262+
263+
You can run Aider in three different ways:
264+
265+
1. **Direct Mode**: Aider starts directly in the specified folder when you click the app button
266+
267+
- Simple setup without persistent context
268+
- Suitable for quick coding sessions
269+
270+
2. **Screen Mode** (Default): Run Aider in a screen session that persists across connections
271+
272+
- Session name: "aider" (or configured via `session_name`)
273+
274+
3. **Tmux Mode**: Run Aider in a tmux session instead of screen
275+
276+
- Set `use_tmux = true` to enable
277+
- Session name: "aider" (or configured via `session_name`)
278+
- Configures tmux with mouse support for shared sessions
279+
280+
Persistent sessions (screen/tmux) allow you to:
281+
282+
- Disconnect and reconnect without losing context
283+
- Run Aider in the background while doing other work
284+
- Switch between terminal and browser interfaces
285+
286+
### Available AI Providers and Models
287+
288+
Aider supports various providers and models, and this module integrates directly with Aider's built-in model aliases:
289+
290+
| Provider | Example Models/Aliases | Default Model |
291+
| ------------- | --------------------------------------------- | ---------------------- |
292+
| **anthropic** | "sonnet" (Claude 3.7 Sonnet), "opus", "haiku" | "sonnet" |
293+
| **openai** | "4o" (GPT-4o), "4" (GPT-4), "3.5-turbo" | "4o" |
294+
| **azure** | Azure OpenAI models | "gpt-4" |
295+
| **google** | "gemini" (Gemini Pro), "gemini-2.5-pro" | "gemini-2.5-pro" |
296+
| **cohere** | "command-r-plus", etc. | "command-r-plus" |
297+
| **mistral** | "mistral-large-latest" | "mistral-large-latest" |
298+
| **ollama** | "llama3", etc. | "llama3" |
299+
| **custom** | Any model name with custom ENV variable | - |
300+
301+
For a complete and up-to-date list of supported aliases and models, please refer to the [Aider LLM documentation](https://aider.chat/docs/llms.html) and the [Aider LLM Leaderboards](https://aider.chat/docs/leaderboards.html) which show performance comparisons across different models.
302+
303+
## Troubleshooting
304+
305+
If you encounter issues:
306+
307+
1. **Screen/Tmux issues**: If you can't reconnect to your session, check if the session exists with `screen -list` or `tmux list-sessions`
308+
2. **API key issues**: Ensure you've entered the correct API key for your selected provider
309+
3. **Browser mode issues**: If the browser interface doesn't open, check that you're accessing it from a machine that can reach your Coder workspace
310+
311+
For more information on using Aider, see the [Aider documentation](https://aider.chat/docs/).
312+
313+
```
314+
315+
```

0 commit comments

Comments
 (0)