cmdPreContext sends extra context before executing a block. Returns true when the action consumed the plan and the caller must exit.
(ctx context.Context, renderer *agent.UIRenderer, blocks []CommandBlock, answer string)
| 641 | // cmdPreContext sends extra context before executing a block. Returns true |
| 642 | // when the action consumed the plan and the caller must exit. |
| 643 | func (a *AgentMode) cmdPreContext(ctx context.Context, renderer *agent.UIRenderer, blocks []CommandBlock, answer string) bool { |
| 644 | cmdNumStr := strings.TrimPrefix(answer, "pc") |
| 645 | cmdNum, err := strconv.Atoi(cmdNumStr) |
| 646 | if err != nil || cmdNum < 1 || cmdNum > len(blocks) { |
| 647 | fmt.Println(i18n.T("agent.error.invalid_command_number_context")) |
| 648 | _ = a.getInput(renderer.Colorize(i18n.T("agent.status.press_enter"), agent.ColorGray)) |
| 649 | return false |
| 650 | } |
| 651 | |
| 652 | userContext := a.getMultilineInput(i18n.T("agent.prompt.additional_context")) |
| 653 | if userContext == "" { |
| 654 | fmt.Println(i18n.T("agent.error.no_context_provided")) |
| 655 | _ = a.getInput(renderer.Colorize(i18n.T("agent.status.press_enter"), agent.ColorGray)) |
| 656 | return false |
| 657 | } |
| 658 | |
| 659 | fmt.Println(i18n.T("agent.status.context_received")) |
| 660 | // Monta o prompt para a IA |
| 661 | toolContext := a.getToolContextString() |
| 662 | prompt := i18n.T("agent.llm_prompt.pre_execution_context", |
| 663 | strings.Join(blocks[cmdNum-1].Commands, "\n"), |
| 664 | userContext, |
| 665 | ) + toolContext |
| 666 | |
| 667 | a.cli.history = append(a.cli.history, models.Message{Role: "user", Content: prompt}) |
| 668 | |
| 669 | // Chama o loop de processamento unificado |
| 670 | a.continueWithNewAIResponse(ctx) |
| 671 | |
| 672 | // Sai do loop do plano de ação atual |
| 673 | return true |
| 674 | } |
| 675 | |
| 676 | // cmdExecuteSingle runs the single block referenced by a numeric answer. |
| 677 | func (a *AgentMode) cmdExecuteSingle(ctx context.Context, renderer *agent.UIRenderer, blocks []CommandBlock, outputs []*CommandOutput, answer string, lastExecuted *int) { |
no test coverage detected