Download orchestrator/gitbucket/src/main.rs from Snapkitty/sov-kernel-monster: direct link, hf CLI and curl.
- Browser
- Download file 4.2 kB
-
https://huggingface.co/Snapkitty/sov-kernel-monster/resolve/main/orchestrator/gitbucket/src/main.rs
- Command line
-
hf download hf://Snapkitty/sov-kernel-monster/orchestrator/gitbucket/src/main.rs
-
curl -L -o main.rs https://huggingface.co/Snapkitty/sov-kernel-monster/resolve/main/orchestrator/gitbucket/src/main.rs
4.2 kB
| use anyhow::Result; | |
| use clap::{Parser, Subcommand}; | |
| mod bucket; | |
| mod extractor; | |
| mod index; | |
| mod planner; | |
| mod seal; | |
| mod schema; | |
| struct Cli { | |
| command: Commands, | |
| } | |
| enum Commands { | |
| /// Extract memory buckets from git history | |
| Extract { | |
| /// Git repo path | |
| repo: String, | |
| /// Start commit (ref or hash) | |
| from: Option<String>, | |
| /// End commit (ref or hash, default: HEAD) | |
| to: Option<String>, | |
| /// Output directory for buckets | |
| output: String, | |
| }, | |
| /// Verify WORM seals on all buckets | |
| Verify { | |
| /// Bucket directory | |
| buckets: String, | |
| }, | |
| /// Query the memory index | |
| Query { | |
| /// Query type: topic, file, entity, agent, type | |
| field: String, | |
| /// Query value | |
| value: String, | |
| /// Token budget | |
| budget: usize, | |
| }, | |
| /// Generate Ed25519 keypair | |
| Keygen, | |
| /// Backfill history from existing git repo | |
| Backfill { | |
| /// Git repo path | |
| repo: String, | |
| /// Start commit | |
| from: Option<String>, | |
| /// End commit | |
| to: String, | |
| }, | |
| } | |
| fn main() -> Result<()> { | |
| let cli = Cli::parse(); | |
| match cli.command { | |
| Commands::Extract { repo, from, to, output } => { | |
| println!("Extracting memory buckets from {}...", repo); | |
| let buckets = extractor::extract_range(&repo, from.as_deref(), to.as_deref())?; | |
| for bucket in &buckets { | |
| let path = format!("{}/{}.json", output, bucket.id); | |
| std::fs::write(&path, serde_json::to_string_pretty(bucket)?)?; | |
| println!(" Wrote {}", path); | |
| } | |
| println!("Extracted {} buckets.", buckets.len()); | |
| } | |
| Commands::Verify { buckets } => { | |
| println!("Verifying WORM seals in {}...", buckets); | |
| let results = seal::verify_all(&buckets)?; | |
| let passed = results.iter().filter(|r| r.is_ok()).count(); | |
| let failed = results.len() - passed; | |
| println!(" {} passed, {} failed", passed, failed); | |
| for (i, result) in results.iter().enumerate() { | |
| if let Err(e) = result { | |
| println!(" FAILED bucket {}: {}", i, e); | |
| } | |
| } | |
| } | |
| Commands::Query { field, value, budget } => { | |
| println!("Querying: {} = {} (budget: {})", field, value, budget); | |
| let context = planner::query(&field, &value, budget)?; | |
| println!("{}", serde_json::to_string_pretty(&context)?); | |
| } | |
| Commands::Keygen => { | |
| let (pubkey, privkey) = seal::keygen()?; | |
| println!("Public key: {}", pubkey); | |
| println!("Private key: {}", privkey); | |
| } | |
| Commands::Backfill { repo, from, to } => { | |
| println!("Backfilling from {} to {} in {}...", | |
| from.as_deref().unwrap_or("first commit"), to, repo); | |
| let buckets = extractor::extract_range(&repo, from.as_deref(), Some(&to))?; | |
| let output = ".gitbucket/buckets"; | |
| std::fs::create_dir_all(output)?; | |
| for bucket in &buckets { | |
| let path = format!("{}/{}.json", output, bucket.id); | |
| std::fs::write(&path, serde_json::to_string_pretty(bucket)?)?; | |
| } | |
| println!("Backfilled {} buckets.", buckets.len()); | |
| } | |
| } | |
| Ok(()) | |
| } | |