Class: KairosMcp::UpgradeAnalyzer
- Inherits:
-
Object
- Object
- KairosMcp::UpgradeAnalyzer
- Defined in:
- lib/kairos_mcp/upgrade_analyzer.rb
Overview
UpgradeAnalyzer: 3-way hash comparison for safe template migration
Compares three versions of each template file:
1. Original (hash stored in .kairos_meta.yml at init time)
2. Current (user's version in the data directory)
3. New (latest template shipped with the gem)
Classification patterns:
Pattern 0 (unchanged): user == original, new == original
Pattern 1 (auto_updatable): user == original, new != original
Pattern 2 (user_modified): user != original, new == original
Pattern 3 (conflict): user != original, new != original
Constant Summary collapse
- PATTERNS =
{ unchanged: 'No changes needed', auto_updatable: 'Safe to auto-update (user has not modified)', user_modified: 'User has modified, template unchanged (keep user version)', conflict: 'Both user and template changed (requires merge/review)' }.freeze
Instance Attribute Summary collapse
-
#has_meta ⇒ Object
readonly
Returns the value of attribute has_meta.
-
#knowledge_results ⇒ Object
readonly
Returns the value of attribute knowledge_results.
-
#meta ⇒ Object
readonly
Returns the value of attribute meta.
-
#results ⇒ Object
readonly
Returns the value of attribute results.
Instance Method Summary collapse
-
#analyze ⇒ Hash
Analyze all template files and knowledge, classify each.
-
#files_by_pattern(pattern) ⇒ Object
Get files by pattern.
-
#gem_version ⇒ Object
Get the installed gem version.
-
#initialize ⇒ UpgradeAnalyzer
constructor
A new instance of UpgradeAnalyzer.
-
#knowledge_summary ⇒ Object
Knowledge summary counts.
-
#meta_version ⇒ Object
Get the version recorded in .kairos_meta.yml.
-
#summary ⇒ Object
Summary counts by pattern (L0 templates only).
-
#upgrade_needed? ⇒ Boolean
Check if an upgrade is needed (version mismatch).
Constructor Details
#initialize ⇒ UpgradeAnalyzer
Returns a new instance of UpgradeAnalyzer.
31 32 33 34 35 36 37 38 |
# File 'lib/kairos_mcp/upgrade_analyzer.rb', line 31 def initialize @templates_dir = KairosMcp.templates_dir @data_dir = KairosMcp.data_dir @meta = @has_meta = File.exist?(KairosMcp.) @results = {} @knowledge_results = {} end |
Instance Attribute Details
#has_meta ⇒ Object (readonly)
Returns the value of attribute has_meta.
29 30 31 |
# File 'lib/kairos_mcp/upgrade_analyzer.rb', line 29 def @has_meta end |
#knowledge_results ⇒ Object (readonly)
Returns the value of attribute knowledge_results.
29 30 31 |
# File 'lib/kairos_mcp/upgrade_analyzer.rb', line 29 def knowledge_results @knowledge_results end |
#meta ⇒ Object (readonly)
Returns the value of attribute meta.
29 30 31 |
# File 'lib/kairos_mcp/upgrade_analyzer.rb', line 29 def @meta end |
#results ⇒ Object (readonly)
Returns the value of attribute results.
29 30 31 |
# File 'lib/kairos_mcp/upgrade_analyzer.rb', line 29 def results @results end |
Instance Method Details
#analyze ⇒ Hash
Analyze all template files and knowledge, classify each
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/kairos_mcp/upgrade_analyzer.rb', line 43 def analyze @results = {} @knowledge_results = {} # Analyze L0 template files KairosMcp::TEMPLATE_FILES.each do |template_name, accessor| @results[template_name] = analyze_file(template_name, accessor) end # Analyze L1 knowledge templates analyze_knowledge @results end |
#files_by_pattern(pattern) ⇒ Object
Get files by pattern
89 90 91 |
# File 'lib/kairos_mcp/upgrade_analyzer.rb', line 89 def files_by_pattern(pattern) @results.select { |_, r| r[:pattern] == pattern } end |
#gem_version ⇒ Object
Get the installed gem version
59 60 61 |
# File 'lib/kairos_mcp/upgrade_analyzer.rb', line 59 def gem_version KairosMcp::VERSION end |
#knowledge_summary ⇒ Object
Knowledge summary counts
82 83 84 85 86 |
# File 'lib/kairos_mcp/upgrade_analyzer.rb', line 82 def knowledge_summary counts = { new: 0, updated: 0, unchanged: 0, user_modified: 0, conflict: 0 } @knowledge_results.each_value { |r| counts[r[:status]] += 1 } counts end |
#meta_version ⇒ Object
Get the version recorded in .kairos_meta.yml
64 65 66 |
# File 'lib/kairos_mcp/upgrade_analyzer.rb', line 64 def @meta['kairos_mcp_version'] end |
#summary ⇒ Object
Summary counts by pattern (L0 templates only)
75 76 77 78 79 |
# File 'lib/kairos_mcp/upgrade_analyzer.rb', line 75 def summary counts = Hash.new(0) @results.each_value { |r| counts[r[:pattern]] += 1 } counts end |
#upgrade_needed? ⇒ Boolean
Check if an upgrade is needed (version mismatch)
69 70 71 72 |
# File 'lib/kairos_mcp/upgrade_analyzer.rb', line 69 def upgrade_needed? return true unless @has_meta != gem_version end |