MCPcopy Create free account
hub / github.com/diillson/chatcli / cmdSimulateThenExecute

Method cmdSimulateThenExecute

cli/agent_command_blocks.go:537–563  ·  view source on GitHub ↗

cmdSimulateThenExecute dry-runs a block, then optionally executes it.

(ctx context.Context, renderer *agent.UIRenderer, blocks []CommandBlock, outputs []*CommandOutput, answer string, lastExecuted *int)

Source from the content-addressed store, hash-verified

535
536// cmdSimulateThenExecute dry-runs a block, then optionally executes it.
537func (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.

Callers 1

handleCommandBlocksMethod · 0.95

Calls 5

getInputMethod · 0.95
simulateCommandBlockMethod · 0.95
TFunction · 0.92
ColorizeMethod · 0.80
GetDefaultTimeoutMethod · 0.80

Tested by

no test coverage detected