#!/bin/bash # AI-Tr: Semantic text transformation tool # Beautiful implementation using composable functions SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" source "$SCRIPT_DIR/ai-common" show_usage() { cat << 'EOF' Usage: ai-tr TRANSFORMATION [FILE...] Transform text format or style while preserving semantic meaning. Arguments: TRANSFORMATION Description of the desired transformation Options: -h Show this help message EOF } build_transformation_prompt() { local transformation="$1" cat << EOF You are a semantic text transformation tool. Apply the following transformation: $transformation CRITICAL REQUIREMENTS: 1. Preserve ALL semantic meaning and factual content 2. Keep the same essential information - do not add, remove, or change facts 3. Only change style, tone, format, or wording as requested 4. Maintain the original structure (same number of distinct points/items) 5. Output ONLY the transformed text - no explanations or commentary Transform each line/paragraph separately to maintain structure. EOF } main() { local transformation="" local files=() local input response # Parse options while getopts "h" opt; do case $opt in h) handle_help_option show_usage ;; \?) handle_invalid_option "$OPTARG" ;; esac done shift $((OPTIND-1)) # Validate environment and arguments ensure_dependencies ensure_argument_provided "Transformation description" "$1" show_usage transformation="$1" shift files=("$@") # Validate files if provided [[ ${#files[@]} -gt 0 ]] && ensure_files_exist "${files[@]}" # Process input if ! input=$(process_input_sources "${files[@]}"); then exit "$EXIT_NO_MATCH" fi # Execute LLM request local prompt prompt=$(build_transformation_prompt "$transformation") if ! response=$(execute_llm_request "$prompt" "$input"); then case $? in "$EXIT_NO_MATCH") print_error "$(error_llm_no_response)" ;; "$EXIT_API_ERROR") print_error "$(error_llm_api_error)" ;; *) print_error "$(error_llm_command_failed)" ;; esac exit $? fi # Output response directly (no special processing needed for transformation) echo "$response" exit "$EXIT_SUCCESS" } main "$@"