From d6b490ecb2914703940d3d6d0249a88cd34b85d1 Mon Sep 17 00:00:00 2001 From: 35C4n0r Date: Thu, 12 Mar 2026 22:34:24 +0530 Subject: [PATCH] feat: add enable_state_persistence variable and update README for state management --- registry/coder-labs/modules/copilot/README.md | 19 ++++++++++-- .../modules/copilot/copilot.tftest.hcl | 29 +++++++++++++++++++ registry/coder-labs/modules/copilot/main.tf | 17 +++++++---- 3 files changed, 57 insertions(+), 8 deletions(-) diff --git a/registry/coder-labs/modules/copilot/README.md b/registry/coder-labs/modules/copilot/README.md index 7c0e5693..f67ad560 100644 --- a/registry/coder-labs/modules/copilot/README.md +++ b/registry/coder-labs/modules/copilot/README.md @@ -13,7 +13,7 @@ Run [GitHub Copilot CLI](https://docs.github.com/copilot/concepts/agents/about-c ```tf module "copilot" { source = "registry.coder.com/coder-labs/copilot/coder" - version = "0.4.0" + version = "0.5.0" agent_id = coder_agent.example.id workdir = "/home/coder/projects" } @@ -51,7 +51,7 @@ data "coder_parameter" "ai_prompt" { module "copilot" { source = "registry.coder.com/coder-labs/copilot/coder" - version = "0.4.0" + version = "0.5.0" agent_id = coder_agent.example.id workdir = "/home/coder/projects" @@ -71,7 +71,7 @@ Customize tool permissions, MCP servers, and Copilot settings: ```tf module "copilot" { source = "registry.coder.com/coder-labs/copilot/coder" - version = "0.4.0" + version = "0.5.0" agent_id = coder_agent.example.id workdir = "/home/coder/projects" @@ -215,6 +215,19 @@ By default, the module resumes the latest Copilot session when the workspace res > [!NOTE] > Session resumption requires persistent storage for the home directory or workspace volume. Without persistent storage, sessions will not resume across workspace restarts. +## State Persistence + +AgentAPI can save and restore its conversation state to disk across workspace restarts. This complements `resume_session` (which resumes the Copilot CLI session) by also preserving the AgentAPI-level context. Enabled by default, requires agentapi >= v0.12.0 (older versions skip it with a warning). + +To disable: + +```tf +module "copilot" { + # ... other config + enable_state_persistence = false +} +``` + ## Troubleshooting If you encounter any issues, check the log files in the `~/.copilot-module` directory within your workspace for detailed information. diff --git a/registry/coder-labs/modules/copilot/copilot.tftest.hcl b/registry/coder-labs/modules/copilot/copilot.tftest.hcl index 0ff2379a..9fdf9370 100644 --- a/registry/coder-labs/modules/copilot/copilot.tftest.hcl +++ b/registry/coder-labs/modules/copilot/copilot.tftest.hcl @@ -347,3 +347,32 @@ run "aibridge_proxy_with_copilot_config" { error_message = "copilot_model environment variable should be set alongside proxy" } } + +run "enable_state_persistence_default" { + command = plan + + variables { + agent_id = "test-agent" + workdir = "/home/coder" + } + + assert { + condition = var.enable_state_persistence == true + error_message = "enable_state_persistence should default to true" + } +} + +run "disable_state_persistence" { + command = plan + + variables { + agent_id = "test-agent" + workdir = "/home/coder" + enable_state_persistence = false + } + + assert { + condition = var.enable_state_persistence == false + error_message = "enable_state_persistence should be false when explicitly disabled" + } +} diff --git a/registry/coder-labs/modules/copilot/main.tf b/registry/coder-labs/modules/copilot/main.tf index 4604f11a..9327fb87 100644 --- a/registry/coder-labs/modules/copilot/main.tf +++ b/registry/coder-labs/modules/copilot/main.tf @@ -119,6 +119,12 @@ variable "subdomain" { default = false } +variable "enable_state_persistence" { + type = bool + description = "Enable AgentAPI conversation state persistence across restarts." + default = true +} + variable "order" { type = number description = "The order determines the position of app in the UI presentation." @@ -291,11 +297,12 @@ module "agentapi" { cli_app_icon = var.cli_app ? var.icon : null cli_app_display_name = var.cli_app ? var.cli_app_display_name : null agentapi_subdomain = var.subdomain - module_dir_name = local.module_dir_name - install_agentapi = var.install_agentapi - agentapi_version = var.agentapi_version - pre_install_script = var.pre_install_script - post_install_script = var.post_install_script + module_dir_name = local.module_dir_name + install_agentapi = var.install_agentapi + agentapi_version = var.agentapi_version + enable_state_persistence = var.enable_state_persistence + pre_install_script = var.pre_install_script + post_install_script = var.post_install_script start_script = <<-EOT #!/bin/bash