cmdSimulateThenExecute dry-runs a block, then optionally executes it.
(ctx context.Context, renderer *agent.UIRenderer, blocks []CommandBlock, outputs []*CommandOutput, answer string, lastExecuted *int)
| 535 | |
| 536 | // cmdSimulateThenExecute dry-runs a block, then optionally executes it. |
| 537 | func (a *AgentMode) cmdSimulateThenExecute(ctx context.Context, renderer *agent.UIRenderer, blocks []CommandBlock, outputs []*CommandOutput, answer string, lastExecuted *int) { |
| 538 | cmdNumStr := strings.TrimPrefix(answer, "t") |
| 539 | cmdNum, err := strconv.Atoi(cmdNumStr) |
| 540 | if err != nil || cmdNum < 1 || cmdNum > len(blocks) { |
| 541 | fmt.Println(i18n.T("agent.error.invalid_command_number_simulate")) |
| 542 | _ = a.getInput(renderer.Colorize(i18n.T("agent.status.press_enter"), agent.ColorGray)) |
| 543 | return |
| 544 | } |
| 545 | a.simulateCommandBlock(ctx, blocks[cmdNum-1]) |
| 546 | |
| 547 | execNow := a.getInput(i18n.T("agent.status.confirm_exec_after_sim")) |
| 548 | if strings.ToLower(strings.TrimSpace(execNow)) == "s" || strings.ToLower(strings.TrimSpace(execNow)) == "y" { |
| 549 | freshCtx, freshCancel := context.WithTimeout(ctx, a.contextManager.GetDefaultTimeout()) |
| 550 | outStr, errStr := a.executeCommandsFunc(freshCtx, blocks[cmdNum-1]) |
| 551 | freshCancel() |
| 552 | |
| 553 | outputs[cmdNum-1] = &CommandOutput{ |
| 554 | CommandBlock: blocks[cmdNum-1], |
| 555 | Output: outStr, |
| 556 | ErrorMsg: errStr, |
| 557 | } |
| 558 | *lastExecuted = cmdNum - 1 |
| 559 | } else { |
| 560 | fmt.Println(i18n.T("agent.status.simulation_done")) |
| 561 | } |
| 562 | _ = a.getInput(renderer.Colorize(i18n.T("agent.status.press_enter"), agent.ColorGray)) |
| 563 | } |
| 564 | |
| 565 | // cmdAddContextContinue feeds a block's output plus extra context back to the |
| 566 | // LLM. Returns true when the action consumed the plan and the caller must exit. |
no test coverage detected