Class: Genie::SessionConfig
- Inherits:
-
Object
- Object
- Genie::SessionConfig
- Defined in:
- lib/genie/session_config.rb
Overview
Handles loading of session configuration such as run_tests_cmd
Constant Summary collapse
- DEFAULT_INSTRUCTIONS =
<<~INSTRUCTIONS # Genie Instructions You are a Genie coding assistant. You help me write code using Test Driven Development (Genie) principles. You have some tools available to you, such as listing files, reading files, and writing files, and you can write code in Ruby. You will always write tests first, and then implement the code to pass those tests. You will not write any code that does not have a test. # Rules 1. We do not have access to any files outside of the base_path. 2. We do not have access to the internet. 3. You will always write tests first, and then implement the code to pass those tests. INSTRUCTIONS
- DEFAULTS =
{ base_path: ".", run_tests_cmd: 'rake test', model: 'gpt-4o-mini', first_question: nil, instructions: DEFAULT_INSTRUCTIONS, ignore_paths: ['tmp', '/tmp'], }
Instance Attribute Summary collapse
-
#base_path ⇒ Object
readonly
Read-only attributes.
-
#first_question ⇒ Object
readonly
Read-only attributes.
-
#ignore_paths ⇒ Object
readonly
Read-only attributes.
-
#instructions ⇒ Object
readonly
Read-only attributes.
-
#model ⇒ Object
readonly
Read-only attributes.
-
#run_tests_cmd ⇒ Object
readonly
Read-only attributes.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(base_path:, run_tests_cmd:, model:, first_question:, instructions:, ignore_paths:) ⇒ SessionConfig
constructor
A new instance of SessionConfig.
Constructor Details
#initialize(base_path:, run_tests_cmd:, model:, first_question:, instructions:, ignore_paths:) ⇒ SessionConfig
Returns a new instance of SessionConfig.
106 107 108 109 110 111 112 113 |
# File 'lib/genie/session_config.rb', line 106 def initialize(base_path:, run_tests_cmd:, model:, first_question:, instructions:, ignore_paths:) @base_path = File.(base_path) @run_tests_cmd = run_tests_cmd @model = model @first_question = first_question @instructions = instructions @ignore_paths = ignore_paths end |
Instance Attribute Details
#base_path ⇒ Object (readonly)
Read-only attributes
5 6 7 |
# File 'lib/genie/session_config.rb', line 5 def base_path @base_path end |
#first_question ⇒ Object (readonly)
Read-only attributes
5 6 7 |
# File 'lib/genie/session_config.rb', line 5 def first_question @first_question end |
#ignore_paths ⇒ Object (readonly)
Read-only attributes
5 6 7 |
# File 'lib/genie/session_config.rb', line 5 def ignore_paths @ignore_paths end |
#instructions ⇒ Object (readonly)
Read-only attributes
5 6 7 |
# File 'lib/genie/session_config.rb', line 5 def instructions @instructions end |
#model ⇒ Object (readonly)
Read-only attributes
5 6 7 |
# File 'lib/genie/session_config.rb', line 5 def model @model end |
#run_tests_cmd ⇒ Object (readonly)
Read-only attributes
5 6 7 |
# File 'lib/genie/session_config.rb', line 5 def run_tests_cmd @run_tests_cmd end |
Class Method Details
.default ⇒ Object
95 96 97 98 99 100 101 102 103 104 |
# File 'lib/genie/session_config.rb', line 95 def self.default new( base_path: DEFAULTS[:base_path], run_tests_cmd: DEFAULTS[:run_tests_cmd], model: DEFAULTS[:model], first_question: DEFAULTS[:first_question], instructions: DEFAULTS[:instructions], ignore_paths: DEFAULTS[:ignore_paths], ) end |
.from_argv(argv) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 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 |
# File 'lib/genie/session_config.rb', line 29 def self.from_argv(argv) = {} config_file = File. "./genie.yml" OptionParser.new do |opts| opts. = "Usage: genie [options]" opts.on("-c", "--config FILE", "Path to config file") do |file| config_file = File.(file) end opts.on("-b", "--base-path PATH", "Base path for the session") do |path| [:base_path] = path end opts.on("-r", "--run-tests CMD", "Command to run tests") do |cmd| [:run_tests_cmd] = cmd end opts.on("-m", "--model NAME", "Name of model to use") do |name| [:model] = name end opts.on("-i", "--instructions TEXT", "Instructions for the session") do |text| [:instructions] = text end opts.on("--ignore-paths LIST", "Comma-separated paths to ignore") do |list| [:ignore_paths] = list.split(',').map(&:strip) end opts.on("-v", "--[no-]verbose", "Enable verbose mode") do |v| ['verbose'] = v end end.parse!(argv) # Last remaining argument is the first question [:first_question] = argv.last if argv.any? file_config = {} if config_file && File.exist?(config_file) file_config = YAML.load_file(config_file, symbolize_names: true) end # 3️⃣ Merge: DEFAULT < FILE < CLI final_config = DEFAULTS.merge(file_config).merge() # We always preface the instructions with context final_config[:instructions] = <<~PREFACE # Context Current Date and Time: \\#{Time.now.iso8601} We are working in a codebase located at '\\#{final_config[:base_path]}'. \\#{final_config[:instructions]} PREFACE new( base_path: final_config[:base_path], run_tests_cmd: final_config[:run_tests_cmd], model: final_config[:model], first_question: final_config[:first_question], instructions: final_config[:instructions], ignore_paths: final_config[:ignore_paths] ) end |