Skip to content
Draft
Show file tree
Hide file tree
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
655 changes: 655 additions & 0 deletions TEST_PLAN.md

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions cmd/amux/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
tea "charm.land/bubbletea/v2"

"github.com/andyrewlee/amux/internal/app"
"github.com/andyrewlee/amux/internal/cli"
"github.com/andyrewlee/amux/internal/logging"
"github.com/andyrewlee/amux/internal/safego"
)
Expand All @@ -36,6 +37,12 @@ func main() {
fmt.Printf("amux %s (commit: %s, built: %s)\n", version, commit, date)
os.Exit(0)
}

// Handle CLI subcommands
if len(os.Args) > 1 {
os.Exit(cli.Run(os.Args[1:]))
}

// Initialize logging
home, _ := os.UserHomeDir()
logDir := filepath.Join(home, ".amux", "logs")
Expand Down
13 changes: 12 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,34 @@ require (
github.com/charmbracelet/x/ansi v0.11.3
github.com/creack/pty v1.1.21
github.com/fsnotify/fsnotify v1.9.0
github.com/gorilla/websocket v1.5.0
github.com/lrstanley/bubblezone v1.0.0
github.com/mattn/go-runewidth v0.0.19
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6
github.com/spf13/cobra v1.9.1
golang.org/x/term v0.39.0
)

require (
github.com/Masterminds/semver/v3 v3.2.1 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/charmbracelet/colorprofile v0.4.1 // indirect
github.com/charmbracelet/ultraviolet v0.0.0-20251212194010-b927aa605560 // indirect
github.com/charmbracelet/x/cellbuf v0.0.14 // indirect
github.com/charmbracelet/x/term v0.2.2 // indirect
github.com/charmbracelet/x/termios v0.1.1 // indirect
github.com/charmbracelet/x/windows v0.2.2 // indirect
github.com/clipperhouse/displaywidth v0.6.1 // indirect
github.com/clipperhouse/stringish v0.1.1 // indirect
github.com/clipperhouse/uax29/v2 v2.3.0 // indirect
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/lucasb-eyer/go-colorful v1.3.0 // indirect
github.com/muesli/cancelreader v0.2.2 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/spf13/pflag v1.0.6 // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
golang.org/x/sync v0.18.0 // indirect
golang.org/x/sys v0.38.0 // indirect
golang.org/x/sys v0.40.0 // indirect
golang.org/x/text v0.24.0 // indirect
)
32 changes: 30 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,22 @@ charm.land/bubbletea/v2 v2.0.0-rc.2.0.20251216153312-819e2e89c62e h1:tXwTmgGpwZT
charm.land/bubbletea/v2 v2.0.0-rc.2.0.20251216153312-819e2e89c62e/go.mod h1:pDM18flq3Z4njKZPA3zCvyVSSIJbMcoqlE82BdGUtL8=
charm.land/lipgloss/v2 v2.0.0-beta.3.0.20251205162909-7869489d8971 h1:xZFcNsJMiIDbFtWRyDmkKNk1sjojfaom4Zoe0cyH/8c=
charm.land/lipgloss/v2 v2.0.0-beta.3.0.20251205162909-7869489d8971/go.mod h1:i61Y3FmdbcBNSKa+pKB3DaE4uVQmBLMs/xlvRyHcXAE=
github.com/Masterminds/semver/v3 v3.2.1 h1:RN9w6+7QoMeJVGyfmbcgs28Br8cvmnucEXnY0rYXWg0=
github.com/Masterminds/semver/v3 v3.2.1/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ=
github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4=
github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
github.com/aymanbagabas/go-udiff v0.3.1 h1:LV+qyBQ2pqe0u42ZsUEtPiCaUoqgA9gYRDs3vj1nolY=
github.com/aymanbagabas/go-udiff v0.3.1/go.mod h1:G0fsKmG+P6ylD0r6N/KgQD/nWzgfnl8ZBcNLgcbrw8E=
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
github.com/charmbracelet/colorprofile v0.4.1 h1:a1lO03qTrSIRaK8c3JRxJDZOvhvIeSco3ej+ngLk1kk=
github.com/charmbracelet/colorprofile v0.4.1/go.mod h1:U1d9Dljmdf9DLegaJ0nGZNJvoXAhayhmidOdcBwAvKk=
github.com/charmbracelet/ultraviolet v0.0.0-20251212194010-b927aa605560 h1:j3PW2hypGoPKBy3ooKzW0TFxaxhyHK3NbkLLn4KeRFc=
github.com/charmbracelet/ultraviolet v0.0.0-20251212194010-b927aa605560/go.mod h1:VWATWLRwYP06VYCEur7FsNR2B1xAo7Y+xl1PTbd1ePc=
github.com/charmbracelet/x/ansi v0.11.3 h1:6DcVaqWI82BBVM/atTyq6yBoRLZFBsnoDoX9GCu2YOI=
github.com/charmbracelet/x/ansi v0.11.3/go.mod h1:yI7Zslym9tCJcedxz5+WBq+eUGMJT0bM06Fqy1/Y4dI=
github.com/charmbracelet/x/cellbuf v0.0.14 h1:lfjq/R7q0YSSU3XLvB0BkLWRxE9bKVKZ6n9HaAeFR24=
github.com/charmbracelet/x/cellbuf v0.0.14/go.mod h1:5//lJr5H8Z1kP1BC93BOGYXuGvIV3qjQXOGGpATT2s0=
github.com/charmbracelet/x/exp/golden v0.0.0-20250806222409-83e3a29d542f h1:pk6gmGpCE7F3FcjaOEKYriCvpmIN4+6OS/RD0vm4uIA=
github.com/charmbracelet/x/exp/golden v0.0.0-20250806222409-83e3a29d542f/go.mod h1:IfZAMTHB6XkZSeXUqriemErjAWCCzT0LwjKFYCZyw0I=
github.com/charmbracelet/x/term v0.2.2 h1:xVRT/S2ZcKdhhOuSP4t5cLi5o+JxklsoEObBSgfgZRk=
Expand All @@ -28,12 +34,21 @@ github.com/clipperhouse/stringish v0.1.1 h1:+NSqMOr3GR6k1FdRhhnXrLfztGzuG+VuFDfa
github.com/clipperhouse/stringish v0.1.1/go.mod h1:v/WhFtE1q0ovMta2+m+UbpZ+2/HEXNWYXQgCt4hdOzA=
github.com/clipperhouse/uax29/v2 v2.3.0 h1:SNdx9DVUqMoBuBoW3iLOj4FQv3dN5mDtuqwuhIGpJy4=
github.com/clipperhouse/uax29/v2 v2.3.0/go.mod h1:Wn1g7MK6OoeDT0vL+Q0SQLDz/KpfsVRgg6W7ihQeh4g=
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
github.com/creack/pty v1.1.21 h1:1/QdRyBaHHJP61QkWMXlOIBfsgdDeeKfK8SYVUWJKf0=
github.com/creack/pty v1.1.21/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4=
github.com/creack/pty v1.1.24 h1:bJrF4RRfyJnbTJqzRLHzcGaZK1NeM5kTC9jGgovnR1s=
github.com/creack/pty v1.1.24/go.mod h1:08sCNb52WyoAwi2QDyzUCTgcvVFhUzewun7wtTfvcwE=
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f h1:Y/CXytFA4m6baUTXGLOoWe4PQhGxaX0KpnayAqC48p4=
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f/go.mod h1:vw97MGsxSvLiUE2X8qFplwetxpGLQrlU1Q9AUEIzCaM=
github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k=
github.com/fsnotify/fsnotify v1.9.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0=
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/lrstanley/bubblezone v1.0.0 h1:bIpUaBilD42rAQwlg/4u5aTqVAt6DSRKYZuSdmkr8UA=
github.com/lrstanley/bubblezone v1.0.0/go.mod h1:kcTekA8HE/0Ll2bWzqHlhA2c513KDNLW7uDfDP4Mly8=
github.com/lucasb-eyer/go-colorful v1.3.0 h1:2/yBRLdWBZKrf7gB40FoiKfAWYQ0lqNcbuQwVHXptag=
github.com/lucasb-eyer/go-colorful v1.3.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
github.com/mattn/go-runewidth v0.0.19 h1:v++JhqYnZuu5jSKrk9RbgF5v4CGUjqRfBm05byFGLdw=
Expand All @@ -44,11 +59,24 @@ github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELU
github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo=
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/spf13/cobra v1.9.1 h1:CXSaggrXdbHK9CF+8ywj8Amf7PBRmPCOJugH954Nnlo=
github.com/spf13/cobra v1.9.1/go.mod h1:nDyEzZ8ogv936Cinf6g1RU9MRY64Ir93oCnqb9wxYW0=
github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o=
github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no=
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=
golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI=
golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo=
golang.org/x/sync v0.18.0 h1:kr88TuHDroi+UVf+0hZnirlk8o8T+4MrK6mr60WkH/I=
golang.org/x/sync v0.18.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
golang.org/x/sys v0.38.0 h1:3yZWxaJjBmCWXqhN1qh02AkOnCQ1poK6oF+a7xWL6Gc=
golang.org/x/sys v0.38.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.40.0 h1:DBZZqJ2Rkml6QMQsZywtnjnnGvHza6BTfYFWY9kjEWQ=
golang.org/x/sys v0.40.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
golang.org/x/term v0.39.0 h1:RclSuaJf32jOqZz74CkPA9qFuVTX7vhLlpfj/IGWlqY=
golang.org/x/term v0.39.0/go.mod h1:yxzUCTP/U+FzoxfdKmLaA0RV1WgE0VY7hXBwKtY/4ww=
golang.org/x/text v0.24.0 h1:dd5Bzh4yt5KYA8f9CJHCP4FB4D51c2c6JvN37xJJkJ0=
golang.org/x/text v0.24.0/go.mod h1:L8rBsPeo2pSS+xqN0d5u2ikmjtmoJbDBT1b7nHvFCdU=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
4 changes: 4 additions & 0 deletions internal/app/app_core.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ const (
DialogDeleteWorkspace = "delete_workspace"
DialogRemoveProject = "remove_project"
DialogSelectAssistant = "select_assistant"
DialogSelectRuntime = "select_runtime"
DialogSandboxAPIKey = "sandbox_api_key"
DialogQuit = "quit"
DialogCleanupTmux = "cleanup_tmux"
)
Expand All @@ -47,6 +49,8 @@ type App struct {
gitStatus GitStatusService
tmuxService *tmuxService
updateService UpdateService
sandboxManager *SandboxManager
runtimeProvider *RuntimeAgentProvider

// State
projects []data.Project
Expand Down
7 changes: 6 additions & 1 deletion internal/app/app_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ func New(version, commit, date string) (*App, error) {
workspaces := data.NewWorkspaceStore(cfg.Paths.MetadataRoot)
scripts := process.NewScriptRunner(cfg.PortStart, cfg.PortRangeSize)
workspaceService := newWorkspaceService(registry, workspaces, scripts, cfg.Paths.WorkspacesRoot)
sandboxManager := NewSandboxManager(cfg)
runtimeProvider := NewRuntimeAgentProvider(cfg, sandboxManager)

// Create status manager (callback will be nil, we use it for caching only)
statusManager := git.NewStatusManager(nil)
Expand Down Expand Up @@ -89,6 +91,8 @@ func New(version, commit, date string) (*App, error) {
gitStatus: gitStatus,
tmuxService: tmuxSvc,
updateService: updateSvc,
sandboxManager: sandboxManager,
runtimeProvider: runtimeProvider,
fileWatcher: fileWatcher,
fileWatcherCh: fileWatcherCh,
fileWatcherErr: fileWatcherErr,
Expand All @@ -97,7 +101,7 @@ func New(version, commit, date string) (*App, error) {
stateWatcherErr: stateWatcherErr,
layout: layout.NewManager(),
dashboard: dashboard.New(),
center: center.New(cfg),
center: center.New(cfg, runtimeProvider),
sidebar: sidebar.NewTabbedSidebar(),
sidebarTerminal: sidebar.NewTerminalModel(),
helpOverlay: common.NewHelpOverlay(),
Expand Down Expand Up @@ -138,6 +142,7 @@ func New(version, commit, date string) (*App, error) {
app.center.SetStyles(app.styles)
app.toast.SetStyles(app.styles)
app.helpOverlay.SetStyles(app.styles)
app.sidebarTerminal.SetTerminalFactory(runtimeProvider.CreateTerminalForWorkspace)
app.setKeymapHintsEnabled(cfg.UI.ShowKeymapHints)
// Propagate tmux config to components
app.center.SetTmuxConfig(tmuxOpts.ServerName, tmuxOpts.ConfigPath)
Expand Down
4 changes: 2 additions & 2 deletions internal/app/harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func newMonitorHarness(cfg *config.Config, opts HarnessOptions) *Harness {
}

func newCenterHarness(cfg *config.Config, opts HarnessOptions) *Harness {
centerModel := center.New(cfg)
centerModel := center.New(cfg, nil)
centerModel.SetShowKeymapHints(opts.ShowKeymapHints)

dash := dashboard.New()
Expand Down Expand Up @@ -167,7 +167,7 @@ func newCenterHarness(cfg *config.Config, opts HarnessOptions) *Harness {
}

func newSidebarHarness(cfg *config.Config, opts HarnessOptions) *Harness {
centerModel := center.New(cfg)
centerModel := center.New(cfg, nil)
centerModel.SetShowKeymapHints(opts.ShowKeymapHints)

dash := dashboard.New()
Expand Down
2 changes: 2 additions & 0 deletions internal/app/keybindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ type KeyMap struct {
NewAgentTab key.Binding
NewTerminalTab key.Binding
Help key.Binding
Monitor key.Binding
CopyMode key.Binding

// Dashboard
Enter key.Binding
Expand Down
86 changes: 86 additions & 0 deletions internal/app/runtime_provider.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package app

import (
"fmt"
"os"

"github.com/andyrewlee/amux/internal/config"
"github.com/andyrewlee/amux/internal/data"
"github.com/andyrewlee/amux/internal/pty"
"github.com/andyrewlee/amux/internal/tmux"
)

// RuntimeAgentProvider routes agent creation based on workspace runtime.
type RuntimeAgentProvider struct {
local *pty.AgentManager
sandbox *SandboxManager
}

func NewRuntimeAgentProvider(cfg *config.Config, sandboxManager *SandboxManager) *RuntimeAgentProvider {
return &RuntimeAgentProvider{
local: pty.NewAgentManager(cfg),
sandbox: sandboxManager,
}
}

func (p *RuntimeAgentProvider) CreateAgent(wt *data.Workspace, agentType pty.AgentType, rows, cols uint16) (*pty.Agent, error) {
if wt != nil && data.NormalizeRuntime(wt.Runtime) == data.RuntimeCloudSandbox {
return p.sandbox.CreateAgent(wt, agentType, rows, cols)
}
return p.local.CreateAgent(wt, agentType, "", rows, cols)
}

func (p *RuntimeAgentProvider) CreateAgentWithTags(wt *data.Workspace, agentType pty.AgentType, sessionName string, rows, cols uint16, tags tmux.SessionTags) (*pty.Agent, error) {
if wt != nil && data.NormalizeRuntime(wt.Runtime) == data.RuntimeCloudSandbox {
return p.sandbox.CreateAgent(wt, agentType, rows, cols)
}
return p.local.CreateAgentWithTags(wt, agentType, sessionName, rows, cols, tags)
}

func (p *RuntimeAgentProvider) CreateViewer(wt *data.Workspace, command string, rows, cols uint16) (*pty.Agent, error) {
if wt != nil && data.NormalizeRuntime(wt.Runtime) == data.RuntimeCloudSandbox {
return p.sandbox.CreateViewer(wt, command, rows, cols)
}
return p.local.CreateViewer(wt, command, "", rows, cols)
}

func (p *RuntimeAgentProvider) CreateViewerWithTags(wt *data.Workspace, command string, sessionName string, rows, cols uint16, tags tmux.SessionTags) (*pty.Agent, error) {
if wt != nil && data.NormalizeRuntime(wt.Runtime) == data.RuntimeCloudSandbox {
return p.sandbox.CreateViewer(wt, command, rows, cols)
}
return p.local.CreateViewerWithTags(wt, command, sessionName, rows, cols, tags)
}

func (p *RuntimeAgentProvider) CloseAgent(agent *pty.Agent) error {
if agent == nil {
return nil
}
// Local manager will remove it from its list; sandbox manager doesn't track agents.
if agent.Workspace != nil && data.NormalizeRuntime(agent.Workspace.Runtime) == data.RuntimeCloudSandbox {
if agent.Terminal != nil {
return agent.Terminal.Close()
}
return nil
}
return p.local.CloseAgent(agent)
}

func (p *RuntimeAgentProvider) CloseAll() {
p.local.CloseAll()
}

// CreateTerminalForWorkspace returns a shell terminal based on runtime.
func (p *RuntimeAgentProvider) CreateTerminalForWorkspace(wt *data.Workspace) (*pty.Terminal, error) {
if wt == nil {
return nil, fmt.Errorf("workspace is required")
}
if data.NormalizeRuntime(wt.Runtime) == data.RuntimeCloudSandbox {
return p.sandbox.CreateShell(wt)
}

shell := os.Getenv("SHELL")
if shell == "" {
shell = "/bin/bash"
}
return pty.New(shell, wt.Root, nil)
}
Loading
Loading