Skip to content

Commit 60de9e2

Browse files
committed
add client version check to fix bad client version
1 parent eef4c5c commit 60de9e2

9 files changed

Lines changed: 115 additions & 10 deletions

plugins/warp/scripts/on-notification.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
# Sends a structured Warp notification when Claude has been idle
44

55
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
6+
source "$SCRIPT_DIR/should-use-structured.sh"
67

78
# Legacy fallback for old Warp versions
8-
if [ -z "$WARP_CLI_AGENT_PROTOCOL_VERSION" ]; then
9+
if ! should_use_structured; then
910
[ "$TERM_PROGRAM" = "WarpTerminal" ] && exec "$SCRIPT_DIR/legacy/on-notification.sh"
1011
exit 0
1112
fi

plugins/warp/scripts/on-permission-request.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
# Sends a structured Warp notification when Claude needs permission to run a tool
44

55
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
6+
source "$SCRIPT_DIR/should-use-structured.sh"
67

78
# No legacy equivalent for this hook
8-
if [ -z "$WARP_CLI_AGENT_PROTOCOL_VERSION" ]; then
9+
if ! should_use_structured; then
910
exit 0
1011
fi
1112

plugins/warp/scripts/on-post-tool-use.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
# transitioning the session status from Blocked back to Running.
55

66
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
7+
source "$SCRIPT_DIR/should-use-structured.sh"
78

89
# No legacy equivalent for this hook
9-
if [ -z "$WARP_CLI_AGENT_PROTOCOL_VERSION" ]; then
10+
if ! should_use_structured; then
1011
exit 0
1112
fi
1213

plugins/warp/scripts/on-prompt-submit.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
# transitioning the session status from idle/blocked back to running.
55

66
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
7+
source "$SCRIPT_DIR/should-use-structured.sh"
78

89
# No legacy equivalent for this hook
9-
if [ -z "$WARP_CLI_AGENT_PROTOCOL_VERSION" ]; then
10+
if ! should_use_structured; then
1011
exit 0
1112
fi
1213

plugins/warp/scripts/on-session-start.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
# Shows welcome message, Warp detection status, and emits plugin version
44

55
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
6+
source "$SCRIPT_DIR/should-use-structured.sh"
67

78
# Legacy fallback for old Warp versions
8-
if [ -z "$WARP_CLI_AGENT_PROTOCOL_VERSION" ]; then
9+
if ! should_use_structured; then
910
exec "$SCRIPT_DIR/legacy/on-session-start.sh"
1011
fi
1112

plugins/warp/scripts/on-stop.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
# Sends a structured Warp notification when Claude completes a task
44

55
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
6+
source "$SCRIPT_DIR/should-use-structured.sh"
67

78
# Legacy fallback for old Warp versions
8-
if [ -z "$WARP_CLI_AGENT_PROTOCOL_VERSION" ]; then
9+
if ! should_use_structured; then
910
[ "$TERM_PROGRAM" = "WarpTerminal" ] && exec "$SCRIPT_DIR/legacy/on-stop.sh"
1011
exit 0
1112
fi
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/bin/bash
2+
# Determines whether the current Warp build supports structured CLI agent notifications.
3+
#
4+
# Usage:
5+
# source "$SCRIPT_DIR/should-use-structured.sh"
6+
# if should_use_structured; then
7+
# # ... send structured notification
8+
# else
9+
# # ... legacy fallback or exit
10+
# fi
11+
#
12+
# Returns 0 (true) when structured notifications are safe to use, 1 (false) otherwise.
13+
14+
# Last known Warp release per channel that unconditionally set
15+
# WARP_CLI_AGENT_PROTOCOL_VERSION without gating it behind the
16+
# HOANotifications feature flag. These builds advertise protocol
17+
# support but can't actually render structured notifications.
18+
LAST_BROKEN_DEV=""
19+
LAST_BROKEN_STABLE="v0.2026.03.25.08.24.stable_05"
20+
LAST_BROKEN_PREVIEW="v0.2026.03.25.08.24.preview_05"
21+
22+
should_use_structured() {
23+
# No protocol version advertised → Warp doesn't know about structured notifications.
24+
[ -z "${WARP_CLI_AGENT_PROTOCOL_VERSION:-}" ] && return 1
25+
26+
# No client version available → can't verify this build has the fix.
27+
# (This catches the broken prod release before this was set, but after WARP_CLI_AGENT_PROTOCOL_VERSION was set without a flag check.)
28+
[ -z "${WARP_CLIENT_VERSION:-}" ] && return 1
29+
30+
# Check whether this version is at or before the last broken release for its channel.
31+
local threshold=""
32+
case "$WARP_CLIENT_VERSION" in
33+
*dev*) threshold="$LAST_BROKEN_DEV" ;;
34+
*stable*) threshold="$LAST_BROKEN_STABLE" ;;
35+
*preview*) threshold="$LAST_BROKEN_PREVIEW" ;;
36+
esac
37+
38+
# If we matched a channel and the version is <= the broken threshold, fall back.
39+
if [ -n "$threshold" ] && [[ ! "$WARP_CLIENT_VERSION" > "$threshold" ]]; then
40+
return 1
41+
fi
42+
43+
return 0
44+
}

plugins/warp/scripts/warp-notify.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
# For structured Warp notifications, title should be "warp://cli-agent"
66
# and body should be a JSON string matching the cli-agent notification schema.
77

8-
# Only emit notifications when Warp declares protocol support.
9-
# This avoids garbled OSC sequences in non-Warp terminals
10-
# (and works over SSH where TERM_PROGRAM isn't propagated).
11-
if [ -z "$WARP_CLI_AGENT_PROTOCOL_VERSION" ]; then
8+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
9+
source "$SCRIPT_DIR/should-use-structured.sh"
10+
11+
# Only emit notifications when we've confirmed the Warp build can render them.
12+
if ! should_use_structured; then
1213
exit 0
1314
fi
1415

plugins/warp/tests/test-hooks.sh

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,60 @@ PLUGIN_CURRENT_PROTOCOL_VERSION=1
142142
# Clean up
143143
unset WARP_CLI_AGENT_PROTOCOL_VERSION
144144

145+
echo ""
146+
echo "=== should-use-structured.sh ==="
147+
148+
source "$SCRIPT_DIR/../scripts/should-use-structured.sh"
149+
150+
echo ""
151+
echo "--- No protocol version → legacy ---"
152+
unset WARP_CLI_AGENT_PROTOCOL_VERSION
153+
unset WARP_CLIENT_VERSION
154+
should_use_structured
155+
assert_eq "no protocol version returns false" "1" "$?"
156+
157+
echo ""
158+
echo "--- Protocol set, no client version → legacy ---"
159+
export WARP_CLI_AGENT_PROTOCOL_VERSION=1
160+
unset WARP_CLIENT_VERSION
161+
should_use_structured
162+
assert_eq "missing WARP_CLIENT_VERSION returns false" "1" "$?"
163+
164+
echo ""
165+
echo "--- Protocol set, dev version → always structured (dev was never broken) ---"
166+
export WARP_CLI_AGENT_PROTOCOL_VERSION=1
167+
export WARP_CLIENT_VERSION="v0.2026.03.30.08.43.dev_00"
168+
should_use_structured
169+
assert_eq "dev version returns true" "0" "$?"
170+
171+
echo ""
172+
echo "--- Protocol set, broken stable version → legacy ---"
173+
export WARP_CLIENT_VERSION="v0.2026.03.25.08.24.stable_05"
174+
should_use_structured
175+
assert_eq "exact broken stable version returns false" "1" "$?"
176+
177+
echo ""
178+
echo "--- Protocol set, newer stable version → structured ---"
179+
export WARP_CLIENT_VERSION="v0.2026.04.01.08.00.stable_00"
180+
should_use_structured
181+
assert_eq "newer stable version returns true" "0" "$?"
182+
183+
echo ""
184+
echo "--- Protocol set, broken preview version → legacy ---"
185+
export WARP_CLIENT_VERSION="v0.2026.03.25.08.24.preview_05"
186+
should_use_structured
187+
assert_eq "exact broken preview version returns false" "1" "$?"
188+
189+
echo ""
190+
echo "--- Protocol set, newer preview version → structured ---"
191+
export WARP_CLIENT_VERSION="v0.2026.04.01.08.00.preview_00"
192+
should_use_structured
193+
assert_eq "newer preview version returns true" "0" "$?"
194+
195+
# Clean up
196+
unset WARP_CLI_AGENT_PROTOCOL_VERSION
197+
unset WARP_CLIENT_VERSION
198+
145199
# --- Routing tests ---
146200
# These test the hook scripts as subprocesses to verify routing behavior.
147201
# We override /dev/tty writes since they'd fail in CI.

0 commit comments

Comments
 (0)