]> begriffs open source - ai-unix/blob - ai-tr
Simpler prompt for fixer
[ai-unix] / ai-tr
1 #!/bin/bash
2
3 # AI-Tr: Semantic text transformation tool
4 # Beautiful implementation using composable functions
5
6 SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
7 source "$SCRIPT_DIR/ai-common"
8
9 show_usage() {
10     cat << 'EOF'
11 Usage: ai-tr TRANSFORMATION [FILE...]
12 Transform text format or style while preserving semantic meaning.
13
14 Arguments:
15   TRANSFORMATION   Description of the desired transformation
16
17 Options:
18   -h              Show this help message
19 EOF
20 }
21
22 build_transformation_prompt() {
23     local transformation="$1"
24     
25     cat << EOF
26 You are a semantic text transformation tool. Apply the following transformation: $transformation
27
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
34
35 Transform each line/paragraph separately to maintain structure.
36 EOF
37 }
38
39 main() {
40     local transformation=""
41     local files=()
42     local input response
43     
44     # Parse options
45     while getopts "h" opt; do
46         case $opt in
47             h) handle_help_option show_usage ;;
48             \?) handle_invalid_option "$OPTARG" ;;
49         esac
50     done
51     
52     shift $((OPTIND-1))
53     
54     # Validate environment and arguments
55     ensure_dependencies
56     ensure_argument_provided "Transformation description" "$1" show_usage
57     
58     transformation="$1"
59     shift
60     files=("$@")
61     
62     # Validate files if provided
63     [[ ${#files[@]} -gt 0 ]] && ensure_files_exist "${files[@]}"
64     
65     # Process input
66     if ! input=$(process_input_sources "${files[@]}"); then
67         exit "$EXIT_NO_MATCH"
68     fi
69     
70     # Execute LLM request
71     local prompt
72     prompt=$(build_transformation_prompt "$transformation")
73     
74     if ! response=$(execute_llm_request "$prompt" "$input"); then
75         case $? in
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)" ;;
79         esac
80         exit $?
81     fi
82     
83     # Output response directly (no special processing needed for transformation)
84     echo "$response"
85     exit "$EXIT_SUCCESS"
86 }
87
88 main "$@"