stemedb/crates/stemedb-storage/src/key_codec/global_keys.rs
jordan b3e8a9a058 feat: Multi-application expansion with chaos testing and community UI
Major additions:
- Community Next.js app (port 18187) for browsing claims with API docs
- stemedb-chaos crate: Fault injection, chaos testing, CRDT properties
- Latent ingestion system: Reddit/FDA ingesters with ADK-Go agents
- Disputed claims handling: Manual review workflows and validation
- Aphoria security scanner: New extractors (SQL injection, command
  injection, weak crypto, TLS version), policy-based ignores, UAT reports
- Docker infrastructure: Dockerfile, docker-compose.yml for full stack
- VulnBank demo: Intentionally vulnerable multi-language test corpus

SDK & API enhancements:
- Source registry handlers for tracking data provenance
- Metrics endpoint
- Skeptic filtering improvements

Code quality:
- Split 14 large files (>500 lines) into focused modules
- All files now under 500-line limit per project guidelines

Documentation:
- Chaos testing guide, circuit breakers, observability docs
- Phase 7 UAT documentation updates
- Martin Kleppmann technical writer agent

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-04 01:24:14 -07:00

116 lines
3.7 KiB
Rust

//! Global keys — metadata, trust, quotas, epochs (sort first under `\x00`).
//!
//! Format: `\x00{TAG}:{suffix}`
use super::builders::global_key;
/// Trust rank key: `\x00TRUST:{agent_id_hex}`
pub fn trust_rank_key(agent_id_hex: &str) -> Vec<u8> {
global_key(b"TRUST:", agent_id_hex.as_bytes())
}
/// Quota record key: `\x00QUOTA:{agent_hex}:{window}`
pub fn quota_key(agent_hex: &str, window: u64) -> Vec<u8> {
let suffix = format!("{}:{}", agent_hex, window);
global_key(b"QUOTA:", suffix.as_bytes())
}
/// Quota limit key: `\x00QLIMIT:{agent_id_hex}`
pub fn quota_limit_key(agent_id_hex: &str) -> Vec<u8> {
global_key(b"QLIMIT:", agent_id_hex.as_bytes())
}
/// Epoch key: `\x00E:{epoch_id_hex}`
pub fn epoch_key(epoch_id_hex: &str) -> Vec<u8> {
global_key(b"E:", epoch_id_hex.as_bytes())
}
/// Superseded marker key: `\x00SUPERSEDED:{epoch_id_hex}`
pub fn superseded_key(epoch_id_hex: &str) -> Vec<u8> {
global_key(b"SUPERSEDED:", epoch_id_hex.as_bytes())
}
/// Supersession record key: `\x00SUP:{target_hash_hex}`
pub fn supersession_key(target_hash_hex: &str) -> Vec<u8> {
global_key(b"SUP:", target_hash_hex.as_bytes())
}
/// Supersession agent index key: `\x00SUP:IDX:{agent_hex}:{ts_be_bytes}`
pub fn supersession_index_key(agent_hex: &str, timestamp_be_bytes: &[u8]) -> Vec<u8> {
let mut suffix = Vec::with_capacity(agent_hex.len() + 1 + timestamp_be_bytes.len());
suffix.extend_from_slice(agent_hex.as_bytes());
suffix.push(b':');
suffix.extend_from_slice(timestamp_be_bytes);
global_key(b"SUP:IDX:", &suffix)
}
/// Supersession agent scan prefix: `\x00SUP:IDX:{agent_hex}:`
pub fn supersession_index_prefix(agent_hex: &str) -> Vec<u8> {
let suffix = format!("{}:", agent_hex);
global_key(b"SUP:IDX:", suffix.as_bytes())
}
/// Audit record key: `\x00AUD:{query_id_hex}`
pub fn audit_key(query_id_hex: &str) -> Vec<u8> {
global_key(b"AUD:", query_id_hex.as_bytes())
}
/// Audit agent index key: `\x00AUDA:{agent_hex}:{timestamp_hex}:{query_hex}`
pub fn audit_agent_index_key(agent_hex: &str, timestamp_hex: &str, query_hex: &str) -> Vec<u8> {
let suffix = format!("{}:{}:{}", agent_hex, timestamp_hex, query_hex);
global_key(b"AUDA:", suffix.as_bytes())
}
/// Audit agent scan prefix: `\x00AUDA:{agent_hex}:`
pub fn audit_agent_prefix(agent_hex: &str) -> Vec<u8> {
let suffix = format!("{}:", agent_hex);
global_key(b"AUDA:", suffix.as_bytes())
}
/// Audit listing prefix: `\x00AUD:`
pub fn audit_scan_prefix() -> Vec<u8> {
global_key(b"AUD:", b"")
}
/// Escalation key: `\x00ESC:{timestamp}:{id_hex}`
pub fn escalation_key(timestamp: u64, id_hex: &str) -> Vec<u8> {
let suffix = format!("{}:{}", timestamp, id_hex);
global_key(b"ESC:", suffix.as_bytes())
}
/// Escalation scan prefix: `\x00ESC:`
pub fn escalation_scan_prefix() -> Vec<u8> {
global_key(b"ESC:", b"")
}
/// Trust pack key: `\x00TP:{pack_id_bytes}`
pub fn trust_pack_key(pack_id: &[u8]) -> Vec<u8> {
global_key(b"TP:", pack_id)
}
/// Trust pack scan prefix: `\x00TP:`
pub fn trust_pack_scan_prefix() -> Vec<u8> {
global_key(b"TP:", b"")
}
/// Gold standard verified key: `\x00GS_VERIFIED:{agent_hex}:{subject}:{predicate}`
pub fn gs_verified_key(agent_hex: &str, subject: &str, predicate: &str) -> Vec<u8> {
let suffix = format!("{}:{}:{}", agent_hex, subject, predicate);
global_key(b"GS_VERIFIED:", suffix.as_bytes())
}
/// Cursor key: `\x00META:cursor:ingest`
pub fn cursor_key() -> Vec<u8> {
global_key(b"META:cursor:ingest", b"")
}
/// Assertion count key: `\x00META:assertion_count`
pub fn assertion_count_key() -> Vec<u8> {
global_key(b"META:assertion_count", b"")
}
/// Trust rank scan prefix for decay: `\x00TRUST:`
pub fn trust_rank_scan_prefix() -> Vec<u8> {
global_key(b"TRUST:", b"")
}