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

Method create_checkpoint

crates/chat-cli/src/cli/chat/checkpoint.rs:149–204  ·  view source on GitHub ↗

Create a new checkpoint point

(
        &mut self,
        tag: &str,
        description: &str,
        history: &VecDeque<HistoryEntry>,
        is_turn: bool,
        tool_name: Option<String>,
    )

Source from the content-addressed store, hash-verified

147
148 /// Create a new checkpoint point
149 pub fn create_checkpoint(
150 &mut self,
151 tag: &str,
152 description: &str,
153 history: &VecDeque<HistoryEntry>,
154 is_turn: bool,
155 tool_name: Option<String>,
156 ) -> Result<()> {
157 // Stage, commit and tag
158 stage_commit_tag(
159 &self.shadow_repo_path.to_string_lossy(),
160 &self.work_tree_path,
161 description,
162 tag,
163 )?;
164
165 // Record checkpoint metadata
166 let checkpoint = Checkpoint {
167 tag: tag.to_string(),
168 timestamp: Local::now(),
169 description: description.to_string(),
170 history_snapshot: history.clone(),
171 is_turn,
172 tool_name,
173 };
174
175 // Check if checkpoint with this tag already exists
176 if let Some(&existing_idx) = self.tag_index.get(tag) {
177 if is_turn {
178 // For turn checkpoints, always move to the end to maintain correct ordering
179 self.checkpoints.remove(existing_idx);
180
181 // Update all indices in tag_index that are greater than the removed index
182 for (_, index) in self.tag_index.iter_mut() {
183 if *index > existing_idx {
184 *index -= 1;
185 }
186 }
187
188 // Add the updated checkpoint at the end
189 self.checkpoints.push(checkpoint);
190 self.tag_index.insert(tag.to_string(), self.checkpoints.len() - 1);
191 }
192 } else {
193 // Add new checkpoint
194 self.checkpoints.push(checkpoint);
195 self.tag_index.insert(tag.to_string(), self.checkpoints.len() - 1);
196 }
197
198 // Cache file stats for this checkpoint
199 if let Ok(stats) = self.compute_file_stats(tag) {
200 self.file_stats_cache.insert(tag.to_string(), stats);
201 }
202
203 Ok(())
204 }
205
206 /// Restore workspace to a specific checkpoint

Callers 2

tool_use_executeMethod · 0.45
handle_responseMethod · 0.45

Calls 8

stage_commit_tagFunction · 0.85
to_stringMethod · 0.80
removeMethod · 0.80
insertMethod · 0.80
compute_file_statsMethod · 0.80
cloneMethod · 0.45
getMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected