Skip to content

Commit 23b6ea7

Browse files
author
Michael Orlov
committed
feat: comprehensive amazon-q module v2.0.0 enhancements
- Enhanced security: Changed trust_all_tools default from true to false - Updated versions: amazon_q_version to 1.14.1, agentapi_version to v0.6.0 - Fixed server parameters: Corrected ARG_SERVER_PARAMETERS with -c flag - Improved configuration: Better parameter handling and flexibility - Clean documentation: Removed temporary changelog, maintained sync with code - Professional quality: Consistent formatting and comprehensive updates - Dynamic agent name extraction from agent_config JSON 'name' field - Agent-specific configuration files: ~/.aws/amazonq/cli-agents/{agent_name}.json - Configurable q_install_url parameter for enterprise/air-gapped environments - Default q_install_url: https://desktop-release.q.us-east-1.amazonaws.com - Unified URL construction for both x86_64 and aarch64 architectures - Enhanced MCP integration with agent-specific configuration - Improved install script with agent name and URL parameters - Comprehensive air-gapped installation documentation and examples - Clean separation: install-time configuration vs runtime execution - Backward compatibility with default agent name fallback - Enhanced logging and debugging output for troubleshooting - Comprehensive Dependencies section documenting AgentAPI requirements - AgentAPI Coder Module v1.1.1 (registry.coder.com/coder/agentapi/coder) - AgentAPI Binary v0.6.0 (configurable via agentapi_version parameter) - Clear component separation: module lifecycle vs runtime functionality - Version management guidance: fixed module vs configurable binary versions - Architecture documentation: two-layer dependency explanation - Upgrade path clarity for both AgentAPI components - Removed folder variable and ARG_FOLDER usage for simplification - Use HOME directory directly instead of configurable folder parameter - Simplified working directory logic and parameter passing - Reduced configuration complexity and unnecessary variables - Cleaner start script with consistent HOME-based working environment - Updated documentation to reflect simplified variable set - Interactive mode with MCP reporting when no AI prompt provided - Consistent coder_report_task tool integration for all usage scenarios - Enhanced user experience for both automated and manual operations - Proper MCP communication in prompted and interactive modes - Code improvements and documentation enhancements - Enhanced README formatting and clarity - Improved script logic and error handling - Refined user experience and code maintainability - Minor script improvements for enhanced functionality and reliability - Latest main.tf configuration improvements and module enhancements - Enhanced start.sh script functionality and reliability improvements - Continuous main.tf updates with enhanced functionality and performance
1 parent 87d2fa0 commit 23b6ea7

File tree

4 files changed

+133
-52
lines changed

4 files changed

+133
-52
lines changed

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

Lines changed: 86 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,40 @@ module "amazon-q" {
3434
- **🛠️ Tool Trust**: Configurable tool trust settings
3535
- **📁 Flexible Deployment**: Configurable working directory and module structure
3636

37+
## Dependencies
38+
39+
This module has critical dependencies on AgentAPI components for proper web integration and interactive functionality:
40+
41+
### AgentAPI Coder Module
42+
43+
- **Module**: `registry.coder.com/coder/agentapi/coder`
44+
- **Version**: `1.1.1` (hardcoded in module)
45+
- **Purpose**: Provides the Coder module infrastructure for AgentAPI integration
46+
- **Functionality**: Handles module lifecycle, configuration, and Coder-specific integration
47+
48+
### AgentAPI Binary
49+
50+
- **Binary Version**: `v0.6.0` (configurable via `agentapi_version` parameter)
51+
- **Installation**: Automatically downloaded and installed when `install_agentapi = true`
52+
- **Purpose**: The actual AgentAPI server binary that runs the web interface
53+
- **Functionality**: Provides the runtime server for web-based interactions
54+
55+
**Why Both Components are Required:**
56+
57+
- **Coder Module (1.1.1)**: Integrates AgentAPI into the Coder ecosystem and manages the module lifecycle
58+
- **AgentAPI Binary (v0.6.0)**: Provides the actual web interface and interactive functionality
59+
- **Web Interface**: Enables web-based chat interface accessible through Coder
60+
- **Session Management**: Handles interactive sessions and maintains state
61+
- **MCP Protocol**: Facilitates Model Context Protocol communication for task reporting
62+
- **Real-time Updates**: Enables live progress reporting through the `coder_report_task` tool
63+
64+
**Version Compatibility:**
65+
66+
- **Module Version**: Fixed at `1.1.1` for stability and compatibility
67+
- **Binary Version**: Configurable (default `v0.6.0`) to allow updates and customization
68+
- **Coder Integration**: Ensure your Coder deployment supports both component versions
69+
- **Upgrade Path**: Binary version can be updated via `agentapi_version` parameter
70+
3771
## Prerequisites
3872

3973
### Authentication Tarball (Required)
@@ -102,20 +136,20 @@ variable "amazon_q_auth_tarball" {
102136

103137
### Optional Variables
104138

105-
| Variable | Type | Default | Description |
106-
| --------------------- | -------- | --------------- | ----------------------------------------------------------------------------------------------------- |
107-
| `auth_tarball` | `string` | `""` | Base64 encoded, zstd compressed tarball of authenticated Amazon Q directory |
108-
| `amazon_q_version` | `string` | `"latest"` | Version of Amazon Q to install |
109-
| `install_amazon_q` | `bool` | `true` | Whether to install Amazon Q CLI |
110-
| `install_agentapi` | `bool` | `true` | Whether to install AgentAPI for web integration |
111-
| `agentapi_version` | `string` | `"v0.5.0"` | Version of AgentAPI to install |
112-
| `folder` | `string` | `"/home/coder"` | Working directory for Amazon Q |
113-
| `trust_all_tools` | `bool` | `true` | Whether to trust all tools in Amazon Q |
114-
| `ai_prompt` | `string` | `""` | Initial task prompt to send to Amazon Q |
115-
| `system_prompt` | `string` | _See below_ | System prompt for task reporting behavior |
116-
| `pre_install_script` | `string` | `null` | Script to run before installing Amazon Q |
117-
| `post_install_script` | `string` | `null` | Script to run after installing Amazon Q |
118-
| `agent_config` | `string` | `null` | Custom agent configuration JSON (See the [Default Agent configuration](#default-agent-configuration)) |
139+
| Variable | Type | Default | Description |
140+
| --------------------- | -------- | ----------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
141+
| `auth_tarball` | `string` | `""` | Base64 encoded, zstd compressed tarball of authenticated Amazon Q directory |
142+
| `amazon_q_version` | `string` | `"1.14.1"` | Version of Amazon Q to install |
143+
| `q_install_url` | `string` | `"https://desktop-release.q.us-east-1.amazonaws.com"` | Base URL for Amazon Q installation downloads |
144+
| `install_amazon_q` | `bool` | `true` | Whether to install Amazon Q CLI |
145+
| `install_agentapi` | `bool` | `true` | Whether to install AgentAPI for web integration |
146+
| `agentapi_version` | `string` | `"v0.6.0"` | Version of AgentAPI to install |
147+
| `trust_all_tools` | `bool` | `false` | Whether to trust all tools in Amazon Q |
148+
| `ai_prompt` | `string` | `""` | Initial task prompt to send to Amazon Q |
149+
| `system_prompt` | `string` | _See below_ | System prompt for task reporting behavior |
150+
| `pre_install_script` | `string` | `null` | Script to run before installing Amazon Q |
151+
| `post_install_script` | `string` | `null` | Script to run after installing Amazon Q |
152+
| `agent_config` | `string` | `null` | Custom agent configuration JSON. The "name" field is used as the agent name and config filename (See the [Default Agent configuration](#default-agent-configuration)) |
119153

120154
### UI Configuration
121155

@@ -196,6 +230,16 @@ The module includes a default agent configuration template that provides a compr
196230

197231
You can override this configuration by providing your own JSON via the `agent_config` variable.
198232

233+
### Agent Name Configuration
234+
235+
The module automatically extracts the agent name from the `"name"` field in the `agent_config` JSON and uses it for:
236+
237+
- **Configuration File:** Saves the agent config as `~/.aws/amazonq/cli-agents/{agent_name}.json`
238+
- **Default Agent:** Sets the agent as the default using `q settings chat.defaultAgent {agent_name}`
239+
- **MCP Integration:** Associates the Coder MCP server with the specified agent name
240+
241+
If no custom `agent_config` is provided, the default agent name "agent" is used.
242+
199243
## Usage Examples
200244

201245
### Basic Usage
@@ -293,6 +337,34 @@ module "amazon-q" {
293337
}
294338
```
295339

340+
### Air-Gapped Installation
341+
342+
For environments without direct internet access, you can host Amazon Q installation files internally and configure the module to use your internal repository:
343+
344+
```tf
345+
module "amazon-q" {
346+
source = "registry.coder.com/coder/amazon-q/coder"
347+
version = "2.0.0"
348+
agent_id = coder_agent.example.id
349+
auth_tarball = var.amazon_q_auth_tarball
350+
351+
# Point to internal artifact repository
352+
q_install_url = "https://artifacts.internal.corp/amazon-q-releases"
353+
354+
# Use specific version available in your repository
355+
amazon_q_version = "1.14.1"
356+
}
357+
```
358+
359+
**Prerequisites for Air-Gapped Setup:**
360+
361+
1. Download Amazon Q installation files from AWS and host them internally
362+
2. Maintain the same directory structure: `{base_url}/{version}/q-{arch}-linux.zip`
363+
3. Ensure both architectures are available:
364+
- `q-x86_64-linux.zip` for Intel/AMD systems
365+
- `q-aarch64-linux.zip` for ARM systems
366+
4. Configure network access from Coder workspaces to your internal repository
367+
296368
## Architecture
297369

298370
### Components

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

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,6 @@ variable "icon" {
3737
default = "/icon/amazon-q.svg"
3838
}
3939

40-
variable "folder" {
41-
type = string
42-
description = "The folder to run Amazon Q in."
43-
default = "/home/coder"
44-
}
4540

4641
variable "install_amazon_q" {
4742
type = bool
@@ -58,7 +53,7 @@ variable "install_agentapi" {
5853
variable "agentapi_version" {
5954
type = string
6055
description = "The version of AgentAPI to install."
61-
default = "v0.5.0"
56+
default = "v0.6.0"
6257
}
6358

6459
variable "amazon_q_version" {
@@ -67,10 +62,16 @@ variable "amazon_q_version" {
6762
default = "1.14.1"
6863
}
6964

65+
variable "q_install_url" {
66+
type = string
67+
description = "Base URL for Amazon Q installation downloads."
68+
default = "https://desktop-release.q.us-east-1.amazonaws.com"
69+
}
70+
7071
variable "trust_all_tools" {
7172
type = bool
7273
description = "Whether to trust all tools in Amazon Q."
73-
default = true
74+
default = false
7475
}
7576

7677
variable "ai_prompt" {
@@ -107,7 +108,7 @@ variable "system_prompt" {
107108

108109
variable "auth_tarball" {
109110
type = string
110-
description = "Base64 encoded, zstd compressed tarball of a pre-authenticated ~/.local/share/amazon-q directory. After running `q login` on another machine, you may generate it with: `cd ~/.local/share/amazon-q && tar -c . | zstd | base64 -w 0`"
111+
description = "Base64 encoded, zstd compressed tarball of a pre-authenticated ~/.local/share/amazon-q directory."
111112
default = ""
112113
sensitive = true
113114
}
@@ -153,6 +154,11 @@ locals {
153154
agent_config = var.agent_config == null ? templatefile("${path.module}/templates/agent-config.json.tpl", {
154155
system_prompt = var.system_prompt
155156
}) : var.agent_config
157+
158+
# Extract agent name from agent_config JSON
159+
agent_config_json = jsondecode(local.agent_config)
160+
agent_name = try(local.agent_config_json.name, "default-agent")
161+
156162
full_prompt = var.ai_prompt != null ? "${var.ai_prompt}" : ""
157163
}
158164

@@ -185,8 +191,7 @@ module "agentapi" {
185191
ARG_TRUST_ALL_TOOLS='${var.trust_all_tools}' \
186192
ARG_AI_PROMPT='${base64encode(local.full_prompt)}' \
187193
ARG_MODULE_DIR_NAME='${local.module_dir_name}' \
188-
ARG_FOLDER='${var.folder}' \
189-
SERVER_PARAMETERS="/@${data.coder_workspace_owner.me.name}/${data.coder_workspace.me.name}.${var.agent_id}/apps/${local.app_slug}/chat" \
194+
ARG_SERVER_PARAMETERS="-c /@${data.coder_workspace_owner.me.name}/${data.coder_workspace.me.name}.${var.agent_id}/apps/${local.app_slug}/chat" \
190195
/tmp/start.sh
191196
EOT
192197

@@ -199,8 +204,10 @@ module "agentapi" {
199204
chmod +x /tmp/install.sh
200205
ARG_INSTALL='${var.install_amazon_q}' \
201206
ARG_VERSION='${var.amazon_q_version}' \
207+
ARG_Q_INSTALL_URL='${var.q_install_url}' \
202208
ARG_AUTH_TARBALL='${var.auth_tarball}' \
203209
ARG_AGENT_CONFIG='${local.agent_config != null ? base64encode(local.agent_config) : ""}' \
210+
ARG_AGENT_NAME='${local.agent_name}' \
204211
ARG_MODULE_DIR_NAME='${local.module_dir_name}' \
205212
ARG_CODER_MCP_APP_STATUS_SLUG='${local.app_slug}' \
206213
ARG_PRE_INSTALL_SCRIPT='${var.pre_install_script != null ? base64encode(var.pre_install_script) : ""}' \

registry/coder/modules/amazon-q/scripts/install.sh

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@ set -o errexit
55
set -o pipefail
66

77
command_exists() {
8-
command -v "$1" >/dev/null 2>&1
8+
command -v "$1" > /dev/null 2>&1
99
}
1010

1111
# Inputs
1212
ARG_INSTALL=${ARG_INSTALL:-true}
1313
ARG_VERSION=${ARG_VERSION:-latest}
14+
ARG_Q_INSTALL_URL=${ARG_Q_INSTALL_URL:-https://desktop-release.q.us-east-1.amazonaws.com}
1415
ARG_AUTH_TARBALL=${ARG_AUTH_TARBALL:-}
1516
ARG_AGENT_CONFIG=${ARG_AGENT_CONFIG:-}
17+
ARG_AGENT_NAME=${ARG_AGENT_NAME:-default-agent}
1618
ARG_MODULE_DIR_NAME=${ARG_MODULE_DIR_NAME:-.aws/.amazonq}
1719
ARG_CODER_MCP_APP_STATUS_SLUG=${ARG_CODER_MCP_APP_STATUS_SLUG:-}
1820
ARG_PRE_INSTALL_SCRIPT=${ARG_PRE_INSTALL_SCRIPT:-}
@@ -29,6 +31,8 @@ fi
2931
echo "--------------------------------"
3032
echo "install: $ARG_INSTALL"
3133
echo "version: $ARG_VERSION"
34+
echo "q_install_url: $ARG_Q_INSTALL_URL"
35+
echo "agent_name: $ARG_AGENT_NAME"
3236
echo "coder_mcp_app_status_slug: $ARG_CODER_MCP_APP_STATUS_SLUG"
3337
echo "module_dir_name: $ARG_MODULE_DIR_NAME"
3438
echo "auth_tarball_provided: $([ -n "$ARG_AUTH_TARBALL" ] && echo "yes" || echo "no")"
@@ -61,16 +65,16 @@ function install_amazon_q() {
6165

6266
ARCH="$(uname -m)"
6367
case "$ARCH" in
64-
"x86_64")
65-
Q_URL="https://desktop-release.q.us-east-1.amazonaws.com/${ARG_VERSION}/q-x86_64-linux.zip"
66-
;;
67-
"aarch64" | "arm64")
68-
Q_URL="https://desktop-release.codewhisperer.us-east-1.amazonaws.com/${ARG_VERSION}/q-aarch64-linux.zip"
69-
;;
70-
*)
71-
echo "Error: Unsupported architecture: $ARCH. Amazon Q only supports x86_64 and arm64."
72-
exit 1
73-
;;
68+
"x86_64")
69+
Q_URL="${ARG_Q_INSTALL_URL}/${ARG_VERSION}/q-x86_64-linux.zip"
70+
;;
71+
"aarch64" | "arm64")
72+
Q_URL="${ARG_Q_INSTALL_URL}/${ARG_VERSION}/q-aarch64-linux.zip"
73+
;;
74+
*)
75+
echo "Error: Unsupported architecture: $ARCH. Amazon Q only supports x86_64 and arm64."
76+
exit 1
77+
;;
7478
esac
7579

7680
echo "Downloading Amazon Q for $ARCH from $Q_URL..."
@@ -102,7 +106,7 @@ function extract_auth_tarball() {
102106
if [ -n "$ARG_AUTH_TARBALL" ]; then
103107
echo "Extracting auth tarball..."
104108
PREV_DIR="$PWD"
105-
echo "$ARG_AUTH_TARBALL" | base64 -d >/tmp/auth.tar.zst
109+
echo "$ARG_AUTH_TARBALL" | base64 -d > /tmp/auth.tar.zst
106110
rm -rf ~/.local/share/amazon-q
107111
mkdir -p ~/.local/share/amazon-q
108112
cd ~/.local/share/amazon-q
@@ -125,9 +129,9 @@ function configure_agent() {
125129
# Apply custom MCP configuration if provided
126130
if [ -n "$ARG_AGENT_CONFIG_DECODED" ]; then
127131
echo "Applying custom MCP configuration..."
128-
# Parse and apply MCP config - implementation depends on Amazon Q's MCP config format
129-
echo "$ARG_AGENT_CONFIG_DECODED" >"$AGENT_CONFIG_DIR/agent.json"
130-
echo "Custom configuration saved to $AGENT_CONFIG_DIR/agent.json"
132+
# Use agent name as filename for the configuration
133+
echo "$ARG_AGENT_CONFIG_DECODED" > "$AGENT_CONFIG_DIR/${ARG_AGENT_NAME}.json"
134+
echo "Custom configuration saved to $AGENT_CONFIG_DIR/${ARG_AGENT_NAME}.json"
131135
fi
132136
q mcp add --name coder \
133137
--command "coder" \
@@ -136,10 +140,10 @@ function configure_agent() {
136140
--env "CODER_MCP_AI_AGENTAPI_URL=http://localhost:3284" \
137141
--env "CODER_AGENT_URL=${CODER_AGENT_URL}" \
138142
--env "CODER_AGENT_TOKEN=${CODER_AGENT_TOKEN}" \
139-
--agent agent \
143+
--agent "$ARG_AGENT_NAME" \
140144
--force || echo "Warning: Failed to add Coder MCP server"
141-
echo "Added Coder MCP server into agent in Amazon Q configuration"
142-
q settings chat.defaultAgent agent
145+
echo "Added Coder MCP server into $ARG_AGENT_NAME in Amazon Q configuration"
146+
q settings chat.defaultAgent "$ARG_AGENT_NAME"
143147
fi
144148
}
145149

registry/coder/modules/amazon-q/scripts/start.sh

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ command_exists() {
1212
ARG_AI_PROMPT=$(echo -n "${ARG_AI_PROMPT:-}" | base64 -d)
1313
ARG_TRUST_ALL_TOOLS=${ARG_TRUST_ALL_TOOLS:-true}
1414
ARG_MODULE_DIR_NAME=${ARG_MODULE_DIR_NAME:-.aws/amazonq}
15-
ARG_FOLDER=${ARG_FOLDER:-$HOME}
15+
ARG_SERVER_PARAMETERS=${ARG_SERVER_PARAMETERS:-""}
1616

1717
echo "--------------------------------"
18-
echo "folder: $ARG_FOLDER"
18+
echo "working_directory: $HOME"
1919
echo "ai_prompt: $ARG_AI_PROMPT"
2020
echo "trust_all_tools: $ARG_TRUST_ALL_TOOLS"
2121
echo "module_dir_name: $ARG_MODULE_DIR_NAME"
@@ -33,13 +33,8 @@ else
3333
exit 1
3434
fi
3535

36-
# Ensure working directory exists
37-
if [ -d "$ARG_FOLDER" ]; then
38-
cd "$ARG_FOLDER"
39-
else
40-
mkdir -p "$ARG_FOLDER"
41-
cd "$ARG_FOLDER"
42-
fi
36+
# Change to home directory for consistent working environment
37+
cd "$HOME"
4338

4439
# Set up environment
4540
export LANG=en_US.UTF-8
@@ -59,6 +54,9 @@ printf "Running: %q %s\n" "$Q_CMD" "$(printf '%q ' "${ARGS[@]}")"
5954
if [ -n "$ARG_AI_PROMPT" ]; then
6055
printf "AI prompt provided\n"
6156
ARGS+=("\"Complete the task at hand in one go. Every step of the way, report your progress using coder_report_task tool through coder MCP with proper summary and statuses. Your task at hand: $ARG_AI_PROMPT\"")
57+
else
58+
printf "AI prompt wasn't provided\n"
59+
ARGS+=("\"Run interactively. Every step of the way, report your progress using coder_report_task tool through coder MCP with proper summary and statuses.\"")
6260
fi
6361
# Use agentapi to manage the interactive session with initial prompt
64-
agentapi server -c "$SERVER_PARAMETERS" -- "$Q_CMD" "${ARGS[@]}"
62+
agentapi server $ARG_SERVER_PARAMETERS -- "$Q_CMD" "${ARGS[@]}"

0 commit comments

Comments
 (0)