Skip to main content

second_brain_adapters/
lib.rs

1pub mod claude_code;
2pub mod claude_memory;
3pub mod cursor;
4mod persist;
5pub mod session_evidence;
6
7pub use persist::{IngestStore, StoreOutcome, store_ingest_result};
8
9use std::path::Path;
10
11use anyhow::Result;
12use second_brain_core::schema::{Conversation, Memory};
13
14/// The project a transcript belongs to is the directory directly under the
15/// adapter's `projects` root. Nothing below that level is a project: Claude
16/// Code nests subagent transcripts as `<session>/subagents/*.jsonl` and
17/// Cursor nests its own as `agent-transcripts/<session>/*.jsonl`, so the
18/// file's parent directory names the wrong thing for both.
19pub fn project_slug(projects_root: &Path, transcript: &Path) -> Option<String> {
20    transcript
21        .strip_prefix(projects_root)
22        .ok()?
23        .components()
24        .next()
25        .map(|c| c.as_os_str().to_string_lossy().to_string())
26}
27
28pub trait Adapter: Send + Sync {
29    fn name(&self) -> &str;
30    fn discover_conversations(&self) -> Result<Vec<ConversationSource>>;
31    fn ingest_conversation(&self, source: &ConversationSource) -> Result<IngestResult>;
32}
33
34#[derive(Debug, Clone)]
35pub struct ConversationSource {
36    pub id: String,
37    pub path: String,
38    pub source_name: String,
39    pub machine_id: String,
40}
41
42#[derive(Debug, Clone)]
43pub struct ExtractedEntity {
44    pub name: String,
45    pub entity_type: String,
46}
47
48#[derive(Debug, Clone)]
49pub struct IngestResult {
50    pub conversation: Conversation,
51    pub memories: Vec<Memory>,
52    pub entities: Vec<(ExtractedEntity, uuid::Uuid)>,
53    pub entities_extracted: usize,
54}