File tree Expand file tree Collapse file tree 2 files changed +50
-5
lines changed
crates/chat-cli/src/cli/chat Expand file tree Collapse file tree 2 files changed +50
-5
lines changed Original file line number Diff line number Diff line change @@ -169,6 +169,30 @@ impl CaptureManager {
169169 Ok ( ( ) )
170170 }
171171
172+ /// Delete the entire captures root (i.e., remove all session captures).
173+ /// This re-creates the empty root directory after deletion.
174+ pub async fn clean_all_sessions ( & self , os : & Os ) -> Result < ( ) > {
175+ let root = self
176+ . shadow_repo_path
177+ . parent ( )
178+ . ok_or_else ( || eyre ! ( "Could not determine captures root" ) ) ?;
179+
180+ // Safety guard: ensure last component looks like "cli-captures"
181+ if root
182+ . file_name ( )
183+ . and_then ( |s| s. to_str ( ) )
184+ . map ( |s| s. contains ( "captures" ) )
185+ != Some ( true )
186+ {
187+ bail ! ( "Refusing to delete unexpected parent directory: {}" , root. display( ) ) ;
188+ }
189+
190+ println ! ( "Deleting captures root: {}" , root. display( ) ) ;
191+ os. fs . remove_dir_all ( root) . await ?;
192+ os. fs . create_dir_all ( root) . await ?; // recreate empty root
193+ Ok ( ( ) )
194+ }
195+
172196 pub fn diff ( & self , tag1 : & str , tag2 : & str ) -> Result < String > {
173197 let _ = self . get_capture ( tag1) ?;
174198 let _ = self . get_capture ( tag2) ?;
Original file line number Diff line number Diff line change @@ -46,7 +46,11 @@ pub enum CaptureSubcommand {
4646 } ,
4747
4848 /// Delete shadow repository
49- Clean ,
49+ Clean {
50+ /// Delete the entire captures root (all sessions)
51+ #[ arg( long) ]
52+ all : bool ,
53+ } ,
5054
5155 /// Display more information about a turn-level checkpoint
5256 Expand { tag : String } ,
@@ -150,15 +154,32 @@ impl CaptureSubcommand {
150154 return Err ( ChatError :: Custom ( format ! ( "Could not display all captures: {e}" ) . into ( ) ) ) ;
151155 } ,
152156 } ,
153- Self :: Clean => {
154- match manager. clean ( os) . await {
157+ Self :: Clean { all } => {
158+ let res = if all {
159+ manager. clean_all_sessions ( os) . await
160+ } else {
161+ manager. clean ( os) . await
162+ } ;
163+ match res {
155164 Ok ( ( ) ) => execute ! (
156165 session. stderr,
157- style:: Print ( "Deleted shadow repository.\n " . blue( ) . bold( ) )
166+ style:: Print (
167+ if all {
168+ "Deleted all session captures under the captures root.\n "
169+ } else {
170+ "Deleted shadow repository for this session.\n "
171+ }
172+ . blue( )
173+ . bold( )
174+ )
158175 ) ?,
159176 Err ( e) => {
160177 session. conversation . capture_manager = None ;
161- return Err ( ChatError :: Custom ( format ! ( "Could not delete shadow repo: {e}" ) . into ( ) ) ) ;
178+ return Err ( ChatError :: Custom ( if all {
179+ format ! ( "Could not delete captures root: {e}" ) . into ( )
180+ } else {
181+ format ! ( "Could not delete shadow repo: {e}" ) . into ( )
182+ } ) ) ;
162183 } ,
163184 }
164185 session. conversation . capture_manager = None ;
You can’t perform that action at this time.
0 commit comments