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
111 changes: 10 additions & 101 deletions crates/terraphim_agent/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -806,35 +806,21 @@ fn get_session_cache_path() -> std::path::PathBuf {
enum SessionsSub {
/// Detect available session sources (Claude Code, Cursor, etc.)
Sources,
/// Import sessions from all available sources
Import {
/// Limit number of sessions to import
#[arg(long, default_value_t = 100)]
limit: usize,
},
/// Import sessions from a specific source
ImportFrom {
/// Source ID (e.g., "claude-code-native")
source: String,
/// Limit number of sessions to import
#[arg(long, default_value_t = 100)]
limit: usize,
},
/// List all cached sessions
/// List all cached sessions (auto-imports if cache is empty)
List {
/// Limit number of sessions to show
#[arg(long, default_value_t = 20)]
limit: usize,
},
/// Search sessions by query string
/// Search sessions by query string (auto-imports if cache is empty)
Search {
/// Search query
query: String,
/// Limit number of results
#[arg(long, default_value_t = 10)]
limit: usize,
},
/// Show session statistics
/// Show session statistics (auto-imports if cache is empty)
Stats,
}

Expand Down Expand Up @@ -1839,7 +1825,7 @@ async fn run_offline_command(

#[cfg(feature = "repl-sessions")]
Command::Sessions { sub } => {
use terraphim_sessions::{SessionService, connector::ImportOptions};
use terraphim_sessions::SessionService;

let service = SessionService::new();

Expand Down Expand Up @@ -1878,46 +1864,10 @@ async fn run_offline_command(
}
Ok(())
}
SessionsSub::Import { limit } => {
let options = ImportOptions {
limit: Some(limit),
..Default::default()
};
match service.import_all(&options).await {
Ok(sessions) => {
// Save to cache file
let cache_path = get_session_cache_path();
if let Ok(data) = serde_json::to_string_pretty(&sessions) {
let _ = std::fs::write(&cache_path, data);
}
println!("Imported {} sessions.", sessions.len());
Ok(())
}
Err(e) => Err(anyhow::anyhow!("Import failed: {}", e)),
}
}
SessionsSub::ImportFrom { source, limit } => {
let options = ImportOptions {
limit: Some(limit),
..Default::default()
};
match service.import_from(&source, &options).await {
Ok(sessions) => {
// Save to cache file
let cache_path = get_session_cache_path();
if let Ok(data) = serde_json::to_string_pretty(&sessions) {
let _ = std::fs::write(&cache_path, data);
}
println!("Imported {} sessions from {}.", sessions.len(), source);
Ok(())
}
Err(e) => Err(anyhow::anyhow!("Import from {} failed: {}", source, e)),
}
}
SessionsSub::List { limit } => {
let sessions = service.list_sessions().await;
if sessions.is_empty() {
println!("No sessions in cache. Import first with 'sessions import'.");
println!("No sessions found.");
} else {
println!("Cached sessions ({} total):", sessions.len());
for session in sessions.iter().take(limit) {
Expand All @@ -1934,10 +1884,7 @@ async fn run_offline_command(
SessionsSub::Search { query, limit } => {
let results = service.search(&query).await;
if results.is_empty() {
println!(
"No sessions matching '{}'. Import first with 'sessions import'.",
query
);
println!("No sessions matching '{}'.", query);
} else {
println!("Found {} matching sessions:", results.len());
for session in results.iter().take(limit) {
Expand Down Expand Up @@ -2613,7 +2560,7 @@ async fn run_server_command(

#[cfg(feature = "repl-sessions")]
Command::Sessions { sub } => {
use terraphim_sessions::{SessionService, connector::ImportOptions};
use terraphim_sessions::SessionService;

let rt = Runtime::new()?;
rt.block_on(async {
Expand Down Expand Up @@ -2641,46 +2588,11 @@ async fn run_server_command(
}
Ok(())
}
SessionsSub::Import { limit } => {
let options = ImportOptions {
limit: Some(limit),
..Default::default()
};
match service.import_all(&options).await {
Ok(sessions) => {
// Save to cache file
let cache_path = get_session_cache_path();
if let Ok(data) = serde_json::to_string_pretty(&sessions) {
let _ = std::fs::write(&cache_path, data);
}
println!("Imported {} sessions.", sessions.len());
Ok(())
}
Err(e) => Err(anyhow::anyhow!("Import failed: {}", e)),
}
}
SessionsSub::ImportFrom { source, limit } => {
let options = ImportOptions {
limit: Some(limit),
..Default::default()
};
match service.import_from(&source, &options).await {
Ok(sessions) => {
// Save to cache file
let cache_path = get_session_cache_path();
if let Ok(data) = serde_json::to_string_pretty(&sessions) {
let _ = std::fs::write(&cache_path, data);
}
println!("Imported {} sessions from {}.", sessions.len(), source);
Ok(())
}
Err(e) => Err(anyhow::anyhow!("Import from {} failed: {}", source, e)),
}
}

SessionsSub::List { limit } => {
let sessions = service.list_sessions().await;
if sessions.is_empty() {
println!("No sessions in cache. Import first with 'sessions import'.");
println!("No sessions found.");
} else {
println!("Cached sessions ({} total):", sessions.len());
for session in sessions.iter().take(limit) {
Expand All @@ -2697,10 +2609,7 @@ async fn run_server_command(
SessionsSub::Search { query, limit } => {
let results = service.search(&query).await;
if results.is_empty() {
println!(
"No sessions matching '{}'. Import first with 'sessions import'.",
query
);
println!("No sessions matching '{}'.", query);
} else {
println!("Found {} matching sessions:", results.len());
for session in results.iter().take(limit) {
Expand Down
55 changes: 6 additions & 49 deletions crates/terraphim_agent/src/repl/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,7 @@ pub enum FileSubcommand {
pub enum SessionsSubcommand {
/// Detect available session sources
Sources,
/// Import sessions from a source
Import {
source: Option<String>,
limit: Option<usize>,
},
/// List imported sessions
/// List imported sessions (auto-imports if cache is empty)
List {
source: Option<String>,
limit: Option<usize>,
Expand Down Expand Up @@ -1105,47 +1100,9 @@ impl FromStr for ReplCommand {
"sources" | "detect" => Ok(ReplCommand::Sessions {
subcommand: SessionsSubcommand::Sources,
}),
"import" => {
let mut source = None;
let mut limit = None;
let mut i = 2;

while i < parts.len() {
match parts[i] {
"--source" => {
if i + 1 < parts.len() {
source = Some(parts[i + 1].to_string());
i += 2;
} else {
return Err(anyhow!("--source requires a value"));
}
}
"--limit" => {
if i + 1 < parts.len() {
limit = Some(
parts[i + 1]
.parse::<usize>()
.map_err(|_| anyhow!("Invalid limit value"))?,
);
i += 2;
} else {
return Err(anyhow!("--limit requires a value"));
}
}
_ => {
// Treat as source if no flag prefix
if source.is_none() && !parts[i].starts_with("--") {
source = Some(parts[i].to_string());
}
i += 1;
}
}
}

Ok(ReplCommand::Sessions {
subcommand: SessionsSubcommand::Import { source, limit },
})
}
"import" => Err(anyhow!(
"The 'import' command has been removed. Sessions are now automatically imported when needed. Use '/sessions list' or '/sessions search <query>' instead."
)),
"list" | "ls" => {
let mut source = None;
let mut limit = None;
Expand Down Expand Up @@ -1345,7 +1302,7 @@ impl FromStr for ReplCommand {
})
}
_ => Err(anyhow!(
"Unknown sessions subcommand: {}. Use: sources, import, 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",
parts[1]
)),
}
Expand Down Expand Up @@ -1502,7 +1459,7 @@ impl ReplCommand {

#[cfg(feature = "repl-sessions")]
"sessions" => Some(
"/sessions <subcommand> - AI coding session history (sources, import, list, search, stats, show, concepts, related, timeline, export, enrich, files, by-file)",
"/sessions <subcommand> - AI coding session history (sources, list, search, stats, show, concepts, related, timeline, export, enrich, files, by-file)",
),

_ => None,
Expand Down
25 changes: 2 additions & 23 deletions crates/terraphim_agent/src/repl/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1766,7 +1766,7 @@ impl ReplHandler {
use comfy_table::presets::UTF8_FULL;
use comfy_table::{Cell, Table};
use terraphim_sessions::{
ConnectorStatus, FileAccess, ImportOptions, MessageRole, Session, SessionService,
ConnectorStatus, FileAccess, MessageRole, Session, SessionService,
};

// Get or create session service
Expand Down Expand Up @@ -1820,24 +1820,6 @@ impl ReplHandler {
println!("{}", table);
}

SessionsSubcommand::Import { source, limit } => {
let options = ImportOptions::new().with_limit(limit.unwrap_or(100));

println!("\n{} Importing sessions...", "⏳".bold());

let sessions = if let Some(source_id) = source {
svc.import_from(&source_id, &options).await?
} else {
svc.import_all(&options).await?
};

println!(
"{} Imported {} session(s)",
"✅".bold(),
sessions.len().to_string().green()
);
}

SessionsSubcommand::List { source, limit } => {
let sessions = if let Some(source_id) = source {
svc.sessions_by_source(&source_id).await
Expand All @@ -1852,10 +1834,7 @@ impl ReplHandler {
};

if sessions.is_empty() {
println!(
"{} No sessions found. Run '/sessions import' first.",
"ℹ".blue().bold()
);
println!("{} No sessions found.", "ℹ".blue().bold());
return Ok(());
}

Expand Down
Loading
Loading