Class: KairosMcp::Tools::SkillsRollback

Inherits:
BaseTool
  • Object
show all
Defined in:
lib/kairos_mcp/tools/skills_rollback.rb

Instance Method Summary collapse

Methods inherited from BaseTool

#initialize, #invoke_tool, #to_full_schema, #to_schema

Constructor Details

This class inherits a constructor from KairosMcp::Tools::BaseTool

Instance Method Details

#call(arguments) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/kairos_mcp/tools/skills_rollback.rb', line 66

def call(arguments)
  command = arguments['command'] || 'list'

  case command
  when 'list'
    versions = VersionManager.list_versions
    if versions.empty?
      return text_content("No version snapshots found.")
    end
    
    output = "Available Version Snapshots:\n\n"
    output += "| Filename | Created | Reason |\n"
    output += "|----------|---------|--------|\n"
    versions.each do |v|
      created = v[:created].strftime('%Y-%m-%d %H:%M:%S')
      reason = v[:reason] || '-'
      output += "| #{v[:filename]} | #{created} | #{reason} |\n"
    end
    text_content(output)

  when 'snapshot'
    reason = arguments['reason'] || 'manual snapshot'
    filename = VersionManager.create_snapshot(reason: reason)
    ActionLog.record(action: 'snapshot_created', details: { filename: filename, reason: reason })
    text_content("Snapshot created: #{filename}")

  when 'rollback'
    version = arguments['version']
    return text_content("Error: version filename is required") unless version
    
    begin
      VersionManager.rollback(version)
      ActionLog.record(action: 'rollback_performed', details: { version: version })
      text_content("Rollback successful. Restored to: #{version}")
    rescue => e
      text_content("Rollback failed: #{e.message}")
    end

  when 'view'
    version = arguments['version']
    return text_content("Error: version filename is required") unless version
    
    begin
      content = VersionManager.get_version_content(version)
      # Truncate if too long
      if content.length > 5000
        content = content[0, 5000] + "\n\n... (truncated)"
      end
      text_content("Content of #{version}:\n\n```ruby\n#{content}\n```")
    rescue => e
      text_content("Error: #{e.message}")
    end

  when 'diff'
    version = arguments['version']
    return text_content("Error: version filename is required") unless version
    
    begin
      diff = VersionManager.diff(version)
      output = "Diff Summary (#{version} vs current):\n\n"
      output += "- Old version: #{diff[:old_lines]} lines\n"
      output += "- Current version: #{diff[:current_lines]} lines\n"
      output += "- Lines added: #{diff[:added]}\n"
      output += "- Lines removed: #{diff[:removed]}\n"
      text_content(output)
    rescue => e
      text_content("Error: #{e.message}")
    end

  else
    text_content("Unknown command: #{command}")
  end
end

#categoryObject



16
17
18
# File 'lib/kairos_mcp/tools/skills_rollback.rb', line 16

def category
  :skills
end

#descriptionObject



12
13
14
# File 'lib/kairos_mcp/tools/skills_rollback.rb', line 12

def description
  'Manage Skills DSL versions. List available versions, create snapshots, or rollback to a previous version.'
end

#examplesObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/kairos_mcp/tools/skills_rollback.rb', line 24

def examples
  [
    {
      title: 'List versions',
      code: 'skills_rollback(command: "list")'
    },
    {
      title: 'Create snapshot',
      code: 'skills_rollback(command: "snapshot", reason: "Before major change")'
    },
    {
      title: 'Rollback to version',
      code: 'skills_rollback(command: "rollback", version: "kairos_20240115_143000.rb")'
    }
  ]
end

#input_schemaObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/kairos_mcp/tools/skills_rollback.rb', line 45

def input_schema
  {
    type: 'object',
    properties: {
      command: {
        type: 'string',
        description: 'Command: "list", "snapshot", "rollback", "view", or "diff"',
        enum: ['list', 'snapshot', 'rollback', 'view', 'diff']
      },
      version: {
        type: 'string',
        description: 'Version filename (for rollback/view/diff commands)'
      },
      reason: {
        type: 'string',
        description: 'Reason for creating snapshot (for snapshot command)'
      }
    }
  }
end

#nameObject



8
9
10
# File 'lib/kairos_mcp/tools/skills_rollback.rb', line 8

def name
  'skills_rollback'
end


41
42
43
# File 'lib/kairos_mcp/tools/skills_rollback.rb', line 41

def related_tools
  %w[skills_evolve skills_dsl_list chain_history]
end

#usecase_tagsObject



20
21
22
# File 'lib/kairos_mcp/tools/skills_rollback.rb', line 20

def usecase_tags
  %w[rollback version snapshot backup restore L0 undo]
end