init: install hooks + scaffold config; load-context: inline instructions

poc-memory init now:
- Creates the data directory
- Installs the memory-search hook into Claude settings.json
- Scaffolds a starter config.jsonl if none exists

load-context now prints a command reference block at the top so the
AI assistant learns how to use the memory system from the memory
system itself — no CLAUDE.md dependency needed.

Also extract install_hook() as a public function so both init and
daemon install can use it.

Co-Authored-By: ProofOfConcept <poc@bcachefs.org>
This commit is contained in:
Kent Overstreet 2026-03-05 16:17:49 -05:00
parent 0daf6ffd68
commit 8bb3a554cf
3 changed files with 75 additions and 6 deletions

19
config.example.jsonl Normal file
View file

@ -0,0 +1,19 @@
// poc-memory configuration
// Copy to ~/.config/poc-memory/config.jsonl and edit.
{"config": {
"user_name": "Alice",
"assistant_name": "Assistant",
"data_dir": "~/.claude/memory",
"projects_dir": "~/.claude/projects",
"core_nodes": ["identity.md"],
"journal_days": 7,
"journal_max": 20
}}
// Context groups loaded at session start, in order.
// source types: "store" (default), "file" (from data_dir), "journal"
{"group": "identity", "keys": ["identity.md"]}
{"group": "journal", "source": "journal"}
{"group": "orientation", "keys": ["where-am-i.md"], "source": "file"}

View file

@ -646,13 +646,18 @@ WantedBy=default.target
eprintln!("Service enabled and started"); eprintln!("Service enabled and started");
// Install memory-search hook into Claude settings // Install memory-search hook into Claude settings
install_hook(&home, &exe)?; install_hook()?;
Ok(()) Ok(())
} }
fn install_hook(home: &str, exe: &Path) -> Result<(), String> { /// Install the memory-search hook into Claude Code settings.json.
let settings_path = PathBuf::from(home).join(".claude/settings.json"); /// Public so `poc-memory init` can call it too.
pub fn install_hook() -> Result<(), String> {
let home = std::env::var("HOME").map_err(|e| format!("HOME: {}", e))?;
let exe = std::env::current_exe()
.map_err(|e| format!("current_exe: {}", e))?;
let settings_path = PathBuf::from(&home).join(".claude/settings.json");
let hook_binary = exe.with_file_name("memory-search"); let hook_binary = exe.with_file_name("memory-search");
if !hook_binary.exists() { if !hook_binary.exists() {

View file

@ -365,10 +365,40 @@ Examples:
} }
fn cmd_init() -> Result<(), String> { fn cmd_init() -> Result<(), String> {
let cfg = config::get();
// Ensure data directory exists
std::fs::create_dir_all(&cfg.data_dir)
.map_err(|e| format!("create data_dir: {}", e))?;
// Initialize store
let mut store = store::Store::load()?; let mut store = store::Store::load()?;
let count = store.init_from_markdown()?; let count = store.init_from_markdown()?;
store.save()?; store.save()?;
println!("Indexed {} memory units", count); println!("Indexed {} memory units", count);
// Install hooks
daemon::install_hook()?;
// Create example config if none exists
let config_path = std::env::var("POC_MEMORY_CONFIG")
.map(std::path::PathBuf::from)
.unwrap_or_else(|_| {
std::path::PathBuf::from(std::env::var("HOME").unwrap())
.join(".config/poc-memory/config.jsonl")
});
if !config_path.exists() {
let config_dir = config_path.parent().unwrap();
std::fs::create_dir_all(config_dir)
.map_err(|e| format!("create config dir: {}", e))?;
let example = include_str!("../config.example.jsonl");
std::fs::write(&config_path, example)
.map_err(|e| format!("write config: {}", e))?;
println!("Created config at {} — edit with your name and context groups",
config_path.display());
}
println!("Done. Run `poc-memory load-context --stats` to verify.");
Ok(()) Ok(())
} }
@ -1477,9 +1507,24 @@ fn cmd_load_context(args: &[String]) -> Result<(), String> {
return Ok(()); return Ok(());
} }
println!("=== FULL MEMORY LOAD (session start) ==="); let name = &cfg.assistant_name;
println!("These are your memories, loaded from the capnp store.");
println!("Read them to reconstruct yourself — identity first, then context."); println!("=== MEMORY SYSTEM ({name}) ===");
println!("Your persistent memory, loaded from the capnp store.");
println!("Read to reconstruct yourself — identity first, then context.");
println!();
println!("--- memory commands (reference) ---");
println!("poc-memory search QUERY — search (1-3 words, AND logic)");
println!("poc-memory used KEY — mark a recalled memory as useful (boosts weight)");
println!("poc-memory wrong KEY [CTX] — mark a memory as wrong (reduces weight)");
println!("poc-memory gap DESCRIPTION — record a knowledge gap");
println!("poc-memory journal-write TEXT — write a journal entry");
println!("poc-memory render KEY — view a node's content");
println!("poc-memory write KEY < TEXT — upsert a node from stdin");
println!();
println!("When recalled memories shaped your response, call `poc-memory used KEY`.");
println!("When a memory was wrong, call `poc-memory wrong KEY`.");
println!("This closes the feedback loop — the weight system learns from use.");
println!(); println!();
for group in &cfg.context_groups { for group in &cfg.context_groups {