From 5b719b2f606c81dfc307e3377992786a33472545 Mon Sep 17 00:00:00 2001 From: Steve Yegge Date: Fri, 26 Dec 2025 00:52:25 -0800 Subject: [PATCH] Make gt witness attach infer rig from cwd when no arg provided MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Align witness attach command with crew at and refinery attach by using MaximumNArgs(1) instead of ExactArgs(1) and inferring the rig from the current working directory when no argument is provided. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- internal/cmd/witness.go | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/internal/cmd/witness.go b/internal/cmd/witness.go index 764e220c..d5d50599 100644 --- a/internal/cmd/witness.go +++ b/internal/cmd/witness.go @@ -13,6 +13,7 @@ import ( "github.com/steveyegge/gastown/internal/style" "github.com/steveyegge/gastown/internal/tmux" "github.com/steveyegge/gastown/internal/witness" + "github.com/steveyegge/gastown/internal/workspace" ) // Witness command flags @@ -67,7 +68,7 @@ Displays running state, monitored polecats, and statistics.`, } var witnessAttachCmd = &cobra.Command{ - Use: "attach ", + Use: "attach [rig]", Aliases: []string{"at"}, Short: "Attach to witness session", Long: `Attach to the Witness tmux session for a rig. @@ -75,8 +76,13 @@ var witnessAttachCmd = &cobra.Command{ Attaches the current terminal to the witness's tmux session. Detach with Ctrl-B D. -If the witness is not running, this will start it first.`, - Args: cobra.ExactArgs(1), +If the witness is not running, this will start it first. +If rig is not specified, infers it from the current directory. + +Examples: + gt witness attach gastown + gt witness attach # infer rig from cwd`, + Args: cobra.MaximumNArgs(1), RunE: runWitnessAttach, } @@ -342,7 +348,22 @@ func ensureWitnessSession(rigName string, r *rig.Rig) (bool, error) { } func runWitnessAttach(cmd *cobra.Command, args []string) error { - rigName := args[0] + rigName := "" + if len(args) > 0 { + rigName = args[0] + } + + // Infer rig from cwd if not provided + if rigName == "" { + townRoot, err := workspace.FindFromCwdOrError() + if err != nil { + return fmt.Errorf("not in a Gas Town workspace: %w", err) + } + rigName, err = inferRigFromCwd(townRoot) + if err != nil { + return fmt.Errorf("could not determine rig: %w\nUsage: gt witness attach ", err) + } + } // Verify rig exists _, r, err := getWitnessManager(rigName)