From 6e18248731fce238b77be44cb87bf988b45deff9 Mon Sep 17 00:00:00 2001 From: 35C4n0r Date: Tue, 3 Feb 2026 18:58:38 +0530 Subject: [PATCH 01/32] feat(coder/modules/agentapi): enhance start script and configuration options for AgentAPI server --- registry/coder/modules/agentapi/README.md | 39 +++++++++++++++++++ registry/coder/modules/agentapi/main.tf | 28 +++++++++++++ .../coder/modules/agentapi/scripts/main.sh | 26 ++++++++++++- .../agentapi/testdata/agentapi-start.sh | 23 ++++------- 4 files changed, 100 insertions(+), 16 deletions(-) diff --git a/registry/coder/modules/agentapi/README.md b/registry/coder/modules/agentapi/README.md index 06897d6b5..fe543aefc 100644 --- a/registry/coder/modules/agentapi/README.md +++ b/registry/coder/modules/agentapi/README.md @@ -27,6 +27,7 @@ module "agentapi" { cli_app_slug = "goose-cli" cli_app_display_name = "Goose CLI" module_dir_name = local.module_dir_name + agentapi_server_type = "claude" install_agentapi = var.install_agentapi pre_install_script = var.pre_install_script post_install_script = var.post_install_script @@ -62,6 +63,44 @@ module "agentapi" { } ``` +## AgentAPI server configuration + +You can configure the AgentAPI server type, terminal dimensions, and initial prompt: + +```tf +module "agentapi" { + # ... other config + agentapi_server_type = "claude" # required + agentapi_term_width = 67 # default: 67 + agentapi_term_height = 1190 # default: 1190 + agentapi_initial_prompt = "You are a helpful assistant." # optional +} +``` + +**Note:** The `agentapi_initial_prompt` is recommended only if the agent doesn't support initial prompt in interaction mode. + ## For module developers For a complete example of how to use this module, see the [Goose module](https://github.com/coder/registry/blob/main/registry/coder/modules/goose/main.tf). + +### Start script behavior + +The `start_script` should write the agent command to `$module_path/agent-command.sh` instead of starting the AgentAPI server directly. The module will start the server using: + +```bash +agentapi server --type --term-width --term-height -- ./agent-command.sh +``` + +Example start script: + +```bash +#!/bin/bash +module_path=${1:-"$HOME/.my-module"} + +cat > "$module_path/agent-command.sh" << 'EOF' +#!/bin/bash +exec my-agent-command +EOF + +chmod +x "$module_path/agent-command.sh" +``` diff --git a/registry/coder/modules/agentapi/main.tf b/registry/coder/modules/agentapi/main.tf index 6914be779..e3e2e9a55 100644 --- a/registry/coder/modules/agentapi/main.tf +++ b/registry/coder/modules/agentapi/main.tf @@ -128,6 +128,29 @@ variable "agentapi_port" { default = 3284 } +variable "agentapi_server_type" { + type = string + description = "The server type for AgentAPI, passed using --agent flag." +} + +variable "agentapi_term_width" { + type = number + description = "The terminal width for AgentAPI." + default = 67 +} + +variable "agentapi_term_height" { + type = number + description = "The terminal height for AgentAPI." + default = 1190 +} + +variable "agentapi_initial_prompt" { + type = string + description = "Initial prompt for the agent. Recommended only if the agent doesn't support initial prompt in interaction mode." + default = null +} + variable "task_log_snapshot" { type = bool description = "Capture last 10 messages when workspace stops for offline viewing while task is paused." @@ -171,6 +194,7 @@ locals { encoded_pre_install_script = var.pre_install_script != null ? base64encode(var.pre_install_script) : "" encoded_install_script = var.install_script != null ? base64encode(var.install_script) : "" encoded_post_install_script = var.post_install_script != null ? base64encode(var.post_install_script) : "" + encoded_initial_prompt = var.agentapi_initial_prompt != null ? base64encode(var.agentapi_initial_prompt) : "" agentapi_start_script_b64 = base64encode(var.start_script) agentapi_wait_for_start_script_b64 = base64encode(file("${path.module}/scripts/agentapi-wait-for-start.sh")) // Chat base path is only set if not using a subdomain. @@ -206,6 +230,10 @@ resource "coder_script" "agentapi" { ARG_WAIT_FOR_START_SCRIPT="$(echo -n '${local.agentapi_wait_for_start_script_b64}' | base64 -d)" \ ARG_POST_INSTALL_SCRIPT="$(echo -n '${local.encoded_post_install_script}' | base64 -d)" \ ARG_AGENTAPI_PORT='${var.agentapi_port}' \ + ARG_AGENTAPI_SERVER_TYPE='${var.agentapi_server_type}' \ + ARG_AGENTAPI_TERM_WIDTH='${var.agentapi_term_width}' \ + ARG_AGENTAPI_TERM_HEIGHT='${var.agentapi_term_height}' \ + ARG_AGENTAPI_INITIAL_PROMPT="$(echo -n '${local.encoded_initial_prompt}' | base64 -d)" \ ARG_AGENTAPI_CHAT_BASE_PATH='${local.agentapi_chat_base_path}' \ ARG_TASK_ID='${try(data.coder_task.me.id, "")}' \ ARG_TASK_LOG_SNAPSHOT='${var.task_log_snapshot}' \ diff --git a/registry/coder/modules/agentapi/scripts/main.sh b/registry/coder/modules/agentapi/scripts/main.sh index 63e013eb9..157e6060a 100644 --- a/registry/coder/modules/agentapi/scripts/main.sh +++ b/registry/coder/modules/agentapi/scripts/main.sh @@ -13,6 +13,10 @@ START_SCRIPT="$ARG_START_SCRIPT" WAIT_FOR_START_SCRIPT="$ARG_WAIT_FOR_START_SCRIPT" POST_INSTALL_SCRIPT="$ARG_POST_INSTALL_SCRIPT" AGENTAPI_PORT="$ARG_AGENTAPI_PORT" +AGENTAPI_SERVER_TYPE="$ARG_AGENTAPI_SERVER_TYPE" +AGENTAPI_TERM_WIDTH="$ARG_AGENTAPI_TERM_WIDTH" +AGENTAPI_TERM_HEIGHT="$ARG_AGENTAPI_TERM_HEIGHT" +AGENTAPI_INITIAL_PROMPT="${ARG_AGENTAPI_INITIAL_PROMPT:-}" AGENTAPI_CHAT_BASE_PATH="${ARG_AGENTAPI_CHAT_BASE_PATH:-}" TASK_ID="${ARG_TASK_ID:-}" TASK_LOG_SNAPSHOT="${ARG_TASK_LOG_SNAPSHOT:-true}" @@ -106,5 +110,25 @@ cd "${WORKDIR}" export AGENTAPI_CHAT_BASE_PATH="${AGENTAPI_CHAT_BASE_PATH:-}" # Disable host header check since AgentAPI is proxied by Coder (which does its own validation) export AGENTAPI_ALLOWED_HOSTS="*" -nohup "$module_path/scripts/agentapi-start.sh" true "${AGENTAPI_PORT}" &> "$module_path/agentapi-start.log" & + +# Call agentapi-start.sh to write agent-command.sh +"$module_path/scripts/agentapi-start.sh" "$module_path" + +# Build agentapi server command arguments +ARGS=( + "server" + "--type" "${AGENTAPI_SERVER_TYPE}" + "--port" "${AGENTAPI_PORT}" + "--term-width" "${AGENTAPI_TERM_WIDTH}" + "--term-height" "${AGENTAPI_TERM_HEIGHT}" +) + +# Add optional initial prompt +if [ -n "${AGENTAPI_INITIAL_PROMPT}" ]; then + ARGS+=("--initial-prompt" "${AGENTAPI_INITIAL_PROMPT}") +fi + +# Start agentapi server with the agent-command.sh script +nohup agentapi "${ARGS[@]}" -- "$module_path/agent-command.sh" &> "$module_path/agentapi-start.log" & + "$module_path/scripts/agentapi-wait-for-start.sh" "${AGENTAPI_PORT}" diff --git a/registry/coder/modules/agentapi/testdata/agentapi-start.sh b/registry/coder/modules/agentapi/testdata/agentapi-start.sh index 259eb0c9f..f0119acdd 100644 --- a/registry/coder/modules/agentapi/testdata/agentapi-start.sh +++ b/registry/coder/modules/agentapi/testdata/agentapi-start.sh @@ -2,21 +2,14 @@ set -o errexit set -o pipefail -use_prompt=${1:-false} -port=${2:-3284} +module_path=${1:-"$HOME/.agentapi-module"} -module_path="$HOME/.agentapi-module" -log_file_path="$module_path/agentapi.log" - -echo "using prompt: $use_prompt" >> /home/coder/test-agentapi-start.log -echo "using port: $port" >> /home/coder/test-agentapi-start.log +# Write the agent command to agent-command.sh +cat > "$module_path/agent-command.sh" << 'EOF' +#!/bin/bash +exec bash -c aiagent +EOF -AGENTAPI_CHAT_BASE_PATH="${AGENTAPI_CHAT_BASE_PATH:-}" -if [ -n "$AGENTAPI_CHAT_BASE_PATH" ]; then - echo "Using AGENTAPI_CHAT_BASE_PATH: $AGENTAPI_CHAT_BASE_PATH" >> /home/coder/test-agentapi-start.log - export AGENTAPI_CHAT_BASE_PATH -fi +chmod +x "$module_path/agent-command.sh" -agentapi server --port "$port" --term-width 67 --term-height 1190 -- \ - bash -c aiagent \ - > "$log_file_path" 2>&1 +echo "Agent command written to $module_path/agent-command.sh" From 3f68310880bb812e0b173424867bc03fd534a759 Mon Sep 17 00:00:00 2001 From: 35C4n0r Date: Wed, 4 Feb 2026 08:10:36 +0530 Subject: [PATCH 02/32] feat(coder/modules/agentapi): enhance start script and configuration options for AgentAPI server --- registry/coder/modules/agentapi/README.md | 11 ++++---- .../coder/modules/agentapi/scripts/main.sh | 2 +- .../agentapi/testdata/agentapi-start.sh | 2 +- registry/coder/modules/claude-code/main.tf | 2 ++ .../modules/claude-code/scripts/start.sh | 26 ++++++++++++++++--- 5 files changed, 32 insertions(+), 11 deletions(-) diff --git a/registry/coder/modules/agentapi/README.md b/registry/coder/modules/agentapi/README.md index fe543aefc..bef0eb20f 100644 --- a/registry/coder/modules/agentapi/README.md +++ b/registry/coder/modules/agentapi/README.md @@ -70,10 +70,10 @@ You can configure the AgentAPI server type, terminal dimensions, and initial pro ```tf module "agentapi" { # ... other config - agentapi_server_type = "claude" # required - agentapi_term_width = 67 # default: 67 - agentapi_term_height = 1190 # default: 1190 - agentapi_initial_prompt = "You are a helpful assistant." # optional + agentapi_server_type = "claude" # required + agentapi_term_width = 67 # default: 67 + agentapi_term_height = 1190 # default: 1190 + agentapi_initial_prompt = "You are a helpful assistant." # optional } ``` @@ -95,7 +95,8 @@ Example start script: ```bash #!/bin/bash -module_path=${1:-"$HOME/.my-module"} +# Hardcode your module's path +module_path="$HOME/.my-module" cat > "$module_path/agent-command.sh" << 'EOF' #!/bin/bash diff --git a/registry/coder/modules/agentapi/scripts/main.sh b/registry/coder/modules/agentapi/scripts/main.sh index 157e6060a..8087173b1 100644 --- a/registry/coder/modules/agentapi/scripts/main.sh +++ b/registry/coder/modules/agentapi/scripts/main.sh @@ -112,7 +112,7 @@ export AGENTAPI_CHAT_BASE_PATH="${AGENTAPI_CHAT_BASE_PATH:-}" export AGENTAPI_ALLOWED_HOSTS="*" # Call agentapi-start.sh to write agent-command.sh -"$module_path/scripts/agentapi-start.sh" "$module_path" +"$module_path/scripts/agentapi-start.sh" # Build agentapi server command arguments ARGS=( diff --git a/registry/coder/modules/agentapi/testdata/agentapi-start.sh b/registry/coder/modules/agentapi/testdata/agentapi-start.sh index f0119acdd..6c5cf7241 100644 --- a/registry/coder/modules/agentapi/testdata/agentapi-start.sh +++ b/registry/coder/modules/agentapi/testdata/agentapi-start.sh @@ -2,7 +2,7 @@ set -o errexit set -o pipefail -module_path=${1:-"$HOME/.agentapi-module"} +module_path="$HOME/.agentapi-module" # Write the agent command to agent-command.sh cat > "$module_path/agent-command.sh" << 'EOF' diff --git a/registry/coder/modules/claude-code/main.tf b/registry/coder/modules/claude-code/main.tf index bfb1ad159..2a62a6632 100644 --- a/registry/coder/modules/claude-code/main.tf +++ b/registry/coder/modules/claude-code/main.tf @@ -374,6 +374,7 @@ module "agentapi" { cli_app_display_name = var.cli_app ? var.cli_app_display_name : null agentapi_subdomain = var.subdomain module_dir_name = local.module_dir_name + agentapi_server_type = "claude" install_agentapi = var.install_agentapi agentapi_version = var.agentapi_version pre_install_script = var.pre_install_script @@ -382,6 +383,7 @@ module "agentapi" { #!/bin/bash set -o errexit set -o pipefail + echo -n '${base64encode(local.start_script)}' | base64 -d > /tmp/start.sh chmod +x /tmp/start.sh diff --git a/registry/coder/modules/claude-code/scripts/start.sh b/registry/coder/modules/claude-code/scripts/start.sh index b20f38338..ec9b4be53 100644 --- a/registry/coder/modules/claude-code/scripts/start.sh +++ b/registry/coder/modules/claude-code/scripts/start.sh @@ -6,6 +6,7 @@ command_exists() { command -v "$1" > /dev/null 2>&1 } +MODULE_PATH="$HOME/.claude-module" ARG_RESUME_SESSION_ID=${ARG_RESUME_SESSION_ID:-} ARG_CONTINUE=${ARG_CONTINUE:-false} ARG_DANGEROUSLY_SKIP_PERMISSIONS=${ARG_DANGEROUSLY_SKIP_PERMISSIONS:-} @@ -216,6 +217,7 @@ function start_agentapi() { printf "Running claude code with args: %s\n" "$(printf '%q ' "${ARGS[@]}")" + # Write the agent command to agent-command.sh if [ "$ARG_ENABLE_BOUNDARY" = "true" ]; then install_boundary @@ -238,12 +240,28 @@ function start_agentapi() { BOUNDARY_CMD=("$CODER_NO_CAPS" "boundary") fi - agentapi server --type claude --term-width 67 --term-height 1190 -- \ - "${BOUNDARY_CMD[@]}" "${BOUNDARY_ARGS[@]}" -- \ - claude "${ARGS[@]}" + # Build properly quoted command arguments + boundary_cmd=$(printf '%q ' "${BOUNDARY_CMD[@]}" "${BOUNDARY_ARGS[@]}") + claude_args=$(printf '%q ' "${ARGS[@]}") + + # Write command to agent-command.sh with boundary + cat > "$MODULE_PATH/agent-command.sh" << EOF +#!/bin/bash +${BOUNDARY_CMD[@]} -- claude ${ARGS[@]} +EOF else - agentapi server --type claude --term-width 67 --term-height 1190 -- claude "${ARGS[@]}" + # Build properly quoted command arguments + claude_args=$(printf '%q ' "${ARGS[@]}") + + # Write command to agent-command.sh without boundary + cat > "$MODULE_PATH/agent-command.sh" << EOF +#!/bin/bash +claude ${ARGS[@]} +EOF fi + + chmod +x "$MODULE_PATH/agent-command.sh" + printf "Agent command written to %s\n" "$MODULE_PATH/agent-command.sh" } validate_claude_installation From f93b366605855073ea254aeb8618b05772a7f689 Mon Sep 17 00:00:00 2001 From: 35C4n0r Date: Wed, 4 Feb 2026 14:56:25 +0530 Subject: [PATCH 03/32] fix: change agentapi source --- registry/coder/modules/claude-code/main.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/registry/coder/modules/claude-code/main.tf b/registry/coder/modules/claude-code/main.tf index 2a62a6632..464d45d24 100644 --- a/registry/coder/modules/claude-code/main.tf +++ b/registry/coder/modules/claude-code/main.tf @@ -359,8 +359,8 @@ locals { } module "agentapi" { - source = "registry.coder.com/coder/agentapi/coder" - version = "2.0.0" + source = "git::https://github.com/coder/registry.git//registry/coder/modules/agentapi?ref=35C4n0r/feat-agentapi-architecture-improv" + # version = "2.0.0" agent_id = var.agent_id web_app_slug = local.app_slug From 787ce3fe0cdf283c2b7ba9616494f7491b8b6d2d Mon Sep 17 00:00:00 2001 From: 35C4n0r Date: Wed, 4 Feb 2026 15:20:27 +0530 Subject: [PATCH 04/32] fix: add start.sh log to the agentapi-start.logs too. --- registry/coder/modules/agentapi/scripts/main.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/registry/coder/modules/agentapi/scripts/main.sh b/registry/coder/modules/agentapi/scripts/main.sh index 8087173b1..12a7e4332 100644 --- a/registry/coder/modules/agentapi/scripts/main.sh +++ b/registry/coder/modules/agentapi/scripts/main.sh @@ -112,7 +112,7 @@ export AGENTAPI_CHAT_BASE_PATH="${AGENTAPI_CHAT_BASE_PATH:-}" export AGENTAPI_ALLOWED_HOSTS="*" # Call agentapi-start.sh to write agent-command.sh -"$module_path/scripts/agentapi-start.sh" +"$module_path/scripts/agentapi-start.sh" &> "$module_path/agentapi-start.log" # Build agentapi server command arguments ARGS=( @@ -128,7 +128,7 @@ if [ -n "${AGENTAPI_INITIAL_PROMPT}" ]; then ARGS+=("--initial-prompt" "${AGENTAPI_INITIAL_PROMPT}") fi -# Start agentapi server with the agent-command.sh script -nohup agentapi "${ARGS[@]}" -- "$module_path/agent-command.sh" &> "$module_path/agentapi-start.log" & +# Start agentapi server with the agent-command.sh script (append logs to same file) +nohup agentapi "${ARGS[@]}" -- "$module_path/agent-command.sh" &>> "$module_path/agentapi-start.log" & "$module_path/scripts/agentapi-wait-for-start.sh" "${AGENTAPI_PORT}" From 6db604bd672a848f0b5c1e4a49a75171cb251e0c Mon Sep 17 00:00:00 2001 From: 35C4n0r Date: Wed, 4 Feb 2026 15:32:51 +0530 Subject: [PATCH 05/32] chore: bun fmt --- registry/coder/modules/agentapi/README.md | 2 +- registry/coder/modules/claude-code/main.tf | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/registry/coder/modules/agentapi/README.md b/registry/coder/modules/agentapi/README.md index bef0eb20f..c586249f7 100644 --- a/registry/coder/modules/agentapi/README.md +++ b/registry/coder/modules/agentapi/README.md @@ -88,7 +88,7 @@ For a complete example of how to use this module, see the [Goose module](https:/ The `start_script` should write the agent command to `$module_path/agent-command.sh` instead of starting the AgentAPI server directly. The module will start the server using: ```bash -agentapi server --type --term-width --term-height -- ./agent-command.sh +agentapi server --type ./agent-command.sh < type > --term-width < width > --term-height < height > -- ``` Example start script: diff --git a/registry/coder/modules/claude-code/main.tf b/registry/coder/modules/claude-code/main.tf index 464d45d24..504d7120c 100644 --- a/registry/coder/modules/claude-code/main.tf +++ b/registry/coder/modules/claude-code/main.tf @@ -359,7 +359,7 @@ locals { } module "agentapi" { - source = "git::https://github.com/coder/registry.git//registry/coder/modules/agentapi?ref=35C4n0r/feat-agentapi-architecture-improv" + source = "git::https://github.com/coder/registry.git//registry/coder/modules/agentapi?ref=35C4n0r/feat-agentapi-architecture-improv" # version = "2.0.0" agent_id = var.agent_id From 833f0ac34ae79caf9f18be263e3fa4c47a378b66 Mon Sep 17 00:00:00 2001 From: 35C4n0r Date: Wed, 4 Feb 2026 10:34:24 +0000 Subject: [PATCH 06/32] chore: fix tests --- registry/coder/modules/agentapi/main.test.ts | 1 + registry/coder/modules/agentapi/testdata/agentapi-start.sh | 2 ++ 2 files changed, 3 insertions(+) diff --git a/registry/coder/modules/agentapi/main.test.ts b/registry/coder/modules/agentapi/main.test.ts index 20b47b1a0..172cd1701 100644 --- a/registry/coder/modules/agentapi/main.test.ts +++ b/registry/coder/modules/agentapi/main.test.ts @@ -58,6 +58,7 @@ const setup = async (props?: SetupProps): Promise<{ id: string }> => { cli_app_display_name: "AgentAPI CLI", cli_app_slug: "agentapi-cli", agentapi_version: "latest", + agentapi_server_type: "claude", module_dir_name: moduleDirName, start_script: await loadTestFile(import.meta.dir, "agentapi-start.sh"), folder: projectDir, diff --git a/registry/coder/modules/agentapi/testdata/agentapi-start.sh b/registry/coder/modules/agentapi/testdata/agentapi-start.sh index 6c5cf7241..d6ae8538b 100644 --- a/registry/coder/modules/agentapi/testdata/agentapi-start.sh +++ b/registry/coder/modules/agentapi/testdata/agentapi-start.sh @@ -13,3 +13,5 @@ EOF chmod +x "$module_path/agent-command.sh" echo "Agent command written to $module_path/agent-command.sh" + +echo "Using AGENTAPI_CHAT_BASE_PATH: ${AGENTAPI_CHAT_BASE_PATH:-not set}" >> /home/coder/test-agentapi-start.log From 3d4d24bdfce4f8bf0946972c90a6f4fbfb8abaed Mon Sep 17 00:00:00 2001 From: 35C4n0r Date: Wed, 4 Feb 2026 14:16:28 +0000 Subject: [PATCH 07/32] chore: revert claude changes --- registry/coder/modules/claude-code/main.tf | 6 ++--- .../modules/claude-code/scripts/start.sh | 26 +++---------------- 2 files changed, 6 insertions(+), 26 deletions(-) diff --git a/registry/coder/modules/claude-code/main.tf b/registry/coder/modules/claude-code/main.tf index 74f9382ab..3ed4a0210 100644 --- a/registry/coder/modules/claude-code/main.tf +++ b/registry/coder/modules/claude-code/main.tf @@ -362,8 +362,8 @@ locals { } module "agentapi" { - source = "git::https://github.com/coder/registry.git//registry/coder/modules/agentapi?ref=35C4n0r/feat-agentapi-architecture-improv" - # version = "2.0.0" + source = "registry.coder.com/coder/agentapi/coder" + version = "2.0.0" agent_id = var.agent_id web_app_slug = local.app_slug @@ -377,7 +377,6 @@ module "agentapi" { cli_app_display_name = var.cli_app ? var.cli_app_display_name : null agentapi_subdomain = var.subdomain module_dir_name = local.module_dir_name - agentapi_server_type = "claude" install_agentapi = var.install_agentapi agentapi_version = var.agentapi_version pre_install_script = var.pre_install_script @@ -386,7 +385,6 @@ module "agentapi" { #!/bin/bash set -o errexit set -o pipefail - echo -n '${base64encode(local.start_script)}' | base64 -d > /tmp/start.sh chmod +x /tmp/start.sh diff --git a/registry/coder/modules/claude-code/scripts/start.sh b/registry/coder/modules/claude-code/scripts/start.sh index ec9b4be53..b20f38338 100644 --- a/registry/coder/modules/claude-code/scripts/start.sh +++ b/registry/coder/modules/claude-code/scripts/start.sh @@ -6,7 +6,6 @@ command_exists() { command -v "$1" > /dev/null 2>&1 } -MODULE_PATH="$HOME/.claude-module" ARG_RESUME_SESSION_ID=${ARG_RESUME_SESSION_ID:-} ARG_CONTINUE=${ARG_CONTINUE:-false} ARG_DANGEROUSLY_SKIP_PERMISSIONS=${ARG_DANGEROUSLY_SKIP_PERMISSIONS:-} @@ -217,7 +216,6 @@ function start_agentapi() { printf "Running claude code with args: %s\n" "$(printf '%q ' "${ARGS[@]}")" - # Write the agent command to agent-command.sh if [ "$ARG_ENABLE_BOUNDARY" = "true" ]; then install_boundary @@ -240,28 +238,12 @@ function start_agentapi() { BOUNDARY_CMD=("$CODER_NO_CAPS" "boundary") fi - # Build properly quoted command arguments - boundary_cmd=$(printf '%q ' "${BOUNDARY_CMD[@]}" "${BOUNDARY_ARGS[@]}") - claude_args=$(printf '%q ' "${ARGS[@]}") - - # Write command to agent-command.sh with boundary - cat > "$MODULE_PATH/agent-command.sh" << EOF -#!/bin/bash -${BOUNDARY_CMD[@]} -- claude ${ARGS[@]} -EOF + agentapi server --type claude --term-width 67 --term-height 1190 -- \ + "${BOUNDARY_CMD[@]}" "${BOUNDARY_ARGS[@]}" -- \ + claude "${ARGS[@]}" else - # Build properly quoted command arguments - claude_args=$(printf '%q ' "${ARGS[@]}") - - # Write command to agent-command.sh without boundary - cat > "$MODULE_PATH/agent-command.sh" << EOF -#!/bin/bash -claude ${ARGS[@]} -EOF + agentapi server --type claude --term-width 67 --term-height 1190 -- claude "${ARGS[@]}" fi - - chmod +x "$MODULE_PATH/agent-command.sh" - printf "Agent command written to %s\n" "$MODULE_PATH/agent-command.sh" } validate_claude_installation From ac1fb953fc0ad549b07a0c4a8b5cfdac7e793d4e Mon Sep 17 00:00:00 2001 From: 35C4n0r Date: Wed, 4 Feb 2026 14:29:15 +0000 Subject: [PATCH 08/32] chore: improve doc --- registry/coder/modules/agentapi/README.md | 24 +++++++---------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/registry/coder/modules/agentapi/README.md b/registry/coder/modules/agentapi/README.md index c586249f7..88338939b 100644 --- a/registry/coder/modules/agentapi/README.md +++ b/registry/coder/modules/agentapi/README.md @@ -32,6 +32,10 @@ module "agentapi" { pre_install_script = var.pre_install_script post_install_script = var.post_install_script start_script = local.start_script + agentapi_server_type = "claude" # required + agentapi_term_width = 67 # default: 67 + agentapi_term_height = 1190 # default: 1190 + agentapi_initial_prompt = "You are a helpful assistant." # optional install_script = <<-EOT #!/bin/bash set -o errexit @@ -63,22 +67,6 @@ module "agentapi" { } ``` -## AgentAPI server configuration - -You can configure the AgentAPI server type, terminal dimensions, and initial prompt: - -```tf -module "agentapi" { - # ... other config - agentapi_server_type = "claude" # required - agentapi_term_width = 67 # default: 67 - agentapi_term_height = 1190 # default: 1190 - agentapi_initial_prompt = "You are a helpful assistant." # optional -} -``` - -**Note:** The `agentapi_initial_prompt` is recommended only if the agent doesn't support initial prompt in interaction mode. - ## For module developers For a complete example of how to use this module, see the [Goose module](https://github.com/coder/registry/blob/main/registry/coder/modules/goose/main.tf). @@ -100,7 +88,9 @@ module_path="$HOME/.my-module" cat > "$module_path/agent-command.sh" << 'EOF' #!/bin/bash -exec my-agent-command +my-agent-command --my-agent-flags +# OR +boundary my-agent-command --my-agent-flags EOF chmod +x "$module_path/agent-command.sh" From 63c5e2cf7b781a26674138e394e140d183d239ba Mon Sep 17 00:00:00 2001 From: 35C4n0r Date: Wed, 4 Feb 2026 15:46:43 +0000 Subject: [PATCH 09/32] chore: improve doc --- registry/coder/modules/agentapi/README.md | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/registry/coder/modules/agentapi/README.md b/registry/coder/modules/agentapi/README.md index 88338939b..3870af747 100644 --- a/registry/coder/modules/agentapi/README.md +++ b/registry/coder/modules/agentapi/README.md @@ -73,24 +73,17 @@ For a complete example of how to use this module, see the [Goose module](https:/ ### Start script behavior -The `start_script` should write the agent command to `$module_path/agent-command.sh` instead of starting the AgentAPI server directly. The module will start the server using: - -```bash -agentapi server --type ./agent-command.sh < type > --term-width < width > --term-height < height > -- -``` +The `start_script` should write the agent command to `$module_path/agent-command.sh` instead of starting the AgentAPI server directly. Example start script: ```bash #!/bin/bash -# Hardcode your module's path module_path="$HOME/.my-module" -cat > "$module_path/agent-command.sh" << 'EOF' +cat > "$module_path/agent-command.sh" << EOF #!/bin/bash my-agent-command --my-agent-flags -# OR -boundary my-agent-command --my-agent-flags EOF chmod +x "$module_path/agent-command.sh" From a3321811c1895d8a094e78e2b969075de9d7ec57 Mon Sep 17 00:00:00 2001 From: 35C4n0r Date: Wed, 4 Feb 2026 15:48:22 +0000 Subject: [PATCH 10/32] chore: remove comments --- registry/coder/modules/agentapi/scripts/main.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/registry/coder/modules/agentapi/scripts/main.sh b/registry/coder/modules/agentapi/scripts/main.sh index 12a7e4332..5ff346fe5 100644 --- a/registry/coder/modules/agentapi/scripts/main.sh +++ b/registry/coder/modules/agentapi/scripts/main.sh @@ -122,13 +122,11 @@ ARGS=( "--term-width" "${AGENTAPI_TERM_WIDTH}" "--term-height" "${AGENTAPI_TERM_HEIGHT}" ) - -# Add optional initial prompt if [ -n "${AGENTAPI_INITIAL_PROMPT}" ]; then ARGS+=("--initial-prompt" "${AGENTAPI_INITIAL_PROMPT}") fi -# Start agentapi server with the agent-command.sh script (append logs to same file) +# Start agentapi server with the agent-command.sh script nohup agentapi "${ARGS[@]}" -- "$module_path/agent-command.sh" &>> "$module_path/agentapi-start.log" & "$module_path/scripts/agentapi-wait-for-start.sh" "${AGENTAPI_PORT}" From 80f47d09ddfad9dd755735876f0697bb2f399266 Mon Sep 17 00:00:00 2001 From: 35C4n0r Date: Wed, 4 Feb 2026 16:18:09 +0000 Subject: [PATCH 11/32] chore: bump module versions (major) --- registry/coder/modules/agentapi/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/registry/coder/modules/agentapi/README.md b/registry/coder/modules/agentapi/README.md index 3870af747..340845a93 100644 --- a/registry/coder/modules/agentapi/README.md +++ b/registry/coder/modules/agentapi/README.md @@ -16,7 +16,7 @@ The AgentAPI module is a building block for modules that need to run an AgentAPI ```tf module "agentapi" { source = "registry.coder.com/coder/agentapi/coder" - version = "2.1.0" + version = "3.0.0" agent_id = var.agent_id web_app_slug = local.app_slug From 4459d3952980c516f4d5de9238f25bb2a6d967ab Mon Sep 17 00:00:00 2001 From: 35C4n0r Date: Thu, 5 Feb 2026 16:17:12 +0000 Subject: [PATCH 12/32] feat: remove the responsibility of running install and start script from agentapi module --- registry/coder/modules/agentapi/README.md | 44 +++++----------- registry/coder/modules/agentapi/main.test.ts | 51 ++++++------------- registry/coder/modules/agentapi/main.tf | 33 +----------- .../coder/modules/agentapi/scripts/main.sh | 27 ---------- .../agentapi/testdata/agentapi-mock.js | 2 +- .../agentapi/testdata/agentapi-start.sh | 17 ------- 6 files changed, 30 insertions(+), 144 deletions(-) delete mode 100644 registry/coder/modules/agentapi/testdata/agentapi-start.sh diff --git a/registry/coder/modules/agentapi/README.md b/registry/coder/modules/agentapi/README.md index 340845a93..117e3a4d6 100644 --- a/registry/coder/modules/agentapi/README.md +++ b/registry/coder/modules/agentapi/README.md @@ -16,41 +16,21 @@ The AgentAPI module is a building block for modules that need to run an AgentAPI ```tf module "agentapi" { source = "registry.coder.com/coder/agentapi/coder" - version = "3.0.0" + version = "4.0.0" agent_id = var.agent_id web_app_slug = local.app_slug web_app_order = var.order web_app_group = var.group web_app_icon = var.icon - web_app_display_name = "Goose" - cli_app_slug = "goose-cli" - cli_app_display_name = "Goose CLI" + web_app_display_name = "ClaudeCode" + cli_app_slug = "claude-cli" + cli_app_display_name = "Claude CLI" module_dir_name = local.module_dir_name - agentapi_server_type = "claude" install_agentapi = var.install_agentapi - pre_install_script = var.pre_install_script - post_install_script = var.post_install_script - start_script = local.start_script - agentapi_server_type = "claude" # required - agentapi_term_width = 67 # default: 67 - agentapi_term_height = 1190 # default: 1190 - agentapi_initial_prompt = "You are a helpful assistant." # optional - install_script = <<-EOT - #!/bin/bash - set -o errexit - set -o pipefail - - echo -n '${base64encode(local.install_script)}' | base64 -d > /tmp/install.sh - chmod +x /tmp/install.sh - - ARG_PROVIDER='${var.goose_provider}' \ - ARG_MODEL='${var.goose_model}' \ - ARG_GOOSE_CONFIG="$(echo -n '${base64encode(local.combined_extensions)}' | base64 -d)" \ - ARG_INSTALL='${var.install_goose}' \ - ARG_GOOSE_VERSION='${var.goose_version}' \ - /tmp/install.sh - EOT + agentapi_server_type = "claude" + agentapi_term_width = 67 + agentapi_term_height = 1190 } ``` @@ -71,11 +51,11 @@ module "agentapi" { For a complete example of how to use this module, see the [Goose module](https://github.com/coder/registry/blob/main/registry/coder/modules/goose/main.tf). -### Start script behavior +### agent-command.sh -The `start_script` should write the agent command to `$module_path/agent-command.sh` instead of starting the AgentAPI server directly. +The calling module must create an executable script at `$HOME/{module_dir_name}/agent-command.sh` before this module's script runs. This script should contain the command to start your AI agent. -Example start script: +Example: ```bash #!/bin/bash @@ -85,6 +65,6 @@ cat > "$module_path/agent-command.sh" << EOF #!/bin/bash my-agent-command --my-agent-flags EOF - -chmod +x "$module_path/agent-command.sh" ``` + +The AgentAPI module will run this script with the agentapi server. diff --git a/registry/coder/modules/agentapi/main.test.ts b/registry/coder/modules/agentapi/main.test.ts index 172cd1701..d869d583f 100644 --- a/registry/coder/modules/agentapi/main.test.ts +++ b/registry/coder/modules/agentapi/main.test.ts @@ -60,7 +60,6 @@ const setup = async (props?: SetupProps): Promise<{ id: string }> => { agentapi_version: "latest", agentapi_server_type: "claude", module_dir_name: moduleDirName, - start_script: await loadTestFile(import.meta.dir, "agentapi-start.sh"), folder: projectDir, ...props?.moduleVariables, }, @@ -69,11 +68,23 @@ const setup = async (props?: SetupProps): Promise<{ id: string }> => { skipAgentAPIMock: props?.skipAgentAPIMock, moduleDir: import.meta.dir, }); + // Create the ai agent mock binary await writeExecutable({ containerId: id, filePath: "/usr/bin/aiagent", content: await loadTestFile(import.meta.dir, "ai-agent-mock.js"), }); + // Create the agent-command.sh script that the module expects + await execContainer(id, [ + "bash", + "-c", + `mkdir -p /home/coder/${moduleDirName}`, + ]); + await writeExecutable({ + containerId: id, + filePath: `/home/coder/${moduleDirName}/agent-command.sh`, + content: "#!/bin/bash\nexec aiagent", + }); return { id }; }; @@ -105,36 +116,6 @@ describe("agentapi", async () => { await expectAgentAPIStarted(id, 3827); }); - test("pre-post-install-scripts", async () => { - const { id } = await setup({ - moduleVariables: { - pre_install_script: `#!/bin/bash\necho "pre-install"`, - install_script: `#!/bin/bash\necho "install"`, - post_install_script: `#!/bin/bash\necho "post-install"`, - }, - }); - - await execModuleScript(id); - await expectAgentAPIStarted(id); - - const preInstallLog = await readFileContainer( - id, - `/home/coder/${moduleDirName}/pre_install.log`, - ); - const installLog = await readFileContainer( - id, - `/home/coder/${moduleDirName}/install.log`, - ); - const postInstallLog = await readFileContainer( - id, - `/home/coder/${moduleDirName}/post_install.log`, - ); - - expect(preInstallLog).toContain("pre-install"); - expect(installLog).toContain("install"); - expect(postInstallLog).toContain("post-install"); - }); - test("install-agentapi", async () => { const { id } = await setup({ skipAgentAPIMock: true }); @@ -161,12 +142,12 @@ describe("agentapi", async () => { expect(respModuleScript.exitCode).toBe(0); await expectAgentAPIStarted(id); - const agentApiStartLog = await readFileContainer( + const agentApiMockLog = await readFileContainer( id, - "/home/coder/test-agentapi-start.log", + "/home/coder/agentapi-mock.log", ); - expect(agentApiStartLog).toContain( - "Using AGENTAPI_CHAT_BASE_PATH: /@default/default.foo/apps/agentapi-web/chat", + expect(agentApiMockLog).toContain( + "AGENTAPI_CHAT_BASE_PATH: /@default/default.foo/apps/agentapi-web/chat", ); }); diff --git a/registry/coder/modules/agentapi/main.tf b/registry/coder/modules/agentapi/main.tf index e3e2e9a55..df1f66229 100644 --- a/registry/coder/modules/agentapi/main.tf +++ b/registry/coder/modules/agentapi/main.tf @@ -87,29 +87,6 @@ variable "cli_app_slug" { description = "The slug of the CLI workspace app." } -variable "pre_install_script" { - type = string - description = "Custom script to run before installing the agent used by AgentAPI." - default = null -} - -variable "install_script" { - type = string - description = "Script to install the agent used by AgentAPI." - default = "" -} - -variable "post_install_script" { - type = string - description = "Custom script to run after installing the agent used by AgentAPI." - default = null -} - -variable "start_script" { - type = string - description = "Script that starts AgentAPI." -} - variable "install_agentapi" { type = bool description = "Whether to install AgentAPI." @@ -191,11 +168,7 @@ variable "module_dir_name" { locals { # we always trim the slash for consistency workdir = trimsuffix(var.folder, "/") - encoded_pre_install_script = var.pre_install_script != null ? base64encode(var.pre_install_script) : "" - encoded_install_script = var.install_script != null ? base64encode(var.install_script) : "" - encoded_post_install_script = var.post_install_script != null ? base64encode(var.post_install_script) : "" encoded_initial_prompt = var.agentapi_initial_prompt != null ? base64encode(var.agentapi_initial_prompt) : "" - agentapi_start_script_b64 = base64encode(var.start_script) agentapi_wait_for_start_script_b64 = base64encode(file("${path.module}/scripts/agentapi-wait-for-start.sh")) // Chat base path is only set if not using a subdomain. // NOTE: @@ -210,7 +183,7 @@ locals { resource "coder_script" "agentapi" { agent_id = var.agent_id - display_name = "Install and start AgentAPI" + display_name = "Start AgentAPI" icon = var.web_app_icon script = <<-EOT #!/bin/bash @@ -222,13 +195,9 @@ resource "coder_script" "agentapi" { ARG_MODULE_DIR_NAME='${var.module_dir_name}' \ ARG_WORKDIR="$(echo -n '${base64encode(local.workdir)}' | base64 -d)" \ - ARG_PRE_INSTALL_SCRIPT="$(echo -n '${local.encoded_pre_install_script}' | base64 -d)" \ - ARG_INSTALL_SCRIPT="$(echo -n '${local.encoded_install_script}' | base64 -d)" \ ARG_INSTALL_AGENTAPI='${var.install_agentapi}' \ ARG_AGENTAPI_VERSION='${var.agentapi_version}' \ - ARG_START_SCRIPT="$(echo -n '${local.agentapi_start_script_b64}' | base64 -d)" \ ARG_WAIT_FOR_START_SCRIPT="$(echo -n '${local.agentapi_wait_for_start_script_b64}' | base64 -d)" \ - ARG_POST_INSTALL_SCRIPT="$(echo -n '${local.encoded_post_install_script}' | base64 -d)" \ ARG_AGENTAPI_PORT='${var.agentapi_port}' \ ARG_AGENTAPI_SERVER_TYPE='${var.agentapi_server_type}' \ ARG_AGENTAPI_TERM_WIDTH='${var.agentapi_term_width}' \ diff --git a/registry/coder/modules/agentapi/scripts/main.sh b/registry/coder/modules/agentapi/scripts/main.sh index 5ff346fe5..87d9147bc 100644 --- a/registry/coder/modules/agentapi/scripts/main.sh +++ b/registry/coder/modules/agentapi/scripts/main.sh @@ -5,13 +5,9 @@ set -x set -o nounset MODULE_DIR_NAME="$ARG_MODULE_DIR_NAME" WORKDIR="$ARG_WORKDIR" -PRE_INSTALL_SCRIPT="$ARG_PRE_INSTALL_SCRIPT" -INSTALL_SCRIPT="$ARG_INSTALL_SCRIPT" INSTALL_AGENTAPI="$ARG_INSTALL_AGENTAPI" AGENTAPI_VERSION="$ARG_AGENTAPI_VERSION" -START_SCRIPT="$ARG_START_SCRIPT" WAIT_FOR_START_SCRIPT="$ARG_WAIT_FOR_START_SCRIPT" -POST_INSTALL_SCRIPT="$ARG_POST_INSTALL_SCRIPT" AGENTAPI_PORT="$ARG_AGENTAPI_PORT" AGENTAPI_SERVER_TYPE="$ARG_AGENTAPI_SERVER_TYPE" AGENTAPI_TERM_WIDTH="$ARG_AGENTAPI_TERM_WIDTH" @@ -42,17 +38,6 @@ if [ ! -d "${WORKDIR}" ]; then mkdir -p "${WORKDIR}" echo "Folder created successfully." fi -if [ -n "${PRE_INSTALL_SCRIPT}" ]; then - echo "Running pre-install script..." - echo -n "${PRE_INSTALL_SCRIPT}" > "$module_path/pre_install.sh" - chmod +x "$module_path/pre_install.sh" - "$module_path/pre_install.sh" 2>&1 | tee "$module_path/pre_install.log" -fi - -echo "Running install script..." -echo -n "${INSTALL_SCRIPT}" > "$module_path/install.sh" -chmod +x "$module_path/install.sh" -"$module_path/install.sh" 2>&1 | tee "$module_path/install.log" # Install AgentAPI if enabled if [ "${INSTALL_AGENTAPI}" = "true" ]; then @@ -90,18 +75,9 @@ if ! command_exists agentapi; then exit 1 fi -echo -n "${START_SCRIPT}" > "$module_path/scripts/agentapi-start.sh" echo -n "${WAIT_FOR_START_SCRIPT}" > "$module_path/scripts/agentapi-wait-for-start.sh" -chmod +x "$module_path/scripts/agentapi-start.sh" chmod +x "$module_path/scripts/agentapi-wait-for-start.sh" -if [ -n "${POST_INSTALL_SCRIPT}" ]; then - echo "Running post-install script..." - echo -n "${POST_INSTALL_SCRIPT}" > "$module_path/post_install.sh" - chmod +x "$module_path/post_install.sh" - "$module_path/post_install.sh" 2>&1 | tee "$module_path/post_install.log" -fi - export LANG=en_US.UTF-8 export LC_ALL=en_US.UTF-8 @@ -111,9 +87,6 @@ export AGENTAPI_CHAT_BASE_PATH="${AGENTAPI_CHAT_BASE_PATH:-}" # Disable host header check since AgentAPI is proxied by Coder (which does its own validation) export AGENTAPI_ALLOWED_HOSTS="*" -# Call agentapi-start.sh to write agent-command.sh -"$module_path/scripts/agentapi-start.sh" &> "$module_path/agentapi-start.log" - # Build agentapi server command arguments ARGS=( "server" diff --git a/registry/coder/modules/agentapi/testdata/agentapi-mock.js b/registry/coder/modules/agentapi/testdata/agentapi-mock.js index 72db716a3..f81d33177 100644 --- a/registry/coder/modules/agentapi/testdata/agentapi-mock.js +++ b/registry/coder/modules/agentapi/testdata/agentapi-mock.js @@ -9,7 +9,7 @@ const port = portIdx ? args[portIdx] : 3284; console.log(`starting server on port ${port}`); fs.writeFileSync( "/home/coder/agentapi-mock.log", - `AGENTAPI_ALLOWED_HOSTS: ${process.env.AGENTAPI_ALLOWED_HOSTS}`, + `AGENTAPI_ALLOWED_HOSTS: ${process.env.AGENTAPI_ALLOWED_HOSTS}\nAGENTAPI_CHAT_BASE_PATH: ${process.env.AGENTAPI_CHAT_BASE_PATH || "not set"}`, ); http diff --git a/registry/coder/modules/agentapi/testdata/agentapi-start.sh b/registry/coder/modules/agentapi/testdata/agentapi-start.sh deleted file mode 100644 index d6ae8538b..000000000 --- a/registry/coder/modules/agentapi/testdata/agentapi-start.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash -set -o errexit -set -o pipefail - -module_path="$HOME/.agentapi-module" - -# Write the agent command to agent-command.sh -cat > "$module_path/agent-command.sh" << 'EOF' -#!/bin/bash -exec bash -c aiagent -EOF - -chmod +x "$module_path/agent-command.sh" - -echo "Agent command written to $module_path/agent-command.sh" - -echo "Using AGENTAPI_CHAT_BASE_PATH: ${AGENTAPI_CHAT_BASE_PATH:-not set}" >> /home/coder/test-agentapi-start.log From 15ca0aa058d4179b6d7508c809ea3f43ee687400 Mon Sep 17 00:00:00 2001 From: 35C4n0r Date: Fri, 6 Feb 2026 18:43:13 +0530 Subject: [PATCH 13/32] feat: sync main.sh --- registry/coder/modules/agentapi/main.tf | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/registry/coder/modules/agentapi/main.tf b/registry/coder/modules/agentapi/main.tf index df1f66229..66aa35209 100644 --- a/registry/coder/modules/agentapi/main.tf +++ b/registry/coder/modules/agentapi/main.tf @@ -179,6 +179,9 @@ locals { agentapi_chat_base_path = var.agentapi_subdomain ? "" : "/@${data.coder_workspace_owner.me.name}/${data.coder_workspace.me.name}.${var.agent_id}/apps/${var.web_app_slug}/chat" main_script = file("${path.module}/scripts/main.sh") shutdown_script = file("${path.module}/scripts/agentapi-shutdown.sh") + + start_script_name = "${var.agentapi_server_type}-start_script" + agentapi_main_script_name = "${var.agentapi_server_type}-main_script" } resource "coder_script" "agentapi" { @@ -190,6 +193,8 @@ resource "coder_script" "agentapi" { set -o errexit set -o pipefail + coder exp sync wait ${local.agentapi_main_script_name} ${local.start_script_name} + echo -n '${base64encode(local.main_script)}' | base64 -d > /tmp/main.sh chmod +x /tmp/main.sh From c6307226a7b85c750a1299c947fb202a2748818e Mon Sep 17 00:00:00 2001 From: 35C4n0r Date: Fri, 6 Feb 2026 19:14:53 +0530 Subject: [PATCH 14/32] fix: fix typo --- registry/coder/modules/agentapi/main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/registry/coder/modules/agentapi/main.tf b/registry/coder/modules/agentapi/main.tf index 66aa35209..ffbc61c92 100644 --- a/registry/coder/modules/agentapi/main.tf +++ b/registry/coder/modules/agentapi/main.tf @@ -193,7 +193,7 @@ resource "coder_script" "agentapi" { set -o errexit set -o pipefail - coder exp sync wait ${local.agentapi_main_script_name} ${local.start_script_name} + coder exp sync want ${local.agentapi_main_script_name} ${local.start_script_name} echo -n '${base64encode(local.main_script)}' | base64 -d > /tmp/main.sh chmod +x /tmp/main.sh From 5edf4a9c00e470f9d69706cceab7737a41a1a55b Mon Sep 17 00:00:00 2001 From: 35C4n0r Date: Fri, 6 Feb 2026 19:20:10 +0530 Subject: [PATCH 15/32] fix: complete commands --- registry/coder/modules/agentapi/main.tf | 2 ++ 1 file changed, 2 insertions(+) diff --git a/registry/coder/modules/agentapi/main.tf b/registry/coder/modules/agentapi/main.tf index ffbc61c92..1d1778c52 100644 --- a/registry/coder/modules/agentapi/main.tf +++ b/registry/coder/modules/agentapi/main.tf @@ -193,7 +193,9 @@ resource "coder_script" "agentapi" { set -o errexit set -o pipefail + trap 'coder exp sync complete ${local.start_script_name}' EXIT coder exp sync want ${local.agentapi_main_script_name} ${local.start_script_name} + coder exp sync start ${local.start_script_name} echo -n '${base64encode(local.main_script)}' | base64 -d > /tmp/main.sh chmod +x /tmp/main.sh From 85e7da3c41ef3fa0e922bcbbfa95debb39995a1a Mon Sep 17 00:00:00 2001 From: 35C4n0r Date: Fri, 6 Feb 2026 19:24:10 +0530 Subject: [PATCH 16/32] fix: complete commands --- registry/coder/modules/agentapi/main.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/registry/coder/modules/agentapi/main.tf b/registry/coder/modules/agentapi/main.tf index 1d1778c52..29766ad13 100644 --- a/registry/coder/modules/agentapi/main.tf +++ b/registry/coder/modules/agentapi/main.tf @@ -193,9 +193,9 @@ resource "coder_script" "agentapi" { set -o errexit set -o pipefail - trap 'coder exp sync complete ${local.start_script_name}' EXIT + trap 'coder exp sync complete ${local.agentapi_main_script_name}' EXIT coder exp sync want ${local.agentapi_main_script_name} ${local.start_script_name} - coder exp sync start ${local.start_script_name} + coder exp sync start ${local.agentapi_main_script_name} echo -n '${base64encode(local.main_script)}' | base64 -d > /tmp/main.sh chmod +x /tmp/main.sh From 03ac608e1f9f792ead79327cf07ea6812443ae04 Mon Sep 17 00:00:00 2001 From: 35C4n0r Date: Fri, 6 Feb 2026 21:34:25 +0530 Subject: [PATCH 17/32] feat: overwrite agentapi logs instead of appending them --- registry/coder/modules/agentapi/main.tf | 2 +- registry/coder/modules/agentapi/scripts/main.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/registry/coder/modules/agentapi/main.tf b/registry/coder/modules/agentapi/main.tf index 29766ad13..7eaf909fa 100644 --- a/registry/coder/modules/agentapi/main.tf +++ b/registry/coder/modules/agentapi/main.tf @@ -180,7 +180,7 @@ locals { main_script = file("${path.module}/scripts/main.sh") shutdown_script = file("${path.module}/scripts/agentapi-shutdown.sh") - start_script_name = "${var.agentapi_server_type}-start_script" + start_script_name = "${var.agentapi_server_type}-start_script" agentapi_main_script_name = "${var.agentapi_server_type}-main_script" } diff --git a/registry/coder/modules/agentapi/scripts/main.sh b/registry/coder/modules/agentapi/scripts/main.sh index 87d9147bc..e4c1abf7e 100644 --- a/registry/coder/modules/agentapi/scripts/main.sh +++ b/registry/coder/modules/agentapi/scripts/main.sh @@ -100,6 +100,6 @@ if [ -n "${AGENTAPI_INITIAL_PROMPT}" ]; then fi # Start agentapi server with the agent-command.sh script -nohup agentapi "${ARGS[@]}" -- "$module_path/agent-command.sh" &>> "$module_path/agentapi-start.log" & +nohup agentapi "${ARGS[@]}" -- "$module_path/agent-command.sh" &> "$module_path/agentapi-start.log" & "$module_path/scripts/agentapi-wait-for-start.sh" "${AGENTAPI_PORT}" From df2d72f6083ffe69ed0ebfc5212238ec363268da Mon Sep 17 00:00:00 2001 From: 35C4n0r Date: Fri, 6 Feb 2026 17:17:57 +0000 Subject: [PATCH 18/32] feat: add mock coder since we now depend on coder command to sync scripts --- registry/coder/modules/agentapi/test-util.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/registry/coder/modules/agentapi/test-util.ts b/registry/coder/modules/agentapi/test-util.ts index 85d1bddd8..d9afb3367 100644 --- a/registry/coder/modules/agentapi/test-util.ts +++ b/registry/coder/modules/agentapi/test-util.ts @@ -115,6 +115,13 @@ export const setup = async ( }); props.registerCleanup(cleanup); await execContainer(id, ["bash", "-c", `mkdir -p '${projectDir}'`]); + // Add a mock coder CLI so that `coder exp sync` commands in the + // startup script succeed inside the test container. + await writeExecutable({ + containerId: id, + filePath: "/usr/bin/coder", + content: "#!/bin/bash\nexit 0", + }); if (!props?.skipAgentAPIMock) { await writeExecutable({ containerId: id, From 65c40ed0ad28a77962dac8e98be112d11832a08c Mon Sep 17 00:00:00 2001 From: 35C4n0r Date: Fri, 6 Feb 2026 17:32:21 +0000 Subject: [PATCH 19/32] feat: rector agentapi_server_type to agent_name --- registry/coder/modules/agentapi/main.tf | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/registry/coder/modules/agentapi/main.tf b/registry/coder/modules/agentapi/main.tf index 7eaf909fa..4bccbb033 100644 --- a/registry/coder/modules/agentapi/main.tf +++ b/registry/coder/modules/agentapi/main.tf @@ -105,9 +105,9 @@ variable "agentapi_port" { default = 3284 } -variable "agentapi_server_type" { +variable "agent_name" { type = string - description = "The server type for AgentAPI, passed using --agent flag." + description = "The agent's name. This is used as server type for AgentAPI, passed using --agent flag." } variable "agentapi_term_width" { @@ -206,7 +206,7 @@ resource "coder_script" "agentapi" { ARG_AGENTAPI_VERSION='${var.agentapi_version}' \ ARG_WAIT_FOR_START_SCRIPT="$(echo -n '${local.agentapi_wait_for_start_script_b64}' | base64 -d)" \ ARG_AGENTAPI_PORT='${var.agentapi_port}' \ - ARG_AGENTAPI_SERVER_TYPE='${var.agentapi_server_type}' \ + ARG_AGENTAPI_SERVER_TYPE='${var.agent_name}' \ ARG_AGENTAPI_TERM_WIDTH='${var.agentapi_term_width}' \ ARG_AGENTAPI_TERM_HEIGHT='${var.agentapi_term_height}' \ ARG_AGENTAPI_INITIAL_PROMPT="$(echo -n '${local.encoded_initial_prompt}' | base64 -d)" \ From c07954592b92a81ac0a4e6ed66bc6cb18fbf6a1a Mon Sep 17 00:00:00 2001 From: 35C4n0r Date: Fri, 6 Feb 2026 17:39:58 +0000 Subject: [PATCH 20/32] chore: fix tests --- registry/coder/modules/agentapi/main.test.ts | 2 +- registry/coder/modules/agentapi/main.tf | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/registry/coder/modules/agentapi/main.test.ts b/registry/coder/modules/agentapi/main.test.ts index d869d583f..b3db16874 100644 --- a/registry/coder/modules/agentapi/main.test.ts +++ b/registry/coder/modules/agentapi/main.test.ts @@ -58,7 +58,7 @@ const setup = async (props?: SetupProps): Promise<{ id: string }> => { cli_app_display_name: "AgentAPI CLI", cli_app_slug: "agentapi-cli", agentapi_version: "latest", - agentapi_server_type: "claude", + agent_name: "claude", module_dir_name: moduleDirName, folder: projectDir, ...props?.moduleVariables, diff --git a/registry/coder/modules/agentapi/main.tf b/registry/coder/modules/agentapi/main.tf index 4bccbb033..877de2a28 100644 --- a/registry/coder/modules/agentapi/main.tf +++ b/registry/coder/modules/agentapi/main.tf @@ -180,8 +180,8 @@ locals { main_script = file("${path.module}/scripts/main.sh") shutdown_script = file("${path.module}/scripts/agentapi-shutdown.sh") - start_script_name = "${var.agentapi_server_type}-start_script" - agentapi_main_script_name = "${var.agentapi_server_type}-main_script" + start_script_name = "${var.agent_name}-start_script" + agentapi_main_script_name = "${var.agent_name}-main_script" } resource "coder_script" "agentapi" { From 4bbc6d929e0a8090771750838d1eedea3e4fe222 Mon Sep 17 00:00:00 2001 From: 35C4n0r Date: Fri, 6 Feb 2026 23:37:59 +0530 Subject: [PATCH 21/32] feat: move install and start script logic to agentapi via agent-helper --- registry/coder/modules/agentapi/main.test.ts | 69 +++++++++++++++++++- registry/coder/modules/agentapi/main.tf | 53 ++++++++++++++- 2 files changed, 119 insertions(+), 3 deletions(-) diff --git a/registry/coder/modules/agentapi/main.test.ts b/registry/coder/modules/agentapi/main.test.ts index b3db16874..e1efbbfb7 100644 --- a/registry/coder/modules/agentapi/main.test.ts +++ b/registry/coder/modules/agentapi/main.test.ts @@ -6,7 +6,12 @@ import { setDefaultTimeout, beforeAll, } from "bun:test"; -import { execContainer, readFileContainer, runTerraformInit } from "~test"; +import { + execContainer, + readFileContainer, + runTerraformInit, + runTerraformApply, +} from "~test"; import { loadTestFile, writeExecutable, @@ -61,6 +66,10 @@ const setup = async (props?: SetupProps): Promise<{ id: string }> => { agent_name: "claude", module_dir_name: moduleDirName, folder: projectDir, + pre_install_script: "echo 'Pre-install'", + install_script: "echo 'Install'", + post_install_script: "echo 'Post-install'", + start_script: "echo 'Start'", ...props?.moduleVariables, }, registerCleanup, @@ -240,6 +249,64 @@ describe("agentapi", async () => { expect(agentApiStartLog).toContain("AGENTAPI_ALLOWED_HOSTS: *"); }); + test("enable-agentapi-false", async () => { + // Test that when enable_agentapi is false: + // 1. AgentAPI web app is not created + // 2. AgentAPI is not started + // 3. CLI app still works and uses agent-command.sh + const { id } = await setup({ + moduleVariables: { + enable_agentapi: "false", + cli_app: "true", + }, + }); + + const respModuleScript = await execModuleScript(id); + expect(respModuleScript.exitCode).toBe(0); + + // Verify agentapi is not running on the default port + const respCheck = await execContainer(id, [ + "bash", + "-c", + "curl -fs -o /dev/null http://localhost:3284/status || echo 'not running'", + ]); + expect(respCheck.stdout).toContain("not running"); + + // Verify agent-command.sh script exists and is executable + const respAgentCommand = await execContainer(id, [ + "bash", + "-c", + `test -x /home/coder/${moduleDirName}/agent-command.sh && echo 'exists'`, + ]); + expect(respAgentCommand.stdout).toContain("exists"); + }); + + test("task-app-id-output", async () => { + // Test that task_app_id output is null when enable_agentapi is false + const projectDir = "/home/coder/project"; + const state = await runTerraformApply(import.meta.dir, { + agent_id: "test-agent", + experiment_report_tasks: "true", + install_agentapi: "false", + web_app_display_name: "AgentAPI Web", + web_app_slug: "agentapi-web", + web_app_icon: "/icon/coder.svg", + cli_app_display_name: "AgentAPI CLI", + cli_app_slug: "agentapi-cli", + agentapi_version: "latest", + agent_name: "claude", + module_dir_name: moduleDirName, + folder: projectDir, + pre_install_script: "echo 'Pre-install'", + install_script: "echo 'Install'", + post_install_script: "echo 'Post-install'", + start_script: "echo 'Start'", + enable_agentapi: "false", + }); + + expect(state.outputs.task_app_id.value).toBeNull(); + }); + describe("shutdown script", async () => { const setupMocks = async ( containerId: string, diff --git a/registry/coder/modules/agentapi/main.tf b/registry/coder/modules/agentapi/main.tf index 877de2a28..e587a581c 100644 --- a/registry/coder/modules/agentapi/main.tf +++ b/registry/coder/modules/agentapi/main.tf @@ -87,6 +87,35 @@ variable "cli_app_slug" { description = "The slug of the CLI workspace app." } +variable "pre_install_script" { + type = string + description = "Custom script to run before installing the agent used by AgentAPI." + default = null +} + +variable "install_script" { + type = string + description = "Script to install the agent used by AgentAPI." + default = "" +} + +variable "post_install_script" { + type = string + description = "Custom script to run after installing the agent used by AgentAPI." + default = null +} + +variable "start_script" { + type = string + description = "Script that starts AgentAPI." +} + +variable "enable_agentapi" { + type = bool + description = "Whether to enable AgentAPI. If false, AgentAPI will not be installed or started, and the web app will not be created." + default = true +} + variable "install_agentapi" { type = bool description = "Whether to install AgentAPI." @@ -182,9 +211,23 @@ locals { start_script_name = "${var.agent_name}-start_script" agentapi_main_script_name = "${var.agent_name}-main_script" + + module_dir_path = "$HOME/${var.module_dir_name}" +} + +module "agent-helper" { + source = "git::https://github.com/coder/registry.git//registry/coder/modules/agent-helper?ref=35C4n0r/feat-agent-helper-module" + agent_id = var.agent_id + agent_name = var.agent_name + module_dir_name = var.module_dir_name + pre_install_script = var.pre_install_script + install_script = var.install_script + post_install_script = var.post_install_script + start_script = var.start_script } resource "coder_script" "agentapi" { + count = var.enable_agentapi ? 1 : 0 agent_id = var.agent_id display_name = "Start AgentAPI" icon = var.web_app_icon @@ -219,6 +262,7 @@ resource "coder_script" "agentapi" { } resource "coder_script" "agentapi_shutdown" { + count = var.enable_agentapi ? 1 : 0 agent_id = var.agent_id display_name = "AgentAPI Shutdown" icon = var.web_app_icon @@ -238,6 +282,7 @@ resource "coder_script" "agentapi_shutdown" { } resource "coder_app" "agentapi_web" { + count = var.enable_agentapi ? 1 : 0 slug = var.web_app_slug display_name = var.web_app_display_name agent_id = var.agent_id @@ -253,7 +298,7 @@ resource "coder_app" "agentapi_web" { } } -resource "coder_app" "agentapi_cli" { +resource "coder_app" "agent_cli" { count = var.cli_app ? 1 : 0 slug = var.cli_app_slug @@ -266,7 +311,11 @@ resource "coder_app" "agentapi_cli" { export LANG=en_US.UTF-8 export LC_ALL=en_US.UTF-8 + %{if var.enable_agentapi~} agentapi attach + %{else} + ${local.module_dir_path}/agent-command.sh + %{endif} EOT icon = var.cli_app_icon order = var.cli_app_order @@ -274,5 +323,5 @@ resource "coder_app" "agentapi_cli" { } output "task_app_id" { - value = coder_app.agentapi_web.id + value = var.enable_agentapi ? coder_app.agentapi_web[0].id : null } From 32fa6cb194ab3973ed6034bee71b3ccc99079b53 Mon Sep 17 00:00:00 2001 From: 35C4n0r Date: Sat, 7 Feb 2026 08:52:29 +0530 Subject: [PATCH 22/32] debug --- registry/coder/modules/agentapi/main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/registry/coder/modules/agentapi/main.tf b/registry/coder/modules/agentapi/main.tf index e587a581c..d0050b6a8 100644 --- a/registry/coder/modules/agentapi/main.tf +++ b/registry/coder/modules/agentapi/main.tf @@ -258,7 +258,7 @@ resource "coder_script" "agentapi" { ARG_TASK_LOG_SNAPSHOT='${var.task_log_snapshot}' \ /tmp/main.sh EOT - run_on_start = true + run_on_start = false } resource "coder_script" "agentapi_shutdown" { From 253f95ff5bdff5c3881cc715b5aca34a14f9d558 Mon Sep 17 00:00:00 2001 From: 35C4n0r Date: Sat, 7 Feb 2026 08:55:35 +0530 Subject: [PATCH 23/32] debug --- registry/coder/modules/agentapi/main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/registry/coder/modules/agentapi/main.tf b/registry/coder/modules/agentapi/main.tf index d0050b6a8..e587a581c 100644 --- a/registry/coder/modules/agentapi/main.tf +++ b/registry/coder/modules/agentapi/main.tf @@ -258,7 +258,7 @@ resource "coder_script" "agentapi" { ARG_TASK_LOG_SNAPSHOT='${var.task_log_snapshot}' \ /tmp/main.sh EOT - run_on_start = false + run_on_start = true } resource "coder_script" "agentapi_shutdown" { From 88b01dba31a677907022d49d24ea3e47e3fb0fcd Mon Sep 17 00:00:00 2001 From: 35C4n0r Date: Sat, 7 Feb 2026 09:16:23 +0530 Subject: [PATCH 24/32] debug: depends on --- registry/coder/modules/agentapi/main.tf | 1 + 1 file changed, 1 insertion(+) diff --git a/registry/coder/modules/agentapi/main.tf b/registry/coder/modules/agentapi/main.tf index e587a581c..45c128525 100644 --- a/registry/coder/modules/agentapi/main.tf +++ b/registry/coder/modules/agentapi/main.tf @@ -259,6 +259,7 @@ resource "coder_script" "agentapi" { /tmp/main.sh EOT run_on_start = true + depends_on = [module.agent-helper] } resource "coder_script" "agentapi_shutdown" { From fde6ae6dc1bdf1d456d31a332370840b0f2750ff Mon Sep 17 00:00:00 2001 From: 35C4n0r Date: Sat, 7 Feb 2026 09:21:07 +0530 Subject: [PATCH 25/32] debug: depends on --- registry/coder/modules/agentapi/main.tf | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/registry/coder/modules/agentapi/main.tf b/registry/coder/modules/agentapi/main.tf index 45c128525..d9794a672 100644 --- a/registry/coder/modules/agentapi/main.tf +++ b/registry/coder/modules/agentapi/main.tf @@ -236,9 +236,9 @@ resource "coder_script" "agentapi" { set -o errexit set -o pipefail - trap 'coder exp sync complete ${local.agentapi_main_script_name}' EXIT - coder exp sync want ${local.agentapi_main_script_name} ${local.start_script_name} - coder exp sync start ${local.agentapi_main_script_name} + # trap 'coder exp sync complete ${local.agentapi_main_script_name}' EXIT + # coder exp sync want ${local.agentapi_main_script_name} ${local.start_script_name} + # coder exp sync start ${local.agentapi_main_script_name} echo -n '${base64encode(local.main_script)}' | base64 -d > /tmp/main.sh chmod +x /tmp/main.sh From c1a3ed53a952ae63eacb8d60cd6686dbc8582a8e Mon Sep 17 00:00:00 2001 From: 35C4n0r Date: Sat, 7 Feb 2026 04:08:13 +0000 Subject: [PATCH 26/32] wip: move scripts to agentapi module --- registry/coder/modules/agentapi/main.tf | 70 ++++++++++++------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/registry/coder/modules/agentapi/main.tf b/registry/coder/modules/agentapi/main.tf index d9794a672..eb791dd4a 100644 --- a/registry/coder/modules/agentapi/main.tf +++ b/registry/coder/modules/agentapi/main.tf @@ -226,41 +226,41 @@ module "agent-helper" { start_script = var.start_script } -resource "coder_script" "agentapi" { - count = var.enable_agentapi ? 1 : 0 - agent_id = var.agent_id - display_name = "Start AgentAPI" - icon = var.web_app_icon - script = <<-EOT - #!/bin/bash - set -o errexit - set -o pipefail - - # trap 'coder exp sync complete ${local.agentapi_main_script_name}' EXIT - # coder exp sync want ${local.agentapi_main_script_name} ${local.start_script_name} - # coder exp sync start ${local.agentapi_main_script_name} - - echo -n '${base64encode(local.main_script)}' | base64 -d > /tmp/main.sh - chmod +x /tmp/main.sh - - ARG_MODULE_DIR_NAME='${var.module_dir_name}' \ - ARG_WORKDIR="$(echo -n '${base64encode(local.workdir)}' | base64 -d)" \ - ARG_INSTALL_AGENTAPI='${var.install_agentapi}' \ - ARG_AGENTAPI_VERSION='${var.agentapi_version}' \ - ARG_WAIT_FOR_START_SCRIPT="$(echo -n '${local.agentapi_wait_for_start_script_b64}' | base64 -d)" \ - ARG_AGENTAPI_PORT='${var.agentapi_port}' \ - ARG_AGENTAPI_SERVER_TYPE='${var.agent_name}' \ - ARG_AGENTAPI_TERM_WIDTH='${var.agentapi_term_width}' \ - ARG_AGENTAPI_TERM_HEIGHT='${var.agentapi_term_height}' \ - ARG_AGENTAPI_INITIAL_PROMPT="$(echo -n '${local.encoded_initial_prompt}' | base64 -d)" \ - ARG_AGENTAPI_CHAT_BASE_PATH='${local.agentapi_chat_base_path}' \ - ARG_TASK_ID='${try(data.coder_task.me.id, "")}' \ - ARG_TASK_LOG_SNAPSHOT='${var.task_log_snapshot}' \ - /tmp/main.sh - EOT - run_on_start = true - depends_on = [module.agent-helper] -} +# resource "coder_script" "agentapi" { +# count = var.enable_agentapi ? 1 : 0 +# agent_id = var.agent_id +# display_name = "Start AgentAPI" +# icon = var.web_app_icon +# script = <<-EOT +# #!/bin/bash +# set -o errexit +# set -o pipefail +# +# # trap 'coder exp sync complete ${local.agentapi_main_script_name}' EXIT +# # coder exp sync want ${local.agentapi_main_script_name} ${local.start_script_name} +# # coder exp sync start ${local.agentapi_main_script_name} +# +# echo -n '${base64encode(local.main_script)}' | base64 -d > /tmp/main.sh +# chmod +x /tmp/main.sh +# +# ARG_MODULE_DIR_NAME='${var.module_dir_name}' \ +# ARG_WORKDIR="$(echo -n '${base64encode(local.workdir)}' | base64 -d)" \ +# ARG_INSTALL_AGENTAPI='${var.install_agentapi}' \ +# ARG_AGENTAPI_VERSION='${var.agentapi_version}' \ +# ARG_WAIT_FOR_START_SCRIPT="$(echo -n '${local.agentapi_wait_for_start_script_b64}' | base64 -d)" \ +# ARG_AGENTAPI_PORT='${var.agentapi_port}' \ +# ARG_AGENTAPI_SERVER_TYPE='${var.agent_name}' \ +# ARG_AGENTAPI_TERM_WIDTH='${var.agentapi_term_width}' \ +# ARG_AGENTAPI_TERM_HEIGHT='${var.agentapi_term_height}' \ +# ARG_AGENTAPI_INITIAL_PROMPT="$(echo -n '${local.encoded_initial_prompt}' | base64 -d)" \ +# ARG_AGENTAPI_CHAT_BASE_PATH='${local.agentapi_chat_base_path}' \ +# ARG_TASK_ID='${try(data.coder_task.me.id, "")}' \ +# ARG_TASK_LOG_SNAPSHOT='${var.task_log_snapshot}' \ +# /tmp/main.sh +# EOT +# run_on_start = true +# depends_on = [module.agent-helper] +# } resource "coder_script" "agentapi_shutdown" { count = var.enable_agentapi ? 1 : 0 From 21757f35d7ec9075c8f1b8774172b34fd3e70428 Mon Sep 17 00:00:00 2001 From: 35C4n0r Date: Sat, 7 Feb 2026 04:32:05 +0000 Subject: [PATCH 27/32] debug --- registry/coder/modules/agentapi/main.tf | 50 +++++++++++++++++++++---- 1 file changed, 42 insertions(+), 8 deletions(-) diff --git a/registry/coder/modules/agentapi/main.tf b/registry/coder/modules/agentapi/main.tf index eb791dd4a..198f9da1f 100644 --- a/registry/coder/modules/agentapi/main.tf +++ b/registry/coder/modules/agentapi/main.tf @@ -216,14 +216,48 @@ locals { } module "agent-helper" { - source = "git::https://github.com/coder/registry.git//registry/coder/modules/agent-helper?ref=35C4n0r/feat-agent-helper-module" - agent_id = var.agent_id - agent_name = var.agent_name - module_dir_name = var.module_dir_name - pre_install_script = var.pre_install_script - install_script = var.install_script - post_install_script = var.post_install_script - start_script = var.start_script + source = "git::https://github.com/coder/registry.git//registry/coder/modules/agent-helper?ref=35C4n0r/feat-agent-helper-module" + agent_id = var.agent_id + agent_name = var.agent_name + module_dir_name = var.module_dir_name + + pre_install_script = var.pre_install_script != null ? <<-EOT + #!/bin/bash + set -o errexit + set -o pipefail + echo -n '${base64encode(var.pre_install_script)}' | base64 -d > /tmp/${var.agent_name}-pre-install.sh + chmod +x /tmp/${var.agent_name}-pre-install.sh + /tmp/${var.agent_name}-pre-install.sh + EOT + : null + + install_script = <<-EOT + #!/bin/bash + set -o errexit + set -o pipefail + echo -n '${base64encode(var.install_script)}' | base64 -d > /tmp/${var.agent_name}-install.sh + chmod +x /tmp/${var.agent_name}-install.sh + /tmp/${var.agent_name}-install.sh + EOT + + post_install_script = var.post_install_script != null ? <<-EOT + #!/bin/bash + set -o errexit + set -o pipefail + echo -n '${base64encode(var.post_install_script)}' | base64 -d > /tmp/${var.agent_name}-post-install.sh + chmod +x /tmp/${var.agent_name}-post-install.sh + /tmp/${var.agent_name}-post-install.sh + EOT + : null + + start_script = <<-EOT + #!/bin/bash + set -o errexit + set -o pipefail + echo -n '${base64encode(var.start_script)}' | base64 -d > /tmp/${var.agent_name}-start.sh + chmod +x /tmp/${var.agent_name}-start.sh + /tmp/${var.agent_name}-start.sh + EOT } # resource "coder_script" "agentapi" { From fabb5b2f2eb92f3c5b38d38204f423862eb1bde1 Mon Sep 17 00:00:00 2001 From: 35C4n0r Date: Sat, 7 Feb 2026 04:37:23 +0000 Subject: [PATCH 28/32] debug --- registry/coder/modules/agentapi/main.tf | 77 +++++++++++++------------ 1 file changed, 40 insertions(+), 37 deletions(-) diff --git a/registry/coder/modules/agentapi/main.tf b/registry/coder/modules/agentapi/main.tf index 198f9da1f..64f4dd367 100644 --- a/registry/coder/modules/agentapi/main.tf +++ b/registry/coder/modules/agentapi/main.tf @@ -213,6 +213,42 @@ locals { agentapi_main_script_name = "${var.agent_name}-main_script" module_dir_path = "$HOME/${var.module_dir_name}" + + helper_pre_install_script = var.pre_install_script != null ? join("\n", [ + "#!/bin/bash", + "set -o errexit", + "set -o pipefail", + "echo -n '${base64encode(var.pre_install_script)}' | base64 -d > /tmp/${var.agent_name}-pre-install.sh", + "chmod +x /tmp/${var.agent_name}-pre-install.sh", + "/tmp/${var.agent_name}-pre-install.sh", + ]) : null + + helper_install_script = join("\n", [ + "#!/bin/bash", + "set -o errexit", + "set -o pipefail", + "echo -n '${base64encode(var.install_script)}' | base64 -d > /tmp/${var.agent_name}-install.sh", + "chmod +x /tmp/${var.agent_name}-install.sh", + "/tmp/${var.agent_name}-install.sh", + ]) + + helper_post_install_script = var.post_install_script != null ? join("\n", [ + "#!/bin/bash", + "set -o errexit", + "set -o pipefail", + "echo -n '${base64encode(var.post_install_script)}' | base64 -d > /tmp/${var.agent_name}-post-install.sh", + "chmod +x /tmp/${var.agent_name}-post-install.sh", + "/tmp/${var.agent_name}-post-install.sh", + ]) : null + + helper_start_script = join("\n", [ + "#!/bin/bash", + "set -o errexit", + "set -o pipefail", + "echo -n '${base64encode(var.start_script)}' | base64 -d > /tmp/${var.agent_name}-start.sh", + "chmod +x /tmp/${var.agent_name}-start.sh", + "/tmp/${var.agent_name}-start.sh", + ]) } module "agent-helper" { @@ -221,43 +257,10 @@ module "agent-helper" { agent_name = var.agent_name module_dir_name = var.module_dir_name - pre_install_script = var.pre_install_script != null ? <<-EOT - #!/bin/bash - set -o errexit - set -o pipefail - echo -n '${base64encode(var.pre_install_script)}' | base64 -d > /tmp/${var.agent_name}-pre-install.sh - chmod +x /tmp/${var.agent_name}-pre-install.sh - /tmp/${var.agent_name}-pre-install.sh - EOT - : null - - install_script = <<-EOT - #!/bin/bash - set -o errexit - set -o pipefail - echo -n '${base64encode(var.install_script)}' | base64 -d > /tmp/${var.agent_name}-install.sh - chmod +x /tmp/${var.agent_name}-install.sh - /tmp/${var.agent_name}-install.sh - EOT - - post_install_script = var.post_install_script != null ? <<-EOT - #!/bin/bash - set -o errexit - set -o pipefail - echo -n '${base64encode(var.post_install_script)}' | base64 -d > /tmp/${var.agent_name}-post-install.sh - chmod +x /tmp/${var.agent_name}-post-install.sh - /tmp/${var.agent_name}-post-install.sh - EOT - : null - - start_script = <<-EOT - #!/bin/bash - set -o errexit - set -o pipefail - echo -n '${base64encode(var.start_script)}' | base64 -d > /tmp/${var.agent_name}-start.sh - chmod +x /tmp/${var.agent_name}-start.sh - /tmp/${var.agent_name}-start.sh - EOT + pre_install_script = local.helper_pre_install_script + install_script = local.helper_install_script + post_install_script = local.helper_post_install_script + start_script = local.helper_start_script } # resource "coder_script" "agentapi" { From 191f4ca2c20581757909ea1a9c75138090c9a58e Mon Sep 17 00:00:00 2001 From: 35C4n0r Date: Sat, 7 Feb 2026 04:48:57 +0000 Subject: [PATCH 29/32] debug --- registry/coder/modules/agentapi/main.tf | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/registry/coder/modules/agentapi/main.tf b/registry/coder/modules/agentapi/main.tf index 64f4dd367..c624d5e95 100644 --- a/registry/coder/modules/agentapi/main.tf +++ b/registry/coder/modules/agentapi/main.tf @@ -251,17 +251,17 @@ locals { ]) } -module "agent-helper" { - source = "git::https://github.com/coder/registry.git//registry/coder/modules/agent-helper?ref=35C4n0r/feat-agent-helper-module" - agent_id = var.agent_id - agent_name = var.agent_name - module_dir_name = var.module_dir_name - - pre_install_script = local.helper_pre_install_script - install_script = local.helper_install_script - post_install_script = local.helper_post_install_script - start_script = local.helper_start_script -} +# module "agent-helper" { +# source = "git::https://github.com/coder/registry.git//registry/coder/modules/agent-helper?ref=35C4n0r/feat-agent-helper-module" +# agent_id = var.agent_id +# agent_name = var.agent_name +# module_dir_name = var.module_dir_name +# +# pre_install_script = local.helper_pre_install_script +# install_script = local.helper_install_script +# post_install_script = local.helper_post_install_script +# start_script = local.helper_start_script +# } # resource "coder_script" "agentapi" { # count = var.enable_agentapi ? 1 : 0 From 4732deb3273d357ab502bd44911d40c296913eac Mon Sep 17 00:00:00 2001 From: 35C4n0r Date: Sat, 7 Feb 2026 04:55:38 +0000 Subject: [PATCH 30/32] debug --- registry/coder/modules/agentapi/main.tf | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/registry/coder/modules/agentapi/main.tf b/registry/coder/modules/agentapi/main.tf index c624d5e95..64f4dd367 100644 --- a/registry/coder/modules/agentapi/main.tf +++ b/registry/coder/modules/agentapi/main.tf @@ -251,17 +251,17 @@ locals { ]) } -# module "agent-helper" { -# source = "git::https://github.com/coder/registry.git//registry/coder/modules/agent-helper?ref=35C4n0r/feat-agent-helper-module" -# agent_id = var.agent_id -# agent_name = var.agent_name -# module_dir_name = var.module_dir_name -# -# pre_install_script = local.helper_pre_install_script -# install_script = local.helper_install_script -# post_install_script = local.helper_post_install_script -# start_script = local.helper_start_script -# } +module "agent-helper" { + source = "git::https://github.com/coder/registry.git//registry/coder/modules/agent-helper?ref=35C4n0r/feat-agent-helper-module" + agent_id = var.agent_id + agent_name = var.agent_name + module_dir_name = var.module_dir_name + + pre_install_script = local.helper_pre_install_script + install_script = local.helper_install_script + post_install_script = local.helper_post_install_script + start_script = local.helper_start_script +} # resource "coder_script" "agentapi" { # count = var.enable_agentapi ? 1 : 0 From 5de7928e02d7821e9268c96bc7a9f70c047c2f54 Mon Sep 17 00:00:00 2001 From: 35C4n0r Date: Sat, 7 Feb 2026 11:05:58 +0530 Subject: [PATCH 31/32] debug --- registry/coder/modules/agentapi/main.tf | 87 +++++++++++++------------ 1 file changed, 46 insertions(+), 41 deletions(-) diff --git a/registry/coder/modules/agentapi/main.tf b/registry/coder/modules/agentapi/main.tf index 64f4dd367..633585fd6 100644 --- a/registry/coder/modules/agentapi/main.tf +++ b/registry/coder/modules/agentapi/main.tf @@ -257,47 +257,52 @@ module "agent-helper" { agent_name = var.agent_name module_dir_name = var.module_dir_name - pre_install_script = local.helper_pre_install_script - install_script = local.helper_install_script - post_install_script = local.helper_post_install_script - start_script = local.helper_start_script -} - -# resource "coder_script" "agentapi" { -# count = var.enable_agentapi ? 1 : 0 -# agent_id = var.agent_id -# display_name = "Start AgentAPI" -# icon = var.web_app_icon -# script = <<-EOT -# #!/bin/bash -# set -o errexit -# set -o pipefail -# -# # trap 'coder exp sync complete ${local.agentapi_main_script_name}' EXIT -# # coder exp sync want ${local.agentapi_main_script_name} ${local.start_script_name} -# # coder exp sync start ${local.agentapi_main_script_name} -# -# echo -n '${base64encode(local.main_script)}' | base64 -d > /tmp/main.sh -# chmod +x /tmp/main.sh -# -# ARG_MODULE_DIR_NAME='${var.module_dir_name}' \ -# ARG_WORKDIR="$(echo -n '${base64encode(local.workdir)}' | base64 -d)" \ -# ARG_INSTALL_AGENTAPI='${var.install_agentapi}' \ -# ARG_AGENTAPI_VERSION='${var.agentapi_version}' \ -# ARG_WAIT_FOR_START_SCRIPT="$(echo -n '${local.agentapi_wait_for_start_script_b64}' | base64 -d)" \ -# ARG_AGENTAPI_PORT='${var.agentapi_port}' \ -# ARG_AGENTAPI_SERVER_TYPE='${var.agent_name}' \ -# ARG_AGENTAPI_TERM_WIDTH='${var.agentapi_term_width}' \ -# ARG_AGENTAPI_TERM_HEIGHT='${var.agentapi_term_height}' \ -# ARG_AGENTAPI_INITIAL_PROMPT="$(echo -n '${local.encoded_initial_prompt}' | base64 -d)" \ -# ARG_AGENTAPI_CHAT_BASE_PATH='${local.agentapi_chat_base_path}' \ -# ARG_TASK_ID='${try(data.coder_task.me.id, "")}' \ -# ARG_TASK_LOG_SNAPSHOT='${var.task_log_snapshot}' \ -# /tmp/main.sh -# EOT -# run_on_start = true -# depends_on = [module.agent-helper] -# } + # pre_install_script = local.helper_pre_install_script + # install_script = local.helper_install_script + # post_install_script = local.helper_post_install_script + # start_script = local.helper_start_script + + pre_install_script = var.pre_install_script + install_script = var.install_script + post_install_script = var.post_install_script + start_script = var.start_script +} + +resource "coder_script" "agentapi" { + count = var.enable_agentapi ? 1 : 0 + agent_id = var.agent_id + display_name = "Start AgentAPI" + icon = var.web_app_icon + script = <<-EOT + #!/bin/bash + set -o errexit + set -o pipefail + + # trap 'coder exp sync complete ${local.agentapi_main_script_name}' EXIT + # coder exp sync want ${local.agentapi_main_script_name} ${local.start_script_name} + # coder exp sync start ${local.agentapi_main_script_name} + + echo -n '${base64encode(local.main_script)}' | base64 -d > /tmp/main.sh + chmod +x /tmp/main.sh + + ARG_MODULE_DIR_NAME='${var.module_dir_name}' \ + ARG_WORKDIR="$(echo -n '${base64encode(local.workdir)}' | base64 -d)" \ + ARG_INSTALL_AGENTAPI='${var.install_agentapi}' \ + ARG_AGENTAPI_VERSION='${var.agentapi_version}' \ + ARG_WAIT_FOR_START_SCRIPT="$(echo -n '${local.agentapi_wait_for_start_script_b64}' | base64 -d)" \ + ARG_AGENTAPI_PORT='${var.agentapi_port}' \ + ARG_AGENTAPI_SERVER_TYPE='${var.agent_name}' \ + ARG_AGENTAPI_TERM_WIDTH='${var.agentapi_term_width}' \ + ARG_AGENTAPI_TERM_HEIGHT='${var.agentapi_term_height}' \ + ARG_AGENTAPI_INITIAL_PROMPT="$(echo -n '${local.encoded_initial_prompt}' | base64 -d)" \ + ARG_AGENTAPI_CHAT_BASE_PATH='${local.agentapi_chat_base_path}' \ + ARG_TASK_ID='${try(data.coder_task.me.id, "")}' \ + ARG_TASK_LOG_SNAPSHOT='${var.task_log_snapshot}' \ + /tmp/main.sh + EOT + run_on_start = true + depends_on = [module.agent-helper] +} resource "coder_script" "agentapi_shutdown" { count = var.enable_agentapi ? 1 : 0 From c2958d58caabe8421c9f0e78ee436d5f1fa08efa Mon Sep 17 00:00:00 2001 From: 35C4n0r Date: Sat, 7 Feb 2026 11:15:29 +0530 Subject: [PATCH 32/32] debug --- registry/coder/modules/agentapi/main.tf | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/registry/coder/modules/agentapi/main.tf b/registry/coder/modules/agentapi/main.tf index 633585fd6..866c30991 100644 --- a/registry/coder/modules/agentapi/main.tf +++ b/registry/coder/modules/agentapi/main.tf @@ -278,9 +278,9 @@ resource "coder_script" "agentapi" { set -o errexit set -o pipefail - # trap 'coder exp sync complete ${local.agentapi_main_script_name}' EXIT - # coder exp sync want ${local.agentapi_main_script_name} ${local.start_script_name} - # coder exp sync start ${local.agentapi_main_script_name} + trap 'coder exp sync complete ${local.agentapi_main_script_name}' EXIT + coder exp sync want ${local.agentapi_main_script_name} ${local.start_script_name} + coder exp sync start ${local.agentapi_main_script_name} echo -n '${base64encode(local.main_script)}' | base64 -d > /tmp/main.sh chmod +x /tmp/main.sh