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

feat: implement tmux support for goose #437

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions goose/README.md
Original file line number Diff line number Diff line change
@@ -24,14 +24,14 @@ module "goose" {

### Prerequisites

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

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

## Examples

Your workspace must have `screen` installed to use this.
Your workspace must have `screen` or `tmux` installed to use this.

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

@@ -99,8 +99,9 @@ module "goose" {
# Enable experimental features
experiment_report_tasks = true
# Run Goose in the background
# Run Goose in the background (use only one of these options)
experiment_use_screen = true
# experiment_use_tmux = true
# Avoid configuring Goose manually
experiment_auto_configure = true
62 changes: 50 additions & 12 deletions goose/main.tf
Original file line number Diff line number Diff line change
@@ -54,6 +54,12 @@ variable "experiment_use_screen" {
default = false
}

variable "experiment_use_tmux" {
type = bool
description = "Whether to use tmux instead of screen for running Goose in the background."
default = false
}

variable "experiment_report_tasks" {
type = bool
description = "Whether to enable task reporting."
@@ -187,8 +193,42 @@ EOL
mkdir -p "$HOME/.config/goose"
echo "$GOOSE_SYSTEM_PROMPT" > "$HOME/.config/goose/.goosehints"
# Handle terminal multiplexer selection (tmux or screen)
if [ "${var.experiment_use_tmux}" = "true" ] && [ "${var.experiment_use_screen}" = "true" ]; then
echo "Error: Both experiment_use_tmux and experiment_use_screen cannot be true simultaneously."
echo "Please set only one of them to true."
exit 1
fi
# Determine goose command
if command_exists goose; then
GOOSE_CMD=goose
elif [ -f "$HOME/.local/bin/goose" ]; then
GOOSE_CMD="$HOME/.local/bin/goose"
else
echo "Error: Goose is not installed. Please enable install_goose or install it manually."
exit 1
fi
# Run with tmux if enabled
if [ "${var.experiment_use_tmux}" = "true" ]; then
echo "Running Goose in the background with tmux..."
# Check if tmux is installed
if ! command_exists tmux; then
echo "Error: tmux is not installed. Please install tmux manually."
exit 1
fi
touch "$HOME/.goose.log"
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
# Create a new tmux session in detached mode
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\""
# Run with screen if enabled
if [ "${var.experiment_use_screen}" = "true" ]; then
elif [ "${var.experiment_use_screen}" = "true" ]; then
echo "Running Goose in the background..."
# Check if screen is installed
@@ -217,16 +257,6 @@ EOL
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
# Determine goose command
if command_exists goose; then
GOOSE_CMD=goose
elif [ -f "$HOME/.local/bin/goose" ]; then
GOOSE_CMD="$HOME/.local/bin/goose"
else
echo "Error: Goose is not installed. Please enable install_goose or install it manually."
exit 1
fi
screen -U -dmS goose bash -c "
cd ${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\"
@@ -270,7 +300,15 @@ resource "coder_app" "goose" {
exit 1
fi
if [ "${var.experiment_use_screen}" = "true" ]; then
if [ "${var.experiment_use_tmux}" = "true" ]; then
if tmux has-session -t goose 2>/dev/null; then
echo "Attaching to existing Goose tmux session." | tee -a "$HOME/.goose.log"
tmux attach-session -t goose
else
echo "Starting a new Goose tmux session." | tee -a "$HOME/.goose.log"
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"
fi
elif [ "${var.experiment_use_screen}" = "true" ]; then
# Check if session exists first
if ! screen -list | grep -q "goose"; then
echo "Error: No existing Goose session found. Please wait for the script to start it."