@@ -45,9 +45,13 @@ pub fn load_credentials() -> Option<Credentials> {
4545 // - Linux: ~/.config/rtk/
4646 let rtk_paths = [
4747 // macOS: ~/Library/Application Support/rtk/credentials.json
48- std:: env:: var ( "HOME" ) . ok ( ) . map ( |h| PathBuf :: from ( & h) . join ( "Library/Application Support/rtk/credentials.json" ) ) ,
48+ std:: env:: var ( "HOME" )
49+ . ok ( )
50+ . map ( |h| PathBuf :: from ( & h) . join ( "Library/Application Support/rtk/credentials.json" ) ) ,
4951 // Linux: ~/.config/rtk/credentials.json
50- std:: env:: var ( "HOME" ) . ok ( ) . map ( |h| PathBuf :: from ( & h) . join ( ".config/rtk/credentials.json" ) ) ,
52+ std:: env:: var ( "HOME" )
53+ . ok ( )
54+ . map ( |h| PathBuf :: from ( & h) . join ( ".config/rtk/credentials.json" ) ) ,
5155 ] ;
5256 for path in rtk_paths. into_iter ( ) . flatten ( ) {
5357 if let Some ( creds) = load_credentials_from_path ( path) {
@@ -62,7 +66,9 @@ fn load_credentials_from_path(path: PathBuf) -> Option<Credentials> {
6266 let content = std:: fs:: read_to_string ( & path) . ok ( ) ?;
6367 let creds: Credentials = serde_json:: from_str ( & content) . ok ( ) ?;
6468 // Validate token is non-empty
65- if creds. token . is_empty ( ) { return None ; }
69+ if creds. token . is_empty ( ) {
70+ return None ;
71+ }
6672 Some ( creds)
6773}
6874
@@ -223,10 +229,13 @@ pub fn login_password(endpoint: &str, email: &str, password: &str) -> Result<Cre
223229 let resp = ureq:: post ( & url)
224230 . set ( "Content-Type" , "application/json" )
225231 . timeout ( std:: time:: Duration :: from_secs ( 10 ) )
226- . send_string ( & serde_json:: json!( {
227- "email" : email,
228- "password" : password,
229- } ) . to_string ( ) )
232+ . send_string (
233+ & serde_json:: json!( {
234+ "email" : email,
235+ "password" : password,
236+ } )
237+ . to_string ( ) ,
238+ )
230239 . context ( "Failed to connect to RTK Cloud" ) ?;
231240
232241 let status = resp. status ( ) ;
@@ -391,8 +400,12 @@ pub fn pull_memories(
391400 last_accessed : Option < String > ,
392401 }
393402
394- fn default_importance_str ( ) -> String { "medium" . to_string ( ) }
395- fn default_scope_str ( ) -> String { "user" . to_string ( ) }
403+ fn default_importance_str ( ) -> String {
404+ "medium" . to_string ( )
405+ }
406+ fn default_scope_str ( ) -> String {
407+ "user" . to_string ( )
408+ }
396409
397410 #[ derive( Deserialize ) ]
398411 struct PullResponse {
@@ -401,39 +414,49 @@ pub fn pull_memories(
401414
402415 let data: PullResponse = serde_json:: from_str ( & body) . context ( "Invalid cloud response" ) ?;
403416
404- let memories = data. memories . into_iter ( ) . map ( |cm| {
405- let importance = cm. importance . parse :: < icm_core:: Importance > ( )
406- . unwrap_or ( icm_core:: Importance :: Medium ) ;
407- let scope = cm. scope . parse :: < Scope > ( ) . unwrap_or ( Scope :: User ) ;
408- let source = cm. source
409- . and_then ( |v| serde_json:: from_value :: < icm_core:: MemorySource > ( v) . ok ( ) )
410- . unwrap_or ( icm_core:: MemorySource :: Manual ) ;
411- let now = chrono:: Utc :: now ( ) ;
412-
413- Memory {
414- id : cm. id ,
415- topic : cm. topic ,
416- summary : cm. summary ,
417- raw_excerpt : cm. raw_excerpt ,
418- keywords : cm. keywords ,
419- importance,
420- scope,
421- source,
422- weight : cm. weight ,
423- access_count : cm. access_count ,
424- related_ids : cm. related_ids ,
425- embedding : None ,
426- created_at : cm. created_at
427- . and_then ( |s| s. parse :: < chrono:: DateTime < chrono:: Utc > > ( ) . ok ( ) )
428- . unwrap_or ( now) ,
429- updated_at : cm. updated_at
430- . and_then ( |s| s. parse :: < chrono:: DateTime < chrono:: Utc > > ( ) . ok ( ) )
431- . unwrap_or ( now) ,
432- last_accessed : cm. last_accessed
433- . and_then ( |s| s. parse :: < chrono:: DateTime < chrono:: Utc > > ( ) . ok ( ) )
434- . unwrap_or ( now) ,
435- }
436- } ) . collect ( ) ;
417+ let memories = data
418+ . memories
419+ . into_iter ( )
420+ . map ( |cm| {
421+ let importance = cm
422+ . importance
423+ . parse :: < icm_core:: Importance > ( )
424+ . unwrap_or ( icm_core:: Importance :: Medium ) ;
425+ let scope = cm. scope . parse :: < Scope > ( ) . unwrap_or ( Scope :: User ) ;
426+ let source = cm
427+ . source
428+ . and_then ( |v| serde_json:: from_value :: < icm_core:: MemorySource > ( v) . ok ( ) )
429+ . unwrap_or ( icm_core:: MemorySource :: Manual ) ;
430+ let now = chrono:: Utc :: now ( ) ;
431+
432+ Memory {
433+ id : cm. id ,
434+ topic : cm. topic ,
435+ summary : cm. summary ,
436+ raw_excerpt : cm. raw_excerpt ,
437+ keywords : cm. keywords ,
438+ importance,
439+ scope,
440+ source,
441+ weight : cm. weight ,
442+ access_count : cm. access_count ,
443+ related_ids : cm. related_ids ,
444+ embedding : None ,
445+ created_at : cm
446+ . created_at
447+ . and_then ( |s| s. parse :: < chrono:: DateTime < chrono:: Utc > > ( ) . ok ( ) )
448+ . unwrap_or ( now) ,
449+ updated_at : cm
450+ . updated_at
451+ . and_then ( |s| s. parse :: < chrono:: DateTime < chrono:: Utc > > ( ) . ok ( ) )
452+ . unwrap_or ( now) ,
453+ last_accessed : cm
454+ . last_accessed
455+ . and_then ( |s| s. parse :: < chrono:: DateTime < chrono:: Utc > > ( ) . ok ( ) )
456+ . unwrap_or ( now) ,
457+ }
458+ } )
459+ . collect ( ) ;
437460
438461 Ok ( memories)
439462}
0 commit comments