sublayer 0.2.6 → 0.2.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cd6e0c13942ecc4a6a8a41dc3f80705f363e71fed66993db9ac455e753027937
4
- data.tar.gz: 7998c6aecf3a1fdab9c31b5dd0cdc3b2838e4ed0d4719de2a9f7242a37c27906
3
+ metadata.gz: 303d94d0e110bb92231590e4fde380733d33f2febd3782dc71b93a431292ee3e
4
+ data.tar.gz: 27b87bdc5a2fab40612a1aad56b10184fcd90100094f66c46ae43ff25c1f1cdb
5
5
  SHA512:
6
- metadata.gz: b8d97003e00766bd9280cd73c8477908d250b689a65cda9f711d35117b8d4b28bea4559c6b743e20ce8fc1e73f724396e1ac96c1eb93f4ec670cad81b5b267ba
7
- data.tar.gz: f62ddfa1032ed5595d99fff93f5027f6c4d07e61183fdb290d3bc84cda3d2b85fd0fb17e7ca03222040f10786b1a8789be5e4f57f66cb17b0bdfacb570009712
6
+ metadata.gz: 8fce247e8089440f0f604c23c9f76d56572304ac9ac5f86fcb8d6777387d45a0d6118b48e31cdaf3e920f724f4702e42890061abbf54294eb6bac919f9ee92ef
7
+ data.tar.gz: 9715cce6c6b31c9924e0699ed756d34434661e186c1a24377ee5451d3fab88f56e7cc5adc772dddcaf48d8f82755ff6ab790c2097e1d72fe6b8c001e6d258035
@@ -9,6 +9,10 @@ module Sublayer
9
9
  class_option :provider, type: :string, desc: "AI provider (OpenAI, Claude, or Gemini)", aliases: :p
10
10
  class_option :model, type: :string, desc: "AI model name to use (e.g. gpt-4o, claude-3-haiku-20240307, gemini-1.5-flash-latest)", aliases: :m
11
11
 
12
+ def self.banner
13
+ "sublayer generate:action"
14
+ end
15
+
12
16
  def confirm_usage_of_ai_api
13
17
  puts "You are about to generate a new agent that uses an AI API to generate content."
14
18
  puts "Please ensure you have the necessary API keys and that you are aware of the costs associated with using the API."
@@ -9,6 +9,10 @@ module Sublayer
9
9
  class_option :provider, type: :string, desc: "AI provider (OpenAI, Claude, or Gemini)", aliases: :p
10
10
  class_option :model, type: :string, desc: "AI model name to use (e.g. gpt-4o, claude-3-haiku-20240307, gemini-1.5-flash-latest)", aliases: :m
11
11
 
12
+ def self.banner
13
+ "sublayer generate:agent"
14
+ end
15
+
12
16
  def confirm_usage_of_ai_api
13
17
  puts "You are about to generate a new agent that uses an AI API to generate content."
14
18
  puts "Please ensure you have the necessary API keys and that you are aware of the costs associated with using the API."
@@ -1,4 +1,5 @@
1
1
  require_relative "generators/sublayer_generator_generator"
2
+ require_relative "generators/sublayer_command_generator"
2
3
 
3
4
  module Sublayer
4
5
  module Commands
@@ -8,6 +9,15 @@ module Sublayer
8
9
  class_option :description, type: :string, desc: "Description of the generator you want to generate", aliases: :d
9
10
  class_option :provider, type: :string, desc: "AI provider (OpenAI, Claude, or Gemini)", aliases: :p
10
11
  class_option :model, type: :string, desc: "AI model name to use (e.g. gpt-4o, claude-3-haiku-20240307, gemini-1.5-flash-latest)", aliases: :m
12
+ class_option :generate_command, type: :boolean, desc: "Generate a command for the new generator", aliases: :c
13
+
14
+ def self.banner
15
+ "sublayer generate:generator"
16
+ end
17
+
18
+ def self.source_root
19
+ File.expand_path("../../templates", __FILE__)
20
+ end
11
21
 
12
22
  def confirm_usage_of_ai_api
13
23
  puts "You are about to generate a new generator that uses an AI API to generate content."
@@ -27,6 +37,10 @@ module Sublayer
27
37
  @description = options[:description] || ask("Enter a description for the Sublayer Generator you'd like to create:")
28
38
  @ai_provider = options[:provider] || ask("Select an AI provider:", default: "OpenAI", limited_to: @available_providers)
29
39
  @ai_model = options[:model] || select_ai_model
40
+
41
+ if is_cli_project? && options[:generate_command].nil?
42
+ @generate_command = yes?("Would you like to create a corresponding CLI command for this generator?")
43
+ end
30
44
  end
31
45
 
32
46
  def generate_generator
@@ -52,7 +66,46 @@ module Sublayer
52
66
  create_file File.join(@destination_folder, @results.filename), @results.code
53
67
  end
54
68
 
69
+ def generate_command_if_requested
70
+ return unless @generate_command
71
+
72
+ say "Generating command..."
73
+
74
+ generator_code = File.read(File.join(@destination_folder, @results.filename))
75
+ command_results = SublayerCommandGenerator.new(generator_code: generator_code).generate
76
+ @command_class_name = command_results.class_name
77
+ @command_description = command_results.description
78
+ @command_execute_body = command_results.execute_body
79
+ @command_filename = command_results.filename
80
+
81
+ commands_folder = File.join("lib", @project_name, "commands")
82
+
83
+ destination_path = File.join(commands_folder, @command_filename)
84
+ template("utilities/cli/command.rb.tt", destination_path)
85
+ end
86
+
55
87
  private
88
+ def is_cli_project?
89
+ config_path = find_config_file
90
+ return false unless config_path
91
+
92
+ config = YAML.load_file(config_path)
93
+ @project_name = config[:project_name]
94
+ config[:project_template] == 'CLI'
95
+ rescue StandardError => e
96
+ say "Error reading project configuration: #{e.message}", :red
97
+ false
98
+ end
99
+
100
+ def find_config_file
101
+ possible_paths = [
102
+ File.join(Dir.pwd, 'config', 'sublayer.yml'),
103
+ File.join(Dir.pwd, 'lib', '*', 'config', 'sublayer.yml' )
104
+ ]
105
+
106
+ Dir.glob(possible_paths).first
107
+ end
108
+
56
109
  def select_ai_model
57
110
  case @ai_provider
58
111
  when "OpenAI"
@@ -0,0 +1,55 @@
1
+ class SublayerCommandGenerator < Sublayer::Generators::Base
2
+ llm_output_adapter type: :named_strings,
3
+ name: "sublayer_command",
4
+ description: "The new command code based on the generator",
5
+ attributes: [
6
+ { name: "class_name", description: "The class name of the command" },
7
+ { name: "description", description: "The description of the command" },
8
+ { name: "execute_body", description: "The code inside the execute method" },
9
+ { name: "filename", description: "The filename of the command, snake_cased with a .rb extension" }
10
+ ]
11
+
12
+ def initialize(generator_code:)
13
+ @generator_code = generator_code
14
+ end
15
+
16
+ def generate
17
+ super
18
+ end
19
+
20
+ def prompt
21
+ <<-PROMPT
22
+ You are an expert Ruby developer.
23
+
24
+ Given the following Sublayer generator code:
25
+
26
+ #{@generator_code}
27
+
28
+ Please generate a Thor command class that interacts with this generator. The command should:
29
+
30
+ - Be a subclass of `BaseCommand`.
31
+ - Include a descriptive class name.
32
+ - Provide a description for the command.
33
+ - Implement an `execute` method that accepts appropriate arguments and invokes the generator.
34
+
35
+ Provide the class name, description, execute method body, and filename for the command.
36
+
37
+ These parameters will be used in a template to create the command file. The template is:
38
+ module <%= project_name.camelize %>
39
+ module Commands
40
+ class <%= command_class_name %> < BaseCommand
41
+ def self.description
42
+ "<%= command_description %>"
43
+ end
44
+
45
+ def execute(*args)
46
+ <%= command_execute_body %>
47
+ end
48
+ end
49
+ end
50
+ end
51
+
52
+ Take into account any parameters the generator requires and map them to command-line arguments.
53
+ PROMPT
54
+ end
55
+ end
@@ -17,6 +17,10 @@ module Sublayer
17
17
  File.dirname(__FILE__)
18
18
  end
19
19
 
20
+ def self.banner
21
+ "sublayer new PROJECT_NAME"
22
+ end
23
+
20
24
  def ask_for_project_details
21
25
  puts options[:template]
22
26
  @project_template = options[:template] || ask("Select a project template:", default: "CLI", limited_to: %w[CLI QuickScript])
@@ -0,0 +1,13 @@
1
+ module <%= @project_name.camelize %>
2
+ module Commands
3
+ class <%= @command_class_name %> < BaseCommand
4
+ def self.description
5
+ "<%= @command_description %>"
6
+ end
7
+
8
+ def execute(*args)
9
+ <%= @command_execute_body %>
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Sublayer
4
- VERSION = "0.2.6"
4
+ VERSION = "0.2.7"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sublayer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Werner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-08-30 00:00:00.000000000 Z
11
+ date: 2024-09-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-openai
@@ -176,6 +176,7 @@ files:
176
176
  - lib/sublayer/cli/commands/generators/example_generator.rb
177
177
  - lib/sublayer/cli/commands/generators/sublayer_action_generator.rb
178
178
  - lib/sublayer/cli/commands/generators/sublayer_agent_generator.rb
179
+ - lib/sublayer/cli/commands/generators/sublayer_command_generator.rb
179
180
  - lib/sublayer/cli/commands/generators/sublayer_generator_generator.rb
180
181
  - lib/sublayer/cli/commands/new_project.rb
181
182
  - lib/sublayer/cli/commands/subcommand_base.rb
@@ -200,6 +201,7 @@ files:
200
201
  - lib/sublayer/cli/templates/quick_script/actions/example_action.rb
201
202
  - lib/sublayer/cli/templates/quick_script/agents/example_agent.rb
202
203
  - lib/sublayer/cli/templates/quick_script/generators/example_generator.rb
204
+ - lib/sublayer/cli/templates/utilities/cli/command.rb.tt
203
205
  - lib/sublayer/components/output_adapters.rb
204
206
  - lib/sublayer/components/output_adapters/formattable.rb
205
207
  - lib/sublayer/components/output_adapters/list_of_named_strings.rb