@@ -25,8 +25,8 @@ pub fn get_app_info() -> AppInfo {
2525}
2626
2727#[ tauri:: command]
28- pub fn read_credentials ( ) -> Result < Credentials , String > {
29- credentials:: read ( )
28+ pub fn credential_status ( ) -> Result < credentials :: CredentialStatus , String > {
29+ credentials:: status ( )
3030}
3131
3232#[ tauri:: command]
@@ -116,71 +116,10 @@ pub fn append_allow_matcher(matcher: String) -> Result<(), String> {
116116 settings:: write_user ( & value)
117117}
118118
119- /// Create a new session JSONL with a metadata header line. Returns the
120- /// generated session id. The id format matches what @deepcode/core's
121- /// SessionManager produces: `YYYY-MM-DD-<random>`.
122- #[ tauri:: command]
123- pub fn session_create ( cwd : String ) -> Result < String , String > {
124- let Some ( home) = dirs:: home_dir ( ) else {
125- return Err ( "no home directory" . into ( ) ) ;
126- } ;
127- let now = std:: time:: SystemTime :: now ( ) ;
128- let secs = now
129- . duration_since ( std:: time:: UNIX_EPOCH )
130- . map_err ( |e| e. to_string ( ) ) ?
131- . as_secs ( ) ;
132- let date = format_date ( secs) ;
133- // Lightweight unique suffix from time-nanos — no extra crate dep
134- let nanos = now
135- . duration_since ( std:: time:: UNIX_EPOCH )
136- . map_err ( |e| e. to_string ( ) ) ?
137- . subsec_nanos ( ) ;
138- let rand_id = format ! ( "{:08x}" , nanos) ;
139- let id = format ! ( "{}-{}" , date, rand_id) ;
140- let dir = home. join ( ".deepcode" ) . join ( "sessions" ) ;
141- std:: fs:: create_dir_all ( & dir) . map_err ( |e| format ! ( "mkdir {}: {}" , dir. display( ) , e) ) ?;
142- let path = dir. join ( format ! ( "{}.v1.jsonl" , id) ) ;
143- let header = serde_json:: json!( {
144- "type" : "session_meta" ,
145- "schema_version" : 1 ,
146- "id" : id,
147- "cwd" : cwd,
148- "created_at" : secs,
149- "client" : "desktop"
150- } ) ;
151- let line = format ! ( "{}\n " , header) ;
152- std:: fs:: write ( & path, line) . map_err ( |e| format ! ( "write {}: {}" , path. display( ) , e) ) ?;
153- Ok ( id)
154- }
155-
156- /// Append a single JSON line to a session's JSONL file.
157- #[ tauri:: command]
158- pub fn session_append ( id : String , message : serde_json:: Value ) -> Result < ( ) , String > {
159- safe_session_id ( & id) ?;
160- let Some ( home) = dirs:: home_dir ( ) else {
161- return Err ( "no home directory" . into ( ) ) ;
162- } ;
163- let dir = home. join ( ".deepcode" ) . join ( "sessions" ) ;
164- std:: fs:: create_dir_all ( & dir) . map_err ( |e| format ! ( "mkdir {}: {}" , dir. display( ) , e) ) ?;
165- let _lock = SessionWriterLock :: acquire ( & dir, & id) ?;
166- let path = ensure_canonical_session ( & dir, & id) ?;
167- let mut normalized = message;
168- normalized[ "type" ] = serde_json:: Value :: String ( "message" . to_string ( ) ) ;
169- normalized[ "schema_version" ] = serde_json:: Value :: Number ( 1 . into ( ) ) ;
170- let line = format ! ( "{}\n " , normalized) ;
171- let mut f = std:: fs:: OpenOptions :: new ( )
172- . create ( true )
173- . append ( true )
174- . open ( & path)
175- . map_err ( |e| format ! ( "open {}: {}" , path. display( ) , e) ) ?;
176- f. write_all ( line. as_bytes ( ) )
177- . map_err ( |e| format ! ( "write {}: {}" , path. display( ) , e) )
178- }
179-
180119/// Read a session's JSONL and return its message lines (skipping the
181120/// `session_meta` header and any unparseable lines). Each returned value is the
182- /// stored message object as written by session_append: `{ type, role, content,
183- /// timestamp }`. Returns an empty vec if the file doesn't exist.
121+ /// canonical `{ type, role, content, timestamp }` object. Returns an empty vec
122+ /// if the file doesn't exist.
184123#[ tauri:: command]
185124pub fn session_read ( id : String ) -> Result < Vec < serde_json:: Value > , String > {
186125 safe_session_id ( & id) ?;
@@ -318,24 +257,6 @@ fn parse_session_messages(text: &str) -> Result<Vec<serde_json::Value>, String>
318257 Ok ( out)
319258}
320259
321- fn format_date ( secs : u64 ) -> String {
322- // Simple YYYY-MM-DD; days since epoch math is enough for filename use.
323- let days = secs / 86_400 ;
324- // Reference: 1970-01-01 was a Thursday; we compute YMD via the
325- // standard "civil_from_days" algorithm by Howard Hinnant.
326- let z = days as i64 + 719_468 ;
327- let era = if z >= 0 { z } else { z - 146_096 } / 146_097 ;
328- let doe = ( z - era * 146_097 ) as u64 ;
329- let yoe = ( doe - doe / 1460 + doe / 36524 - doe / 146_096 ) / 365 ;
330- let y = yoe as i64 + era * 400 ;
331- let doy = doe - ( 365 * yoe + yoe / 4 - yoe / 100 ) ;
332- let mp = ( 5 * doy + 2 ) / 153 ;
333- let d = doy - ( 153 * mp + 2 ) / 5 + 1 ;
334- let m = if mp < 10 { mp + 3 } else { mp - 9 } ;
335- let y = if m <= 2 { y + 1 } else { y } ;
336- format ! ( "{:04}-{:02}-{:02}" , y, m, d)
337- }
338-
339260/// List session files under ~/.deepcode/sessions/. Returns just metadata.
340261#[ derive( Serialize ) ]
341262pub struct SessionMeta {
0 commit comments