Created
February 12, 2026 17:39
-
-
Save dargue3/61094ebef31af202d9bf5479a09549fa to your computer and use it in GitHub Desktop.
Have a local LLM parse a large stdout from the given command to cut down on massive stack-trace-induced context window explosions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Script: parse-output.sh | |
| # Purpose: Run a command and use Qwen LLM to parse any error output | |
| # Usage: ./parse-output.sh [--show-output] <command> | |
| # Default: Quiet mode (LLM-friendly output only) | |
| # Debug mode: Use --show-output to see full command output and progress | |
| MODEL="mlx-community/Qwen3-30B-A3B-4bit-DWQ" | |
| ENABLE_THINKING=false | |
| # Check for show-output flag | |
| SHOW_OUTPUT=false | |
| if [ "$1" = "--show-output" ]; then | |
| SHOW_OUTPUT=true | |
| shift # Remove the flag from arguments | |
| fi | |
| # Check if a command was provided | |
| if [ $# -eq 0 ]; then | |
| echo "Usage: $0 [--show-output] <command>" | |
| echo "Example: $0 ./gradlew test" | |
| echo "Example: $0 --show-output ./gradlew test" | |
| exit 1 | |
| fi | |
| # Create temporary files | |
| TEMP_OUTPUT=$(mktemp) | |
| TEMP_ERROR=$(mktemp) | |
| TEMP_MLX_OUTPUT=$(mktemp) | |
| # Function to clean up temporary files | |
| cleanup() { | |
| rm -f "$TEMP_OUTPUT" "$TEMP_ERROR" "${TEMP_OUTPUT}.combined" "$TEMP_MLX_OUTPUT" | |
| } | |
| trap cleanup EXIT | |
| # Run the command | |
| if [ "$SHOW_OUTPUT" = true ]; then | |
| echo "Running: $@" | |
| echo "----------------------------------------" | |
| "$@" > >(tee "$TEMP_OUTPUT") 2> >(tee "$TEMP_ERROR" >&2) | |
| EXIT_CODE=$? | |
| else | |
| # Default quiet mode - capture silently | |
| "$@" > "$TEMP_OUTPUT" 2> "$TEMP_ERROR" | |
| EXIT_CODE=$? | |
| fi | |
| # Show status in debug mode | |
| if [ "$SHOW_OUTPUT" = true ]; then | |
| echo "" | |
| echo "----------------------------------------" | |
| echo "Command failed with exit code: $EXIT_CODE" | |
| echo "Analyzing error with Qwen..." | |
| echo "----------------------------------------" | |
| fi | |
| # Combine outputs | |
| cat "$TEMP_OUTPUT" "$TEMP_ERROR" > "${TEMP_OUTPUT}.combined" | |
| # Create the prompt | |
| # Conditionally add /no_think based on ENABLE_THINKING | |
| if [ "$ENABLE_THINKING" = true ]; then | |
| NO_THINK="" | |
| else | |
| NO_THINK="/no_think" | |
| fi | |
| PROMPT="$NO_THINK | |
| You are an expert error analyzer for Java applications and build systems. | |
| <input> | |
| $(cat "${TEMP_OUTPUT}.combined") | |
| </input> | |
| <instructions> | |
| - Extract only essential information for debugging | |
| - Focus on user code, not framework internals | |
| - Include specific error messages and line numbers | |
| - Remove all JUnit/TestNG/Gradle/Maven internals | |
| - Be extremely concise but include all critical details | |
| - Do NOT make suggestions or explanations, just extract information. | |
| </instructions> | |
| <output_format> | |
| For each failed test, note: | |
| - The name of the suite(s) and test(s) that failed. | |
| - All relevant text from each error output, | |
| e.g. 'java.lang.NullPointerException: Cannot invoke org.springframework.cache.Cache.invalidate() because the return value of com.netflix.uhcapi.cache.TopNContentCache.getTopNQueryCache() is null' | |
| - Only 3-5 most important lines from user code, not framework internals. | |
| </output_format> | |
| " | |
| # Run mlx_lm and capture output | |
| mlx_lm.generate \ | |
| --model "$MODEL" \ | |
| --prompt "$PROMPT" \ | |
| --max-tokens 2000 \ | |
| --temp 0.1 > "$TEMP_MLX_OUTPUT" 2>&1 | |
| # Extract and display the generated text | |
| if [ "$SHOW_OUTPUT" = true ]; then | |
| # Debug mode - show full mlx output | |
| cat "$TEMP_MLX_OUTPUT" | |
| else | |
| # Default quiet mode - extract only the generated content | |
| # First extract content between ========== markers, then remove <think> blocks | |
| awk '/^==========/{if(++count==1) next; if(count==2) exit} count==1' "$TEMP_MLX_OUTPUT" | \ | |
| sed '/<think>/,/<\/think>/d' | \ | |
| sed '/^$/d' | |
| fi | |
| # Exit with original error code | |
| exit $EXIT_CODE |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Prerequisite installs: