lib/aia/main.rb in aia-0.5.14 vs lib/aia/main.rb in aia-0.5.15

- old
+ new

@@ -18,15 +18,20 @@ SPINNER_FORMAT = :bouncing_ball include AIA::DynamicContent include AIA::UserQuery - attr_accessor :logger, :tools, :backend, :directive_output + attr_accessor :logger, :tools, :backend, :directive_output, :piped_content attr_reader :spinner def initialize(args= ARGV) + unless $stdin.tty? + @piped_content = $stdin.readlines.join.chomp + $stdin.reopen("/dev/tty") + end + @directive_output = "" AIA::Tools.load_tools AIA::Cli.new(args) @@ -46,10 +51,12 @@ @directives_processor = AIA::Directives.new @prompt = AIA::Prompt.new.prompt + @prompt.text += piped_content unless piped_content.nil? + # TODO: still should verify that the tools are ion the $PATH # tools.class.verify_tools end @@ -61,11 +68,11 @@ # This will be recursive with the new options # --next and --pipeline def call - directive_output = @directives_processor.execute_my_directives + @directive_output = @directives_processor.execute_my_directives if AIA.config.chat? AIA.config.out_file = STDOUT AIA.config.extra = "--quiet" if 'mods' == AIA.config.backend end @@ -93,11 +100,11 @@ abort "backend not found: #{AIA.config.backend}" if backend_klass.nil? the_prompt = @prompt.to_s - the_prompt.prepend(directive_output + "\n") unless directive_output.nil? || directive_output.empty? + the_prompt.prepend(@directive_output + "\n") unless @directive_output.nil? || @directive_output.empty? if AIA.config.terse? the_prompt.prepend "Be terse in your response. " end @@ -189,13 +196,14 @@ if result parts = the_prompt_text[signal.size..].split(' ') directive = parts.shift parameters = parts.join(' ') AIA.config.directives << [directive, parameters] - directive_output = @directives_processor.execute_my_directives + + @directive_output = @directives_processor.execute_my_directives else - directive_output = "" + @directive_output = "" end result end @@ -208,21 +216,22 @@ until the_prompt_text.empty? the_prompt_text = render_erb(the_prompt_text) if AIA.config.erb? the_prompt_text = render_env(the_prompt_text) if AIA.config.shell? if handle_directives(the_prompt_text) - unless directive_output.nil? - the_prompt_text = insert_terse_phrase(the_prompt_text) - the_prompt_text << directive_output + if @directive_output.nil? || @directive_output.empty? + # Do nothing + else + the_prompt_text = @directive_output + the_prompt_text = render_erb(the_prompt_text) if AIA.config.erb? + the_prompt_text = render_env(the_prompt_text) if AIA.config.shell? result = get_and_display_result(the_prompt_text) - log_the_follow_up(the_prompt_text, result) AIA.speak result end else the_prompt_text = insert_terse_phrase(the_prompt_text) result = get_and_display_result(the_prompt_text) - log_the_follow_up(the_prompt_text, result) AIA.speak result end the_prompt_text = ask_question_with_reline("\nFollow Up: ")