When you compile your command you can specify :
CRTCMD CMD(xxxx) ALLOW(*INTERACT)
by default this parameter is set to *ALL
I think that is easier than your validity checker, even if it was not a bad idea.
About the only way I can think of to determine if it’s in a compiled program would be to resolve and process the call stack to see if the previous call stack entries indicated a compiled program that you could recognize.
In any case, a validity checker is an inappropriate way to handle this. That’s not what they are designed to do and would add a troublesome level of complexity to the execution. I can’t see how it could avoid putting a significant performance drag on the process.
The ALLOW() attribute of the command is designed to control how a command may be used. That’s the appropriate method.