Skip to content
Open
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
2 changes: 1 addition & 1 deletion src/auth/token_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl<'a, R: ConfigRepository> TokenManager<'a, R> {
.ok()
.and_then(|c| DateTime::parse_from_rfc3339(&c.value).ok())
.map(|dt| dt.with_timezone(&Utc))
.unwrap_or_else(|| Utc::now());
.unwrap_or_else(Utc::now);

let id_token = config_service::fetch_by_key(self.repo, &ConfigKeys::CodexIdToken.to_key())
.ok()
Expand Down
23 changes: 11 additions & 12 deletions src/branch/comparison.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
/// Branch comparison features for TermAI
// Branch comparison features for TermAI
//
// This module provides sophisticated comparison capabilities between conversation branches,
// allowing users to analyze different approaches, solutions, and outcomes side-by-side.
#[allow(dead_code)]
///
/// This module provides sophisticated comparison capabilities between conversation branches,
/// allowing users to analyze different approaches, solutions, and outcomes side-by-side.

use crate::branch::entity::branch_entity::BranchEntity;
use crate::branch::service::BranchService;
use crate::repository::db::SqliteRepository;
Expand Down Expand Up @@ -168,7 +167,7 @@ impl BranchComparator {
// Header
output.push_str(&format!("{}\n", "📊 Side-by-Side Branch Comparison".bright_green().bold()));
output.push_str(&format!("{}\n", "═".repeat(40).dimmed()));
output.push_str("\n");
output.push('\n');

// Branch headers
let branch_names: Vec<String> = comparison.branches.iter()
Expand Down Expand Up @@ -269,7 +268,7 @@ impl BranchComparator {

output.push_str(&format!("{}\n", "📋 Comparison Summary".bright_yellow().bold()));
output.push_str(&format!("{}\n", "═".repeat(20).dimmed()));
output.push_str("\n");
output.push('\n');

let summary = &comparison.summary;

Expand All @@ -282,7 +281,7 @@ impl BranchComparator {
"Overall similarity:".bright_cyan(),
summary.similarity_percentage
));
output.push_str("\n");
output.push('\n');

// Quality scores
if !summary.quality_scores.is_empty() {
Expand All @@ -305,7 +304,7 @@ impl BranchComparator {
}
));
}
output.push_str("\n");
output.push('\n');
}

// Unique insights
Expand All @@ -327,7 +326,7 @@ impl BranchComparator {
insight.description
));
}
output.push_str("\n");
output.push('\n');
}

// Recommendations
Expand Down Expand Up @@ -647,7 +646,7 @@ impl QuickCompare {
let mut output = String::new();
output.push_str(&format!("{}\n", "🎯 Branch Outcomes Comparison".bright_green().bold()));
output.push_str(&format!("{}\n", "═".repeat(30).dimmed()));
output.push_str("\n");
output.push('\n');

for (i, branch) in comparison.branches.iter().enumerate() {
let branch_name = branch.branch_name.as_deref().unwrap_or("unnamed");
Expand Down Expand Up @@ -678,7 +677,7 @@ impl QuickCompare {
output.push_str(&format!(" {} {}\n", "Description:".dimmed(), description.dimmed()));
}

output.push_str("\n");
output.push('\n');
}

// Add recommendations
Expand Down
17 changes: 8 additions & 9 deletions src/branch/merge.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/// Branch merging and integration module for TermAI
///
/// This module provides sophisticated merging capabilities for conversation branches,
/// allowing users to consolidate insights, resolve conflicts, and maintain conversation flow.

// Branch merging and integration module for TermAI
//
// This module provides sophisticated merging capabilities for conversation branches,
// allowing users to consolidate insights, resolve conflicts, and maintain conversation flow.
use crate::branch::entity::branch_entity::BranchEntity;
use crate::branch::service::BranchService;
use crate::branch::comparison::{BranchComparator, BranchComparison};
Expand Down Expand Up @@ -301,7 +300,7 @@ impl BranchMerger {

output.push_str(&format!("{}\n", "📋 Merge Preview".bright_green().bold()));
output.push_str(&format!("{}\n", "═".repeat(15).dimmed()));
output.push_str("\n");
output.push('\n');

// Source branches
output.push_str(&format!("{}\n", "Source branches:".bright_cyan()));
Expand All @@ -324,7 +323,7 @@ impl BranchMerger {
};
output.push_str(&format!("{} {}\n", "Strategy:".bright_cyan(), strategy_desc.bright_white()));

output.push_str("\n");
output.push('\n');

// Conflicts
if !merge.conflicts.is_empty() {
Expand All @@ -349,7 +348,7 @@ impl BranchMerger {
}

// Resolution plan
output.push_str("\n");
output.push('\n');
output.push_str(&format!("{}\n", "🎯 Resolution Plan:".bright_yellow().bold()));
for action in &merge.resolution_plan.suggested_actions {
output.push_str(&format!(" • {}\n", action));
Expand Down Expand Up @@ -564,7 +563,7 @@ impl BranchMerger {
branch.created_at.format("%Y-%m-%d %H:%M:%S")
));
output.push_str(&format!("Status: {}\n", branch.status));
output.push_str("\n");
output.push('\n');

for (i, message) in messages.iter().enumerate() {
output.push_str(&format!("Message {} ({:?}):\n", i + 1, message.role));
Expand Down
16 changes: 7 additions & 9 deletions src/branch/mod.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
/// Conversation branching module for TermAI
///
/// This module provides tree-like conversation management, allowing users to:
/// - Branch conversations at any point to explore alternative paths
/// - Compare different approaches and solutions
/// - Merge successful branches back into main conversations
/// - Navigate complex problem-solving workflows efficiently

// Conversation branching module for TermAI
//
// This module provides tree-like conversation management, allowing users to:
// - Branch conversations at any point to explore alternative paths
// - Compare different approaches and solutions
// - Merge successful branches back into main conversations
// - Navigate complex problem-solving workflows efficiently
#[allow(dead_code)]
#[allow(unused_imports)]

pub mod entity;
pub mod repository;
pub mod service;
Expand Down
4 changes: 2 additions & 2 deletions src/branch/repository/branch_message_repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl BranchMessageRepository {
)?;

let rows = stmt.query_map(params![branch_id], |row| {
Ok(row.get::<_, String>(0)?)
row.get::<_, String>(0)
})?;

let mut message_ids = Vec::new();
Expand Down Expand Up @@ -139,7 +139,7 @@ impl BranchMessageRepository {
)?;

let rows = stmt.query_map(params![message_id], |row| {
Ok(row.get::<_, String>(0)?)
row.get::<_, String>(0)
})?;

let mut branch_ids = Vec::new();
Expand Down
4 changes: 2 additions & 2 deletions src/branch/repository/branch_metadata_repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl BranchMetadataRepository {
)?;

let mut rows = stmt.query_map(params![branch_id, key], |row| {
Ok(row.get::<_, String>(0)?)
row.get::<_, String>(0)
})?;

match rows.next() {
Expand Down Expand Up @@ -93,7 +93,7 @@ impl BranchMetadataRepository {
)?;

let rows = stmt.query_map(params![key, value], |row| {
Ok(row.get::<_, String>(0)?)
row.get::<_, String>(0)
})?;

let mut branch_ids = Vec::new();
Expand Down
11 changes: 5 additions & 6 deletions src/branch/service/branch_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl BranchService {

// Copy messages if needed
if let Some(parent_id) = &parent_branch_id {
Self::copy_branch_messages_to_point(repo, &parent_id, &branch_id, from_message_index)?;
Self::copy_branch_messages_to_point(repo, parent_id, &branch_id, from_message_index)?;
} else {
Self::copy_session_messages_to_point(repo, session_id, &branch_id, from_message_index)?;
}
Expand Down Expand Up @@ -146,8 +146,7 @@ impl BranchService {
}
}

/// Internal helper methods

// Internal helper methods
fn create_branch_in_db(repo: &mut SqliteRepository, branch: &BranchEntity) -> Result<()> {
repo.conn.execute(
"INSERT INTO conversation_branches (id, session_id, parent_branch_id, branch_name, description, created_at, last_activity, status)
Expand All @@ -174,7 +173,7 @@ impl BranchService {
)?;

let rows = stmt.query_map(params![branch_id], |row| {
Ok(row.get::<_, String>(0)?)
row.get::<_, String>(0)
})?;

let mut message_ids = Vec::new();
Expand Down Expand Up @@ -455,7 +454,7 @@ impl BranchService {
let mut children_map: std::collections::HashMap<String, Vec<&BranchEntity>> = std::collections::HashMap::new();
for branch in branches {
if let Some(parent_id) = &branch.parent_branch_id {
children_map.entry(parent_id.clone()).or_insert_with(Vec::new).push(branch);
children_map.entry(parent_id.clone()).or_default().push(branch);
}
}

Expand Down Expand Up @@ -495,7 +494,7 @@ impl BranchService {
let mut children_map: std::collections::HashMap<String, Vec<&BranchEntity>> = std::collections::HashMap::new();
for branch in branches {
if let Some(parent_id) = &branch.parent_branch_id {
children_map.entry(parent_id.clone()).or_insert_with(Vec::new).push(branch);
children_map.entry(parent_id.clone()).or_default().push(branch);
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/branch/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl BranchTree {
}

// Add legend
output.push_str("\n");
output.push('\n');
output.push_str(&format!("{}\n", "Legend:".bright_yellow().bold()));
output.push_str(&format!(" {} Current branch\n", "*".bright_green()));
output.push_str(&format!(" {} Active branch\n", "●".bright_blue()));
Expand All @@ -68,7 +68,7 @@ impl BranchTree {

if let Some(parent_id) = &branch.parent_branch_id {
children_map.entry(parent_id.clone())
.or_insert_with(Vec::new)
.or_default()
.push(branch.clone());
}
}
Expand Down Expand Up @@ -174,7 +174,7 @@ impl BranchTree {

// Format timestamp
let time_info = format!(" [{}]",
node.branch.created_at.format("%Y-%m-%d").to_string()
node.branch.created_at.format("%Y-%m-%d")
).dimmed();

// Add line to output
Expand Down Expand Up @@ -273,7 +273,7 @@ impl BranchTree {
output.push_str(&format!("{}\n", "🌳 Interactive Branch Navigator".bright_green().bold()));
output.push_str(&format!("{}\n", "═".repeat(32).dimmed()));
output.push_str(&format!("{}\n", "[↑↓] Navigate [Enter] Switch [q] Quit".bright_yellow()));
output.push_str("\n");
output.push('\n');

for root_node in &tree_nodes {
Self::render_interactive_node(&mut output, root_node, "", true, selected_branch_id)?;
Expand Down
6 changes: 2 additions & 4 deletions src/chat/demo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ pub async fn demo_enhanced_chat_formatting() -> Result<()> {
let mut formatter = ChatFormatter::new();

// Demo different types of responses that would come from an AI
let sample_responses = vec![
(
let sample_responses = [(
"Simple response",
"Hello! I'm your AI assistant. How can I help you today?"
),
Expand Down Expand Up @@ -120,8 +119,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
> The key is that async operations don't block the thread while waiting!

This makes your applications much more efficient when dealing with I/O-bound workloads."#
),
];
)];

// Demonstrate each type of response
for (i, (description, content)) in sample_responses.iter().enumerate() {
Expand Down
27 changes: 12 additions & 15 deletions src/chat/formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,24 +406,21 @@ impl ChatFormatter {
let trimmed = line.trim();

// Handle headers - improved styling with better visual separation
if trimmed.starts_with("### ") {
let title = &trimmed[4..]; // Remove "### "
if let Some(title) = trimmed.strip_prefix("### ") {
// Remove "### "
return format!("🔷 {}", title).bright_cyan().bold().to_string().into();
} else if trimmed.starts_with("##") {
let title = if trimmed.starts_with("## ") {
&trimmed[3..] // Remove "## "
} else {
&trimmed[2..] // Remove "##"
};
} else if let Some(title) = trimmed.strip_prefix("## ") {
return format!("🔵 {}", title.trim()).bright_blue().bold().to_string().into();
} else if let Some(title) = trimmed.strip_prefix("##") {
return format!("🔵 {}", title.trim()).bright_blue().bold().to_string().into();
} else if trimmed.starts_with("# ") {
let title = &trimmed[2..]; // Remove "# "
} else if let Some(title) = trimmed.strip_prefix("# ") {
// Remove "# "
return format!("🟢 {}", title).bright_green().bold().to_string().into();
}

// Handle lists
if trimmed.starts_with("- ") || trimmed.starts_with("* ") {
return format!(" • {}", &trimmed[2..]).bright_yellow().to_string().into();
if let Some(item) = trimmed.strip_prefix("- ").or_else(|| trimmed.strip_prefix("* ")) {
return format!(" • {}", item).bright_yellow().to_string().into();
}

// Handle numbered lists
Expand All @@ -434,8 +431,8 @@ impl ChatFormatter {
}

// Handle blockquotes
if trimmed.starts_with("> ") {
return format!("│ {}", &trimmed[2..]).bright_magenta().italic().to_string().into();
if let Some(quote) = trimmed.strip_prefix("> ") {
return format!("│ {}", quote).bright_magenta().italic().to_string().into();
}

// Handle bold and italic
Expand Down Expand Up @@ -738,7 +735,7 @@ impl ChatFormatter {
pub fn format_context_info(&self, context_size: usize, files: &[String]) -> String {
let mut info = String::new();
info.push_str(
&format!("📁 Context Information:\n")
&"📁 Context Information:\n".to_string()
.bright_blue()
.bold()
.to_string(),
Expand Down
8 changes: 4 additions & 4 deletions src/chat/interactive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ where
sessions_service::session_add_messages(
self.session_repo,
self.message_repo,
&mut self.session,
&self.session,
)?;
self.repl
.print_message(&self.formatter.format_session_saved(&session_name));
Expand Down Expand Up @@ -349,7 +349,7 @@ where
sessions_service::session_add_messages(
self.session_repo,
self.message_repo,
&mut self.session,
&self.session,
)?;
}
Err(e) => {
Expand Down Expand Up @@ -444,7 +444,7 @@ where
}

// Extract content from the path
let new_context = extract_content(&Some(path.to_string()), &vec![], &vec![]);
let new_context = extract_content(&Some(path.to_string()), &[], &[]);

if let Some(mut files) = new_context {
// Remove duplicates and add new files
Expand Down Expand Up @@ -513,7 +513,7 @@ where
sessions_service::session_add_messages(
self.session_repo,
self.message_repo,
&mut self.session,
&self.session,
)?;
self.repl.print_message(
&self
Expand Down
2 changes: 1 addition & 1 deletion src/commands/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ async fn suggest_presets_for_context(files: &[Files]) -> Result<Vec<(String, Str
}
}

if has_tests || (has_code && !has_tests) {
if has_tests || has_code {
for preset in &builtin_presets {
if preset.name == "Test Generator" {
let reason = if has_tests {
Expand Down
Loading
Loading