From b66aead35c8db31370d73ed7edc05cda3edc4058 Mon Sep 17 00:00:00 2001 From: 35C4n0r Date: Mon, 14 Jul 2025 22:04:23 +0530 Subject: [PATCH 01/18] feat: basic tmux module --- .gitignore | 3 + registry/anomaly/.images/avatar.jpeg | Bin 0 -> 9064 bytes registry/anomaly/README.md | 13 ++ registry/anomaly/modules/tmux/main.tf | 60 ++++++++ registry/anomaly/modules/tmux/run.sh | 193 ++++++++++++++++++++++++++ 5 files changed, 269 insertions(+) create mode 100644 registry/anomaly/.images/avatar.jpeg create mode 100644 registry/anomaly/README.md create mode 100644 registry/anomaly/modules/tmux/main.tf create mode 100755 registry/anomaly/modules/tmux/run.sh diff --git a/.gitignore b/.gitignore index 157c642a..55947fc5 100644 --- a/.gitignore +++ b/.gitignore @@ -145,3 +145,6 @@ dist # Generated credentials from google-github-actions/auth gha-creds-*.json + +# IDEs +.idea diff --git a/registry/anomaly/.images/avatar.jpeg b/registry/anomaly/.images/avatar.jpeg new file mode 100644 index 0000000000000000000000000000000000000000..ca1072d8dce0807e1688f16be0e3bddfa5d29ef7 GIT binary patch literal 9064 zcmbVwd00|;`!}GFl9uMN)NC=6K+{JQTvAIjOc0dKCC17n9S)WgSyooh4^2%^>bT%W zYQ*YVSvXNmGi{iamV!EF%dfC3mulK)edhf-^Sj>b{qucau1mm+a}L~}`?K8l`D^U2 zhp0l76%IEKhqanFZ=SWa72XE2wV6NP#(9y$LTH)Gisj2(TwPbL_F1!X)mnE~S7IP( ztuL8Ep{!UF92Vpk>f=xGLt9&0+swCdvbA;cb8~g``+t7?brofAh3-f9TcB5=F!pE* zd-Pv7(Fzm_jYa?cK>g1Hjj^!A;^tXdyu``b#e=YhNb;mm0|JAB*F|okMQx6z zGkE;?gv6vRg7h63nO_TGQO@3dx%&?s%sX0GRD7(Y6sfL}*4EWGG|Ci8m0F{1ZEHVw zUf1*81^vZK*Kgc3^xo>beaC1T9vS^ z_h-knJwy1#t0~Vs-p!TtcSZkq1r_{%RrJ3L`rq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-hIYPsk%4$p8wIM@vQ6D&nx&DwQd2b$(i70Is5DwRKwS(UO1$=G zrZ#6Pm_w8fP0C8}*0%)f&-3(q6mh<$!`BauY*~X!iO=zJV9)T6u-qAw75~XIezRRL z;71N)5kAbY-+cMkm~2~G#m9qFGg~fy+eLtr{(aN*p=PxHew^U$$<~qY0Z`+ z@WWeO@d~ZkC^#4nsXUwUI_jMf)L@^TCJbdKyGrB}l?!aB_fS&ExV{z)NoDh9}- zJ)=E*`0+6h zi!{ceubfIjlp<+1@4_ikg~XB0wd!)(@ucO`3EsooJ?}U{kL{`IyOXj!<7Xu`zf{x_ z7Z?QndQ#XcstTt5dT#T7n~FZA#2!=)K=Dh9pr)a4JPa@^hPa$@3BDNi^(DOz;>6G2 zG1*Rhc_y)Ti&ZQLq=aJ@`|-p9XL&>wJ%S>&v4x5elz=$kMnPpF3?iDYs76w}J)q2d ztcSCb(rYl9dT%i2A|0;Sq=#28V*I|C+s1@fCkAKn&{ zf(^~X7at!)X;i%pZ`2&yn_?UexGy!t$tLq$AKEm2p>B={4ptF<4A>CGxO0u>Mq&FZ zDbhwcb^wy*$}v?9=$LrTzjqTE&-o|UW|POdDR=zo0@cBD`}f-n(V#`RYJ`Xa$4XHb zL4ha%gXGV|AVfI^VGhYq$)HFS#EEA4+6>WU{^4j9q2Pd~+uYDgZXGi<3~w^I*vViu zWgKreCnj(xosXtLY&4zb!L^Hj9I&f`|D~PZ+8b!Ikn!f~PoEv7{aL2ZmEv{D#$n&+ z)g|`a$sZnsbSPi$=$y4QW){GtYJlT`(9^W@1Fj>YvKH5adqn7kJF$;#qJWJd}zD@3vt;N#{@q*{AV`d$d=M~PMwpd zH{AmBN7e_2k8Ut=076OGFlbSv|I-wH=Wgrv?1!Zk^Xb%WTFcmrC60V1GaZl00^lhIv z3r3a&4u5#}^Og14z0GbE&i2>?`J;0j0^G9Wmy8K2q /dev/null; then + print_info "tmux is already installed" + return 0 + fi + + print_info "Installing tmux..." + + # Detect package manager and install tmux + if command -v apt-get &> /dev/null; then + sudo apt-get update + sudo apt-get install -y tmux + elif command -v yum &> /dev/null; then + sudo yum install -y tmux + elif command -v dnf &> /dev/null; then + sudo dnf install -y tmux + elif command -v zypper &> /dev/null; then + sudo zypper install -y tmux + elif command -v apk &> /dev/null; then + sudo apk add tmux + elif command -v brew &> /dev/null; then + brew install tmux + else + print_error "No supported package manager found. Please install tmux manually." + exit 1 + fi + + print_info "tmux installed successfully" +} + +# Function to install Tmux Plugin Manager (TPM) +install_tpm() { + local tpm_dir="$HOME/.tmux/plugins/tpm" + + if [ -d "$tpm_dir" ]; then + print_info "TPM is already installed" + return 0 + fi + + print_info "Installing Tmux Plugin Manager (TPM)..." + + # Create plugins directory + mkdir -p "$HOME/.tmux/plugins" + + # Clone TPM repository + if command -v git &> /dev/null; then + git clone https://github.com/tmux-plugins/tpm "$tpm_dir" + print_info "TPM installed successfully" + else + print_error "Git is not installed. Please install git to use tmux plugins." + exit 1 + fi +} + +# Function to create tmux configuration +setup_tmux_config() { + print_info "Setting up tmux configuration..." + + local config_dir="$HOME/.tmux" + local config_file="$HOME/.tmux.conf" + + mkdir -p "$config_dir" + + cat > "$config_file" << EOF +# Tmux Configuration File + +# ============================================================================= +# PLUGIN CONFIGURATION +# ============================================================================= + +# List of plugins +set -g @plugin 'tmux-plugins/tpm' +set -g @plugin 'tmux-plugins/tmux-sensible' +set -g @plugin 'tmux-plugins/tmux-resurrect' +set -g @plugin 'tmux-plugins/tmux-continuum' + +# tmux-continuum configuration +set -g @continuum-restore 'on' +set -g @continuum-save-interval '$${SAVE_INTERVAL}' +set -g @continuum-boot 'on' +set -g status-right 'Continuum status: #{continuum_status}' + +# ============================================================================= +# KEY BINDINGS FOR SESSION MANAGEMENT +# ============================================================================= + +# Quick session save and restore +bind C-s run-shell "~/.tmux/plugins/tmux-resurrect/scripts/save.sh" +bind C-r run-shell "~/.tmux/plugins/tmux-resurrect/scripts/restore.sh" + +# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf) +run '~/.tmux/plugins/tpm/tpm' +EOF + + print_info "tmux configuration created at $config_file" +} + +# Function to install tmux plugins +install_plugins() { + print_info "Installing tmux plugins..." + + # Check if TPM is installed + if [ ! -d "$HOME/.tmux/plugins/tpm" ]; then + print_error "TPM is not installed. Cannot install plugins." + return 1 + fi + + # Install plugins using TPM + "$HOME/.tmux/plugins/tpm/bin/install_plugins" + + print_info "tmux plugins installed successfully" +} + +# Function to start tmux session +start_tmux_session() { + print_info "Setting up tmux session..." + + # Check if session already exists + if tmux has-session -t "$SESSION_NAME" 2>/dev/null; then + print_warning "Session '$SESSION_NAME' already exists" + return 0 + fi + + # Create new session + if [ -n "$STARTUP_COMMAND" ]; then + print_info "Creating tmux session '$SESSION_NAME' with startup command" + tmux new-session -d -s "$SESSION_NAME" "$STARTUP_COMMAND" + else + print_info "Creating tmux session '$SESSION_NAME'" + tmux new-session -d -s "$SESSION_NAME" + fi + + print_info "tmux session '$SESSION_NAME' created successfully" +} + +# Function to display usage information +show_usage_info() { + echo -e "$${BOLD}βœ… tmux setup complete!$${RESET}" + echo "" + echo -e "$${BOLD}πŸ“‹ Quick reference:$${RESET}" + echo " β€’ Attach to session: tmux attach -t $${SESSION_NAME}" + echo " β€’ Detach from session: Ctrl+a, then d" + echo " β€’ List sessions: tmux list-sessions" + echo " β€’ Kill session: tmux kill-session -t $${SESSION_NAME}" + echo "" + echo -e "$${BOLD}πŸ”„ Session persistence:$${RESET}" + echo " β€’ Auto-save interval: every $${SAVE_INTERVAL} minutes" + echo " β€’ Manual save: Ctrl+a, then Ctrl+s" + echo " β€’ Manual restore: Ctrl+a, then Ctrl+r" + echo " β€’ Sessions automatically restore on boot" + echo "" + echo -e "$${BOLD}πŸ”Œ Plugin management:$${RESET}" + echo " β€’ Install plugins: Ctrl+a, then I" + echo " β€’ Update plugins: Ctrl+a, then U" + echo " β€’ Uninstall plugins: Ctrl+a, then alt+u" + echo "" +} + +# Main execution +main() { + echo -e "$${BOLD}Setting up tmux with session persistence...$${RESET}" + echo "" + + # Install dependencies + install_tmux + install_tpm + + # Setup tmux configuration + setup_tmux_config + + # Install plugins + install_plugins + + # Start tmux session + start_tmux_session + + # Show usage information + show_usage_info +} + +# Run main function +main \ No newline at end of file From 3e894dcd8fa1abc1773f105d9ed4e46d0e1fb52f Mon Sep 17 00:00:00 2001 From: 35C4n0r Date: Mon, 14 Jul 2025 22:11:39 +0530 Subject: [PATCH 02/18] fix: echo statements --- registry/anomaly/modules/tmux/run.sh | 30 ++++++++++++++-------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/registry/anomaly/modules/tmux/run.sh b/registry/anomaly/modules/tmux/run.sh index d7f6c526..fb6bc55c 100755 --- a/registry/anomaly/modules/tmux/run.sh +++ b/registry/anomaly/modules/tmux/run.sh @@ -8,14 +8,14 @@ TMUX_CONFIG="${TMUX_CONFIG}" # Function to install tmux install_tmux() { - print_info "Checking for tmux installation..." + echo "Checking for tmux installation..." if command -v tmux &> /dev/null; then - print_info "tmux is already installed" + echo "tmux is already installed" return 0 fi - print_info "Installing tmux..." + echo "Installing tmux..." # Detect package manager and install tmux if command -v apt-get &> /dev/null; then @@ -36,7 +36,7 @@ install_tmux() { exit 1 fi - print_info "tmux installed successfully" + echo "tmux installed successfully" } # Function to install Tmux Plugin Manager (TPM) @@ -44,11 +44,11 @@ install_tpm() { local tpm_dir="$HOME/.tmux/plugins/tpm" if [ -d "$tpm_dir" ]; then - print_info "TPM is already installed" + echo "TPM is already installed" return 0 fi - print_info "Installing Tmux Plugin Manager (TPM)..." + echo "Installing Tmux Plugin Manager (TPM)..." # Create plugins directory mkdir -p "$HOME/.tmux/plugins" @@ -56,7 +56,7 @@ install_tpm() { # Clone TPM repository if command -v git &> /dev/null; then git clone https://github.com/tmux-plugins/tpm "$tpm_dir" - print_info "TPM installed successfully" + echo "TPM installed successfully" else print_error "Git is not installed. Please install git to use tmux plugins." exit 1 @@ -65,7 +65,7 @@ install_tpm() { # Function to create tmux configuration setup_tmux_config() { - print_info "Setting up tmux configuration..." + echo "Setting up tmux configuration..." local config_dir="$HOME/.tmux" local config_file="$HOME/.tmux.conf" @@ -103,12 +103,12 @@ bind C-r run-shell "~/.tmux/plugins/tmux-resurrect/scripts/restore.sh" run '~/.tmux/plugins/tpm/tpm' EOF - print_info "tmux configuration created at $config_file" + echo "tmux configuration created at $config_file" } # Function to install tmux plugins install_plugins() { - print_info "Installing tmux plugins..." + echo "Installing tmux plugins..." # Check if TPM is installed if [ ! -d "$HOME/.tmux/plugins/tpm" ]; then @@ -119,12 +119,12 @@ install_plugins() { # Install plugins using TPM "$HOME/.tmux/plugins/tpm/bin/install_plugins" - print_info "tmux plugins installed successfully" + echo "tmux plugins installed successfully" } # Function to start tmux session start_tmux_session() { - print_info "Setting up tmux session..." + echo "Setting up tmux session..." # Check if session already exists if tmux has-session -t "$SESSION_NAME" 2>/dev/null; then @@ -134,14 +134,14 @@ start_tmux_session() { # Create new session if [ -n "$STARTUP_COMMAND" ]; then - print_info "Creating tmux session '$SESSION_NAME' with startup command" + echo "Creating tmux session '$SESSION_NAME' with startup command" tmux new-session -d -s "$SESSION_NAME" "$STARTUP_COMMAND" else - print_info "Creating tmux session '$SESSION_NAME'" + echo "Creating tmux session '$SESSION_NAME'" tmux new-session -d -s "$SESSION_NAME" fi - print_info "tmux session '$SESSION_NAME' created successfully" + echo "tmux session '$SESSION_NAME' created successfully" } # Function to display usage information From b3680df5897190ed76026e2c992459c6640c9742 Mon Sep 17 00:00:00 2001 From: 35C4n0r Date: Mon, 14 Jul 2025 22:58:30 +0530 Subject: [PATCH 03/18] feat: replace echo with printf - better logs --- registry/anomaly/modules/tmux/run.sh | 95 ++++++++-------------------- 1 file changed, 25 insertions(+), 70 deletions(-) diff --git a/registry/anomaly/modules/tmux/run.sh b/registry/anomaly/modules/tmux/run.sh index fb6bc55c..9a571136 100755 --- a/registry/anomaly/modules/tmux/run.sh +++ b/registry/anomaly/modules/tmux/run.sh @@ -1,21 +1,21 @@ #!/usr/bin/env bash +BOLD='\033[0;1m' + # Convert templated variables to shell variables -SESSION_NAME="${SESSION_NAME}" -STARTUP_COMMAND="${STARTUP_COMMAND}" SAVE_INTERVAL="${SAVE_INTERVAL}" TMUX_CONFIG="${TMUX_CONFIG}" # Function to install tmux install_tmux() { - echo "Checking for tmux installation..." + printf "Checking for tmux installation\n" if command -v tmux &> /dev/null; then - echo "tmux is already installed" + printf "tmux is already installed \n\n" return 0 fi - echo "Installing tmux..." + printf "Installing tmux \n\n" # Detect package manager and install tmux if command -v apt-get &> /dev/null; then @@ -32,11 +32,11 @@ install_tmux() { elif command -v brew &> /dev/null; then brew install tmux else - print_error "No supported package manager found. Please install tmux manually." + printf "No supported package manager found. Please install tmux manually. \n" exit 1 fi - echo "tmux installed successfully" + printf "tmux installed successfully \n" } # Function to install Tmux Plugin Manager (TPM) @@ -44,11 +44,11 @@ install_tpm() { local tpm_dir="$HOME/.tmux/plugins/tpm" if [ -d "$tpm_dir" ]; then - echo "TPM is already installed" + printf "TPM is already installed" return 0 fi - echo "Installing Tmux Plugin Manager (TPM)..." + printf "Installing Tmux Plugin Manager (TPM) \n" # Create plugins directory mkdir -p "$HOME/.tmux/plugins" @@ -56,23 +56,27 @@ install_tpm() { # Clone TPM repository if command -v git &> /dev/null; then git clone https://github.com/tmux-plugins/tpm "$tpm_dir" - echo "TPM installed successfully" + printf "TPM installed successfully" else - print_error "Git is not installed. Please install git to use tmux plugins." + printf "Git is not installed. Please install git to use tmux plugins. \n" exit 1 fi } # Function to create tmux configuration setup_tmux_config() { - echo "Setting up tmux configuration..." + printf "Setting up tmux configuration \n" local config_dir="$HOME/.tmux" local config_file="$HOME/.tmux.conf" mkdir -p "$config_dir" - cat > "$config_file" << EOF + if [ -n "$TMUX_CONFIG" ]; then + printf "$TMUX_CONFIG" > "$config_file" + printf "$${BOLD}Custom tmux configuration applied at {$config_file} \n\n" + else + cat > "$config_file" << EOF # Tmux Configuration File # ============================================================================= @@ -102,75 +106,30 @@ bind C-r run-shell "~/.tmux/plugins/tmux-resurrect/scripts/restore.sh" # Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf) run '~/.tmux/plugins/tpm/tpm' EOF - - echo "tmux configuration created at $config_file" + printf "tmux configuration created at {$config_file} \n\n" + fi } # Function to install tmux plugins install_plugins() { - echo "Installing tmux plugins..." + printf "Installing tmux plugins" # Check if TPM is installed if [ ! -d "$HOME/.tmux/plugins/tpm" ]; then - print_error "TPM is not installed. Cannot install plugins." + printf "TPM is not installed. Cannot install plugins. \n" return 1 fi # Install plugins using TPM "$HOME/.tmux/plugins/tpm/bin/install_plugins" - echo "tmux plugins installed successfully" -} - -# Function to start tmux session -start_tmux_session() { - echo "Setting up tmux session..." - - # Check if session already exists - if tmux has-session -t "$SESSION_NAME" 2>/dev/null; then - print_warning "Session '$SESSION_NAME' already exists" - return 0 - fi - - # Create new session - if [ -n "$STARTUP_COMMAND" ]; then - echo "Creating tmux session '$SESSION_NAME' with startup command" - tmux new-session -d -s "$SESSION_NAME" "$STARTUP_COMMAND" - else - echo "Creating tmux session '$SESSION_NAME'" - tmux new-session -d -s "$SESSION_NAME" - fi - - echo "tmux session '$SESSION_NAME' created successfully" -} - -# Function to display usage information -show_usage_info() { - echo -e "$${BOLD}βœ… tmux setup complete!$${RESET}" - echo "" - echo -e "$${BOLD}πŸ“‹ Quick reference:$${RESET}" - echo " β€’ Attach to session: tmux attach -t $${SESSION_NAME}" - echo " β€’ Detach from session: Ctrl+a, then d" - echo " β€’ List sessions: tmux list-sessions" - echo " β€’ Kill session: tmux kill-session -t $${SESSION_NAME}" - echo "" - echo -e "$${BOLD}πŸ”„ Session persistence:$${RESET}" - echo " β€’ Auto-save interval: every $${SAVE_INTERVAL} minutes" - echo " β€’ Manual save: Ctrl+a, then Ctrl+s" - echo " β€’ Manual restore: Ctrl+a, then Ctrl+r" - echo " β€’ Sessions automatically restore on boot" - echo "" - echo -e "$${BOLD}πŸ”Œ Plugin management:$${RESET}" - echo " β€’ Install plugins: Ctrl+a, then I" - echo " β€’ Update plugins: Ctrl+a, then U" - echo " β€’ Uninstall plugins: Ctrl+a, then alt+u" - echo "" + printf "tmux plugins installed successfully \n" } # Main execution main() { - echo -e "$${BOLD}Setting up tmux with session persistence...$${RESET}" - echo "" + printf "$${BOLD} πŸ› οΈSetting up tmux with session persistence! \n\n" + printf "" # Install dependencies install_tmux @@ -182,11 +141,7 @@ main() { # Install plugins install_plugins - # Start tmux session - start_tmux_session - - # Show usage information - show_usage_info + printf "$${BOLD}βœ… tmux setup complete! \n\n" } # Run main function From 9d735c8f2cd2b59ed7898810b8631b67c4eccf15 Mon Sep 17 00:00:00 2001 From: 35C4n0r Date: Mon, 14 Jul 2025 23:13:54 +0530 Subject: [PATCH 04/18] feat: add test --- registry/anomaly/modules/tmux/main.test.ts | 35 ++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 registry/anomaly/modules/tmux/main.test.ts diff --git a/registry/anomaly/modules/tmux/main.test.ts b/registry/anomaly/modules/tmux/main.test.ts new file mode 100644 index 00000000..802147db --- /dev/null +++ b/registry/anomaly/modules/tmux/main.test.ts @@ -0,0 +1,35 @@ +import { describe, it, expect } from "bun:test"; +import { + runTerraformApply, + runTerraformInit, + testRequiredVariables, + findResourceInstance, +} from "~test"; +import path from "path"; + +const moduleDir = path.resolve(__dirname); + +const requiredVars = { + agent_id: "dummy-agent-id", +}; + +describe("tmux module", async () => { + await runTerraformInit(moduleDir); + + // 1. Required variables + testRequiredVariables(moduleDir, requiredVars); + + // 2. coder_script resource is created + it("creates coder_script resource", async () => { + const state = await runTerraformApply(moduleDir, requiredVars); + const scriptResource = findResourceInstance(state, "coder_script"); + expect(scriptResource).toBeDefined(); + expect(scriptResource.agent_id).toBe(requiredVars.agent_id); + + // check that the script contains expected lines + expect(scriptResource.script).toContain("Installing tmux"); + expect(scriptResource.script).toContain("Installing Tmux Plugin Manager (TPM)"); + expect(scriptResource.script).toContain("tmux configuration created at"); + expect(scriptResource.script).toContain("βœ… tmux setup complete!"); + }); +}); From b27641fdebdc2d1511f5bc19bd741fac0fd4e075 Mon Sep 17 00:00:00 2001 From: 35C4n0r Date: Mon, 14 Jul 2025 23:15:43 +0530 Subject: [PATCH 05/18] feat: update readme and format --- registry/anomaly/README.md | 8 +-- registry/anomaly/modules/tmux/README.md | 80 +++++++++++++++++++++++++ registry/anomaly/modules/tmux/main.tf | 25 +------- 3 files changed, 86 insertions(+), 27 deletions(-) create mode 100644 registry/anomaly/modules/tmux/README.md diff --git a/registry/anomaly/README.md b/registry/anomaly/README.md index 59f00242..9640f6ca 100644 --- a/registry/anomaly/README.md +++ b/registry/anomaly/README.md @@ -1,13 +1,13 @@ --- display_name: "Jay Kumar" -bio: "Brief description of who you are and what you do" +bio: "I'm a Software Engineer :)" avatar_url: "./.images/avatar.png" github: "35C4n0r" -linkedin: "https://www.linkedin.com/in/jaykum4r" # Optional -support_email: "work.jaykumar@gmail.co" # Optional +linkedin: "https://www.linkedin.com/in/jaykum4r" +support_email: "work.jaykumar@gmail.com" status: "community" --- # Your Name -Brief description of who you are and what you do. \ No newline at end of file +I'm a Software Engineer :) \ No newline at end of file diff --git a/registry/anomaly/modules/tmux/README.md b/registry/anomaly/modules/tmux/README.md new file mode 100644 index 00000000..b52d9c9a --- /dev/null +++ b/registry/anomaly/modules/tmux/README.md @@ -0,0 +1,80 @@ +# tmux Terraform Module + +This module provisions and configures [tmux](https://github.com/tmux/tmux) with session persistence and plugin support +for a Coder agent. It automatically installs tmux, the Tmux Plugin Manager (TPM), and a set of useful plugins, and sets +up a default or custom tmux configuration with session save/restore capabilities. + +## Features + +- Installs tmux if not already present +- Installs TPM (Tmux Plugin Manager) +- Configures tmux with plugins for sensible defaults, session persistence, and automation: + - `tmux-plugins/tpm` + - `tmux-plugins/tmux-sensible` + - `tmux-plugins/tmux-resurrect` + - `tmux-plugins/tmux-continuum` +- Supports custom tmux configuration +- Enables automatic session save/restore +- Configurable save interval + +## Usage + +```hcl +module "tmux" { + source = "path/to/this/module" + agent_id = coder_agent.example.id + tmux_config = "" # Optional: custom tmux.conf content + save_interval = 1 # Optional: save interval in minutes +} +``` + +## Input Variables + +| Name | Type | Description | Default | +| ------------- | ------ | ----------------------------------- | ------- | +| agent_id | string | The ID of a Coder agent. | n/a | +| tmux_config | string | Custom tmux configuration to apply. | "" | +| save_interval | number | Save interval (in minutes). | 1 | + +## How It Works + +- **tmux Installation:** + - Checks if tmux is installed; if not, installs it using the system's package manager (supports apt, yum, dnf, + zypper, apk, brew). +- **TPM Installation:** + - Installs the Tmux Plugin Manager (TPM) to `~/.tmux/plugins/tpm` if not already present. +- **tmux Configuration:** + - If `tmux_config` is provided, writes it to `~/.tmux.conf`. + - Otherwise, generates a default configuration with plugin support and session persistence (using tmux-resurrect and + tmux-continuum). + - Sets up key bindings for quick session save (`Ctrl+s`) and restore (`Ctrl+r`). +- **Plugin Installation:** + - Installs plugins via TPM. +- **Session Persistence:** + - Enables automatic session save/restore at the configured interval. + +## Example + +```hcl +module "tmux" { + source = "./registry/anomaly/modules/tmux" + agent_id = var.agent_id + tmux_config = <<-EOT + set -g mouse on + set -g history-limit 10000 + EOT + save_interval = 2 +} +``` + +## Outputs + +This module does not export outputs. + +## Notes + +- If you provide a custom `tmux_config`, it will completely replace the default configuration. Ensure you include plugin + and TPM initialization lines if you want plugin support. +- The script will attempt to install dependencies using `sudo` where required. +- If `git` is not installed, TPM installation will fail. +- If you are using custom config, you'll be responsible for setting up persistence diff --git a/registry/anomaly/modules/tmux/main.tf b/registry/anomaly/modules/tmux/main.tf index 3e2d5458..497c7c5e 100644 --- a/registry/anomaly/modules/tmux/main.tf +++ b/registry/anomaly/modules/tmux/main.tf @@ -14,30 +14,12 @@ variable "agent_id" { description = "The ID of a Coder agent." } -variable "session_name" { - type = string - description = "The name of the tmux session to create." - default = "workspace" -} - -variable "startup_command" { - type = string - description = "Command to run when the tmux session starts." - default = "" -} - variable "tmux_config" { type = string description = "Custom tmux configuration to apply." default = "" } -variable "auto_attach" { - type = bool - description = "Whether to automatically attach to the tmux session when the app starts." - default = true -} - variable "save_interval" { type = number description = "Save interval (in minutes)." @@ -49,11 +31,8 @@ resource "coder_script" "tmux" { display_name = "tmux" icon = "/icon/terminal.svg" script = templatefile("${path.module}/run.sh", { - SESSION_NAME = var.session_name - STARTUP_COMMAND = var.startup_command - TMUX_CONFIG = var.tmux_config - AUTO_ATTACH = var.auto_attach - SAVE_INTERVAL = var.save_interval + TMUX_CONFIG = var.tmux_config + SAVE_INTERVAL = var.save_interval }) run_on_start = true run_on_stop = false From f36ce2767ad1bccaa2848faf2f110053df847c5b Mon Sep 17 00:00:00 2001 From: 35C4n0r Date: Mon, 14 Jul 2025 23:19:18 +0530 Subject: [PATCH 06/18] feat: update readme --- registry/anomaly/modules/tmux/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/registry/anomaly/modules/tmux/README.md b/registry/anomaly/modules/tmux/README.md index b52d9c9a..7560670a 100644 --- a/registry/anomaly/modules/tmux/README.md +++ b/registry/anomaly/modules/tmux/README.md @@ -63,7 +63,6 @@ module "tmux" { set -g mouse on set -g history-limit 10000 EOT - save_interval = 2 } ``` From 8b05a5d2004eedc7d272a7829a74867e4f066bf1 Mon Sep 17 00:00:00 2001 From: 35C4n0r Date: Tue, 15 Jul 2025 00:47:46 +0530 Subject: [PATCH 07/18] feat: update readme --- registry/anomaly/modules/tmux/README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/registry/anomaly/modules/tmux/README.md b/registry/anomaly/modules/tmux/README.md index 7560670a..7991d4c3 100644 --- a/registry/anomaly/modules/tmux/README.md +++ b/registry/anomaly/modules/tmux/README.md @@ -14,7 +14,8 @@ up a default or custom tmux configuration with session save/restore capabilities - `tmux-plugins/tmux-resurrect` - `tmux-plugins/tmux-continuum` - Supports custom tmux configuration -- Enables automatic session save/restore +- Enables automatic session save +- To restore in case of server restart `prefix + ctrl+r` - Configurable save interval ## Usage @@ -76,4 +77,5 @@ This module does not export outputs. and TPM initialization lines if you want plugin support. - The script will attempt to install dependencies using `sudo` where required. - If `git` is not installed, TPM installation will fail. +- To restore in case of server restart `prefix + ctrl+r` - If you are using custom config, you'll be responsible for setting up persistence From dac1878aa143a4892ea53e07d3a916dd1c471378 Mon Sep 17 00:00:00 2001 From: 35C4n0r Date: Tue, 15 Jul 2025 01:15:35 +0530 Subject: [PATCH 08/18] ci: bun fmt --- registry/anomaly/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/registry/anomaly/README.md b/registry/anomaly/README.md index 9640f6ca..a9f074d2 100644 --- a/registry/anomaly/README.md +++ b/registry/anomaly/README.md @@ -10,4 +10,4 @@ status: "community" # Your Name -I'm a Software Engineer :) \ No newline at end of file +I'm a Software Engineer :) From 427586d8a73c6e802adecc6c3e3a0df7b74c3126 Mon Sep 17 00:00:00 2001 From: 35C4n0r Date: Wed, 16 Jul 2025 19:50:45 +0530 Subject: [PATCH 09/18] feat: add frontmatter --- registry/anomaly/modules/tmux/README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/registry/anomaly/modules/tmux/README.md b/registry/anomaly/modules/tmux/README.md index 7991d4c3..51ea4b6a 100644 --- a/registry/anomaly/modules/tmux/README.md +++ b/registry/anomaly/modules/tmux/README.md @@ -1,3 +1,11 @@ +--- +display_name: "Tmux" +description: "Tmux for coder agent :)" +icon: "../../../../.icons/tmux.svg" +verified: false +tags: ["tmux", "terminal", "persistent"] +--- + # tmux Terraform Module This module provisions and configures [tmux](https://github.com/tmux/tmux) with session persistence and plugin support From cf8014f4ace7d69332753fa72da8df363cf7b50d Mon Sep 17 00:00:00 2001 From: 35C4n0r Date: Wed, 16 Jul 2025 20:00:55 +0530 Subject: [PATCH 10/18] feat: add tmux svg --- .icons/tmux.svg | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 .icons/tmux.svg diff --git a/.icons/tmux.svg b/.icons/tmux.svg new file mode 100644 index 00000000..061cddd9 --- /dev/null +++ b/.icons/tmux.svg @@ -0,0 +1,18 @@ + + + + logomark + wordmark + Created with Sketch. + + + + + + + + + + + + + \ No newline at end of file From d9f8c95543737c0c182b301f71e5fcea403a498e Mon Sep 17 00:00:00 2001 From: 35C4n0r Date: Sat, 19 Jul 2025 10:19:42 +0530 Subject: [PATCH 11/18] feat: update readme --- registry/anomaly/modules/tmux/README.md | 31 +++++++------------------ 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/registry/anomaly/modules/tmux/README.md b/registry/anomaly/modules/tmux/README.md index 51ea4b6a..ea072c7f 100644 --- a/registry/anomaly/modules/tmux/README.md +++ b/registry/anomaly/modules/tmux/README.md @@ -6,7 +6,7 @@ verified: false tags: ["tmux", "terminal", "persistent"] --- -# tmux Terraform Module +# tmux This module provisions and configures [tmux](https://github.com/tmux/tmux) with session persistence and plugin support for a Coder agent. It automatically installs tmux, the Tmux Plugin Manager (TPM), and a set of useful plugins, and sets @@ -28,7 +28,7 @@ up a default or custom tmux configuration with session save/restore capabilities ## Usage -```hcl +```tf module "tmux" { source = "path/to/this/module" agent_id = coder_agent.example.id @@ -37,14 +37,6 @@ module "tmux" { } ``` -## Input Variables - -| Name | Type | Description | Default | -| ------------- | ------ | ----------------------------------- | ------- | -| agent_id | string | The ID of a Coder agent. | n/a | -| tmux_config | string | Custom tmux configuration to apply. | "" | -| save_interval | number | Save interval (in minutes). | 1 | - ## How It Works - **tmux Installation:** @@ -64,7 +56,7 @@ module "tmux" { ## Example -```hcl +```tf module "tmux" { source = "./registry/anomaly/modules/tmux" agent_id = var.agent_id @@ -75,15 +67,10 @@ module "tmux" { } ``` -## Outputs - -This module does not export outputs. - -## Notes - -- If you provide a custom `tmux_config`, it will completely replace the default configuration. Ensure you include plugin +> [!NOTE] +> - If you provide a custom `tmux_config`, it will completely replace the default configuration. Ensure you include plugin and TPM initialization lines if you want plugin support. -- The script will attempt to install dependencies using `sudo` where required. -- If `git` is not installed, TPM installation will fail. -- To restore in case of server restart `prefix + ctrl+r` -- If you are using custom config, you'll be responsible for setting up persistence +> - The script will attempt to install dependencies using `sudo` where required. +> - If `git` is not installed, TPM installation will fail. +> - To restore in case of server restart `prefix + ctrl+r` +> - If you are using custom config, you'll be responsible for setting up persistence From 0c243cc0bf473b197ca8c8f8083e31a1dd87354d Mon Sep 17 00:00:00 2001 From: 35C4n0r Date: Tue, 22 Jul 2025 12:04:33 +0530 Subject: [PATCH 12/18] feat: start.sh --- .../anomaly/modules/tmux/scripts/start.sh | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100755 registry/anomaly/modules/tmux/scripts/start.sh diff --git a/registry/anomaly/modules/tmux/scripts/start.sh b/registry/anomaly/modules/tmux/scripts/start.sh new file mode 100755 index 00000000..0dcb14e2 --- /dev/null +++ b/registry/anomaly/modules/tmux/scripts/start.sh @@ -0,0 +1,59 @@ +#!/usr/bin/env bash + +# Convert templated variables to shell variables +SESSIONS='${SESSIONS}' + +# Function to check if tmux is installed +check_tmux() { + if ! command -v tmux &> /dev/null; then + echo "tmux is not installed. Please run the tmux setup script first." + exit 1 + fi +} + +# Function to handle a single session +handle_session() { + local session_name="$1" + + # Check if the session exists + if tmux has-session -t "$session_name" 2>/dev/null; then + echo "Session '$session_name' exists, attaching to it..." + tmux attach-session -t "$session_name" + else + echo "Session '$session_name' does not exist, creating it..." + tmux new-session -d -s "$session_name" + tmux attach-session -t "$session_name" + fi +} + +# Main function +main() { + # Check if tmux is installed + check_tmux + + # If no sessions are specified, create or attach to a default session + if [ "$SESSIONS" = "[]" ] || [ -z "$SESSIONS" ]; then + echo "No sessions specified, using default session..." + handle_session "default" + exit 0 + fi + + # Parse the JSON array by removing brackets and quotes, then split by commas + # Remove the opening and closing brackets + sessions_str=$${SESSIONS#[} + sessions_str=$${sessions_str%]} + + # Remove quotes and split by commas + sessions_str=$(echo "$sessions_str" | sed s/\"//g) + IFS=',' read -ra SESSION_ARRAY <<< "$sessions_str" + + # Handle each session + for session in "$${SESSION_ARRAY[@]}"; do + # Trim whitespace + session=$(echo "$session" | sed s/^[[:space:]]*//\;s/[[:space:]]*$//) + handle_session "$session" + done +} + +# Run the main function +main From a1b4848fb9913a0899a371e09189409ab212131c Mon Sep 17 00:00:00 2001 From: 35C4n0r Date: Tue, 22 Jul 2025 12:12:49 +0530 Subject: [PATCH 13/18] feat: enhance tmux session management and configuration --- registry/anomaly/modules/tmux/main.tf | 43 ++++++++++++++++++- .../anomaly/modules/tmux/{ => scripts}/run.sh | 5 +++ .../anomaly/modules/tmux/scripts/start.sh | 26 +---------- 3 files changed, 48 insertions(+), 26 deletions(-) rename registry/anomaly/modules/tmux/{ => scripts}/run.sh (94%) diff --git a/registry/anomaly/modules/tmux/main.tf b/registry/anomaly/modules/tmux/main.tf index 497c7c5e..e2c1a7db 100644 --- a/registry/anomaly/modules/tmux/main.tf +++ b/registry/anomaly/modules/tmux/main.tf @@ -26,14 +26,53 @@ variable "save_interval" { default = 1 } +variable "order" { + type = number + description = "The order determines the position of app in the UI presentation. The lowest order is shown first and apps with equal order are sorted by name (ascending order)." + default = null +} + +variable "group" { + type = string + description = "The name of a group that this app belongs to." + default = null +} + +variable "icon" { + type = string + description = "The icon to use for the app." + default = "/icon/tmux.svg" +} + +variable "sessions" { + type = list(string) + description = "List of tmux sessions to create or start." + default = ["default"] +} + resource "coder_script" "tmux" { agent_id = var.agent_id display_name = "tmux" icon = "/icon/terminal.svg" - script = templatefile("${path.module}/run.sh", { + script = templatefile("${path.module}/scripts/run.sh", { TMUX_CONFIG = var.tmux_config SAVE_INTERVAL = var.save_interval }) run_on_start = true run_on_stop = false -} \ No newline at end of file +} + +resource "coder_app" "tmux_sessions" { + for_each = toset(var.sessions) + + agent_id = var.agent_id + slug = "tmux-${each.value}" + display_name = "tmux - ${each.value}" + icon = var.icon + order = var.order + group = var.group + + command = templatefile("${path.module}/scripts/start.sh", { + SESSION_NAME = each.value + }) +} diff --git a/registry/anomaly/modules/tmux/run.sh b/registry/anomaly/modules/tmux/scripts/run.sh similarity index 94% rename from registry/anomaly/modules/tmux/run.sh rename to registry/anomaly/modules/tmux/scripts/run.sh index 9a571136..90c0d84b 100755 --- a/registry/anomaly/modules/tmux/run.sh +++ b/registry/anomaly/modules/tmux/scripts/run.sh @@ -142,6 +142,11 @@ main() { install_plugins printf "$${BOLD}βœ… tmux setup complete! \n\n" + + printf "$${BOLD} Attempting to restore sessions\n" + tmux new-session -d \; source-file ~/.tmux.conf \; run-shell '~/.tmux/plugins/tmux-resurrect/scripts/restore.sh' + printf "$${BOLD} Sessions restored: -> %s\n" "$(tmux ls)" + } # Run main function diff --git a/registry/anomaly/modules/tmux/scripts/start.sh b/registry/anomaly/modules/tmux/scripts/start.sh index 0dcb14e2..4638c8f7 100755 --- a/registry/anomaly/modules/tmux/scripts/start.sh +++ b/registry/anomaly/modules/tmux/scripts/start.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # Convert templated variables to shell variables -SESSIONS='${SESSIONS}' +SESSION_NAME='${SESSION_NAME}' # Function to check if tmux is installed check_tmux() { @@ -30,29 +30,7 @@ handle_session() { main() { # Check if tmux is installed check_tmux - - # If no sessions are specified, create or attach to a default session - if [ "$SESSIONS" = "[]" ] || [ -z "$SESSIONS" ]; then - echo "No sessions specified, using default session..." - handle_session "default" - exit 0 - fi - - # Parse the JSON array by removing brackets and quotes, then split by commas - # Remove the opening and closing brackets - sessions_str=$${SESSIONS#[} - sessions_str=$${sessions_str%]} - - # Remove quotes and split by commas - sessions_str=$(echo "$sessions_str" | sed s/\"//g) - IFS=',' read -ra SESSION_ARRAY <<< "$sessions_str" - - # Handle each session - for session in "$${SESSION_ARRAY[@]}"; do - # Trim whitespace - session=$(echo "$session" | sed s/^[[:space:]]*//\;s/[[:space:]]*$//) - handle_session "$session" - done + handle_session "${SESSION_NAME}" } # Run the main function From 6d0c19d6b4b33e87e72fa262689be4450a4defdb Mon Sep 17 00:00:00 2001 From: 35C4n0r Date: Tue, 22 Jul 2025 12:18:13 +0530 Subject: [PATCH 14/18] feat: add multi-session support for tmux in Coder UI --- registry/anomaly/modules/tmux/README.md | 33 ++++++++++++++++++------- registry/anomaly/modules/tmux/main.tf | 4 +-- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/registry/anomaly/modules/tmux/README.md b/registry/anomaly/modules/tmux/README.md index ea072c7f..240f3ffd 100644 --- a/registry/anomaly/modules/tmux/README.md +++ b/registry/anomaly/modules/tmux/README.md @@ -23,8 +23,8 @@ up a default or custom tmux configuration with session save/restore capabilities - `tmux-plugins/tmux-continuum` - Supports custom tmux configuration - Enables automatic session save -- To restore in case of server restart `prefix + ctrl+r` - Configurable save interval +- **Supports multiple named tmux sessions, each as a separate app in the Coder UI** ## Usage @@ -32,11 +32,21 @@ up a default or custom tmux configuration with session save/restore capabilities module "tmux" { source = "path/to/this/module" agent_id = coder_agent.example.id - tmux_config = "" # Optional: custom tmux.conf content - save_interval = 1 # Optional: save interval in minutes + tmux_config = "" # Optional: custom tmux.conf content + save_interval = 1 # Optional: save interval in minutes + sessions = ["default", "dev", "ops"] # Optional: list of tmux sessions + order = 1 # Optional: UI order + group = "Terminal" # Optional: UI group + icon = "/icon/tmux.svg" # Optional: app icon } ``` +## Multi-Session Support + +This module can provision multiple tmux sessions, each as a separate app in the Coder UI. Use the `sessions` variable to specify a list of session names. For each session, a `coder_app` is created, allowing you to launch or attach to that session directly from the UI. + +- **sessions**: List of tmux session names (default: `["default"]`). + ## How It Works - **tmux Installation:** @@ -58,19 +68,24 @@ module "tmux" { ```tf module "tmux" { - source = "./registry/anomaly/modules/tmux" - agent_id = var.agent_id - tmux_config = <<-EOT + source = "./registry/anomaly/modules/tmux" + agent_id = var.agent_id + sessions = ["default", "dev", "anomaly"] + tmux_config = <<-EOT set -g mouse on set -g history-limit 10000 EOT + group = "Terminal" + order = 2 } ``` > [!NOTE] +> > - If you provide a custom `tmux_config`, it will completely replace the default configuration. Ensure you include plugin - and TPM initialization lines if you want plugin support. +> and TPM initialization lines if you want plugin support and session persistence. > - The script will attempt to install dependencies using `sudo` where required. > - If `git` is not installed, TPM installation will fail. -> - To restore in case of server restart `prefix + ctrl+r` -> - If you are using custom config, you'll be responsible for setting up persistence +> - If you are using custom config, you'll be responsible for setting up persistence and plugins. +> - The `order`, `group`, and `icon` variables allow you to customize how tmux apps appear in the Coder UI. +> - In case of session restart or shh reconnection, the tmux session will be automatically restored :) diff --git a/registry/anomaly/modules/tmux/main.tf b/registry/anomaly/modules/tmux/main.tf index e2c1a7db..36f8471f 100644 --- a/registry/anomaly/modules/tmux/main.tf +++ b/registry/anomaly/modules/tmux/main.tf @@ -45,9 +45,9 @@ variable "icon" { } variable "sessions" { - type = list(string) + type = list(string) description = "List of tmux sessions to create or start." - default = ["default"] + default = ["default"] } resource "coder_script" "tmux" { From 9f32bd56c237d4e074a734fe263c039eed5c0e94 Mon Sep 17 00:00:00 2001 From: 35C4n0r Date: Thu, 24 Jul 2025 07:55:17 +0530 Subject: [PATCH 15/18] docs: change NOTE to IMPORTANT and add tmux icon --- .icons/tmux.svg | 19 +------------------ registry/anomaly/modules/tmux/README.md | 2 +- 2 files changed, 2 insertions(+), 19 deletions(-) diff --git a/.icons/tmux.svg b/.icons/tmux.svg index 061cddd9..ac0174ed 100644 --- a/.icons/tmux.svg +++ b/.icons/tmux.svg @@ -1,18 +1 @@ - - - - logomark + wordmark - Created with Sketch. - - - - - - - - - - - - - \ No newline at end of file + \ No newline at end of file diff --git a/registry/anomaly/modules/tmux/README.md b/registry/anomaly/modules/tmux/README.md index 240f3ffd..e9b40f28 100644 --- a/registry/anomaly/modules/tmux/README.md +++ b/registry/anomaly/modules/tmux/README.md @@ -80,7 +80,7 @@ module "tmux" { } ``` -> [!NOTE] +> [!IMPORTANT] > > - If you provide a custom `tmux_config`, it will completely replace the default configuration. Ensure you include plugin > and TPM initialization lines if you want plugin support and session persistence. From c82fe73727c425d2b588652ef8fac3a6767396af Mon Sep 17 00:00:00 2001 From: 35C4n0r Date: Thu, 24 Jul 2025 15:30:33 +0530 Subject: [PATCH 16/18] docs: update README with module source and example for tmux --- registry/anomaly/modules/tmux/README.md | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/registry/anomaly/modules/tmux/README.md b/registry/anomaly/modules/tmux/README.md index e9b40f28..cd8d275e 100644 --- a/registry/anomaly/modules/tmux/README.md +++ b/registry/anomaly/modules/tmux/README.md @@ -12,6 +12,14 @@ This module provisions and configures [tmux](https://github.com/tmux/tmux) with for a Coder agent. It automatically installs tmux, the Tmux Plugin Manager (TPM), and a set of useful plugins, and sets up a default or custom tmux configuration with session save/restore capabilities. +```tf +module "tmux" { + source = "registry.coder.com/anomaly/aider/coder" + version = "1.0.0" + agent_id = coder_agent.example.id +} +``` + ## Features - Installs tmux if not already present @@ -30,7 +38,7 @@ up a default or custom tmux configuration with session save/restore capabilities ```tf module "tmux" { - source = "path/to/this/module" + source = "registry.coder.com/anomaly/aider/coder" agent_id = coder_agent.example.id tmux_config = "" # Optional: custom tmux.conf content save_interval = 1 # Optional: save interval in minutes @@ -68,7 +76,7 @@ This module can provision multiple tmux sessions, each as a separate app in the ```tf module "tmux" { - source = "./registry/anomaly/modules/tmux" + source = "registry.coder.com/anomaly/aider/coder" agent_id = var.agent_id sessions = ["default", "dev", "anomaly"] tmux_config = <<-EOT From 41c86360df410d29fca39efeb168e3b8fde60334 Mon Sep 17 00:00:00 2001 From: 35C4n0r Date: Thu, 24 Jul 2025 21:33:15 +0530 Subject: [PATCH 17/18] fix: add versions --- registry/anomaly/modules/tmux/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/registry/anomaly/modules/tmux/README.md b/registry/anomaly/modules/tmux/README.md index cd8d275e..1d9a1cd3 100644 --- a/registry/anomaly/modules/tmux/README.md +++ b/registry/anomaly/modules/tmux/README.md @@ -39,6 +39,7 @@ module "tmux" { ```tf module "tmux" { source = "registry.coder.com/anomaly/aider/coder" + version = "1.0.0" agent_id = coder_agent.example.id tmux_config = "" # Optional: custom tmux.conf content save_interval = 1 # Optional: save interval in minutes @@ -77,6 +78,7 @@ This module can provision multiple tmux sessions, each as a separate app in the ```tf module "tmux" { source = "registry.coder.com/anomaly/aider/coder" + version = "1.0.0" agent_id = var.agent_id sessions = ["default", "dev", "anomaly"] tmux_config = <<-EOT From fddc6ea736b2c98b9adf2a9794fedf48055efd4e Mon Sep 17 00:00:00 2001 From: 35C4n0r Date: Fri, 25 Jul 2025 01:11:46 +0530 Subject: [PATCH 18/18] fix: fix README.md --- registry/anomaly/modules/tmux/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/registry/anomaly/modules/tmux/README.md b/registry/anomaly/modules/tmux/README.md index 1d9a1cd3..e0bdd5f2 100644 --- a/registry/anomaly/modules/tmux/README.md +++ b/registry/anomaly/modules/tmux/README.md @@ -14,7 +14,7 @@ up a default or custom tmux configuration with session save/restore capabilities ```tf module "tmux" { - source = "registry.coder.com/anomaly/aider/coder" + source = "registry.coder.com/anomaly/tmux/coder" version = "1.0.0" agent_id = coder_agent.example.id } @@ -38,7 +38,7 @@ module "tmux" { ```tf module "tmux" { - source = "registry.coder.com/anomaly/aider/coder" + source = "registry.coder.com/anomaly/tmux/coder" version = "1.0.0" agent_id = coder_agent.example.id tmux_config = "" # Optional: custom tmux.conf content @@ -77,7 +77,7 @@ This module can provision multiple tmux sessions, each as a separate app in the ```tf module "tmux" { - source = "registry.coder.com/anomaly/aider/coder" + source = "registry.coder.com/anomaly/tmux/coder" version = "1.0.0" agent_id = var.agent_id sessions = ["default", "dev", "anomaly"]