Compare commits

...

1 Commits

Author SHA1 Message Date
DevelopmentCats ae24c2da97 feat: add session resumption 2025-10-23 16:23:03 -05:00
4 changed files with 66 additions and 5 deletions
@@ -108,6 +108,18 @@ 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")
@@ -158,6 +170,8 @@ 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,6 +9,7 @@ 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:-}
@@ -20,6 +21,7 @@ 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,24 +10,36 @@ command_exists() {
ARG_AI_PROMPT=$(echo -n "${ARG_AI_PROMPT:-}" | base64 -d)
ARG_FORCE=${ARG_FORCE:-false}
ARG_MODEL=${ARG_MODEL:-}
ARG_OUTPUT_FORMAT=${ARG_OUTPUT_FORMAT:-json}
ARG_CONTINUE=${ARG_CONTINUE:-true}
ARG_RESUME_SESSION_ID=${ARG_RESUME_SESSION_ID:-}
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 "output_format: $ARG_OUTPUT_FORMAT"
echo "continue: $ARG_CONTINUE"
echo "resume_session_id: ${ARG_RESUME_SESSION_ID:-<none>}"
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
@@ -56,6 +68,34 @@ 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,6 +6,11 @@ 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