Compare commits

..

1 Commits

Author SHA1 Message Date
Danielle Maywood e3ff43c0a6 refactor(coder/agentapi): support terraform-provider-coder v2.12.0 (#485)
In terraform-provider-coder v2.12.0 and the
up-coming coder v2.28 release we have removed the
requirement for the "AI Prompt" parameter, and are intending on slightly
re-designing the API of the AI task modules.

Instead of `agentapi` defining the `coder_ai_task` resource, it will
output the `task_app_id`. Consumers of the module will then be expected
to create the `coder_ai_task` resource themselves with this
`task_app_id`.
2025-10-24 11:54:12 +01:00
6 changed files with 9 additions and 72 deletions
@@ -108,18 +108,6 @@ variable "post_install_script" {
default = null
}
variable "continue" {
type = bool
description = "Automatically continue existing sessions on workspace restart. When true, resumes existing conversation if found, otherwise creates new session. When false, always starts fresh."
default = true
}
variable "resume_session_id" {
type = string
description = "Resume a specific session by ID. Takes precedence over automatic session detection."
default = ""
}
locals {
app_slug = "cursorcli"
install_script = file("${path.module}/scripts/install.sh")
@@ -170,8 +158,6 @@ module "agentapi" {
ARG_FORCE='${var.force}' \
ARG_MODEL='${var.model}' \
ARG_AI_PROMPT='${base64encode(var.ai_prompt)}' \
ARG_CONTINUE='${var.continue}' \
ARG_RESUME_SESSION_ID='${var.resume_session_id}' \
ARG_MODULE_DIR_NAME='${local.module_dir_name}' \
ARG_FOLDER='${var.folder}' \
/tmp/start.sh
@@ -9,7 +9,6 @@ command_exists() {
# Inputs
ARG_INSTALL=${ARG_INSTALL:-true}
ARG_VERSION=${ARG_VERSION:-latest}
ARG_MODULE_DIR_NAME=${ARG_MODULE_DIR_NAME:-.cursor-cli-module}
ARG_FOLDER=${ARG_FOLDER:-$HOME}
ARG_CODER_MCP_APP_STATUS_SLUG=${ARG_CODER_MCP_APP_STATUS_SLUG:-}
@@ -21,7 +20,6 @@ ARG_WORKSPACE_RULES_JSON=$(echo -n "$ARG_WORKSPACE_RULES_JSON" | base64 -d)
echo "--------------------------------"
echo "install: $ARG_INSTALL"
echo "version: $ARG_VERSION"
echo "folder: $ARG_FOLDER"
echo "coder_mcp_app_status_slug: $ARG_CODER_MCP_APP_STATUS_SLUG"
echo "module_dir_name: $ARG_MODULE_DIR_NAME"
@@ -10,36 +10,24 @@ command_exists() {
ARG_AI_PROMPT=$(echo -n "${ARG_AI_PROMPT:-}" | base64 -d)
ARG_FORCE=${ARG_FORCE:-false}
ARG_MODEL=${ARG_MODEL:-}
ARG_CONTINUE=${ARG_CONTINUE:-true}
ARG_RESUME_SESSION_ID=${ARG_RESUME_SESSION_ID:-}
ARG_OUTPUT_FORMAT=${ARG_OUTPUT_FORMAT:-json}
ARG_MODULE_DIR_NAME=${ARG_MODULE_DIR_NAME:-.cursor-cli-module}
ARG_FOLDER=${ARG_FOLDER:-$HOME}
echo "--------------------------------"
echo "install: $ARG_INSTALL"
echo "version: $ARG_VERSION"
echo "folder: $ARG_FOLDER"
echo "ai_prompt: $ARG_AI_PROMPT"
echo "force: $ARG_FORCE"
echo "model: $ARG_MODEL"
echo "continue: $ARG_CONTINUE"
echo "resume_session_id: ${ARG_RESUME_SESSION_ID:-<none>}"
echo "output_format: $ARG_OUTPUT_FORMAT"
echo "module_dir_name: $ARG_MODULE_DIR_NAME"
echo "folder: $ARG_FOLDER"
echo "--------------------------------"
mkdir -p "$HOME/$ARG_MODULE_DIR_NAME"
SESSION_FILE="$HOME/$ARG_MODULE_DIR_NAME/session_id.txt"
get_stored_session_id() {
if [ -f "$SESSION_FILE" ]; then
cat "$SESSION_FILE" | tr -d '\n' || echo ""
fi
}
store_session_id() {
echo "$1" > "$SESSION_FILE"
echo "Stored session ID: $1"
}
# Find cursor agent cli
if command_exists cursor-agent; then
CURSOR_CMD=cursor-agent
@@ -68,34 +56,6 @@ if [ "$ARG_FORCE" = "true" ]; then
ARGS+=("-f")
fi
if [ -n "$ARG_RESUME_SESSION_ID" ]; then
echo "Using explicit resume_session_id: $ARG_RESUME_SESSION_ID"
ARGS+=("--resume" "$ARG_RESUME_SESSION_ID")
elif [ "$ARG_CONTINUE" = "true" ]; then
STORED_SESSION=$(get_stored_session_id)
if [ -n "$STORED_SESSION" ]; then
echo "Found existing session: $STORED_SESSION"
echo "Resuming conversation..."
ARGS+=("--resume" "$STORED_SESSION")
else
echo "No existing session found"
echo "Creating new session for this workspace..."
NEW_SESSION=$($CURSOR_CMD create-chat 2>&1 | tr -d '\n')
if [ -n "$NEW_SESSION" ]; then
store_session_id "$NEW_SESSION"
ARGS+=("--resume" "$NEW_SESSION")
else
echo "Warning: Failed to create session, continuing without session resume"
fi
fi
else
echo "Continue disabled, starting fresh session"
rm -f "$SESSION_FILE"
fi
if [ -n "$ARG_AI_PROMPT" ]; then
printf "AI prompt provided\n"
ARGS+=("Complete the task at hand in one go. Every step of the way, report your progress using coder_report_task tool with proper summary and statuses. Your task at hand: $ARG_AI_PROMPT")
@@ -6,11 +6,6 @@ if [[ "$1" == "--version" ]]; then
exit 0
fi
if [[ "$1" == "create-chat" ]]; then
echo "12345678-1234-1234-1234-123456789abc"
exit 0
fi
set -e
while true; do
+1 -1
View File
@@ -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 = "1.2.0"
version = "2.0.0"
agent_id = var.agent_id
web_app_slug = local.app_slug
+3 -5
View File
@@ -4,7 +4,7 @@ terraform {
required_providers {
coder = {
source = "coder/coder"
version = ">= 2.7"
version = ">= 2.12"
}
}
}
@@ -239,8 +239,6 @@ resource "coder_app" "agentapi_cli" {
group = var.cli_app_group
}
resource "coder_ai_task" "agentapi" {
sidebar_app {
id = coder_app.agentapi_web.id
}
output "task_app_id" {
value = coder_app.agentapi_web.id
}