consciousness/poc-memory/src/bin/diag-key.rs
Kent Overstreet 81fec99767 history: show DELETED marker on tombstone entries
cmd_history was silently hiding the deleted flag, making it
impossible to tell from the output that a node had been deleted.
This masked the kernel-patterns deletion — looked like the node
existed in the log but wouldn't load.

Also adds merge-logs and diag-key diagnostic binaries, and makes
Node::to_capnp public for use by external tools.

Co-Authored-By: Kent Overstreet <kent.overstreet@linux.dev>
2026-03-17 18:00:58 -04:00

45 lines
1.9 KiB
Rust

// Diagnostic: dump all entries matching a key pattern from a capnp log
use std::io::BufReader;
use std::fs;
use capnp::{message, serialize};
use poc_memory::memory_capnp;
use poc_memory::store::Node;
fn main() {
let args: Vec<String> = std::env::args().collect();
if args.len() != 3 {
eprintln!("usage: diag-key <nodes.capnp> <key-substring>");
std::process::exit(1);
}
let path = &args[1];
let pattern = &args[2];
let file = fs::File::open(path).unwrap();
let mut reader = BufReader::new(file);
let mut entry_num = 0u64;
let mut matches = 0u64;
while let Ok(msg) = serialize::read_message(&mut reader, message::ReaderOptions::new()) {
let log = msg.get_root::<memory_capnp::node_log::Reader>().unwrap();
for node_reader in log.get_nodes().unwrap() {
entry_num += 1;
let node = Node::from_capnp_migrate(node_reader).unwrap();
// Exact substring match, but exclude keys with trailing chars
// (e.g. "kernel-patterns-foo") unless pattern itself has the dash
if node.key == *pattern || (node.key.contains(pattern) && !node.key.contains(&format!("{}-", pattern))) {
matches += 1;
println!("Entry #{}: key={:?} (len={})", entry_num, node.key, node.key.len());
println!(" key bytes: {:02x?}", node.key.as_bytes());
println!(" uuid: {:02x?}", node.uuid);
println!(" version: {}", node.version);
println!(" deleted: {}", node.deleted);
println!(" timestamp: {}", node.timestamp);
println!(" content len: {}", node.content.len());
println!(" provenance: {}", node.provenance);
println!();
}
}
}
eprintln!("Scanned {} entries, {} matches for {:?}", entry_num, matches, pattern);
}