Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
As I add more features, Agent would inevitably be bloated with methods, or I would need to create different kinds of agents. So I removed it in favour of commands, which are self-explanatory. Also, there's one less concept to learn
- Loading branch information
1 parent
2aa92b4
commit 59bd32e
Showing
24 changed files
with
235 additions
and
178 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# frozen_string_literal: true | ||
|
||
module Senior | ||
module Commands | ||
# Auto debugs a given method using AI to suggest fixes until the method no longer raises exceptions | ||
# | ||
# @api private | ||
# | ||
class AutoDebugMethod | ||
# Instantiates a new AutoDebugMethod | ||
# | ||
# @api private | ||
# | ||
# @param brain [Object] The interface to an AI's API | ||
# | ||
def initialize(brain = Brains::OpenAI.new) | ||
@brain = brain | ||
end | ||
|
||
# Calls the given method continuously, using AI to attempt to fix it until it no longer raises exceptions | ||
# | ||
# @api private | ||
# | ||
# @param broken_method [Method] A broken method to be fixed | ||
# @param args [Object] Arguments given to a broken method | ||
# @param broken_method_source [String|nil] Source code of the broken method | ||
# | ||
# @return [Object] The return value of the previously broken but now fixed method | ||
# | ||
def call(broken_method, args, broken_method_source = nil) | ||
broken_method.call(*args) | ||
rescue StandardError => e | ||
puts "The invocation #{broken_method.name}(#{args}) failed. Debugging..." | ||
|
||
suggested_fix_method_source = brain.suggest_method_fix( | ||
erroneous_source: broken_method_source || broken_method.source, | ||
exception_backtrace: e.backtrace&.first.to_s | ||
) | ||
|
||
puts "\nSuggested fix:\n#{suggested_fix_method_source}\n\n" | ||
|
||
suggested_fix_method_name = eval(suggested_fix_method_source) | ||
|
||
call(method(suggested_fix_method_name), args, suggested_fix_method_source) | ||
end | ||
|
||
private | ||
|
||
# The interface to an AI's API | ||
# | ||
# @api private | ||
# | ||
# @return [Object] | ||
# | ||
attr_reader :brain | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# frozen_string_literal: true | ||
|
||
module Senior | ||
module Commands | ||
# Suggests a fix for a broken method | ||
# | ||
# @api private | ||
# | ||
class SuggestMethodFix | ||
# Instantiates a new SuggestMethodFix | ||
# | ||
# @api private | ||
# | ||
# @param brain [Object] The interface to an AI's API | ||
# | ||
def initialize(brain = Brains::OpenAI.new) | ||
@brain = brain | ||
end | ||
|
||
# Suggests a fix for a broken method | ||
# | ||
# @api private | ||
# | ||
# @param broken_method [Method] A broken method to be fixed | ||
# @param args [Object] Arguments given to a broken method | ||
# | ||
# @return [String] The suggested fix | ||
# | ||
def call(broken_method, args) | ||
broken_method.call(*args) | ||
rescue StandardError => e | ||
brain.suggest_method_fix( | ||
erroneous_source: broken_method.source, | ||
exception_backtrace: e.backtrace&.first.to_s | ||
) | ||
end | ||
|
||
private | ||
|
||
# The interface to an AI's API | ||
# | ||
# @api private | ||
# | ||
# @return [Object] | ||
# | ||
attr_reader :brain | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
module Senior | ||
VERSION: String | ||
|
||
self.@configuration: Configuration::Main | ||
self.@agent: Agent | ||
self.@brain: _IBrain | ||
|
||
def self.auto_debug: (Method broken_method, untyped args, String? | nil broken_method_source) -> untyped | ||
def self.suggest_fix: (Method broken_method, untyped args) -> String | ||
def self.auto_debug_method: (Method broken_method, untyped args, String? | nil broken_method_source) -> untyped | ||
def self.suggest_method_fix: (Method broken_method, untyped args) -> String | ||
def self.configuration: -> Configuration::Main | ||
def self.configure: -> untyped | ||
def self.agent: -> Agent | ||
def self.brain: -> _IBrain | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
interface _IBrain | ||
def suggest_fix: (erroneous_source: String, exception_backtrace: String) -> String | ||
def suggest_method_fix: (erroneous_source: String, exception_backtrace: String) -> String | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# frozen_string_literal: true | ||
|
||
module Senior | ||
module Commands | ||
class AutoDebugMethod | ||
def initialize: (?_IBrain brain) -> void | ||
def call: (Method broken_method, untyped args, String? | nil broken_method_source) -> untyped | ||
|
||
private | ||
|
||
attr_reader brain: _IBrain | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# frozen_string_literal: true | ||
|
||
module Senior | ||
module Commands | ||
class SuggestMethodFix | ||
def initialize: (?_IBrain brain) -> void | ||
def call: (Method broken_method, untyped args) -> String | ||
|
||
private | ||
|
||
attr_reader brain: _IBrain | ||
end | ||
end | ||
end |
Oops, something went wrong.