cli: convert write/delete/journal-write to use memory_rpc
- cmd_write → memory_write RPC - cmd_node_delete → new memory_delete MCP tool + RPC - cmd_journal_write → journal_new RPC Removes validate_inline_refs and find_current_transcript (now handled server-side or not needed). Co-Authored-By: Proof of Concept <poc@bcachefs.org>
This commit is contained in:
parent
7842b6fc8b
commit
366b17163d
3 changed files with 37 additions and 121 deletions
|
|
@ -66,30 +66,6 @@ pub fn cmd_tail(n: usize, full: bool, provenance: Option<&str>, dedup: bool) ->
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn find_current_transcript() -> Option<String> {
|
||||
let projects = crate::config::get().projects_dir.clone();
|
||||
if !projects.exists() { return None; }
|
||||
|
||||
let mut newest: Option<(std::time::SystemTime, std::path::PathBuf)> = None;
|
||||
if let Ok(dirs) = std::fs::read_dir(&projects) {
|
||||
for dir_entry in dirs.filter_map(|e| e.ok()) {
|
||||
if !dir_entry.path().is_dir() { continue; }
|
||||
if let Ok(files) = std::fs::read_dir(dir_entry.path()) {
|
||||
for f in files.filter_map(|e| e.ok()) {
|
||||
let p = f.path();
|
||||
if p.extension().map(|x| x == "jsonl").unwrap_or(false)
|
||||
&& let Ok(meta) = p.metadata()
|
||||
&& let Ok(mtime) = meta.modified()
|
||||
&& newest.as_ref().is_none_or(|(t, _)| mtime > *t) {
|
||||
newest = Some((mtime, p));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
newest.map(|(_, p)| p.to_string_lossy().to_string())
|
||||
}
|
||||
|
||||
pub fn cmd_journal_tail(n: usize, full: bool, level: u8) -> Result<(), String> {
|
||||
let format = if full { "full" } else { "compact" };
|
||||
let result = crate::mcp_server::memory_rpc(
|
||||
|
|
@ -105,36 +81,18 @@ pub fn cmd_journal_write(name: &str, text: &[String]) -> Result<(), String> {
|
|||
return Err("journal write requires text".into());
|
||||
}
|
||||
super::check_dry_run();
|
||||
let text = text.join(" ");
|
||||
|
||||
let timestamp = crate::store::format_datetime(crate::store::now_epoch());
|
||||
let content = format!("## {} — {}\n\n{}", timestamp, name, text);
|
||||
|
||||
let key: String = name.split_whitespace()
|
||||
.map(|w| w.to_lowercase()
|
||||
.chars().filter(|c| c.is_alphanumeric() || *c == '-')
|
||||
.collect::<String>())
|
||||
.filter(|s| !s.is_empty())
|
||||
.collect::<Vec<_>>()
|
||||
.join("-");
|
||||
|
||||
let source_ref = find_current_transcript();
|
||||
|
||||
let mut store = crate::store::Store::load()?;
|
||||
|
||||
let mut node = crate::store::new_node(&key, &content);
|
||||
node.node_type = crate::store::NodeType::EpisodicSession;
|
||||
node.provenance = "journal".to_string();
|
||||
if let Some(src) = source_ref {
|
||||
node.source_ref = src;
|
||||
}
|
||||
|
||||
store.upsert_node(node)?;
|
||||
store.save()?;
|
||||
|
||||
let word_count = text.split_whitespace().count();
|
||||
println!("Appended entry at {} ({} words)", timestamp, word_count);
|
||||
let body = text.join(" ");
|
||||
|
||||
let result = crate::mcp_server::memory_rpc(
|
||||
"journal_new",
|
||||
serde_json::json!({
|
||||
"name": name,
|
||||
"title": name,
|
||||
"body": body,
|
||||
"level": 0
|
||||
}),
|
||||
).map_err(|e| e.to_string())?;
|
||||
println!("{}", result);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue