MCPcopy Create free account
hub / github.com/aws/amazon-q-developer-cli / execute

Method execute

crates/chat-cli/src/cli/chat/cli/reply.rs:21–107  ·  view source on GitHub ↗
(self, session: &mut ChatSession)

Source from the content-addressed store, hash-verified

19
20impl ReplyArgs {
21 pub async fn execute(self, session: &mut ChatSession) -> Result<ChatState, ChatError> {
22 // Get the most recent assistant message from transcript
23 let last_assistant_message = session
24 .conversation
25 .transcript
26 .iter()
27 .rev()
28 .find(|msg| !msg.starts_with("> "))
29 .cloned();
30
31 let initial_text = match last_assistant_message {
32 Some(msg) => {
33 // Format with > prefix for each line
34 msg.lines()
35 .map(|line| format!("> {}", line))
36 .collect::<Vec<_>>()
37 .join("\n")
38 },
39 None => {
40 execute!(
41 session.stderr,
42 StyledText::warning_fg(),
43 style::Print("\nNo assistant message found to reply to.\n\n"),
44 StyledText::reset(),
45 )?;
46
47 return Ok(ChatState::PromptUser {
48 skip_printing_tools: true,
49 });
50 },
51 };
52
53 let content = match open_editor(Some(initial_text.clone())) {
54 Ok(content) => content,
55 Err(err) => {
56 execute!(
57 session.stderr,
58 StyledText::error_fg(),
59 style::Print(format!("\nError opening editor: {}\n\n", err)),
60 StyledText::reset(),
61 )?;
62
63 return Ok(ChatState::PromptUser {
64 skip_printing_tools: true,
65 });
66 },
67 };
68
69 Ok(
70 match content.trim().is_empty() || content.trim() == initial_text.trim() {
71 true => {
72 execute!(
73 session.stderr,
74 StyledText::warning_fg(),
75 style::Print("\nNo changes made in editor, not submitting.\n\n"),
76 StyledText::reset(),
77 )?;
78

Callers

nothing calls this directly

Calls 5

open_editorFunction · 0.85
joinMethod · 0.80
mapMethod · 0.80
cloneMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected