From ea5d72a07b31efc108ef6bb1b5df57c36b85e229 Mon Sep 17 00:00:00 2001 From: beads/crew/emma Date: Mon, 12 Jan 2026 00:35:40 -0800 Subject: [PATCH] feat(crew): add --debug flag to crew at command Add --debug flag for troubleshooting crew attach issues. Shows: - Current working directory - Detected rig and crew name - Computed session ID - Whether inside tmux - Which session we are attaching to Also adds Attaching to session message before attach. Co-Authored-By: Claude Opus 4.5 --- internal/cmd/crew.go | 2 ++ internal/cmd/crew_at.go | 32 +++++++++++++++++++++++++++++--- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/internal/cmd/crew.go b/internal/cmd/crew.go index efb9918c..27dbf864 100644 --- a/internal/cmd/crew.go +++ b/internal/cmd/crew.go @@ -21,6 +21,7 @@ var ( crewAll bool crewListAll bool crewDryRun bool + crewDebug bool ) var crewCmd = &cobra.Command{ @@ -333,6 +334,7 @@ func init() { crewAtCmd.Flags().BoolVarP(&crewDetached, "detached", "d", false, "Start session without attaching") crewAtCmd.Flags().StringVar(&crewAccount, "account", "", "Claude Code account handle to use (overrides default)") crewAtCmd.Flags().StringVar(&crewAgentOverride, "agent", "", "Agent alias to run crew worker with (overrides rig/town default)") + crewAtCmd.Flags().BoolVar(&crewDebug, "debug", false, "Show debug output for troubleshooting") crewRemoveCmd.Flags().StringVar(&crewRig, "rig", "", "Rig to use") crewRemoveCmd.Flags().BoolVar(&crewForce, "force", false, "Force remove (skip safety checks)") diff --git a/internal/cmd/crew_at.go b/internal/cmd/crew_at.go index 245e89c5..e32f94f3 100644 --- a/internal/cmd/crew_at.go +++ b/internal/cmd/crew_at.go @@ -2,6 +2,7 @@ package cmd import ( "fmt" + "os" "github.com/spf13/cobra" "github.com/steveyegge/gastown/internal/beads" @@ -18,6 +19,13 @@ import ( func runCrewAt(cmd *cobra.Command, args []string) error { var name string + // Debug mode: --debug flag or GT_DEBUG env var + debug := crewDebug || os.Getenv("GT_DEBUG") != "" + if debug { + cwd, _ := os.Getwd() + fmt.Printf("[DEBUG] runCrewAt: args=%v, crewRig=%q, cwd=%q\n", args, crewRig, cwd) + } + // Determine crew name: from arg, or auto-detect from cwd if len(args) > 0 { name = args[0] @@ -53,6 +61,10 @@ func runCrewAt(cmd *cobra.Command, args []string) error { fmt.Printf("Detected crew workspace: %s/%s\n", detected.rigName, name) } + if debug { + fmt.Printf("[DEBUG] after detection: name=%q, crewRig=%q\n", name, crewRig) + } + crewMgr, r, err := getCrewManager(crewRig) if err != nil { return err @@ -96,10 +108,16 @@ func runCrewAt(cmd *cobra.Command, args []string) error { // Check if session exists t := tmux.NewTmux() sessionID := crewSessionName(r.Name, name) + if debug { + fmt.Printf("[DEBUG] sessionID=%q (r.Name=%q, name=%q)\n", sessionID, r.Name, name) + } hasSession, err := t.HasSession(sessionID) if err != nil { return fmt.Errorf("checking session: %w", err) } + if debug { + fmt.Printf("[DEBUG] hasSession=%v\n", hasSession) + } // Before creating a new session, check if there's already a runtime session // running in this crew's directory (might have been started manually or via @@ -258,8 +276,12 @@ func runCrewAt(cmd *cobra.Command, args []string) error { } // If inside tmux (but different session), don't switch - just inform user - if tmux.IsInsideTmux() { - fmt.Printf("Started %s/%s. Use C-b s to switch.\n", r.Name, name) + insideTmux := tmux.IsInsideTmux() + if debug { + fmt.Printf("[DEBUG] tmux.IsInsideTmux()=%v\n", insideTmux) + } + if insideTmux { + fmt.Printf("Session %s ready. Use C-b s to switch.\n", sessionID) return nil } @@ -269,6 +291,10 @@ func runCrewAt(cmd *cobra.Command, args []string) error { return nil } - // Attach to session + // Attach to session - show which session we're attaching to + fmt.Printf("Attaching to %s...\n", sessionID) + if debug { + fmt.Printf("[DEBUG] calling attachToTmuxSession(%q)\n", sessionID) + } return attachToTmuxSession(sessionID) }