diff --git a/backend/src/analysis/context_analyzer.cpp b/backend/src/analysis/context_analyzer.cpp index ec61d31..e77549a 100644 --- a/backend/src/analysis/context_analyzer.cpp +++ b/backend/src/analysis/context_analyzer.cpp @@ -12,6 +12,9 @@ namespace analysis { namespace { +// Maximum number of lines to scan for imports (imports typically at file top) +constexpr size_t IMPORT_SCAN_LIMIT = 50; + /** * @brief Trim whitespace from string. */ @@ -209,8 +212,8 @@ std::vector extract_imports( ) { std::vector imports; - // Scan first 50 lines (imports are typically at the top) - size_t scan_limit = std::min(lines.size(), size_t(50)); + // Scan first lines for imports (imports are typically at the top) + size_t scan_limit = std::min(lines.size(), IMPORT_SCAN_LIMIT); for (size_t i = 0; i < scan_limit; ++i) { std::string line = trim(lines[i]); diff --git a/backend/src/analysis/risk_analyzer.cpp b/backend/src/analysis/risk_analyzer.cpp index 4a3372d..dc439c6 100644 --- a/backend/src/analysis/risk_analyzer.cpp +++ b/backend/src/analysis/risk_analyzer.cpp @@ -13,6 +13,11 @@ namespace analysis { namespace { +// Confidence score weights for risk assessment +constexpr double BASE_CONFIDENCE = 0.5; // Base confidence level +constexpr double SIMILARITY_WEIGHT = 0.3; // Weight for code similarity +constexpr double CHANGE_RATIO_WEIGHT = 0.2; // Weight for change ratio + /** * @brief Trim whitespace from string. */ @@ -198,8 +203,10 @@ RiskAssessment analyze_risk_ours( // Calculate confidence score based on various factors double change_ratio = (our_changes + their_changes) > 0 ? - static_cast(our_changes) / (our_changes + their_changes) : 0.5; - assessment.confidence_score = 0.5 + (0.3 * similarity_to_theirs) + (0.2 * change_ratio); + static_cast(our_changes) / (our_changes + their_changes) : BASE_CONFIDENCE; + assessment.confidence_score = BASE_CONFIDENCE + + (SIMILARITY_WEIGHT * similarity_to_theirs) + + (CHANGE_RATIO_WEIGHT * change_ratio); // Add recommendations if (assessment.level >= RiskLevel::MEDIUM) { @@ -273,8 +280,10 @@ RiskAssessment analyze_risk_theirs( // Calculate confidence score double change_ratio = (our_changes + their_changes) > 0 ? - static_cast(their_changes) / (our_changes + their_changes) : 0.5; - assessment.confidence_score = 0.5 + (0.3 * similarity_to_ours) + (0.2 * change_ratio); + static_cast(their_changes) / (our_changes + their_changes) : BASE_CONFIDENCE; + assessment.confidence_score = BASE_CONFIDENCE + + (SIMILARITY_WEIGHT * similarity_to_ours) + + (CHANGE_RATIO_WEIGHT * change_ratio); // Add recommendations if (assessment.level >= RiskLevel::MEDIUM) { diff --git a/backend/src/merge/three_way_merge.cpp b/backend/src/merge/three_way_merge.cpp index 466944d..7a58132 100644 --- a/backend/src/merge/three_way_merge.cpp +++ b/backend/src/merge/three_way_merge.cpp @@ -70,13 +70,9 @@ MergeResult three_way_merge( conflict.their_lines.push_back({their_line, Line::THEIRS}); conflict.end_line = result.merged_lines.size(); - // Perform context analysis - // Use the merged lines we have so far as context - std::vector context_lines; - for (const auto& line : result.merged_lines) { - context_lines.push_back(line.content); - } - conflict.context = analysis::analyze_context(context_lines, i, i); + // Perform context analysis using ours version as context + // (could also use base or theirs, but ours is typically most relevant) + conflict.context = analysis::analyze_context(ours, i, i); // Perform risk analysis for different resolution strategies std::vector base_vec = {base_line};