After some additional tests, it appears that the Direction command does not take into account the transformations applied in the code. It always use the values defined in the installation.
The implementation of Direction uses Plane_X_const and is there by not affected by your modification.
If you have a variable feature. You should also be able to use the it by selecting the Direction vector option and then insert the an expression like this:
Not it exactly when created. You can change it in Polyscope before the program execution is started. But when the program is started, Polycope have used the value to generate the script for the controller. This article might assist you with gaining insight to the structure:
Post Scriptum : my function is working with the tool contact, I saw you are using distance. If you need me to custom my function for a distance application, let me now