1313# The function extracts common fields (session_id, cwd, project) from the
1414# hook's stdin JSON (passed as $1), then merges any extra jq args you pass.
1515
16+ # The current protocol version this plugin knows how to produce.
17+ PLUGIN_CURRENT_PROTOCOL_VERSION=1
18+
19+ # Negotiate the protocol version with Warp.
20+ # Uses min(plugin_current, warp_declared), falling back to 1 if Warp doesn't advertise a version.
21+ negotiate_protocol_version () {
22+ local warp_version=" ${WARP_CLI_AGENT_PROTOCOL_VERSION:- 1} "
23+ if [ " $warp_version " -lt " $PLUGIN_CURRENT_PROTOCOL_VERSION " ] 2> /dev/null; then
24+ echo " $warp_version "
25+ else
26+ echo " $PLUGIN_CURRENT_PROTOCOL_VERSION "
27+ fi
28+ }
29+
1630build_payload () {
1731 local input=" $1 "
1832 local event=" $2 "
1933 shift 2
2034
35+ local protocol_version
36+ protocol_version=$( negotiate_protocol_version)
37+
2138 # Extract common fields from the hook input
2239 local session_id cwd project
2340 session_id=$( echo " $input " | jq -r ' .session_id // empty' 2> /dev/null)
@@ -30,11 +47,12 @@ build_payload() {
3047 # Build the payload: common fields + any extra args passed by the caller.
3148 # Extra args should be jq flag pairs like: --arg key "value" or --argjson key '{"a":1}'
3249 jq -nc \
50+ --argjson v " $protocol_version " \
3351 --arg agent " claude" \
3452 --arg event " $event " \
3553 --arg session_id " $session_id " \
3654 --arg cwd " $cwd " \
3755 --arg project " $project " \
3856 " $@ " \
39- ' {v:1 , agent:$agent, event:$event, session_id:$session_id, cwd:$cwd, project:$project} + $ARGS.named'
57+ ' {v:$v , agent:$agent, event:$event, session_id:$session_id, cwd:$cwd, project:$project} + $ARGS.named'
4058}
0 commit comments