forked from kent/consciousness
store: remove dead code and move params to config
Remove: - score_weight() - never called - position field on Node - never read (was for export) - Provenance enum - inline helper for capnp migration - migrate_transcript_progress + CLI command - init_from_markdown, import_file, ingest_units - export command and export_to_markdown - RetrievalEvent, GapRecord types - classify_filename, new_transcript_segment Move spreading activation params to Config: - default_node_weight, edge_decay, max_hops, min_activation - Remove Params struct and StoreView::params() Simplify cmd_init to just seed identity via upsert(). Simplify cmd_import to use parse_units + upsert directly. -576 lines Co-Authored-By: Proof of Concept <poc@bcachefs.org>
This commit is contained in:
parent
6104c63890
commit
7d49f29fde
10 changed files with 69 additions and 576 deletions
|
|
@ -1,6 +1,6 @@
|
|||
// cli/admin.rs — admin subcommand handlers
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
use anyhow::Result;
|
||||
use crate::hippocampus as memory;
|
||||
use crate::hippocampus::store;
|
||||
|
||||
|
|
@ -25,19 +25,16 @@ pub async fn cmd_init() -> Result<()> {
|
|||
install_default_file(&cfg.data_dir, "on-consciousness.md",
|
||||
include_str!("../../defaults/on-consciousness.md"))?;
|
||||
|
||||
// Initialize store and seed default identity node if empty
|
||||
// Seed identity node if empty
|
||||
let arc = memory::access_local()?;
|
||||
let mut store = arc.lock().await;
|
||||
let count = store.init_from_markdown().map_err(|e| anyhow::anyhow!("{}", e))?;
|
||||
for key in &cfg.core_nodes {
|
||||
if !store.nodes.contains_key(key) && key == "identity" {
|
||||
let default = include_str!("../../defaults/identity.md");
|
||||
store.upsert(key, default).map_err(|e| anyhow::anyhow!("{}", e))?;
|
||||
println!("Seeded {} in store", key);
|
||||
}
|
||||
if !store.nodes.contains_key("identity") {
|
||||
let default = include_str!("../../defaults/identity.md");
|
||||
store.upsert("identity", default)?;
|
||||
println!("Seeded identity in store");
|
||||
}
|
||||
store.save().map_err(|e| anyhow::anyhow!("{}", e))?;
|
||||
println!("Indexed {} memory units", count);
|
||||
store.save()?;
|
||||
println!("Initialized with {} nodes", store.nodes.len());
|
||||
|
||||
// Create config if none exists
|
||||
let config_path = std::env::var("POC_MEMORY_CONFIG")
|
||||
|
|
@ -325,8 +322,7 @@ pub async fn cmd_import(files: &[String]) -> Result<()> {
|
|||
|
||||
let arc = memory::access_local()?;
|
||||
let mut store = arc.lock().await;
|
||||
let mut total_new = 0;
|
||||
let mut total_updated = 0;
|
||||
let mut count = 0;
|
||||
|
||||
for arg in files {
|
||||
let path = std::path::PathBuf::from(arg);
|
||||
|
|
@ -340,52 +336,21 @@ pub async fn cmd_import(files: &[String]) -> Result<()> {
|
|||
}
|
||||
mem_path
|
||||
};
|
||||
let (n, u) = store.import_file(&resolved)?;
|
||||
total_new += n;
|
||||
total_updated += u;
|
||||
}
|
||||
|
||||
if total_new > 0 || total_updated > 0 {
|
||||
store.save()?;
|
||||
}
|
||||
println!("Import: {} new, {} updated", total_new, total_updated);
|
||||
Ok(())
|
||||
}
|
||||
let filename = resolved.file_name().unwrap().to_string_lossy().to_string();
|
||||
let content = std::fs::read_to_string(&resolved)?;
|
||||
let units = store::parse_units(&filename, &content);
|
||||
|
||||
pub async fn cmd_export(files: &[String], export_all: bool) -> Result<()> {
|
||||
let arc = memory::access_local()?;
|
||||
let store = arc.lock().await;
|
||||
|
||||
let targets: Vec<String> = if export_all {
|
||||
let mut files: Vec<String> = store.nodes.keys()
|
||||
.filter(|k| !k.contains('#'))
|
||||
.cloned()
|
||||
.collect();
|
||||
files.sort();
|
||||
files
|
||||
} else if files.is_empty() {
|
||||
anyhow::bail!("export requires file keys or --all");
|
||||
} else {
|
||||
files.iter().map(|a| {
|
||||
a.strip_suffix(".md").unwrap_or(a).to_string()
|
||||
}).collect()
|
||||
};
|
||||
|
||||
let mem_dir = store::memory_dir();
|
||||
|
||||
for file_key in &targets {
|
||||
match store.export_to_markdown(file_key) {
|
||||
Some(content) => {
|
||||
let out_path = mem_dir.join(format!("{}.md", file_key));
|
||||
std::fs::write(&out_path, &content)
|
||||
.with_context(|| format!("write {}", out_path.display()))?;
|
||||
let section_count = content.matches("<!-- mem:").count() + 1;
|
||||
println!("Exported {} ({} sections)", file_key, section_count);
|
||||
}
|
||||
None => eprintln!("No nodes for '{}'", file_key),
|
||||
for unit in units {
|
||||
store.upsert(&unit.key, &unit.content)?;
|
||||
count += 1;
|
||||
}
|
||||
}
|
||||
|
||||
if count > 0 {
|
||||
store.save()?;
|
||||
}
|
||||
println!("Imported {} memory units", count);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue