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

Method handle_restore

crates/chat-cli/src/cli/chat/cli/checkpoint.rs:168–237  ·  view source on GitHub ↗
(
        &self,
        session: &mut ChatSession,
        tag: Option<String>,
        hard: bool,
    )

Source from the content-addressed store, hash-verified

166 }
167
168 async fn handle_restore(
169 &self,
170 session: &mut ChatSession,
171 tag: Option<String>,
172 hard: bool,
173 ) -> Result<ChatState, ChatError> {
174 // Take manager out temporarily to avoid borrow issues
175 let Some(manager) = session.conversation.checkpoint_manager.take() else {
176 execute!(
177 session.stderr,
178 StyledText::warning_fg(),
179 style::Print("⚠️ Checkpoints not enabled. Use '/checkpoint init' to enable.\n"),
180 StyledText::reset(),
181 )?;
182 return Ok(ChatState::PromptUser {
183 skip_printing_tools: true,
184 });
185 };
186
187 let tag_result = if let Some(tag) = tag {
188 Ok(tag)
189 } else {
190 // Interactive selection
191 match gather_turn_checkpoints(&manager) {
192 Ok(entries) => {
193 if let Some(idx) = select_checkpoint(&entries, "Select checkpoint to restore:") {
194 Ok(entries[idx].tag.clone())
195 } else {
196 Err(())
197 }
198 },
199 Err(e) => {
200 session.conversation.checkpoint_manager = Some(manager);
201 return Err(ChatError::Custom(format!("Failed to gather checkpoints: {}", e).into()));
202 },
203 }
204 };
205
206 let tag = match tag_result {
207 Ok(tag) => tag,
208 Err(_) => {
209 session.conversation.checkpoint_manager = Some(manager);
210 return Ok(ChatState::PromptUser {
211 skip_printing_tools: true,
212 });
213 },
214 };
215
216 match manager.restore(&mut session.conversation, &tag, hard) {
217 Ok(_) => {
218 execute!(
219 session.stderr,
220 StyledText::info_fg(),
221 style::SetAttribute(Attribute::Bold),
222 style::Print(format!("✓ Restored to checkpoint {}\n", tag)),
223 StyledText::reset(),
224 StyledText::reset_attributes(),
225 )?;

Callers 1

executeMethod · 0.80

Calls 5

gather_turn_checkpointsFunction · 0.85
select_checkpointFunction · 0.85
CustomClass · 0.85
restoreMethod · 0.80
cloneMethod · 0.45

Tested by

no test coverage detected