cmdBatchExecute runs every block in sequence after a confirmation prompt.
(ctx context.Context, renderer *agent.UIRenderer, blocks []CommandBlock, outputs []*CommandOutput, lastExecuted *int)
| 436 | |
| 437 | // cmdBatchExecute runs every block in sequence after a confirmation prompt. |
| 438 | func (a *AgentMode) cmdBatchExecute(ctx context.Context, renderer *agent.UIRenderer, blocks []CommandBlock, outputs []*CommandOutput, lastExecuted *int) { |
| 439 | hasDanger := false |
| 440 | for _, b := range blocks { |
| 441 | for _, c := range b.Commands { |
| 442 | if a.validator.IsDangerous(c) { |
| 443 | hasDanger = true |
| 444 | break |
| 445 | } |
| 446 | } |
| 447 | if hasDanger { |
| 448 | break |
| 449 | } |
| 450 | } |
| 451 | |
| 452 | if hasDanger { |
| 453 | fmt.Println(i18n.T("agent.status.batch_warning")) |
| 454 | fmt.Println(i18n.T("agent.status.batch_check_individual")) |
| 455 | } |
| 456 | |
| 457 | if runtime.GOOS != "windows" { |
| 458 | cmd := exec.Command(sttyPath, "sane") |
| 459 | cmd.Stdin = os.Stdin |
| 460 | cmd.Stdout = os.Stdout |
| 461 | _ = cmd.Run() |
| 462 | } |
| 463 | |
| 464 | fmt.Print(i18n.T("agent.status.batch_confirm")) |
| 465 | confirmationInput := a.readLine() |
| 466 | confirmation := strings.ToLower(confirmationInput) |
| 467 | if confirmation != "s" && confirmation != "y" { |
| 468 | fmt.Println(i18n.T("agent.status.batch_canceled")) |
| 469 | _ = a.getInput(renderer.Colorize(i18n.T("agent.status.press_enter"), agent.ColorGray)) |
| 470 | return |
| 471 | } |
| 472 | |
| 473 | for i, block := range blocks { |
| 474 | fmt.Printf(i18n.T("agent.status.executing_command", i+1)+"\n", i+1) |
| 475 | fmt.Printf(" %s %s\n", i18n.T("agent.plan.field.type"), block.Language) |
| 476 | for j, cmd := range block.Commands { |
| 477 | fmt.Printf(" %s %d/%d: %s\n", i18n.T("agent.label.command"), j+1, len(block.Commands), cmd) |
| 478 | } |
| 479 | |
| 480 | freshCtx, freshCancel := context.WithTimeout(ctx, a.contextManager.GetDefaultTimeout()) |
| 481 | outStr, errStr := a.executeCommandsFunc(freshCtx, block) |
| 482 | freshCancel() |
| 483 | |
| 484 | outputs[i] = &CommandOutput{ |
| 485 | CommandBlock: block, |
| 486 | Output: outStr, |
| 487 | ErrorMsg: errStr, |
| 488 | } |
| 489 | *lastExecuted = i |
| 490 | } |
| 491 | |
| 492 | fmt.Println(i18n.T("agent.status.all_commands_executed")) |
| 493 | fmt.Println(i18n.T("agent.status.summary")) |
| 494 | for i, out := range outputs { |
| 495 | status := "OK" |
no test coverage detected