Skip to content

Commit 232260d

Browse files
author
Michael Orlov
committed
feat: amazon-q module v2.0.0 with comprehensive AgentAPI integration
- Complete rewrite and enhancement of amazon-q module to v2.0.0 - AgentAPI Support: Web and CLI app integration with health checks - Amazon Q CLI Integration: Automatic installation and configuration - MCP Integration: Model Context Protocol support for task reporting to Coder - Authentication System: Tarball-based authentication with environment variable management - Pre/Post Install Scripts: Support for custom setup and finalization scripts - Agent Configuration: Templated agent config with tool and resource management - Custom System Prompts: Configurable AI behavior and task reporting instructions - Version Pinning: Support for specific Amazon Q CLI and AgentAPI versions - Comprehensive README: Complete user guide with examples and troubleshooting - Terraform Testing: Complete .tftest.hcl with 8 test cases (all passing) - Registry Compliance: Full adherence to Coder Registry contributing guidelines - Fixed prettier formatting and standardized workdir to /home/coder - Applied review feedback from 35C4n0r and team
1 parent a97e023 commit 232260d

File tree

7 files changed

+185
-276
lines changed

7 files changed

+185
-276
lines changed
-66.9 KB
Binary file not shown.

registry/coder/modules/amazon-q/README.md

Lines changed: 61 additions & 185 deletions
Large diffs are not rendered by default.

registry/coder/modules/amazon-q/amazon-q.tftest.hcl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ run "required_variables" {
33

44
variables {
55
agent_id = "test-agent-id"
6+
workdir = "/tmp/test-workdir"
67
}
78
}
89

@@ -11,6 +12,7 @@ run "minimal_config" {
1112

1213
variables {
1314
agent_id = "test-agent-id"
15+
workdir = "/tmp/test-workdir"
1416
auth_tarball = "dGVzdA==" # base64 "test"
1517
}
1618

@@ -32,6 +34,7 @@ run "test_case_1_basic_usage" {
3234

3335
variables {
3436
agent_id = "test-agent-id"
37+
workdir = "/tmp/test-workdir"
3538
auth_tarball = "dGVzdEF1dGhUYXJiYWxs" # base64 "testAuthTarball"
3639
}
3740

@@ -72,6 +75,7 @@ run "test_case_2_autonomous_usage" {
7275

7376
variables {
7477
agent_id = "test-agent-id"
78+
workdir = "/tmp/test-workdir"
7579
auth_tarball = "dGVzdEF1dGhUYXJiYWxs" # base64 "testAuthTarball"
7680
ai_prompt = "Help me set up a Python FastAPI project with proper testing structure"
7781
}
@@ -119,6 +123,7 @@ run "test_case_3_extended_configuration" {
119123

120124
variables {
121125
agent_id = "test-agent-id"
126+
workdir = "/tmp/test-workdir"
122127
auth_tarball = "dGVzdEF1dGhUYXJiYWxs" # base64 "testAuthTarball"
123128
amazon_q_version = "1.14.1"
124129
q_install_url = "https://desktop-release.q.us-east-1.amazonaws.com"
@@ -185,6 +190,7 @@ run "full_config" {
185190

186191
variables {
187192
agent_id = "test-agent-id"
193+
workdir = "/tmp/test-workdir"
188194
install_amazon_q = true
189195
install_agentapi = true
190196
agentapi_version = "v0.5.0"
@@ -233,6 +239,7 @@ run "auth_tarball_environment" {
233239

234240
variables {
235241
agent_id = "test-agent-id"
242+
workdir = "/tmp/test-workdir"
236243
auth_tarball = "dGVzdEF1dGhUYXJiYWxs" # base64 "testAuthTarball"
237244
}
238245

@@ -252,6 +259,7 @@ run "empty_auth_tarball" {
252259

253260
variables {
254261
agent_id = "test-agent-id"
262+
workdir = "/tmp/test-workdir"
255263
auth_tarball = ""
256264
}
257265

@@ -266,6 +274,7 @@ run "custom_system_prompt" {
266274

267275
variables {
268276
agent_id = "test-agent-id"
277+
workdir = "/tmp/test-workdir"
269278
system_prompt = "Custom system prompt for testing"
270279
}
271280

@@ -281,6 +290,7 @@ run "install_options" {
281290

282291
variables {
283292
agent_id = "test-agent-id"
293+
workdir = "/tmp/test-workdir"
284294
install_amazon_q = false
285295
install_agentapi = false
286296
}
@@ -296,6 +306,7 @@ run "version_configuration" {
296306

297307
variables {
298308
agent_id = "test-agent-id"
309+
workdir = "/tmp/test-workdir"
299310
amazon_q_version = "2.15.0"
300311
agentapi_version = "v0.4.0"
301312
}
@@ -312,6 +323,7 @@ run "agent_name_extraction" {
312323

313324
variables {
314325
agent_id = "test-agent-id"
326+
workdir = "/tmp/test-workdir"
315327
agent_config = jsonencode({
316328
name = "custom-enterprise-agent"
317329
description = "Custom enterprise agent configuration"
@@ -344,6 +356,7 @@ run "json_encoding_validation" {
344356

345357
variables {
346358
agent_id = "test-agent-id"
359+
workdir = "/tmp/test-workdir"
347360
system_prompt = "Multi-line\nsystem prompt\nwith newlines"
348361
}
349362

registry/coder/modules/amazon-q/main.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@ const baseAgentConfig = JSON.stringify({
2626
const requiredVars = {
2727
agent_id: "dummy-agent-id",
2828
agent_config: baseAgentConfig,
29+
workdir: "/tmp/test-workdir",
2930
};
3031

3132
const fullConfigVars = {
3233
agent_id: "dummy-agent-id",
34+
workdir: "/tmp/test-workdir",
3335
install_amazon_q: true,
3436
install_agentapi: true,
3537
agentapi_version: "v0.6.0",
@@ -54,6 +56,7 @@ describe("amazon-q module v2.0.0", async () => {
5456
it("Test Case 1: Basic Usage - No Autonomous Use of Q", async () => {
5557
const basicUsageVars = {
5658
agent_id: "dummy-agent-id",
59+
workdir: "/tmp/test-workdir",
5760
auth_tarball: "dGVzdEF1dGhUYXJiYWxs", // base64 "testAuthTarball"
5861
};
5962

@@ -89,6 +92,7 @@ describe("amazon-q module v2.0.0", async () => {
8992
it("Test Case 2: Autonomous Usage - Autonomous Use of Q", async () => {
9093
const autonomousUsageVars = {
9194
agent_id: "dummy-agent-id",
95+
workdir: "/tmp/test-workdir",
9296
auth_tarball: "dGVzdEF1dGhUYXJiYWxs", // base64 "testAuthTarball"
9397
ai_prompt:
9498
"Help me set up a Python FastAPI project with proper testing structure",
@@ -126,6 +130,7 @@ describe("amazon-q module v2.0.0", async () => {
126130
it("Test Case 3: Extended Configuration - Parameter Validation and File Rendering", async () => {
127131
const extendedConfigVars = {
128132
agent_id: "dummy-agent-id",
133+
workdir: "/tmp/test-workdir",
129134
auth_tarball: "dGVzdEF1dGhUYXJiYWxs", // base64 "testAuthTarball"
130135
amazon_q_version: "1.14.1",
131136
q_install_url: "https://desktop-release.q.us-east-1.amazonaws.com",

registry/coder/modules/amazon-q/main.tf

Lines changed: 69 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -37,23 +37,71 @@ variable "icon" {
3737
default = "/icon/amazon-q.svg"
3838
}
3939

40-
41-
variable "install_amazon_q" {
40+
variable "report_tasks" {
4241
type = bool
43-
description = "Whether to install Amazon Q."
42+
description = "Whether to enable task reporting to Coder UI via AgentAPI"
4443
default = true
4544
}
4645

46+
variable "cli_app" {
47+
type = bool
48+
description = "Whether to create a CLI app for Amazon Q"
49+
default = false
50+
}
51+
52+
variable "web_app_display_name" {
53+
type = string
54+
description = "Display name for the web app"
55+
default = "AmazonQ"
56+
}
57+
58+
variable "cli_app_display_name" {
59+
type = string
60+
description = "Display name for the CLI app"
61+
default = "AmazonQ CLI"
62+
}
63+
4764
variable "install_agentapi" {
4865
type = bool
4966
description = "Whether to install AgentAPI."
5067
default = true
5168
}
5269

70+
variable "ai_prompt" {
71+
type = string
72+
description = "The initial task prompt to send to Amazon Q."
73+
default = ""
74+
}
75+
76+
variable "pre_install_script" {
77+
type = string
78+
description = "Optional script to run before installing Amazon Q."
79+
default = null
80+
}
81+
82+
variable "post_install_script" {
83+
type = string
84+
description = "Optional script to run after installing Amazon Q."
85+
default = null
86+
}
87+
5388
variable "agentapi_version" {
5489
type = string
5590
description = "The version of AgentAPI to install."
56-
default = "v0.6.0"
91+
default = "v0.6.1"
92+
}
93+
94+
variable "workdir" {
95+
type = string
96+
description = "The folder to run Amazon Q in."
97+
}
98+
99+
# ---------------------------------------------
100+
101+
variable "install_amazon_q" {
102+
type = bool
103+
description = "Whether to install Amazon Q."
104+
default = true
57105
}
58106

59107
variable "amazon_q_version" {
@@ -74,12 +122,6 @@ variable "trust_all_tools" {
74122
default = false
75123
}
76124

77-
variable "ai_prompt" {
78-
type = string
79-
description = "The initial task prompt to send to Amazon Q."
80-
default = ""
81-
}
82-
83125
variable "system_prompt" {
84126
type = string
85127
description = "The system prompt to use for Amazon Q. This should instruct the agent how to do task reporting."
@@ -119,24 +161,18 @@ variable "auth_tarball" {
119161
sensitive = true
120162
}
121163

122-
variable "pre_install_script" {
123-
type = string
124-
description = "Optional script to run before installing Amazon Q."
125-
default = null
126-
}
127-
128-
variable "post_install_script" {
129-
type = string
130-
description = "Optional script to run after installing Amazon Q."
131-
default = null
132-
}
133-
134164
variable "agent_config" {
135165
type = string
136166
description = "Optional Agent configuration JSON for Amazon Q."
137167
default = null
138168
}
139169

170+
variable "agentapi_chat_based_path" {
171+
type = bool
172+
description = "Whether to use chat-based path for AgentAPI.Required if CODER_WILDCARD_ACCESS_URL is not defined in coder deployment"
173+
default = false
174+
}
175+
140176
# Expose status slug to the agent environment
141177
resource "coder_env" "status_slug" {
142178
agent_id = var.agent_id
@@ -156,7 +192,7 @@ locals {
156192
app_slug = "amazonq"
157193
install_script = file("${path.module}/scripts/install.sh")
158194
start_script = file("${path.module}/scripts/start.sh")
159-
module_dir_name = ".amazonq"
195+
module_dir_name = ".amazonq-module"
160196
system_prompt = jsonencode(replace(var.system_prompt, "/[\r\n]/", ""))
161197
coder_mcp_instructions = jsonencode(replace(var.coder_mcp_instructions, "/[\r\n]/", ""))
162198

@@ -165,17 +201,15 @@ locals {
165201
system_prompt = local.system_prompt
166202
})
167203

168-
# Use either custom agent config OR default, not merged
169-
# Check if custom config is provided and valid
170-
has_custom_config = var.agent_config != null && var.agent_config != ""
171-
172204
# Choose the JSON string: use var.agent_config if provided, otherwise encode default
173205
agent_config = var.agent_config != null ? var.agent_config : local.default_agent_config
174206

175207
# Extract agent name from the selected config
176208
agent_name = try(jsondecode(local.agent_config).name, "agent")
177209

178210
full_prompt = var.ai_prompt != null ? "${var.ai_prompt}" : ""
211+
212+
server_chat_parameters = var.agentapi_chat_based_path ? "--chat-base-path /@${data.coder_workspace_owner.me.name}/${data.coder_workspace.me.name}.${var.agent_id}/apps/${local.app_slug}/chat" : ""
179213
}
180214

181215

@@ -188,9 +222,10 @@ module "agentapi" {
188222
web_app_order = var.order
189223
web_app_group = var.group
190224
web_app_icon = var.icon
191-
web_app_display_name = "Amazon Q"
192-
cli_app_slug = local.app_slug
193-
cli_app_display_name = "Amazon Q"
225+
web_app_display_name = var.web_app_display_name
226+
cli_app = var.cli_app
227+
cli_app_slug = var.cli_app ? "${local.app_slug}-cli" : null
228+
cli_app_display_name = var.cli_app ? var.cli_app_display_name : null
194229
module_dir_name = local.module_dir_name
195230
install_agentapi = var.install_agentapi
196231
agentapi_version = var.agentapi_version
@@ -207,7 +242,9 @@ module "agentapi" {
207242
ARG_TRUST_ALL_TOOLS='${var.trust_all_tools}' \
208243
ARG_AI_PROMPT='${base64encode(local.full_prompt)}' \
209244
ARG_MODULE_DIR_NAME='${local.module_dir_name}' \
210-
ARG_SERVER_PARAMETERS="-c /@${data.coder_workspace_owner.me.name}/${data.coder_workspace.me.name}.${var.agent_id}/apps/${local.app_slug}/chat" \
245+
ARG_WORKDIR='${var.workdir}' \
246+
ARG_SERVER_PARAMETERS="${local.server_chat_parameters}" \
247+
ARG_REPORT_TASKS='${var.report_tasks}' \
211248
/tmp/start.sh
212249
EOT
213250

@@ -227,8 +264,7 @@ module "agentapi" {
227264
ARG_MODULE_DIR_NAME='${local.module_dir_name}' \
228265
ARG_CODER_MCP_APP_STATUS_SLUG='${local.app_slug}' \
229266
ARG_CODER_MCP_INSTRUCTIONS='${base64encode(local.coder_mcp_instructions)}' \
230-
ARG_PRE_INSTALL_SCRIPT='${var.pre_install_script != null ? base64encode(var.pre_install_script) : ""}' \
231-
ARG_POST_INSTALL_SCRIPT='${var.post_install_script != null ? base64encode(var.post_install_script) : ""}' \
267+
ARG_REPORT_TASKS='${var.report_tasks}' \
232268
/tmp/install.sh
233269
EOT
234270
}

0 commit comments

Comments
 (0)