-
Notifications
You must be signed in to change notification settings - Fork 0
fix(metacognitive-guard): handle grep exit code 1 in pipelines #49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -43,15 +43,15 @@ score=0 | |||||
|
|
||||||
| # 1. HEDGING LANGUAGE (uncertainty markers) - count each instance | ||||||
| HEDGE_COUNT=$(echo "$RESPONSE" | grep -oiE \ | ||||||
| "I think|I believe|probably|might be|could be|I'm not sure|not certain|unclear|I assume|possibly|perhaps" \ | ||||||
| | wc -l | tr -d ' ') | ||||||
| "I think|I believe|probably|might be|could be|I'm not sure|not certain|unclear|I assume|possibly|perhaps" 2>/dev/null \ | ||||||
| | wc -l | tr -d ' ' || echo "0") | ||||||
| if [[ "$HEDGE_COUNT" -gt 3 ]]; then | ||||||
| signals+=("hedging:$HEDGE_COUNT instances of uncertain language") | ||||||
| score=$((score + HEDGE_COUNT * 2)) | ||||||
| fi | ||||||
|
|
||||||
| # 2. EXCESSIVE QUESTIONS (avoiding action) - count each question mark | ||||||
| QUESTION_COUNT=$(echo "$RESPONSE" | grep -o '?' | wc -l | tr -d ' ') | ||||||
| QUESTION_COUNT=$(echo "$RESPONSE" | grep -o '?' 2>/dev/null | wc -l | tr -d ' ' || echo "0") | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since you are searching for a literal character
Suggested change
|
||||||
| RESPONSE_LINES=$(echo "$RESPONSE" | wc -l | tr -d ' ') | ||||||
| if [[ "$QUESTION_COUNT" -gt 3 && "$RESPONSE_LINES" -lt 30 ]]; then | ||||||
| signals+=("deflecting:$QUESTION_COUNT questions in short response") | ||||||
|
|
@@ -77,17 +77,17 @@ fi | |||||
|
|
||||||
| # 5. APOLOGETIC PATTERNS (sign of prior failure) - count each instance | ||||||
| APOLOGY_COUNT=$(echo "$RESPONSE" | grep -oiE \ | ||||||
| "sorry|apologize|my mistake|I was wrong|let me try again|I missed" \ | ||||||
| | wc -l | tr -d ' ') | ||||||
| "sorry|apologize|my mistake|I was wrong|let me try again|I missed" 2>/dev/null \ | ||||||
| | wc -l | tr -d ' ' || echo "0") | ||||||
|
Comment on lines
+80
to
+81
|
||||||
| if [[ "$APOLOGY_COUNT" -gt 1 ]]; then | ||||||
| signals+=("apologetic:$APOLOGY_COUNT apologies") | ||||||
| score=$((score + APOLOGY_COUNT * 8)) | ||||||
| fi | ||||||
|
|
||||||
| # 6. WEASEL WORDS (avoiding commitment) - count each instance | ||||||
| WEASEL_COUNT=$(echo "$RESPONSE" | grep -oiE \ | ||||||
| "generally|typically|usually|in most cases|it depends|that said|to be fair" \ | ||||||
| | wc -l | tr -d ' ') | ||||||
| "generally|typically|usually|in most cases|it depends|that said|to be fair" 2>/dev/null \ | ||||||
| | wc -l | tr -d ' ' || echo "0") | ||||||
|
Comment on lines
+89
to
+90
|
||||||
| if [[ "$WEASEL_COUNT" -gt 2 ]]; then | ||||||
| signals+=("weaseling:$WEASEL_COUNT non-committal phrases") | ||||||
| score=$((score + WEASEL_COUNT * 3)) | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fallback pattern
|| echo "0"is placed aftertr -d ' ', but the pipe chain already includeswc -lwhich should always succeed and return a numeric value (even "0" when grep finds nothing). The issue is thatgrepexits with code 1 when no matches are found, causing the pipeline to fail due toset -o pipefail.The correct fix should place the fallback immediately after the grep command, before the
wc -l:grep -oiE "..." 2>/dev/null || echo "" | wc -l | tr -d ' 'Or wrap just the grep in a subshell with the fallback:
(grep -oiE "..." 2>/dev/null || true) | wc -l | tr -d ' 'The current placement of
|| echo "0"after the entire pipeline means it will only execute if the final command (tr) fails, which is not the intended behavior.