session-search

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Session Search

会话搜索

Use this skill when searching through AI coding assistant history to find relevant past work, patterns, or context from previous sessions.
当你需要在AI编码助手历史记录中查找相关的过往工作、模式或之前会话的上下文时,可以使用此技能。

Overview

概述

Terraphim provides unified session search across multiple AI coding assistants:
  • Claude Code - Native session parsing from
    ~/.claude/projects/
  • Cursor - IDE session history
  • Aider - Git-based conversation logs
  • OpenCode - Session history
Key Capabilities:
  • Full-text search across messages
  • Knowledge graph-enriched concept search
  • Related session discovery
  • Timeline visualization
  • Export to JSON/Markdown
Terraphim提供跨多个AI编码助手的统一会话搜索功能:
  • Claude Code - 从
    ~/.claude/projects/
    原生解析会话
  • Cursor - IDE会话历史
  • Aider - 基于Git的对话日志
  • OpenCode - 会话历史
核心功能:
  • 跨消息的全文搜索
  • 知识图谱增强的概念搜索
  • 相关会话发现
  • 时间线可视化
  • 导出为JSON/Markdown格式

Architecture

架构

┌─────────────────────────────────────────────────────────────────┐
│                     Session Sources                             │
│  ┌──────────────┐  ┌──────────────┐  ┌──────────────┐          │
│  │ Claude Code  │  │   Cursor     │  │    Aider     │          │
│  │ ~/.claude/   │  │ ~/.cursor/   │  │ .aider.chat  │          │
│  └──────────────┘  └──────────────┘  └──────────────┘          │
└─────────────────────────────────────────────────────────────────┘
              ┌───────────────────────────────┐
              │     terraphim_sessions        │
              │   (Connector Registry)        │
              └───────────────────────────────┘
              ┌───────────────┴───────────────┐
              │                               │
              ▼                               ▼
   ┌──────────────────────┐       ┌──────────────────────┐
   │   SessionService     │       │   SessionEnricher    │
   │   (Import, Search)   │       │   (Concept Matching) │
   └──────────────────────┘       └──────────────────────┘
              ┌───────────────────────────────┐
              │   Knowledge Graph Concepts    │
              │   (terraphim_automata)        │
              └───────────────────────────────┘
┌─────────────────────────────────────────────────────────────────┐
│                     Session Sources                             │
│  ┌──────────────┐  ┌──────────────┐  ┌──────────────┐          │
│  │ Claude Code  │  │   Cursor     │  │    Aider     │          │
│  │ ~/.claude/   │  │ ~/.cursor/   │  │ .aider.chat  │          │
│  └──────────────┘  └──────────────┘  └──────────────┘          │
└─────────────────────────────────────────────────────────────────┘
              ┌───────────────────────────────┐
              │     terraphim_sessions        │
              │   (Connector Registry)        │
              └───────────────────────────────┘
              ┌───────────────┴───────────────┐
              │                               │
              ▼                               ▼
   ┌──────────────────────┐       ┌──────────────────────┐
   │   SessionService     │       │   SessionEnricher    │
   │   (Import, Search)   │       │   (Concept Matching) │
   └──────────────────────┘       └──────────────────────┘
              ┌───────────────────────────────┐
              │   Knowledge Graph Concepts    │
              │   (terraphim_automata)        │
              └───────────────────────────────┘

For Humans

面向人类用户

Quick Start with REPL

使用REPL快速开始

bash
undefined
bash
undefined

Build with session features

Build with session features

cargo build -p terraphim_agent --features repl-full --release
cargo build -p terraphim_agent --features repl-full --release

Launch REPL

Launch REPL

./target/release/terraphim-agent
./target/release/terraphim-agent

In REPL:

In REPL:

/sessions sources # Detect available sources /sessions import # Import from all sources /sessions search "rust" # Search for "rust" in sessions /sessions stats # Show statistics
undefined
/sessions sources # Detect available sources /sessions import # Import from all sources /sessions search "rust" # Search for "rust" in sessions /sessions stats # Show statistics
undefined

Session Commands Reference

会话命令参考

CommandDescription
/sessions sources
Detect available session sources
/sessions import [source] [--limit N]
Import sessions from source
/sessions list [source] [--limit N]
List imported sessions
/sessions search <query>
Full-text search
/sessions stats
Show statistics
/sessions show <id>
Show session details
/sessions concepts <concept>
Search by knowledge graph concept
/sessions related <id> [--min N]
Find related sessions
`/sessions timeline [--group dayweek
`/sessions export [--format jsonmd] [--output file]`
/sessions enrich [id]
Enrich with concepts
命令描述
/sessions sources
检测可用的会话源
/sessions import [source] [--limit N]
从指定源导入会话
/sessions list [source] [--limit N]
列出已导入的会话
/sessions search <query>
全文搜索
/sessions stats
显示统计信息
/sessions show <id>
显示会话详情
/sessions concepts <concept>
按知识图谱概念搜索
/sessions related <id> [--min N]
查找相关会话
`/sessions timeline [--group dayweek
`/sessions export [--format jsonmd] [--output file]`
/sessions enrich [id]
用概念增强会话

Example Workflows

示例工作流

Find previous work on a topic:
/sessions search "authentication"
/sessions show abc123-def456
Discover patterns across projects:
/sessions import
/sessions stats
/sessions timeline --group week --limit 10
Find related solutions:
/sessions concepts "error handling"
/sessions related abc123 --min 3
查找关于某个主题的过往工作:
/sessions search "authentication"
/sessions show abc123-def456
跨项目发现模式:
/sessions import
/sessions stats
/sessions timeline --group week --limit 10
查找相关解决方案:
/sessions concepts "error handling"
/sessions related abc123 --min 3

CLI Usage

CLI使用方式

bash
undefined
bash
undefined

Direct CLI search (without REPL)

Direct CLI search (without REPL)

terraphim-agent sessions search "database migration"
terraphim-agent sessions search "database migration"

Import and search in one pipeline

Import and search in one pipeline

terraphim-agent sessions import && terraphim-agent sessions search "API design"
terraphim-agent sessions import && terraphim-agent sessions search "API design"

Export specific session

Export specific session

terraphim-agent sessions export --session abc123 --format markdown --output session.md
undefined
terraphim-agent sessions export --session abc123 --format markdown --output session.md
undefined

For AI Agents

面向AI Agent

Detecting Session Capabilities

检测会话功能

Check if sessions feature is available:
bash
undefined
检查会话功能是否可用:
bash
undefined

Check if terraphim-agent has session support

Check if terraphim-agent has session support

if terraphim-agent sessions sources 2>/dev/null | grep -q "claude-code"; then echo "Session search available" fi
undefined
if terraphim-agent sessions sources 2>/dev/null | grep -q "claude-code"; then echo "Session search available" fi
undefined

Programmatic Usage (Rust)

编程式使用(Rust)

rust
use terraphim_sessions::{SessionService, ImportOptions};

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    // Create service
    let service = SessionService::new();

    // Detect sources
    let sources = service.detect_sources();
    for source in sources {
        println!("{}: {:?}", source.id, source.status);
    }

    // Import sessions
    let options = ImportOptions::default().with_limit(100);
    let sessions = service.import_all(&options).await?;

    // Search
    let results = service.search("async rust").await;
    for session in results {
        println!("{}: {} messages",
            session.id,
            session.message_count()
        );
    }

    Ok(())
}
rust
use terraphim_sessions::{SessionService, ImportOptions};

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    // Create service
    let service = SessionService::new();

    // Detect sources
    let sources = service.detect_sources();
    for source in sources {
        println!("{}: {:?}", source.id, source.status);
    }

    // Import sessions
    let options = ImportOptions::default().with_limit(100);
    let sessions = service.import_all(&options).await?;

    // Search
    let results = service.search("async rust").await;
    for session in results {
        println!("{}: {} messages",
            session.id,
            session.message_count()
        );
    }

    Ok(())
}

Knowledge Graph Enrichment

知识图谱增强

rust
use terraphim_sessions::{SessionEnricher, EnrichmentConfig};

// Create enricher with automata
let config = EnrichmentConfig {
    thesaurus_path: "docs/src/kg/".into(),
    min_confidence: 0.8,
};
let enricher = SessionEnricher::new(config)?;

// Enrich session with concepts
let enriched = enricher.enrich(&session)?;

// Get matched concepts
for concept in enriched.concepts {
    println!("{}: {} occurrences",
        concept.term,
        concept.occurrences.len()
    );
}

// Find related sessions by shared concepts
let related = find_related_sessions(&sessions, &enriched, 3)?;
rust
use terraphim_sessions::{SessionEnricher, EnrichmentConfig};

// Create enricher with automata
let config = EnrichmentConfig {
    thesaurus_path: "docs/src/kg/".into(),
    min_confidence: 0.8,
};
let enricher = SessionEnricher::new(config)?;

// Enrich session with concepts
let enriched = enricher.enrich(&session)?;

// Get matched concepts
for concept in enriched.concepts {
    println!("{}: {} occurrences",
        concept.term,
        concept.occurrences.len()
    );
}

// Find related sessions by shared concepts
let related = find_related_sessions(&sessions, &enriched, 3)?;

MCP Integration

MCP集成

Session search can be exposed via MCP tools:
json
{
  "tool": "session_search",
  "arguments": {
    "query": "error handling patterns",
    "limit": 10
  }
}
会话搜索可通过MCP工具暴露:
json
{
  "tool": "session_search",
  "arguments": {
    "query": "error handling patterns",
    "limit": 10
  }
}

claude-log-analyzer Usage

claude-log-analyzer使用方式

For detailed session analysis:
rust
use claude_log_analyzer::{Analyzer, Reporter};

// Analyze from default location
let analyzer = Analyzer::from_default_location()?;
let analyses = analyzer.analyze(None)?;

// Get agent usage statistics
for analysis in &analyses {
    for agent in &analysis.agents {
        println!("{}: {} invocations",
            agent.agent_type,
            agent.invocation_count
        );
    }
}

// Generate report
let reporter = Reporter::new();
reporter.print_terminal(&analyses);
用于详细的会话分析:
rust
use claude_log_analyzer::{Analyzer, Reporter};

// Analyze from default location
let analyzer = Analyzer::from_default_location()?;
let analyses = analyzer.analyze(None)?;

// Get agent usage statistics
for analysis in &analyses {
    for agent in &analysis.agents {
        println!("{}: {} invocations",
            agent.agent_type,
            agent.invocation_count
        );
    }
}

// Generate report
let reporter = Reporter::new();
reporter.print_terminal(&analyses);

Use Cases

使用场景

1. Learning from Past Work

1. 从过往工作中学习

You: "How did I solve the authentication issue last month?"
Claude: [session-search skill]

Action:
1. /sessions search "authentication"
2. /sessions timeline --group week
3. /sessions show <relevant-id>

Output:
- Session summaries matching query
- Timeline of related work
- Full conversation details
You: "How did I solve the authentication issue last month?"
Claude: [session-search skill]

Action:
1. /sessions search "authentication"
2. /sessions timeline --group week
3. /sessions show <relevant-id>

Output:
- Session summaries matching query
- Timeline of related work
- Full conversation details

2. Discovering Patterns

2. 发现模式

You: "What agents have I used most frequently?"
Claude: [session-search skill]

Action:
1. Import all sessions
2. Analyze agent usage via claude-log-analyzer
3. Generate statistics

Output:
- Agent usage breakdown
- Most productive agents
- Collaboration patterns
You: "What agents have I used most frequently?"
Claude: [session-search skill]

Action:
1. Import all sessions
2. Analyze agent usage via claude-log-analyzer
3. Generate statistics

Output:
- Agent usage breakdown
- Most productive agents
- Collaboration patterns

3. Context for New Tasks

3. 为新任务提供上下文

You: "I need to implement caching again"
Claude: [session-search skill]

Action:
1. /sessions concepts "caching"
2. /sessions related <cache-session-id>
3. Extract relevant patterns

Output:
- Previous caching implementations
- Related design decisions
- Code patterns to reuse
You: "I need to implement caching again"
Claude: [session-search skill]

Action:
1. /sessions concepts "caching"
2. /sessions related <cache-session-id>
3. Extract relevant patterns

Output:
- Previous caching implementations
- Related design decisions
- Code patterns to reuse

4. Knowledge Transfer

4. 知识转移

You: "Export my sessions about the payment system"
Claude: [session-search skill]

Action:
1. /sessions search "payment"
2. /sessions export --format markdown --output payments-history.md

Output:
- Markdown file with full session history
- Ready for sharing or archival
You: "Export my sessions about the payment system"
Claude: [session-search skill]

Action:
1. /sessions search "payment"
2. /sessions export --format markdown --output payments-history.md

Output:
- Markdown file with full session history
- Ready for sharing or archival

Session Data Model

会话数据模型

rust
pub struct Session {
    pub id: SessionId,
    pub source: String,           // "claude-code", "cursor", etc.
    pub title: Option<String>,
    pub messages: Vec<Message>,
    pub metadata: SessionMetadata,
}

pub struct Message {
    pub role: MessageRole,        // User, Assistant, System
    pub content: String,
    pub timestamp: Option<DateTime>,
}

pub struct SessionMetadata {
    pub project_path: Option<String>,
    pub started_at: Option<DateTime>,
    pub ended_at: Option<DateTime>,
    pub agent_types: Vec<String>,
}
rust
pub struct Session {
    pub id: SessionId,
    pub source: String,           // "claude-code", "cursor", etc.
    pub title: Option<String>,
    pub messages: Vec<Message>,
    pub metadata: SessionMetadata,
}

pub struct Message {
    pub role: MessageRole,        // User, Assistant, System
    pub content: String,
    pub timestamp: Option<DateTime>,
}

pub struct SessionMetadata {
    pub project_path: Option<String>,
    pub started_at: Option<DateTime>,
    pub ended_at: Option<DateTime>,
    pub agent_types: Vec<String>,
}

Configuration

配置

Feature Flags

特性标志

toml
[dependencies]
terraphim_agent = {
    version = "1.6",
    features = ["repl-sessions"]
}

terraphim_sessions = {
    version = "1.6",
    features = ["tsa-full", "enrichment"]
}
toml
[dependencies]
terraphim_agent = {
    version = "1.6",
    features = ["repl-sessions"]
}

terraphim_sessions = {
    version = "1.6",
    features = ["tsa-full", "enrichment"]
}

Environment Variables

环境变量

VariableDescription
CLAUDE_SESSIONS_DIR
Override Claude sessions location
TERRAPHIM_VERBOSE
Enable verbose logging
变量描述
CLAUDE_SESSIONS_DIR
覆盖Claude会话的存储位置
TERRAPHIM_VERBOSE
启用详细日志

Troubleshooting

故障排除

IssueSolution
No sessions foundRun
/sessions sources
to check available sources
Import failsCheck permissions on
~/.claude/projects/
Search too slowUse
--limit
to reduce scope
Concepts not matchingVerify knowledge graph files in
docs/src/kg/
Feature not availableRebuild with
--features repl-sessions
问题解决方案
未找到会话运行
/sessions sources
检查可用的会话源
导入失败检查
~/.claude/projects/
的权限
搜索过慢使用
--limit
参数缩小搜索范围
概念不匹配验证
docs/src/kg/
目录下的知识图谱文件
功能不可用使用
--features repl-sessions
重新构建

Related Skills

相关技能

  • terraphim-hooks
    - Knowledge graph-based text replacement
  • debugging
    - Use session history for debugging context
  • architecture
    - Reference past architectural decisions
  • terraphim-hooks
    - 基于知识图谱的文本替换
  • debugging
    - 使用会话历史获取调试上下文
  • architecture
    - 参考过往的架构决策