Class: Studio::Blueprint

Inherits:
Object
  • Object
show all
Defined in:
lib/studio/blueprint.rb

Overview

rubocop:todo Style/Documentation

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Blueprint

Returns a new instance of Blueprint.



13
14
15
16
17
# File 'lib/studio/blueprint.rb', line 13

def initialize(argv)
  @argv = argv.dup
  @base_command = @argv.shift
  @blueprint_args = parse_blueprint_args(@argv)
end

Instance Attribute Details

#argvObject (readonly)

Returns the value of attribute argv.



7
8
9
# File 'lib/studio/blueprint.rb', line 7

def argv
  @argv
end

#base_commandObject (readonly)

Returns the value of attribute base_command.



7
8
9
# File 'lib/studio/blueprint.rb', line 7

def base_command
  @base_command
end

#blueprint_argsObject (readonly)

Returns the value of attribute blueprint_args.



7
8
9
# File 'lib/studio/blueprint.rb', line 7

def blueprint_args
  @blueprint_args
end

Class Method Details

.argv(argv) ⇒ Object



9
10
11
# File 'lib/studio/blueprint.rb', line 9

def self.argv(argv)
  new(argv)
end

Instance Method Details

#execute(args = []) ⇒ Object

Execute the command with provided arguments



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/studio/blueprint.rb', line 20

def execute(args = [])
  full_command = build_command(args)

  # Spawn the process and capture output
  stdout, stderr, status = Open3.capture3(*full_command)

  {
    stdout: stdout,
    stderr: stderr,
    exit_code: status.exitstatus,
    success: status.success?
  }
rescue StandardError => e
  {
    stdout: "",
    stderr: "Studio error: #{e.message}",
    exit_code: 1,
    success: false
  }
end

#input_schemaObject

Get the input schema for MCP tool



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/studio/blueprint.rb', line 57

def input_schema
  schema = {
    type: "object",
    properties: {}
  }

  if @blueprint_args.empty?
    schema[:properties][:args] = {
      type: "array",
      items: { type: "string" },
      description: "Additional command line arguments"
    }
  else
    # Add blueprint arguments to schema
    @blueprint_args.each do |blueprint_arg|
      schema[:properties][blueprint_arg[:name].to_sym] = {
        type: "string",
        description: blueprint_arg[:description]
      }
    end
  end

  schema
end

#tool_descriptionObject

Get the tool description for MCP



47
48
49
50
51
52
53
54
# File 'lib/studio/blueprint.rb', line 47

def tool_description
  if @blueprint_args.any?
    blueprint_desc = @blueprint_args.map { |arg| "{{#{arg[:name]}}}" }.join(" ")
    "Run the shell command `#{@base_command} #{blueprint_desc}`"
  else
    "Run the shell command `#{@base_command} [args]`"
  end
end

#tool_nameObject

Get the tool name for MCP



42
43
44
# File 'lib/studio/blueprint.rb', line 42

def tool_name
  @base_command.gsub(/[^a-zA-Z0-9_]/, "_")
end