Skip to content

Commit 1583557

Browse files
feat: add copilot_version variable for version control in Copilot module and use new continue param for resuming sessions
1 parent 5bceee2 commit 1583557

File tree

4 files changed

+23
-23
lines changed

4 files changed

+23
-23
lines changed

registry/coder-labs/modules/copilot/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ module "copilot" {
7575
agent_id = coder_agent.example.id
7676
workdir = "/home/coder/projects"
7777
78+
# Version pinning (defaults to "0.0.334", use "latest" for newest version)
79+
copilot_version = "latest"
80+
7881
# Tool permissions
7982
allow_tools = ["shell(git)", "shell(npm)", "write"]
8083
trusted_directories = ["/home/coder/projects", "/tmp"]

registry/coder-labs/modules/copilot/main.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,12 @@ variable "agentapi_version" {
121121
default = "v0.10.0"
122122
}
123123

124+
variable "copilot_version" {
125+
type = string
126+
description = "The version of GitHub Copilot CLI to install. Use 'latest' for the latest version or specify a version like '0.0.334'."
127+
default = "0.0.334"
128+
}
129+
124130
variable "report_tasks" {
125131
type = bool
126132
description = "Whether to enable task reporting to Coder UI via AgentAPI."
@@ -291,6 +297,7 @@ module "agentapi" {
291297
ARG_MCP_CONFIG='${var.mcp_config != "" ? base64encode(var.mcp_config) : ""}' \
292298
ARG_COPILOT_CONFIG='${base64encode(local.final_copilot_config)}' \
293299
ARG_EXTERNAL_AUTH_ID='${var.external_auth_id}' \
300+
ARG_COPILOT_VERSION='${var.copilot_version}' \
294301
/tmp/install.sh
295302
EOT
296303
}

registry/coder-labs/modules/copilot/scripts/install.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ ARG_MCP_APP_STATUS_SLUG=${ARG_MCP_APP_STATUS_SLUG:-}
1313
ARG_MCP_CONFIG=$(echo -n "${ARG_MCP_CONFIG:-}" | base64 -d 2> /dev/null || echo "")
1414
ARG_COPILOT_CONFIG=$(echo -n "${ARG_COPILOT_CONFIG:-}" | base64 -d 2> /dev/null || echo "")
1515
ARG_EXTERNAL_AUTH_ID=${ARG_EXTERNAL_AUTH_ID:-github}
16+
ARG_COPILOT_VERSION=${ARG_COPILOT_VERSION:-0.0.334}
1617

1718
validate_prerequisites() {
1819
if ! command_exists node; then
@@ -34,8 +35,12 @@ validate_prerequisites() {
3435

3536
install_copilot() {
3637
if ! command_exists copilot; then
37-
echo "Installing GitHub Copilot CLI..."
38-
npm install -g @github/copilot
38+
echo "Installing GitHub Copilot CLI (version: ${ARG_COPILOT_VERSION})..."
39+
if [ "$ARG_COPILOT_VERSION" = "latest" ]; then
40+
npm install -g @github/copilot
41+
else
42+
npm install -g "@github/copilot@${ARG_COPILOT_VERSION}"
43+
fi
3944

4045
if ! command_exists copilot; then
4146
echo "ERROR: Failed to install Copilot"

registry/coder-labs/modules/copilot/scripts/start.sh

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -73,23 +73,11 @@ check_existing_session() {
7373
if copilot --help > /dev/null 2>&1; then
7474
local session_dir="$HOME/.copilot/history-session-state"
7575
if [ -d "$session_dir" ] && [ -n "$(ls "$session_dir"/session_*_*.json 2> /dev/null)" ]; then
76-
local latest_session_file
77-
latest_session_file=$(ls "$session_dir"/session_*_*.json 2> /dev/null | sort -t_ -k3 -n -r | head -n 1)
78-
79-
if [ -n "$latest_session_file" ]; then
80-
local session_id
81-
session_id=$(basename "$latest_session_file" | sed 's/session_\(.*\)_[0-9]*.json/\1/')
82-
83-
if [ -n "$session_id" ]; then
84-
echo "Found existing Copilot sessions. Will resume latest: $session_id" >&2
85-
echo "$session_id"
86-
return 0
87-
fi
88-
fi
76+
echo "Found existing Copilot session. Will continue latest session." >&2
77+
return 0
8978
fi
9079
fi
9180
fi
92-
echo ""
9381
return 1
9482
}
9583

@@ -131,16 +119,13 @@ start_agentapi() {
131119

132120
build_copilot_args
133121

134-
local session_id
135-
session_id=$(check_existing_session)
136-
137-
if [ -n "$session_id" ]; then
138-
echo "Resuming Copilot session: $session_id"
122+
if check_existing_session; then
123+
echo "Continuing latest Copilot session..."
139124
if [ ${#COPILOT_ARGS[@]} -gt 0 ]; then
140125
echo "Copilot arguments: ${COPILOT_ARGS[*]}"
141-
agentapi server --type copilot --term-width 120 --term-height 40 -- copilot --resume "$session_id" "${COPILOT_ARGS[@]}"
126+
agentapi server --type copilot --term-width 120 --term-height 40 -- copilot --continue "${COPILOT_ARGS[@]}"
142127
else
143-
agentapi server --type copilot --term-width 120 --term-height 40 -- copilot --resume "$session_id"
128+
agentapi server --type copilot --term-width 120 --term-height 40 -- copilot --continue
144129
fi
145130
else
146131
echo "Starting new Copilot session..."

0 commit comments

Comments
 (0)