Skip to content

Commit 79ae316

Browse files
committed
Refactor Aider module
1 parent 79e2fdd commit 79ae316

File tree

5 files changed

+101
-75
lines changed

5 files changed

+101
-75
lines changed

registry/coder/modules/aider/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,11 @@ module "aider" {
4848
agent_id = coder_agent.example.id
4949
credentials = var.gemini_api_key
5050
install_aider = true
51+
workdir = "/home/coder"
5152
ai_provider = "google"
5253
model = "gemini"
5354
install_agentapi = true
54-
task_prompt = data.coder_parameter.ai_prompt.value
55+
ai_prompt = data.coder_parameter.ai_prompt.value
5556
system_prompt = "..."
5657
}
5758
```

registry/coder/modules/aider/main.test.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,10 @@ describe("Aider", async () => {
100100
});
101101

102102
test("custom-folder", async () => {
103-
const folder = "/tmp/aider-test";
103+
const workdir = "/tmp/aider-test";
104104
const { id } = await setup({
105105
moduleVariables: {
106-
folder,
106+
workdir,
107107
model: "gemini",
108108
},
109109
});
@@ -112,15 +112,14 @@ describe("Aider", async () => {
112112
id,
113113
"/home/coder/.aider-module/install.log",
114114
);
115-
expect(resp).toContain(folder);
115+
expect(resp).toContain(workdir);
116116
});
117117

118118
test("pre-post-install-scripts", async () => {
119119
const { id } = await setup({
120120
moduleVariables: {
121-
experiment_pre_install_script: "#!/bin/bash\necho 'pre-install-script'",
122-
experiment_post_install_script:
123-
"#!/bin/bash\necho 'post-install-script'",
121+
pre_install_script: "#!/bin/bash\necho 'pre-install-script'",
122+
post_install_script: "#!/bin/bash\necho 'post-install-script'",
124123
model: "gemini",
125124
},
126125
});
@@ -163,7 +162,7 @@ describe("Aider", async () => {
163162
},
164163
});
165164
await execModuleScript(id, {
166-
ARG_TASK_PROMPT: `${prompt}`,
165+
ARG_AI_PROMPT: `${prompt}`,
167166
});
168167
const resp = await readFileContainer(
169168
id,

registry/coder/modules/aider/main.tf

Lines changed: 71 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,76 @@ variable "icon" {
3636
default = "/icon/aider.svg"
3737
}
3838

39-
variable "folder" {
39+
variable "workdir" {
4040
type = string
4141
description = "The folder to run Aider in."
4242
default = "/home/coder"
4343
}
4444

45-
variable "install_aider" {
45+
variable "report_tasks" {
4646
type = bool
47-
description = "Whether to install Aider."
47+
description = "Whether to enable task reporting to Coder UI via AgentAPI"
4848
default = true
4949
}
5050

51-
variable "experiment_report_tasks" {
51+
variable "cli_app" {
52+
type = bool
53+
description = "Whether to create a CLI app for Aider"
54+
default = false
55+
}
56+
57+
variable "web_app_display_name" {
58+
type = string
59+
description = "Display name for the web app"
60+
default = "Aider"
61+
}
62+
63+
variable "cli_app_display_name" {
64+
type = string
65+
description = "Display name for the CLI app"
66+
default = "Aider CLI"
67+
}
68+
69+
variable "pre_install_script" {
70+
type = string
71+
description = "Custom script to run before installing Aider."
72+
default = null
73+
}
74+
75+
variable "post_install_script" {
76+
type = string
77+
description = "Custom script to run after installing Aider."
78+
default = null
79+
}
80+
81+
variable "install_agentapi" {
82+
type = bool
83+
description = "Whether to install AgentAPI."
84+
default = true
85+
}
86+
87+
variable "agentapi_version" {
88+
type = string
89+
description = "The version of AgentAPI to install."
90+
default = "v0.6.3"
91+
}
92+
93+
variable "ai_prompt" {
94+
type = string
95+
description = "Initial task prompt for Claude Code."
96+
default = ""
97+
}
98+
99+
resource "coder_env" "ai_prompt" {
100+
agent_id = var.agent_id
101+
name = "ARG_AI_PROMPT"
102+
value = var.ai_prompt
103+
}
104+
# ---------------------------------------------
105+
106+
variable "install_aider" {
52107
type = bool
53-
description = "Whether to enable task reporting."
108+
description = "Whether to install Aider."
54109
default = true
55110
}
56111

@@ -76,24 +131,6 @@ variable "system_prompt" {
76131
EOT
77132
}
78133

79-
variable "aider_prompt" {
80-
type = bool
81-
description = "This prompt will be sent to Aider and should run only once, and AgentAPI will be disabled."
82-
default = false
83-
}
84-
85-
variable "experiment_pre_install_script" {
86-
type = string
87-
description = "Custom script to run before installing Aider."
88-
default = null
89-
}
90-
91-
variable "experiment_post_install_script" {
92-
type = string
93-
description = "Custom script to run after installing Aider."
94-
default = null
95-
}
96-
97134
variable "experiment_additional_extensions" {
98135
type = string
99136
description = "Additional extensions configuration in YAML format to append to the config."
@@ -128,30 +165,6 @@ variable "custom_env_var_name" {
128165
default = ""
129166
}
130167

131-
variable "install_agentapi" {
132-
type = bool
133-
description = "Whether to install AgentAPI."
134-
default = true
135-
}
136-
137-
variable "agentapi_version" {
138-
type = string
139-
description = "The version of AgentAPI to install."
140-
default = "v0.6.3"
141-
}
142-
143-
variable "task_prompt" {
144-
type = string
145-
description = "Task prompt to use with Aider"
146-
default = ""
147-
}
148-
149-
resource "coder_env" "ai_prompt" {
150-
agent_id = var.agent_id
151-
name = "ARG_TASK_PROMPT"
152-
value = var.task_prompt
153-
}
154-
155168
variable "base_aider_config" {
156169
type = string
157170
description = <<-EOT
@@ -243,34 +256,34 @@ locals {
243256

244257
module "agentapi" {
245258
source = "registry.coder.com/coder/agentapi/coder"
246-
version = "1.0.1"
259+
version = "1.1.1"
247260

248261
agent_id = var.agent_id
249262
web_app_slug = local.app_slug
250263
web_app_order = var.order
251264
web_app_group = var.group
252265
web_app_icon = var.icon
253-
web_app_display_name = "Aider"
254-
cli_app_slug = "${local.app_slug}-cli"
255-
cli_app_display_name = "Aider CLI"
266+
web_app_display_name = var.web_app_display_name
267+
cli_app = var.cli_app
268+
cli_app_slug = var.cli_app ? "${local.app_slug}-cli" : null
269+
cli_app_display_name = var.cli_app ? var.cli_app_display_name : null
256270
module_dir_name = local.module_dir_name
257271
install_agentapi = var.install_agentapi
258272
agentapi_version = var.agentapi_version
259-
pre_install_script = var.experiment_pre_install_script
260-
post_install_script = var.experiment_post_install_script
273+
pre_install_script = var.pre_install_script
274+
post_install_script = var.post_install_script
261275
start_script = <<-EOT
262276
#!/bin/bash
263277
set -o errexit
264278
set -o pipefail
265279
266280
echo -n '${base64encode(local.start_script)}' | base64 -d > /tmp/start.sh
267281
chmod +x /tmp/start.sh
268-
AIDER_START_DIRECTORY='${var.folder}' \
269-
ARG_API_KEY='${var.credentials}' \
282+
AIDER_START_DIRECTORY='${var.workdir}' \
283+
ARG_API_KEY='${base64encode(var.credentials)}' \
270284
ARG_MODEL='${var.model}' \
271285
ARG_PROVIDER='${var.ai_provider}' \
272286
ARG_ENV_API_NAME_HOLDER='${local.env_var_name}' \
273-
AIDER_PROMPT='${var.aider_prompt}' \
274287
/tmp/start.sh
275288
EOT
276289

@@ -281,10 +294,10 @@ module "agentapi" {
281294
282295
echo -n '${base64encode(local.install_script)}' | base64 -d > /tmp/install.sh
283296
chmod +x /tmp/install.sh
284-
AIDER_START_DIRECTORY='${var.folder}' \
297+
AIDER_START_DIRECTORY='${var.workdir}' \
285298
ARG_INSTALL_AIDER='${var.install_aider}' \
286299
AIDER_SYSTEM_PROMPT='${var.system_prompt}' \
287-
ARG_IMPLEMENT_MCP='${var.experiment_report_tasks}' \
300+
ARG_REPORT_TASKS='${var.report_tasks}' \
288301
ARG_AIDER_CONFIG="$(echo -n '${base64encode(trimspace(local.combined_extensions))}' | base64 -d)" \
289302
/tmp/install.sh
290303
EOT

registry/coder/modules/aider/scripts/install.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ command_exists() {
66
command -v "$1" > /dev/null 2>&1
77
}
88

9+
# Inputs
10+
AIDER_START_DIRECTORY=${AIDER_START_DIRECTORY:-/home/coder}
11+
ARG_INSTALL_AIDER=${ARG_INSTALL_AIDER:-true}
12+
AIDER_SYSTEM_PROMPT=${AIDER_SYSTEM_PROMPT:-}
13+
ARG_REPORT_TASKS=${ARG_REPORT_TASKS:-true}
14+
ARG_AIDER_CONFIG=${ARG_AIDER_CONFIG:-}
15+
916
echo "--------------------------------"
1017
echo "Install flag: $ARG_INSTALL_AIDER"
1118
echo "Workspace: $AIDER_START_DIRECTORY"
@@ -39,7 +46,7 @@ function setup_system_prompt() {
3946
}
4047

4148
function configure_aider_settings() {
42-
if [ "${ARG_IMPLEMENT_MCP}" = "true" ]; then
49+
if [ "${ARG_REPORT_TASKS}" = "true" ]; then
4350
echo "Configuring Aider to report tasks via Coder MCP..."
4451

4552
mkdir -p "$HOME/.config/aider"

registry/coder/modules/aider/scripts/start.sh

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ set -euo pipefail
44
# Ensure pipx-installed apps are in PATH
55
export PATH="$HOME/.local/bin:$PATH"
66

7+
AIDER_START_DIRECTORY=${AIDER_START_DIRECTORY:-/home/coder}
8+
ARG_API_KEY=$(echo -n "${ARG_API_KEY:-}" | base64 -d)
9+
ARG_MODEL=${ARG_MODEL:-}
10+
ARG_PROVIDER=${ARG_PROVIDER:-}
11+
ARG_ENV_API_NAME_HOLDER=${ARG_ENV_API_NAME_HOLDER:-}
12+
713
echo "--------------------------------"
814
echo "Provider: $ARG_PROVIDER"
915
echo "Module: $ARG_MODEL"
@@ -16,16 +22,16 @@ else
1622
printf "API key not provided\n"
1723
fi
1824

19-
if [[ "${AIDER_PROMPT}" == "true" && -n "${ARG_TASK_PROMPT:-}" ]]; then
20-
printf "Aider start only with this prompt : $ARG_TASK_PROMPT"
21-
mkdir -p $HOME/.aider-module/
22-
echo aider --model $ARG_MODEL --yes-always --message "$ARG_TASK_PROMPT" > $HOME/.aider-module/aider_output.txt
25+
# if [[ "${AIDER_PROMPT}" == "true" && -n "${ARG_AI_PROMPT:-}" ]]; then
26+
# printf "Aider start only with this prompt : $ARG_AI_PROMPT"
27+
# mkdir -p $HOME/.aider-module/
28+
# echo aider --model $ARG_MODEL --yes-always --message "$ARG_AI_PROMPT" > $HOME/.aider-module/aider_output.txt
2329

24-
elif [ -n "${ARG_TASK_PROMPT:-}" ]; then
25-
printf "Aider task prompt provided : $ARG_TASK_PROMPT"
26-
PROMPT="Every step of the way, report tasks to Coder with proper descriptions and statuses. Your task at hand: $ARG_TASK_PROMPT"
30+
if [ -n "${ARG_AI_PROMPT:-}" ]; then
31+
printf "Aider task prompt provided : $ARG_AI_PROMPT"
32+
PROMPT="Every step of the way, report tasks to Coder with proper descriptions and statuses. Your task at hand: $ARG_AI_PROMPT"
2733

28-
agentapi server --term-width=67 --term-height=1190 -- aider --model $ARG_MODEL --yes-always --message "$ARG_TASK_PROMPT"
34+
agentapi server --term-width=67 --term-height=1190 -- aider --model $ARG_MODEL --yes-always --message "$ARG_AI_PROMPT"
2935
else
3036
printf "No task prompt given.\n"
3137
agentapi server --term-width=67 --term-height=1190 -- aider --model $ARG_MODEL --yes-always

0 commit comments

Comments
 (0)