Skip to content

Commit 53afe73

Browse files
committed
style: cargo fmt
1 parent 87292b6 commit 53afe73

6 files changed

Lines changed: 102 additions & 59 deletions

File tree

Cargo.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/icm-cli/src/cloud.rs

Lines changed: 65 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

crates/icm-cli/src/main.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -985,7 +985,10 @@ fn cmd_extract_patterns(
985985
return Ok(());
986986
}
987987

988-
println!("Detected {} pattern(s) in topic '{topic}':\n", patterns.len());
988+
println!(
989+
"Detected {} pattern(s) in topic '{topic}':\n",
990+
patterns.len()
991+
);
989992

990993
for (i, cluster) in patterns.iter().enumerate() {
991994
println!(
@@ -994,7 +997,10 @@ fn cmd_extract_patterns(
994997
cluster.count,
995998
cluster.keywords.join(", ")
996999
);
997-
println!(" Summary: {}", &cluster.representative_summary[..cluster.representative_summary.len().min(120)]);
1000+
println!(
1001+
" Summary: {}",
1002+
&cluster.representative_summary[..cluster.representative_summary.len().min(120)]
1003+
);
9981004
}
9991005

10001006
if let Some(memoir_name) = memoir {

crates/icm-core/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,7 @@ pub use error::{IcmError, IcmResult};
1313
pub use fastembed_embedder::FastEmbedder;
1414
pub use memoir::{Concept, ConceptLink, Label, Memoir, MemoirStats, Relation};
1515
pub use memoir_store::MemoirStore;
16-
pub use memory::{Importance, Memory, MemorySource, PatternCluster, Scope, StoreStats, TopicHealth};
16+
pub use memory::{
17+
Importance, Memory, MemorySource, PatternCluster, Scope, StoreStats, TopicHealth,
18+
};
1719
pub use store::MemoryStore;

crates/icm-mcp/src/tools.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ const AUTO_CONSOLIDATE_THRESHOLD: usize = 10;
1515
/// Returns a human-readable message if consolidation happened, or empty string.
1616
fn try_auto_consolidate(store: &SqliteStore, topic: &str, threshold: usize) -> String {
1717
match store.auto_consolidate(topic, threshold) {
18-
Ok(true) => format!(
19-
"Auto-consolidated topic '{topic}' (exceeded {threshold} entries)."
20-
),
18+
Ok(true) => format!("Auto-consolidated topic '{topic}' (exceeded {threshold} entries)."),
2119
Ok(false) => String::new(),
2220
Err(e) => {
2321
tracing::warn!("auto-consolidation failed for topic '{topic}': {e}");
@@ -618,9 +616,8 @@ fn tool_recall(
618616
let mut scored_results = results;
619617
if let Some(t) = topic {
620618
// Prefix matching: "wshm" matches "wshm", "wshm:owner/repo", etc.
621-
scored_results.retain(|(m, _)| {
622-
m.topic == t || m.topic.starts_with(&format!("{t}:"))
623-
});
619+
scored_results
620+
.retain(|(m, _)| m.topic == t || m.topic.starts_with(&format!("{t}:")));
624621
}
625622
if let Some(kw) = keyword {
626623
scored_results.retain(|(m, _)| m.keywords.iter().any(|k| k.contains(kw)));

crates/icm-store/src/store.rs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1467,10 +1467,18 @@ impl SqliteStore {
14671467
}
14681468

14691469
// Sort by weight DESC (get_by_topic already does this, but be explicit)
1470-
memories.sort_by(|a, b| b.weight.partial_cmp(&a.weight).unwrap_or(std::cmp::Ordering::Equal));
1470+
memories.sort_by(|a, b| {
1471+
b.weight
1472+
.partial_cmp(&a.weight)
1473+
.unwrap_or(std::cmp::Ordering::Equal)
1474+
});
14711475

14721476
// Take the top 3 summaries for the consolidated summary
1473-
let top_summaries: Vec<&str> = memories.iter().take(3).map(|m| m.summary.as_str()).collect();
1477+
let top_summaries: Vec<&str> = memories
1478+
.iter()
1479+
.take(3)
1480+
.map(|m| m.summary.as_str())
1481+
.collect();
14741482
let consolidated_summary = top_summaries.join(" | ");
14751483

14761484
// Merge all unique keywords
@@ -1490,7 +1498,8 @@ impl SqliteStore {
14901498
// Build the consolidated memory
14911499
let mut consolidated = Memory::new(topic.into(), consolidated_summary, Importance::High);
14921500
consolidated.keywords = all_keywords;
1493-
consolidated.raw_excerpt = Some(format!("auto-consolidated from {original_count} memories"));
1501+
consolidated.raw_excerpt =
1502+
Some(format!("auto-consolidated from {original_count} memories"));
14941503
consolidated.weight = 1.0;
14951504

14961505
// Replace all memories in the topic with the consolidated one
@@ -1680,7 +1689,13 @@ impl SqliteStore {
16801689
let concept_name = if cluster.keywords.is_empty() {
16811690
format!("pattern-{}", &cluster.memory_ids[0][..8])
16821691
} else {
1683-
cluster.keywords.iter().take(3).cloned().collect::<Vec<_>>().join("-")
1692+
cluster
1693+
.keywords
1694+
.iter()
1695+
.take(3)
1696+
.cloned()
1697+
.collect::<Vec<_>>()
1698+
.join("-")
16841699
};
16851700

16861701
// Build definition from cluster representative + count

0 commit comments

Comments
 (0)