diff --git a/src/help_and_version.sh b/src/help_and_version.sh index a62451c..891347a 100644 --- a/src/help_and_version.sh +++ b/src/help_and_version.sh @@ -5,7 +5,7 @@ readonly YO="✌️" # All versioning follows semver as defined at https://semver.org/ -readonly VERSION="0.2.1" +readonly VERSION="0.2.2" # Display version information show_version() { @@ -37,6 +37,7 @@ show_help() { including .pdf, .docx, images (.png, .jpeg, .tiff, etc.), and any text file (.txt, .md, .py, .zsh, etc.). This flag can be repeated to bring in several files. -y, --system Run a few system commands and integrate the information into Yo's context. + -t, --text "TEXT" Include the specified text in Yo's context. Finally, we have several flags that require an internet connection: -s, --search "TERMS" Perform a web search using the specified quoted terms and integrate the results into diff --git a/src/llm_session_management.sh b/src/llm_session_management.sh index a18a3dd..bf3c8fe 100644 --- a/src/llm_session_management.sh +++ b/src/llm_session_management.sh @@ -15,6 +15,8 @@ generate_prompt() { add_system_info=$8 add_directory_info=$9 add_clipboard_info=${10} + add_screenshot_info=${11} + text_input_list=${12} # Check that inputs are valid check_mode mode || return 1 @@ -71,6 +73,19 @@ generate_prompt() { done fi + # Add website information if available + if [ -n "${text_input_list}" ]; then + while [ -n "${text_input_list}" ]; do + text_input=$(echo "${text_input_list}" | head -n 1) + text_input_list=$(echo "${text_input_list}" | tail -n +2) + timestamp_log_to_stderr "🔗" "Reviewing \"$(echo "${text_input}" | cut -c1-30)\"..." >&2 + prompt="${prompt} $(generate_text_context "${text_input}" "${query}")\n\n" || { + echo "Error: Failed to generate website information context for ${text_input}." >&2 + return 1 + } + done + fi + # Add website information if available if [ -n "${website_urls}" ]; then while [ -n "${website_urls}" ]; do diff --git a/src/main.sh b/src/main.sh index c771a46..ae8836e 100755 --- a/src/main.sh +++ b/src/main.sh @@ -52,9 +52,11 @@ query="" file_path_list="" website_url_list="" search_term_list="" +text_input_list="" surf_and_add_results=false add_directory_info=false add_system_info=false add_clipboard_info=false add_usage_info=false task_model_override=false casual_model_override=false balanced_model_override=false serious_model_override=false +add_screenshot_info=false # Make verbose a global variable VERBOSE=false @@ -156,6 +158,16 @@ while [ $# -gt 0 ]; do exit 1 fi ;; + # Read in a text + -t | --text) + if [ -n "$2" ] && [ "${2#-}" = "$2" ]; then + text_input_list="${text_input_list}$2\n" + shift + else + echo "Error: --file requires a file." >&2 + exit 1 + fi + ;; # Read in a file -w | --website) @@ -206,6 +218,9 @@ while [ $# -gt 0 ]; do surf_and_add_results=true ;; + # Add screenshot info + -sc | --screenshot) add_screenshot_info=true ;; + # Add system information to the context -y | --system) add_system_info=true ;; @@ -299,7 +314,9 @@ prompt=$( "${add_usage_info}" \ "${add_system_info}" \ "${add_directory_info}" \ - "${add_clipboard_info}" + "${add_clipboard_info}" \ + "${add_screenshot_info}" \ + "${text_input_list}" ) || { echo "Error: Failed to generate prompt." >&2 exit 1 diff --git a/src/prompt_generators.sh b/src/prompt_generators.sh index 1dfb4b6..0c57069 100644 --- a/src/prompt_generators.sh +++ b/src/prompt_generators.sh @@ -156,6 +156,27 @@ generate_clipboard_info_context() { EOF } +# Generate text information +generate_text_context() { + + # Parse arguments + text_info=$1 + query=$2 + + # Compress if needed + text_info=$(compress_text "${clipboard_info}" true true true "${query}") || { + echo "Error: Failed to compress text_info information." >&2 + return 1 + } + + cat <<-EOF + Here are the contents of a text input: + ================= BEGINNING OF CURRENT CLIPBOARD CONTENTS ================= + ${text_info} + ==================== END OF CURRENT CLIPBOARD CONTENTS ==================== + EOF +} + # Generate file contents context generate_file_context() { diff --git a/tests/test_local_flags.sh b/tests/test_local_flags.sh index decd9ec..fc5fb82 100644 --- a/tests/test_local_flags.sh +++ b/tests/test_local_flags.sh @@ -1,7 +1,7 @@ #!/usr/bin/env sh # shellcheck enable=all -source tests/utilities.zsh +. tests/utilities.sh # Run setup setup @@ -37,5 +37,15 @@ answer_should_contain \ "--task-model --system" \ "how many cores do i have" +# Text the --text flag +answer_should_contain \ + "3|three" \ + "--task-model --text 'the ball is under cup number 3'" \ + "what cup is the ball under" +answer_should_contain \ + "3|three" \ + "--task-model --text 'the ball is under cup number 3' --text 'the ball is really really under cup number 3'" \ + "what cup is the ball under" + # Run cleanup cleanup