cli: convert simple commands to use memory_rpc
Commands now forward to daemon (or fallback to local store): - query → memory_query - journal tail → journal_tail - graph link-set → memory_link_set - graph link-add → memory_link_add - weight-set → memory_weight_set - node rename → memory_rename Removes ~50 lines of duplicated store access code. Co-Authored-By: Proof of Concept <poc@bcachefs.org>
This commit is contained in:
parent
d2a82d4327
commit
11b58e6b0b
4 changed files with 34 additions and 87 deletions
|
|
@ -153,35 +153,23 @@ pub fn cmd_link(key: &[String]) -> Result<(), String> {
|
|||
&format!("neighbors('{}') | select strength,clustering_coefficient", resolved))
|
||||
}
|
||||
|
||||
pub fn cmd_link_add(source: &str, target: &str, reason: &[String]) -> Result<(), String> {
|
||||
pub fn cmd_link_add(source: &str, target: &str, _reason: &[String]) -> Result<(), String> {
|
||||
super::check_dry_run();
|
||||
let mut store = store::Store::load()?;
|
||||
let source = store.resolve_key(source)?;
|
||||
let target = store.resolve_key(target)?;
|
||||
let reason = reason.join(" ");
|
||||
|
||||
match store.add_link(&source, &target, "manual") {
|
||||
Ok(strength) => {
|
||||
store.save()?;
|
||||
println!("Linked: {} → {} (strength={:.2}, {})", source, target, strength, reason);
|
||||
}
|
||||
Err(msg) if msg.contains("already exists") => {
|
||||
println!("Link already exists: {} ↔ {}", source, target);
|
||||
}
|
||||
Err(e) => return Err(e),
|
||||
}
|
||||
let result = crate::mcp_server::memory_rpc(
|
||||
"memory_link_add",
|
||||
serde_json::json!({"source": source, "target": target}),
|
||||
).map_err(|e| e.to_string())?;
|
||||
println!("{}", result);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn cmd_link_set(source: &str, target: &str, strength: f32) -> Result<(), String> {
|
||||
super::check_dry_run();
|
||||
let mut store = store::Store::load()?;
|
||||
let source = store.resolve_key(source)?;
|
||||
let target = store.resolve_key(target)?;
|
||||
|
||||
let old = store.set_link_strength(&source, &target, strength)?;
|
||||
println!("Set: {} ↔ {} strength {:.2} → {:.2}", source, target, old, strength);
|
||||
store.save()?;
|
||||
let result = crate::mcp_server::memory_rpc(
|
||||
"memory_link_set",
|
||||
serde_json::json!({"source": source, "target": target, "strength": strength}),
|
||||
).map_err(|e| e.to_string())?;
|
||||
println!("{}", result);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue