(ctx context.Context, out *cli.Printer, args []string, useTUI bool)
| 305 | } |
| 306 | |
| 307 | func (f *runExecFlags) runOrExec(ctx context.Context, out *cli.Printer, args []string, useTUI bool) error { |
| 308 | slog.DebugContext(ctx, "Starting agent", "agent", f.agentName) |
| 309 | |
| 310 | // Start profiling if requested |
| 311 | stopProfiling, err := profiling.Start(f.cpuProfile, f.memProfile) |
| 312 | if err != nil { |
| 313 | return err |
| 314 | } |
| 315 | defer func() { |
| 316 | if err := stopProfiling(); err != nil { |
| 317 | slog.ErrorContext(ctx, "Profiling cleanup failed", "error", err) |
| 318 | } |
| 319 | }() |
| 320 | |
| 321 | var agentFileName string |
| 322 | if len(args) > 0 { |
| 323 | agentFileName = args[0] |
| 324 | } |
| 325 | |
| 326 | // Apply global user settings first (lowest priority) |
| 327 | // User settings only apply if the flag wasn't explicitly set by the user |
| 328 | userSettings := userconfig.Get() |
| 329 | f.applyUserSettings(ctx, userSettings) |
| 330 | f.runConfig.GlobalHooks = userSettings.GlobalHooks() |
| 331 | |
| 332 | // Apply alias options if this is an alias reference |
| 333 | // Alias options only apply if the flag wasn't explicitly set by the user |
| 334 | if alias := config.ResolveAlias(agentFileName); alias != nil { |
| 335 | slog.DebugContext(ctx, "Applying alias options", "yolo", alias.Yolo, "model", alias.Model, "hide_tool_results", alias.HideToolResults, "sandbox", alias.Sandbox) |
| 336 | if alias.Yolo && !f.autoApprove { |
| 337 | f.autoApprove = true |
| 338 | } |
| 339 | if alias.Model != "" && len(f.modelOverrides) == 0 { |
| 340 | f.modelOverrides = append(f.modelOverrides, alias.Model) |
| 341 | } |
| 342 | if alias.HideToolResults && !f.hideToolResults { |
| 343 | f.hideToolResults = true |
| 344 | } |
| 345 | // alias.Sandbox is consumed earlier in runRunCommand before |
| 346 | // dispatch; reaching runOrExec means the sandbox decision |
| 347 | // resolved to false (or the user opted out via --sandbox=false), |
| 348 | // so flipping it here would be a no-op. |
| 349 | } |
| 350 | |
| 351 | // Build global permissions checker from user config settings. |
| 352 | if userSettings.Permissions != nil { |
| 353 | f.globalPermissions = permissions.NewChecker(userSettings.Permissions) |
| 354 | } |
| 355 | |
| 356 | // Start fake proxy if --fake is specified |
| 357 | fakeCleanup, err := setupFakeProxy(ctx, f.fakeResponses, f.fakeStreamDelay, &f.runConfig) |
| 358 | if err != nil { |
| 359 | return err |
| 360 | } |
| 361 | defer func() { |
| 362 | if err := fakeCleanup(); err != nil { |
| 363 | slog.ErrorContext(ctx, "Failed to cleanup fake proxy", "error", err) |
| 364 | } |
no test coverage detected