in internal/engine/common/commands.go [40:98]
func ExecuteCodeBlockAsync(codeBlock parsers.CodeBlock, env map[string]string) tea.Cmd {
return func() tea.Msg {
logging.GlobalLogger.Infof(
"Executing command asynchronously:\n %s", codeBlock.Content)
output, err := shells.ExecuteBashCommand(codeBlock.Content, shells.BashCommandConfiguration{
EnvironmentVariables: env,
InheritEnvironment: true,
InteractiveCommand: false,
WriteToHistory: true,
})
if err != nil {
logging.GlobalLogger.Errorf("Error executing command:\n %s", err.Error())
return FailedCommandMessage{
StdOut: output.StdOut,
StdErr: output.StdErr,
Error: err,
SimilarityScore: 0,
}
}
// Check command output against the expected output.
actualOutput := output.StdOut
expectedOutput := codeBlock.ExpectedOutput.Content
expectedSimilarity := codeBlock.ExpectedOutput.ExpectedSimilarity
expectedRegex := codeBlock.ExpectedOutput.ExpectedRegex
expectedOutputLanguage := codeBlock.ExpectedOutput.Language
score, outputComparisonError := CompareCommandOutputs(
actualOutput,
expectedOutput,
expectedSimilarity,
expectedRegex,
expectedOutputLanguage,
)
if outputComparisonError != nil {
logging.GlobalLogger.Errorf(
"Error comparing command outputs: %s",
outputComparisonError.Error(),
)
return FailedCommandMessage{
StdOut: output.StdOut,
StdErr: output.StdErr,
Error: outputComparisonError,
SimilarityScore: score,
}
}
logging.GlobalLogger.Infof("Command output to stdout:\n %s", output.StdOut)
return SuccessfulCommandMessage{
StdOut: output.StdOut,
StdErr: output.StdErr,
SimilarityScore: score,
}
}
}