second_brain_adapters/
lib.rs1pub mod claude_code;
2pub mod claude_memory;
3pub mod cursor;
4mod document;
5pub mod git;
6pub mod markdown;
7mod persist;
8pub mod raw_text;
9pub mod repo_instructions;
10pub mod session_evidence;
11
12pub use persist::{IngestStore, StoreOutcome, store_document_result, store_ingest_result};
13
14use std::path::Path;
15
16use anyhow::Result;
17use second_brain_core::schema::{Conversation, Memory};
18
19pub fn project_slug(projects_root: &Path, transcript: &Path) -> Option<String> {
25 transcript
26 .strip_prefix(projects_root)
27 .ok()?
28 .components()
29 .next()
30 .map(|c| c.as_os_str().to_string_lossy().to_string())
31}
32
33pub fn encode_project_dir(path: &Path) -> String {
39 path.to_string_lossy()
40 .chars()
41 .flat_map(|c| {
42 let dashes = if c.is_ascii_alphanumeric() {
43 0
44 } else {
45 c.len_utf16()
46 };
47 std::iter::repeat_n('-', dashes).chain((dashes == 0).then_some(c))
48 })
49 .collect()
50}
51
52pub trait Adapter: Send + Sync {
53 fn name(&self) -> &str;
54 fn discover_conversations(&self) -> Result<Vec<ConversationSource>>;
55 fn ingest_conversation(&self, source: &ConversationSource) -> Result<IngestResult>;
56 fn session_key(&self, _path: &Path, _content: &str) -> Option<String> {
59 None
60 }
61}
62
63#[derive(Debug, Clone)]
64pub struct ConversationSource {
65 pub id: String,
66 pub path: String,
67 pub source_name: String,
68 pub machine_id: String,
69}
70
71#[derive(Debug, Clone)]
72pub struct ExtractedEntity {
73 pub name: String,
74 pub entity_type: String,
75}
76
77#[derive(Debug, Clone)]
78pub struct IngestResult {
79 pub conversation: Conversation,
80 pub memories: Vec<Memory>,
81 pub entities: Vec<(ExtractedEntity, uuid::Uuid)>,
82 pub entities_extracted: usize,
83}