URL-like strings are checked for after the test for “does this file exist” which suggests the inferred directory was incorrect. You can confirm this for sure by cmd-clicking on an absolute path.
For example, clicking the output of ls tmp|fgrep .kt will treat file.kt as a URL since it looked for /file.kt, while the second one will open it since it looked for /tmp/file.kt.
If you can’t tell why the directory is inferred incorrectly, well, it can be complicated. Generally installing shell integration makes everything just work. If you can send me a debug log that includes everything from cding into the directory, listing the file, and clicking on it and opening a URL I’d be happy to look at it and see what went wrong.