Skip to content
This repository was archived by the owner on May 15, 2025. It is now read-only.

Commit bc6e54c

Browse files
committed
tmux support for goose
1 parent 856400c commit bc6e54c

File tree

2 files changed

+54
-15
lines changed

2 files changed

+54
-15
lines changed

goose/README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ module "goose" {
2424

2525
### Prerequisites
2626

27-
- `screen` must be installed in your workspace to run Goose in the background
27+
- `screen` or `tmux` must be installed in your workspace to run Goose in the background
2828
- You must add the [Coder Login](https://registry.coder.com/modules/coder-login) module to your template
2929

3030
The `codercom/oss-dogfood:latest` container image can be used for testing on container-based workspaces.
3131

3232
## Examples
3333

34-
Your workspace must have `screen` installed to use this.
34+
Your workspace must have `screen` or `tmux` installed to use this.
3535

3636
### Run in the background and report tasks (Experimental)
3737

@@ -99,8 +99,9 @@ module "goose" {
9999
# Enable experimental features
100100
experiment_report_tasks = true
101101
102-
# Run Goose in the background
102+
# Run Goose in the background (use only one of these options)
103103
experiment_use_screen = true
104+
# experiment_use_tmux = true
104105
105106
# Avoid configuring Goose manually
106107
experiment_auto_configure = true

goose/main.tf

Lines changed: 50 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ variable "experiment_use_screen" {
5454
default = false
5555
}
5656

57+
variable "experiment_use_tmux" {
58+
type = bool
59+
description = "Whether to use tmux instead of screen for running Goose in the background."
60+
default = false
61+
}
62+
5763
variable "experiment_report_tasks" {
5864
type = bool
5965
description = "Whether to enable task reporting."
@@ -187,8 +193,42 @@ EOL
187193
mkdir -p "$HOME/.config/goose"
188194
echo "$GOOSE_SYSTEM_PROMPT" > "$HOME/.config/goose/.goosehints"
189195
196+
# Handle terminal multiplexer selection (tmux or screen)
197+
if [ "${var.experiment_use_tmux}" = "true" ] && [ "${var.experiment_use_screen}" = "true" ]; then
198+
echo "Error: Both experiment_use_tmux and experiment_use_screen cannot be true simultaneously."
199+
echo "Please set only one of them to true."
200+
exit 1
201+
fi
202+
203+
# Determine goose command
204+
if command_exists goose; then
205+
GOOSE_CMD=goose
206+
elif [ -f "$HOME/.local/bin/goose" ]; then
207+
GOOSE_CMD="$HOME/.local/bin/goose"
208+
else
209+
echo "Error: Goose is not installed. Please enable install_goose or install it manually."
210+
exit 1
211+
fi
212+
213+
# Run with tmux if enabled
214+
if [ "${var.experiment_use_tmux}" = "true" ]; then
215+
echo "Running Goose in the background with tmux..."
216+
217+
# Check if tmux is installed
218+
if ! command_exists tmux; then
219+
echo "Error: tmux is not installed. Please install tmux manually."
220+
exit 1
221+
fi
222+
223+
touch "$HOME/.goose.log"
224+
225+
export LANG=en_US.UTF-8
226+
export LC_ALL=en_US.UTF-8
227+
228+
# Create a new tmux session in detached mode
229+
tmux new-session -d -s goose -c ${var.folder} "$GOOSE_CMD run --text \"Review your goosehints. Every step of the way, report tasks to Coder with proper descriptions and statuses. Your task at hand: $GOOSE_TASK_PROMPT\" --interactive | tee -a \"$HOME/.goose.log\""
190230
# Run with screen if enabled
191-
if [ "${var.experiment_use_screen}" = "true" ]; then
231+
elif [ "${var.experiment_use_screen}" = "true" ]; then
192232
echo "Running Goose in the background..."
193233
194234
# Check if screen is installed
@@ -217,16 +257,6 @@ EOL
217257
export LANG=en_US.UTF-8
218258
export LC_ALL=en_US.UTF-8
219259
220-
# Determine goose command
221-
if command_exists goose; then
222-
GOOSE_CMD=goose
223-
elif [ -f "$HOME/.local/bin/goose" ]; then
224-
GOOSE_CMD="$HOME/.local/bin/goose"
225-
else
226-
echo "Error: Goose is not installed. Please enable install_goose or install it manually."
227-
exit 1
228-
fi
229-
230260
screen -U -dmS goose bash -c "
231261
cd ${var.folder}
232262
\"$GOOSE_CMD\" run --text \"Review your goosehints. Every step of the way, report tasks to Coder with proper descriptions and statuses. Your task at hand: $GOOSE_TASK_PROMPT\" --interactive | tee -a \"$HOME/.goose.log\"
@@ -270,7 +300,15 @@ resource "coder_app" "goose" {
270300
exit 1
271301
fi
272302
273-
if [ "${var.experiment_use_screen}" = "true" ]; then
303+
if [ "${var.experiment_use_tmux}" = "true" ]; then
304+
if tmux has-session -t goose 2>/dev/null; then
305+
echo "Attaching to existing Goose tmux session." | tee -a "$HOME/.goose.log"
306+
tmux attach-session -t goose
307+
else
308+
echo "Starting a new Goose tmux session." | tee -a "$HOME/.goose.log"
309+
tmux new-session -s goose -c ${var.folder} "$GOOSE_CMD run --text \"Review goosehints. Your task: $GOOSE_TASK_PROMPT\" --interactive | tee -a \"$HOME/.goose.log\"; exec bash"
310+
fi
311+
elif [ "${var.experiment_use_screen}" = "true" ]; then
274312
# Check if session exists first
275313
if ! screen -list | grep -q "goose"; then
276314
echo "Error: No existing Goose session found. Please wait for the script to start it."

0 commit comments

Comments
 (0)