Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/terraphim_agent/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ terraphim_hooks = { path = "../terraphim_hooks", version = "1.0.0" }
terraphim_tracker = { path = "../terraphim_tracker", version = "1.0.0" }
terraphim_orchestrator = { path = "../terraphim_orchestrator", version = "1.0.0" }
# Session search - uses workspace version (path for dev, version for crates.io)
terraphim_sessions = { path = "../terraphim_sessions", version = "1.6.0", optional = true, features = ["tsa-full", "aider-connector"] }
terraphim_sessions = { path = "../terraphim_sessions", version = "1.6.0", optional = true, features = ["tsa-full", "aider-connector", "search-index"] }

[dev-dependencies]
serial_test = "3.3"
Expand Down
10 changes: 9 additions & 1 deletion crates/terraphim_agent/src/repl/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ pub enum SessionsSubcommand {
Files { session_id: String, json: bool },
/// Find sessions by file path
ByFile { file_path: String, json: bool },
/// Build search index and show index statistics
Index { verbose: bool },
}

#[cfg(feature = "firecracker")]
Expand Down Expand Up @@ -1309,8 +1311,14 @@ impl FromStr for ReplCommand {
subcommand: SessionsSubcommand::ByFile { file_path, json },
})
}
"index" => {
let verbose = parts.contains(&"--verbose") || parts.contains(&"-v");
Ok(ReplCommand::Sessions {
subcommand: SessionsSubcommand::Index { verbose },
})
}
_ => Err(anyhow!(
"Unknown sessions subcommand: {}. Use: sources, list, search, stats, show, concepts, related, timeline, export, enrich, files, by-file",
"Unknown sessions subcommand: {}. Use: sources, list, search, stats, show, concepts, related, timeline, export, enrich, files, by-file, index",
parts[1]
)),
}
Expand Down
168 changes: 131 additions & 37 deletions crates/terraphim_agent/src/repl/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1904,49 +1904,105 @@ impl ReplHandler {
}

SessionsSubcommand::Search { query } => {
let sessions = svc.search(&query).await;
#[cfg(feature = "enrichment")]
{
let thesaurus = if let Some(ref tui_service) = self.service {
let role_name: terraphim_types::RoleName = self.current_role.clone().into();
tui_service.get_thesaurus(&role_name).await.ok()
} else {
None
};
let sessions = svc.search_with_thesaurus(&query, thesaurus).await;

if sessions.is_empty() {
println!("{} No sessions match '{}'", "ℹ".blue().bold(), query.cyan());
return Ok(());
}
if sessions.is_empty() {
println!("{} No sessions match '{}'", "ℹ".blue().bold(), query.cyan());
return Ok(());
}

println!(
"\n{} sessions match '{}':",
sessions.len().to_string().green(),
query.cyan()
);
let mut table = Table::new();
table
.load_preset(UTF8_FULL)
.apply_modifier(UTF8_ROUND_CORNERS)
.set_header(vec![
Cell::new("ID").add_attribute(comfy_table::Attribute::Bold),
Cell::new("Source").add_attribute(comfy_table::Attribute::Bold),
Cell::new("Title").add_attribute(comfy_table::Attribute::Bold),
]);
println!(
"\n{} sessions match '{}':",
sessions.len().to_string().green(),
query.cyan()
);
let mut table = Table::new();
table
.load_preset(UTF8_FULL)
.apply_modifier(UTF8_ROUND_CORNERS)
.set_header(vec![
Cell::new("ID").add_attribute(comfy_table::Attribute::Bold),
Cell::new("Source").add_attribute(comfy_table::Attribute::Bold),
Cell::new("Title").add_attribute(comfy_table::Attribute::Bold),
]);

for session in sessions.iter().take(10) {
let title = session
.title
.as_ref()
.map(|t| {
if t.len() > 50 {
format!("{}...", &t[..50])
} else {
t.clone()
}
})
.unwrap_or_else(|| "-".to_string());
for session in sessions.iter().take(10) {
let title = session
.title
.as_ref()
.map(|t| {
if t.len() > 50 {
format!("{}...", &t[..50])
} else {
t.clone()
}
})
.unwrap_or_else(|| "-".to_string());

table.add_row(vec![
Cell::new(&session.external_id[..8.min(session.external_id.len())]),
Cell::new(&session.source),
Cell::new(title),
]);
table.add_row(vec![
Cell::new(&session.external_id[..8.min(session.external_id.len())]),
Cell::new(&session.source),
Cell::new(title),
]);
}

println!("{}", table);
}

println!("{}", table);
#[cfg(not(feature = "enrichment"))]
{
let sessions = svc.search(&query).await;

if sessions.is_empty() {
println!("{} No sessions match '{}'", "ℹ".blue().bold(), query.cyan());
return Ok(());
}

println!(
"\n{} sessions match '{}':",
sessions.len().to_string().green(),
query.cyan()
);
let mut table = Table::new();
table
.load_preset(UTF8_FULL)
.apply_modifier(UTF8_ROUND_CORNERS)
.set_header(vec![
Cell::new("ID").add_attribute(comfy_table::Attribute::Bold),
Cell::new("Source").add_attribute(comfy_table::Attribute::Bold),
Cell::new("Title").add_attribute(comfy_table::Attribute::Bold),
]);

for session in sessions.iter().take(10) {
let title = session
.title
.as_ref()
.map(|t| {
if t.len() > 50 {
format!("{}...", &t[..50])
} else {
t.clone()
}
})
.unwrap_or_else(|| "-".to_string());

table.add_row(vec![
Cell::new(&session.external_id[..8.min(session.external_id.len())]),
Cell::new(&session.source),
Cell::new(title),
]);
}

println!("{}", table);
}
}

SessionsSubcommand::Stats => {
Expand Down Expand Up @@ -2546,6 +2602,44 @@ impl ReplHandler {
println!("{}", table);
}
}

SessionsSubcommand::Index { verbose } => {
let sessions = svc.list_sessions().await;
let count = sessions.len();
let total_messages: usize = sessions.iter().map(|s| s.message_count()).sum();

println!("\n{} Search Index Status", "🔍".bold());
println!("{}", "─".repeat(40));
println!(" Sessions indexed: {}", count.to_string().green());
println!(" Total messages: {}", total_messages.to_string().green());
println!(" Scorer: {}", "BM25 (Okapi)".cyan());

if verbose {
let sources: std::collections::HashMap<&str, usize> = {
let mut map = std::collections::HashMap::new();
for s in &sessions {
*map.entry(s.source.as_str()).or_default() += 1;
}
map
};
println!("\n {} By source:", "▸".blue());
for (source, cnt) in sources {
println!(" {}: {}", source.magenta(), cnt);
}

let total_chars: usize = sessions
.iter()
.map(|s| {
s.messages.iter().map(|m| m.content.len()).sum::<usize>()
+ s.title.as_ref().map(|t| t.len()).unwrap_or(0)
})
.sum();
println!(
"\n Total text size: {} chars",
total_chars.to_string().yellow()
);
}
}
}

Ok(())
Expand Down
Loading
Loading