@@ -2,6 +2,7 @@ use crate::protocol::CodexConfig;
22use crate :: services:: { codex, session} ;
33use crate :: state:: CodexState ;
44use tauri:: { AppHandle , State } ;
5+ use std:: fs;
56
67// Re-export types for external use
78pub use crate :: services:: session:: Conversation ;
@@ -75,3 +76,66 @@ pub async fn delete_session_file(file_path: String) -> Result<(), String> {
7576pub async fn get_latest_session_id ( ) -> Result < Option < String > , String > {
7677 session:: get_latest_session_id ( ) . await
7778}
79+
80+ #[ tauri:: command]
81+ pub async fn get_session_files ( ) -> Result < Vec < String > , String > {
82+ let home = dirs:: home_dir ( ) . ok_or ( "Could not find home directory" ) ?;
83+ let sessions_dir = home. join ( ".codex" ) . join ( "sessions" ) ;
84+
85+ if !sessions_dir. exists ( ) {
86+ return Ok ( vec ! [ ] ) ;
87+ }
88+
89+ let mut session_files = Vec :: new ( ) ;
90+
91+ // Walk through year/month/day directories
92+ if let Ok ( entries) = fs:: read_dir ( & sessions_dir) {
93+ for entry in entries. flatten ( ) {
94+ if entry. file_type ( ) . map ( |ft| ft. is_dir ( ) ) . unwrap_or ( false ) {
95+ let year_path = entry. path ( ) ;
96+ if let Ok ( month_entries) = fs:: read_dir ( & year_path) {
97+ for month_entry in month_entries. flatten ( ) {
98+ if month_entry. file_type ( ) . map ( |ft| ft. is_dir ( ) ) . unwrap_or ( false ) {
99+ let month_path = month_entry. path ( ) ;
100+ if let Ok ( day_entries) = fs:: read_dir ( & month_path) {
101+ for day_entry in day_entries. flatten ( ) {
102+ if day_entry. file_type ( ) . map ( |ft| ft. is_dir ( ) ) . unwrap_or ( false ) {
103+ let day_path = day_entry. path ( ) ;
104+ if let Ok ( file_entries) = fs:: read_dir ( & day_path) {
105+ for file_entry in file_entries. flatten ( ) {
106+ if let Some ( filename) = file_entry. file_name ( ) . to_str ( ) {
107+ if filename. ends_with ( ".jsonl" ) {
108+ session_files. push ( file_entry. path ( ) . to_string_lossy ( ) . to_string ( ) ) ;
109+ }
110+ }
111+ }
112+ }
113+ }
114+ }
115+ }
116+ }
117+ }
118+ }
119+ }
120+ }
121+ }
122+
123+ Ok ( session_files)
124+ }
125+
126+ #[ tauri:: command]
127+ pub async fn read_session_file ( file_path : String ) -> Result < String , String > {
128+ fs:: read_to_string ( & file_path) . map_err ( |e| format ! ( "Failed to read session file: {}" , e) )
129+ }
130+
131+ #[ tauri:: command]
132+ pub async fn read_history_file ( ) -> Result < String , String > {
133+ let home = dirs:: home_dir ( ) . ok_or ( "Could not find home directory" ) ?;
134+ let history_path = home. join ( ".codex" ) . join ( "history.jsonl" ) ;
135+
136+ if !history_path. exists ( ) {
137+ return Ok ( String :: new ( ) ) ;
138+ }
139+
140+ fs:: read_to_string ( & history_path) . map_err ( |e| format ! ( "Failed to read history file: {}" , e) )
141+ }
0 commit comments