Shared memory and context tools for agentic work.
Code Rooms
use serde::{Deserialize, Serialize};
use std::collections::hash_map::DefaultHasher;
use std::hash::{Hash, Hasher};
use std::path::Path;
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "snake_case")]
pub enum SourceKind {
NativeLight,
NativeArticle,
NativeBibtex,
NativeCrossref,
NativeRfc,
NativePatent,
Markdown,
Text,
Html,
Pdf,
Docx,
Pptx,
Xlsx,
Unknown,
}
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Default)]
pub enum ConfidenceLevel {
Explicit,
#[default]
Parsed,
Inferred,
pub enum DocumentBlockKind {
Heading,
Paragraph,
ListItem,
Code,
Quote,
Table,
Link,
pub enum DocumentSectionKind {
Overview,
Api,
Constraints,
Tests,
Rollout,
Reference,
Appendix,
pub enum DocumentEntityKind {
Symbol,
FilePath,
ToolId,
CitationId,
CodeRef,
NamedTerm,
TestName,
pub enum DocumentClaimKind {
Requirement,
Invariant,
Warning,
Decision,
TestExpectation,
Capability,
pub enum ClaimModality {
Must,
Should,
May,
Is,
#[derive(Clone, Debug, Serialize, Deserialize, Default)]
pub struct DocumentMetadata {
pub title: Option<String>,
pub subtitle: Option<String>,
pub authors: Vec<String>,
pub doi: Option<String>,
pub published_at: Option<String>,
pub language: Option<String>,
pub extra: std::collections::HashMap<String, String>,
pub struct ProvenanceSpan {
pub line_start: Option<u32>,
pub line_end: Option<u32>,
pub excerpt: Option<String>,
pub struct DocumentSpan {
pub text: String,
pub kind: String,
pub confidence: ConfidenceLevel,
pub provenance: ProvenanceSpan,
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct DocumentBlock {
pub block_id: String,
pub kind: DocumentBlockKind,
#[serde(default)]
pub spans: Vec<DocumentSpan>,
pub struct DocumentSection {
pub section_id: String,
pub heading: String,
pub level: u8,
pub kind: DocumentSectionKind,
pub parent_section_id: Option<String>,
pub blocks: Vec<DocumentBlock>,
pub struct DocumentTableCell {
pub struct DocumentTableRow {
pub cells: Vec<DocumentTableCell>,
pub struct DocumentTable {
pub table_id: String,
pub headers: Vec<String>,
pub rows: Vec<DocumentTableRow>,
pub struct DocumentLink {
pub label: String,
pub target: String,
pub struct DocumentCitation {
pub citation_kind: String,
pub venue: Option<String>,
pub year: Option<String>,
pub struct DocumentEntityCandidate {
pub kind: DocumentEntityKind,
pub aliases: Vec<String>,
pub struct DocumentClaimCandidate {
pub claim_id: String,
pub kind: DocumentClaimKind,
pub modality: ClaimModality,
pub subject: Option<String>,
pub predicate: Option<String>,
pub object: Option<String>,
pub negated: bool,
pub struct DocumentCodeCandidate {
pub candidate_kind: DocumentEntityKind,
pub struct CanonicalDocument {
pub doc_id: String,
pub source_path: String,
pub source_kind: SourceKind,
pub detected_type: String,
pub producer: String,
pub content_hash: String,
pub title: String,
pub plain_text: String,
pub metadata: DocumentMetadata,
pub sections: Vec<DocumentSection>,
pub tables: Vec<DocumentTable>,
pub links: Vec<DocumentLink>,
pub citations: Vec<DocumentCitation>,
pub entities: Vec<DocumentEntityCandidate>,
pub claims: Vec<DocumentClaimCandidate>,
pub code_candidates: Vec<DocumentCodeCandidate>,
pub structured_origin: serde_json::Value,
pub fn short_hash(input: &str) -> String {
let mut hasher = DefaultHasher::new();
input.hash(&mut hasher);
format!("{:016x}", hasher.finish())
pub fn short_hash_bytes(input: &[u8]) -> String {
pub fn source_key(source_path: &str) -> String {
short_hash(source_path)
pub fn source_kind_from_extension(path: &Path) -> SourceKind {
match path
.extension()
.and_then(|value| value.to_str())
.map(|value| value.to_ascii_lowercase())
.as_deref()
{
Some("md" | "markdown") => SourceKind::Markdown,
Some("txt" | "rst" | "adoc") => SourceKind::Text,
Some("html" | "htm") => SourceKind::Html,
Some("pdf") => SourceKind::Pdf,
Some("docx") => SourceKind::Docx,
Some("pptx") => SourceKind::Pptx,
Some("xlsx") => SourceKind::Xlsx,
_ => SourceKind::Unknown,