You have a multi-line variable, so you need (?m) at the start of the regex to work on each line. However, you also made it more complicated than needed, I think. \S is "non-whitespace," but you could just use \s to find the whitespace directly:
(?m)^(\s)
This seems to work in my testing, replacing the captured group with two hyphens:
Oh wait, I misread your request as "leading whitespace" ... you just want the first whitespace, so "who am I" become "who--am I", right? If so, then I think this works:
That looks... overly complicated. It'll be clearer if you can provide some sample inputs and required outputs, but to replace the first white space character of every line in a block of text try:
"Treating as multi-line find 0 or more non-white space characters followed by a white space character, saving the non-white space run in capture group 1. Replace that entire match with capture group 1 followed by --."
Stepping back (in the light of the XY Pattern) to the problem itself,
and skipping past the need for homebrew to install tree,
have you experimented with Keyboard Maestro's built-in Prompt for Folder ?