diff --git a/internal/cmd/doctor.go b/internal/cmd/doctor.go index cd119b05..e25c30ac 100644 --- a/internal/cmd/doctor.go +++ b/internal/cmd/doctor.go @@ -10,9 +10,10 @@ import ( ) var ( - doctorFix bool - doctorVerbose bool - doctorRig string + doctorFix bool + doctorVerbose bool + doctorRig string + doctorRestartSessions bool ) var doctorCmd = &cobra.Command{ @@ -82,6 +83,7 @@ func init() { doctorCmd.Flags().BoolVar(&doctorFix, "fix", false, "Attempt to automatically fix issues") doctorCmd.Flags().BoolVarP(&doctorVerbose, "verbose", "v", false, "Show detailed output") doctorCmd.Flags().StringVar(&doctorRig, "rig", "", "Check specific rig only") + doctorCmd.Flags().BoolVar(&doctorRestartSessions, "restart-sessions", false, "Restart patrol sessions when fixing stale settings (use with --fix)") rootCmd.AddCommand(doctorCmd) } @@ -94,9 +96,10 @@ func runDoctor(cmd *cobra.Command, args []string) error { // Create check context ctx := &doctor.CheckContext{ - TownRoot: townRoot, - RigName: doctorRig, - Verbose: doctorVerbose, + TownRoot: townRoot, + RigName: doctorRig, + Verbose: doctorVerbose, + RestartSessions: doctorRestartSessions, } // Create doctor and register checks diff --git a/internal/doctor/claude_settings_check.go b/internal/doctor/claude_settings_check.go index b222acb9..fbce040c 100644 --- a/internal/doctor/claude_settings_check.go +++ b/internal/doctor/claude_settings_check.go @@ -495,14 +495,17 @@ func (c *ClaudeSettingsCheck) Fix(ctx *CheckContext) error { continue } - // Only cycle patrol roles that can auto-recover (daemon restarts them). - // Crew and polecats are spawned on-demand and won't auto-restart. - if sf.agentType == "witness" || sf.agentType == "refinery" || - sf.agentType == "deacon" || sf.agentType == "mayor" { - running, _ := t.HasSession(sf.sessionName) - if running { - // Cycle the agent by killing and letting gt up restart it - _ = t.KillSession(sf.sessionName) + // Only cycle patrol roles if --restart-sessions was explicitly passed. + // This prevents unexpected session restarts during routine --fix operations. + // Crew and polecats are spawned on-demand and won't auto-restart anyway. + if ctx.RestartSessions { + if sf.agentType == "witness" || sf.agentType == "refinery" || + sf.agentType == "deacon" || sf.agentType == "mayor" { + running, _ := t.HasSession(sf.sessionName) + if running { + // Cycle the agent by killing and letting gt up restart it + _ = t.KillSession(sf.sessionName) + } } } } diff --git a/internal/doctor/types.go b/internal/doctor/types.go index 2bb18dc0..6115afd3 100644 --- a/internal/doctor/types.go +++ b/internal/doctor/types.go @@ -38,9 +38,10 @@ func (s CheckStatus) String() string { // CheckContext provides context for running checks. type CheckContext struct { - TownRoot string // Root directory of the Gas Town workspace - RigName string // Rig name (empty for town-level checks) - Verbose bool // Enable verbose output + TownRoot string // Root directory of the Gas Town workspace + RigName string // Rig name (empty for town-level checks) + Verbose bool // Enable verbose output + RestartSessions bool // Restart patrol sessions when fixing (requires explicit --restart-sessions flag) } // RigPath returns the full path to the rig directory.