3 # AI-Tr: Semantic text transformation tool
4 # Beautiful implementation using composable functions
6 SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
7 source "$SCRIPT_DIR/ai-common"
11 Usage: ai-tr TRANSFORMATION [FILE...]
12 Transform text format or style while preserving semantic meaning.
15 TRANSFORMATION Description of the desired transformation
18 -h Show this help message
22 build_transformation_prompt() {
23 local transformation="$1"
26 You are a semantic text transformation tool. Apply the following transformation: $transformation
28 CRITICAL REQUIREMENTS:
29 1. Preserve ALL semantic meaning and factual content
30 2. Keep the same essential information - do not add, remove, or change facts
31 3. Only change style, tone, format, or wording as requested
32 4. Maintain the original structure (same number of distinct points/items)
33 5. Output ONLY the transformed text - no explanations or commentary
35 Transform each line/paragraph separately to maintain structure.
40 local transformation=""
45 while getopts "h" opt; do
47 h) handle_help_option show_usage ;;
48 \?) handle_invalid_option "$OPTARG" ;;
54 # Validate environment and arguments
56 ensure_argument_provided "Transformation description" "$1" show_usage
62 # Validate files if provided
63 [[ ${#files[@]} -gt 0 ]] && ensure_files_exist "${files[@]}"
66 if ! input=$(process_input_sources "${files[@]}"); then
72 prompt=$(build_transformation_prompt "$transformation")
74 if ! response=$(execute_llm_request "$prompt" "$input"); then
76 "$EXIT_NO_MATCH") print_error "$(error_llm_no_response)" ;;
77 "$EXIT_API_ERROR") print_error "$(error_llm_api_error)" ;;
78 *) print_error "$(error_llm_command_failed)" ;;
83 # Output response directly (no special processing needed for transformation)