session-search
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSession 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
undefinedbash
undefinedBuild 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
undefinedSession Commands Reference
会话命令参考
| Command | Description |
|---|---|
| Detect available session sources |
| Import sessions from source |
| List imported sessions |
| Full-text search |
| Show statistics |
| Show session details |
| Search by knowledge graph concept |
| Find related sessions |
| `/sessions timeline [--group day | week |
| `/sessions export [--format json | md] [--output file]` |
| Enrich with concepts |
| 命令 | 描述 |
|---|---|
| 检测可用的会话源 |
| 从指定源导入会话 |
| 列出已导入的会话 |
| 全文搜索 |
| 显示统计信息 |
| 显示会话详情 |
| 按知识图谱概念搜索 |
| 查找相关会话 |
| `/sessions timeline [--group day | week |
| `/sessions export [--format json | md] [--output file]` |
| 用概念增强会话 |
Example Workflows
示例工作流
Find previous work on a topic:
/sessions search "authentication"
/sessions show abc123-def456Discover patterns across projects:
/sessions import
/sessions stats
/sessions timeline --group week --limit 10Find 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 3CLI Usage
CLI使用方式
bash
undefinedbash
undefinedDirect 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
undefinedterraphim-agent sessions export --session abc123 --format markdown --output session.md
undefinedFor AI Agents
面向AI Agent
Detecting Session Capabilities
检测会话功能
Check if sessions feature is available:
bash
undefined检查会话功能是否可用:
bash
undefinedCheck 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
undefinedif terraphim-agent sessions sources 2>/dev/null | grep -q "claude-code"; then
echo "Session search available"
fi
undefinedProgrammatic 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 detailsYou: "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 details2. 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 patternsYou: "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 patterns3. 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 reuseYou: "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 reuse4. 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 archivalYou: "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 archivalSession 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
环境变量
| Variable | Description |
|---|---|
| Override Claude sessions location |
| Enable verbose logging |
| 变量 | 描述 |
|---|---|
| 覆盖Claude会话的存储位置 |
| 启用详细日志 |
Troubleshooting
故障排除
| Issue | Solution |
|---|---|
| No sessions found | Run |
| Import fails | Check permissions on |
| Search too slow | Use |
| Concepts not matching | Verify knowledge graph files in |
| Feature not available | Rebuild with |
| 问题 | 解决方案 |
|---|---|
| 未找到会话 | 运行 |
| 导入失败 | 检查 |
| 搜索过慢 | 使用 |
| 概念不匹配 | 验证 |
| 功能不可用 | 使用 |
Related Skills
相关技能
- - Knowledge graph-based text replacement
terraphim-hooks - - Use session history for debugging context
debugging - - Reference past architectural decisions
architecture
- - 基于知识图谱的文本替换
terraphim-hooks - - 使用会话历史获取调试上下文
debugging - - 参考过往的架构决策
architecture