You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(goose): Add tmux support and Session Name variable to Goose (#113)
- Add Multiplexer, and tmux with mouse support.
- Add check to make sure tmux and screen are not set at the same time.
- Add Variable for session name so the name of the screen or tmux
session can be customized.
Tested in dev environment.
Reference: #31
Copy file name to clipboardExpand all lines: registry/coder/modules/goose/README.md
+11-7Lines changed: 11 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,7 +14,7 @@ Run the [Goose](https://block.github.io/goose/) agent in your workspace to gener
14
14
```tf
15
15
module "goose" {
16
16
source = "registry.coder.com/coder/goose/coder"
17
-
version = "1.1.1"
17
+
version = "1.2.0"
18
18
agent_id = coder_agent.example.id
19
19
folder = "/home/coder"
20
20
install_goose = true
@@ -24,14 +24,14 @@ module "goose" {
24
24
25
25
## Prerequisites
26
26
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
28
28
- You must add the [Coder Login](https://registry.coder.com/modules/coder-login) module to your template
29
29
30
30
The `codercom/oss-dogfood:latest` container image can be used for testing on container-based workspaces.
31
31
32
32
## Examples
33
33
34
-
Your workspace must have `screen` installed to use this.
34
+
Your workspace must have `screen`or `tmux`installed to use the background session functionality.
35
35
36
36
### Run in the background and report tasks (Experimental)
37
37
@@ -90,7 +90,7 @@ resource "coder_agent" "main" {
90
90
module "goose" {
91
91
count = data.coder_workspace.me.start_count
92
92
source = "registry.coder.com/coder/goose/coder"
93
-
version = "1.1.1"
93
+
version = "1.2.0"
94
94
agent_id = coder_agent.example.id
95
95
folder = "/home/coder"
96
96
install_goose = true
@@ -99,8 +99,12 @@ module "goose" {
99
99
# Enable experimental features
100
100
experiment_report_tasks = true
101
101
102
-
# Run Goose in the background
102
+
# Run Goose in the background with screen (pick one: screen or tmux)
103
103
experiment_use_screen = true
104
+
# experiment_use_tmux = true # Alternative: use tmux instead of screen
105
+
106
+
# Optional: customize the session name (defaults to "goose")
107
+
# session_name = "goose-session"
104
108
105
109
# Avoid configuring Goose manually
106
110
experiment_auto_configure = true
@@ -143,12 +147,12 @@ Note: The indentation in the heredoc is preserved, so you can write the YAML nat
143
147
144
148
## Run standalone
145
149
146
-
Run Goose as a standalone app in your workspace. This will install Goose and run it directly without using screen or any task reporting to the Coder UI.
150
+
Run Goose as a standalone app in your workspace. This will install Goose and run it directly without using screen or tmux, and without any task reporting to the Coder UI.
if [ "${var.experiment_use_screen}" = "true" ]; then
202
+
# Handle terminal multiplexer selection (tmux or screen)
203
+
if [ "${var.experiment_use_tmux}" = "true" ] && [ "${var.experiment_use_screen}" = "true" ]; then
204
+
echo "Error: Both experiment_use_tmux and experiment_use_screen cannot be true simultaneously."
205
+
echo "Please set only one of them to true."
206
+
exit 1
207
+
fi
208
+
209
+
# Determine goose command
210
+
if command_exists goose; then
211
+
GOOSE_CMD=goose
212
+
elif [ -f "$HOME/.local/bin/goose" ]; then
213
+
GOOSE_CMD="$HOME/.local/bin/goose"
214
+
else
215
+
echo "Error: Goose is not installed. Please enable install_goose or install it manually."
216
+
exit 1
217
+
fi
218
+
219
+
# Run with tmux if enabled
220
+
if [ "${var.experiment_use_tmux}" = "true" ]; then
221
+
echo "Running Goose in the background with tmux..."
222
+
223
+
# Check if tmux is installed
224
+
if ! command_exists tmux; then
225
+
echo "Error: tmux is not installed. Please install tmux manually."
226
+
exit 1
227
+
fi
228
+
229
+
touch "$HOME/.goose.log"
230
+
231
+
export LANG=en_US.UTF-8
232
+
export LC_ALL=en_US.UTF-8
233
+
234
+
# Configure tmux for shared sessions
235
+
if [ ! -f "$HOME/.tmux.conf" ]; then
236
+
echo "Creating ~/.tmux.conf with shared session settings..."
237
+
echo "set -g mouse on" > "$HOME/.tmux.conf"
238
+
fi
239
+
240
+
if ! grep -q "^set -g mouse on$" "$HOME/.tmux.conf"; then
241
+
echo "Adding 'set -g mouse on' to ~/.tmux.conf..."
242
+
echo "set -g mouse on" >> "$HOME/.tmux.conf"
243
+
fi
244
+
245
+
# Create a new tmux session in detached mode
246
+
tmux new-session -d -s ${var.session_name} -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\"; exec bash"
247
+
elif [ "${var.experiment_use_screen}" = "true" ]; then
192
248
echo "Running Goose in the background..."
193
249
194
250
# Check if screen is installed
@@ -217,31 +273,11 @@ EOL
217
273
export LANG=en_US.UTF-8
218
274
export LC_ALL=en_US.UTF-8
219
275
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
-
230
-
screen -U -dmS goose bash -c "
276
+
screen -U -dmS ${var.session_name} bash -c "
231
277
cd ${var.folder}
232
278
\"$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\"
233
279
/bin/bash
234
280
"
235
-
else
236
-
# Check if goose is installed before running
237
-
if command_exists goose; then
238
-
GOOSE_CMD=goose
239
-
elif [ -f "$HOME/.local/bin/goose" ]; then
240
-
GOOSE_CMD="$HOME/.local/bin/goose"
241
-
else
242
-
echo "Error: Goose is not installed. Please enable install_goose or install it manually."
if [ "${var.experiment_use_screen}" = "true" ]; then
309
+
export LANG=en_US.UTF-8
310
+
export LC_ALL=en_US.UTF-8
311
+
312
+
if [ "${var.experiment_use_tmux}" = "true" ]; then
313
+
if tmux has-session -t ${var.session_name} 2>/dev/null; then
314
+
echo "Attaching to existing Goose tmux session." | tee -a "$HOME/.goose.log"
315
+
tmux attach-session -t ${var.session_name}
316
+
else
317
+
echo "Starting a new Goose tmux session." | tee -a "$HOME/.goose.log"
318
+
tmux new-session -s ${var.session_name} -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\"; exec bash"
319
+
fi
320
+
elif [ "${var.experiment_use_screen}" = "true" ]; then
274
321
# Check if session exists first
275
-
if ! screen -list | grep -q "goose"; then
322
+
if ! screen -list | grep -q "${var.session_name}"; then
276
323
echo "Error: No existing Goose session found. Please wait for the script to start it."
277
324
exit 1
278
325
fi
279
326
# Only attach to existing session
280
-
screen -xRR goose
327
+
screen -xRR ${var.session_name}
281
328
else
282
329
cd ${var.folder}
283
-
export LANG=en_US.UTF-8
284
-
export LC_ALL=en_US.UTF-8
285
330
"$GOOSE_CMD" run --text "Review goosehints. Your task: $GOOSE_TASK_PROMPT" --interactive
0 commit comments