From 9358555ad4db184d3a3225fc290a7620b563191c Mon Sep 17 00:00:00 2001 From: moped Date: Wed, 14 Oct 2026 00:42:39 +0200 Subject: [PATCH] Strip markdown from the Stop notification response Warp shows the notification body as plain text, so markdown in the agent's last reply came through literally: **bold**, `code`, bullets, headings and raw newlines. on-stop.sh now passes the response through a new strip_markdown helper in build-payload.sh before truncating it. Underscores are left alone so identifiers like __init__ survive. --- plugins/warp/scripts/build-payload.sh | 12 ++++++++++++ plugins/warp/scripts/on-stop.sh | 1 + plugins/warp/tests/test-hooks.sh | 10 ++++++++++ 3 files changed, 23 insertions(+) diff --git a/plugins/warp/scripts/build-payload.sh b/plugins/warp/scripts/build-payload.sh index 9ad610e..313fe8f 100644 --- a/plugins/warp/scripts/build-payload.sh +++ b/plugins/warp/scripts/build-payload.sh @@ -27,6 +27,18 @@ negotiate_protocol_version() { fi } +# Notification bodies are shown as plain text, so markdown syntax from the +# agent's reply appears literally. Removes the common markers and folds +# newlines into spaces. Underscores are left alone so identifiers like +# __init__ survive. +strip_markdown() { + jq -rn --arg s "$1" '$s + | gsub("(?m)^\\s*(#+|[-*+]|\\d+\\.)\\s+"; "") + | gsub("\\*\\*|`"; "") + | gsub("\\[(?[^\\]]+)\\]\\([^)]*\\)"; "\(.t)") + | gsub("\\s*\\n+\\s*"; " ")' +} + build_payload() { local input="$1" local event="$2" diff --git a/plugins/warp/scripts/on-stop.sh b/plugins/warp/scripts/on-stop.sh index 34e06f7..a5fea58 100755 --- a/plugins/warp/scripts/on-stop.sh +++ b/plugins/warp/scripts/on-stop.sh @@ -55,6 +55,7 @@ if [ -n "$TRANSCRIPT_PATH" ] && [ -f "$TRANSCRIPT_PATH" ]; then [.[] | select(.type == "assistant" and .message.content)] | last | [.message.content[] | select(.type == "text") | .text] | join(" ") ' "$TRANSCRIPT_PATH" 2>/dev/null) + RESPONSE=$(strip_markdown "$RESPONSE") # Truncate for notification display if [ -n "$QUERY" ] && [ ${#QUERY} -gt 200 ]; then diff --git a/plugins/warp/tests/test-hooks.sh b/plugins/warp/tests/test-hooks.sh index e2d3ea7..8a64923 100755 --- a/plugins/warp/tests/test-hooks.sh +++ b/plugins/warp/tests/test-hooks.sh @@ -312,6 +312,16 @@ assert_eq "legacy Warp shows active message" \ "🔔 Warp plugin active. You'll receive native Warp notifications when tasks complete or input is needed." \ "$SYS_MSG" +echo "" +echo "--- Markdown is stripped from notification text ---" +assert_eq "bold and code removed" "Use master now" "$(strip_markdown 'Use **`master`** now')" +assert_eq "headings and bullets removed, newlines folded" "Title one two" "$(strip_markdown $'## Title\n\n- one\n* two')" +assert_eq "numbered list removed" "first second" "$(strip_markdown $'1. first\n2. second')" +assert_eq "link keeps its text" "see the docs" "$(strip_markdown 'see [the docs](https://example.com)')" +assert_eq "underscores kept" "call __init__ and snake_case" "$(strip_markdown 'call __init__ and snake_case')" +assert_eq "plain text unchanged" 'It means greeting. Use: printf("hello")' "$(strip_markdown 'It means greeting. Use: printf("hello")')" +assert_eq "empty input" "" "$(strip_markdown '')" + echo "" echo "--- Modern-only hooks exit silently without protocol version ---"