From 3f68310880bb812e0b173424867bc03fd534a759 Mon Sep 17 00:00:00 2001 From: 35C4n0r Date: Wed, 4 Feb 2026 08:10:36 +0530 Subject: [PATCH] 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 fe543aef..bef0eb20 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 157e6060..8087173b 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 f0119acd..6c5cf724 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 bfb1ad15..2a62a663 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 b20f3833..ec9b4be5 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