(cmd *cobra.Command, args []string)
| 210 | } |
| 211 | |
| 212 | func (f *runExecFlags) runRunCommand(cmd *cobra.Command, args []string) (commandErr error) { |
| 213 | ctx := cmd.Context() |
| 214 | |
| 215 | if f.exec { |
| 216 | telemetry.TrackCommand(ctx, "exec", args) |
| 217 | defer func() { // do not inline this defer so that commandErr is not resolved early |
| 218 | telemetry.TrackCommandError(ctx, "exec", args, commandErr) |
| 219 | }() |
| 220 | } else { |
| 221 | telemetry.TrackCommand(ctx, "run", args) |
| 222 | defer func() { // do not inline this defer so that commandErr is not resolved early |
| 223 | telemetry.TrackCommandError(ctx, "run", args, commandErr) |
| 224 | }() |
| 225 | } |
| 226 | |
| 227 | // Validate an explicit --theme value early so a typo fails fast with a |
| 228 | // helpful message instead of silently falling back to the default theme |
| 229 | // once the TUI starts. |
| 230 | if f.theme != "" { |
| 231 | if err := validateTheme(f.theme); err != nil { |
| 232 | return err |
| 233 | } |
| 234 | } |
| 235 | |
| 236 | useTUI := !f.exec && (f.forceTUI || isatty.IsTerminal(os.Stdout.Fd())) |
| 237 | f.leanChanged = cmd.Flags().Changed("lean") |
| 238 | |
| 239 | // When --agent-picker is set, show a full-screen picker up front and use |
| 240 | // the chosen ref as the agent to run. Resolving it here (before sandbox |
| 241 | // and alias resolution) means the selected agent's own sandbox/alias |
| 242 | // defaults are honoured exactly as if it had been passed positionally. |
| 243 | // The picker is interactive, so it requires a TUI. |
| 244 | if cmd.Flags().Changed("agent-picker") { |
| 245 | if !useTUI { |
| 246 | return errors.New("--agent-picker requires an interactive terminal and cannot be used with --exec") |
| 247 | } |
| 248 | refs := parseAgentPickerRefs(f.agentPickerSpec) |
| 249 | applyTheme(f.theme) |
| 250 | // Seed the picker's "Lean Mode" checkbox with the lean state the run |
| 251 | // would otherwise use (--lean, or the user-config default applied in |
| 252 | // applyUserSettings) so the checkbox never lies about the run mode. |
| 253 | initialLean := f.lean || (!f.leanChanged && userconfig.Get().Lean && !f.tour) |
| 254 | chosen, lean, err := selectAgentRef(ctx, refs, f.runConfig.EnvProvider(), initialLean) |
| 255 | if err != nil { |
| 256 | if errors.Is(err, errAgentPickerCancelled) { |
| 257 | cli.NewPrinter(cmd.OutOrStdout()).Println("Agent selection cancelled.") |
| 258 | return nil |
| 259 | } |
| 260 | return err |
| 261 | } |
| 262 | // The checkbox is the user's explicit choice: it wins over both the |
| 263 | // --lean flag and the user-config lean default. |
| 264 | f.lean = lean |
| 265 | f.leanChanged = true |
| 266 | // With --agent-picker the agent comes from the picker, so any |
| 267 | // positional args are messages. Prepend the chosen ref so the rest |
| 268 | // of the pipeline (which expects args[0] to be the agent) is happy. |
| 269 | args = prependAgentRef(chosen, args) |
nothing calls this directly
no test coverage detected