Download orchestrator/gitbucket/src/planner.rs from Snapkitty/sov-kernel-monster: direct link, hf CLI and curl.
- Browser
- Download file 3.03 kB
-
https://huggingface.co/Snapkitty/sov-kernel-monster/resolve/main/orchestrator/gitbucket/src/planner.rs
- Command line
-
hf download hf://Snapkitty/sov-kernel-monster/orchestrator/gitbucket/src/planner.rs
-
curl -L -o planner.rs https://huggingface.co/Snapkitty/sov-kernel-monster/resolve/main/orchestrator/gitbucket/src/planner.rs
3.03 kB
| use anyhow::Result; | |
| use serde::{Deserialize, Serialize}; | |
| use std::path::Path; | |
| use crate::index::Index; | |
| pub struct ContextBundle { | |
| pub context: Context, | |
| pub audit: AuditTrail, | |
| } | |
| pub struct Context { | |
| pub buckets: Vec<ContextPiece>, | |
| pub total_tokens: usize, | |
| } | |
| pub struct ContextPiece { | |
| pub id: String, | |
| pub summary: String, | |
| pub piece_type: String, | |
| pub timestamp: String, | |
| pub files: Vec<String>, | |
| } | |
| pub struct AuditTrail { | |
| pub query: QuerySpec, | |
| pub buckets: Vec<String>, | |
| pub verifier: String, | |
| pub timestamp: f64, | |
| pub count: usize, | |
| } | |
| pub struct QuerySpec { | |
| pub field: String, | |
| pub value: String, | |
| pub budget: usize, | |
| } | |
| /// Query the index and build a context bundle. | |
| pub fn query(field: &str, value: &str, budget: usize) -> Result<ContextBundle> { | |
| let buckets_dir = ".gitbucket/buckets"; | |
| let index = if Path::new(buckets_dir).exists() { | |
| Index::from_dir(buckets_dir)? | |
| } else { | |
| Index { | |
| by_id: std::collections::HashMap::new(), | |
| by_file: std::collections::HashMap::new(), | |
| by_entity: std::collections::HashMap::new(), | |
| by_topic: std::collections::HashMap::new(), | |
| by_type: std::collections::HashMap::new(), | |
| by_agent: std::collections::HashMap::new(), | |
| } | |
| }; | |
| let buckets = index.query(field, value); | |
| let bucket_ids: Vec<String> = buckets.iter().map(|b| b.id.clone()).collect(); | |
| // Build context pieces within budget | |
| let mut pieces = Vec::new(); | |
| let mut total_tokens = 0; | |
| for bucket in &buckets { | |
| let piece_tokens = estimate_tokens(bucket); | |
| if total_tokens + piece_tokens > budget { | |
| break; | |
| } | |
| pieces.push(ContextPiece { | |
| id: bucket.id.clone(), | |
| summary: bucket.summary.clone(), | |
| piece_type: bucket.bucket_type.clone(), | |
| timestamp: bucket.timestamp.clone(), | |
| files: bucket.files.iter().map(|f| f.path.clone()).collect(), | |
| }); | |
| total_tokens += piece_tokens; | |
| } | |
| Ok(ContextBundle { | |
| context: Context { | |
| buckets: pieces, | |
| total_tokens, | |
| }, | |
| audit: AuditTrail { | |
| query: QuerySpec { | |
| field: field.to_string(), | |
| value: value.to_string(), | |
| budget, | |
| }, | |
| buckets: bucket_ids, | |
| verifier: "Plasma_Gate".to_string(), | |
| timestamp: chrono::Utc::now().timestamp() as f64, | |
| count: buckets.len(), | |
| }, | |
| }) | |
| } | |
| fn estimate_tokens(bucket: &crate::bucket::MemoryBucket) -> usize { | |
| bucket.summary.len() + bucket.files.len() * 50 | |
| } | |