scittle 2024-12-16

I am using the scittle nrepl setup with some success, but having an issue: With this bb.edn, I am able to use bb dev task to start the nrepl (relay) server. And if I jack into port 1339 in Calva, I am able to eval the cljs code from my editor. I also have the bb nrepl-eval task to evaluate a code (string) in scittle runtime from the command line. If I jack-in in Calva first, the nrepl-eval task works. But If i dont jack-in first, and try to use the bb task first, i get this error that symbols are unresolved: ex: bb nrepl-eval "(test-trace)"

"#error {:message \"Could not resolve symbol: test-trace\", :data {:type :sci/error, :line 1, :column 1, :message \"Could not resolve symbol: test-trace\", :sci.impl/callstack #object[cljs.core.Volatile {:val ({:line 1, :column 1, :ns #object[Tr user], :file nil})}], :file nil, :phase \"analysis\"}, :cause #error {:message \"Could not resolve symbol: test-trace\", :data {:type :sci/error, :line 1, :column 1, :file nil, :phase \"analysis\"}}}"
I assumed that the scittle file ns is loded on js webpage startup. I get printouts from code in devtools on page reload. Any insights? Do I need to require the desired ns somewhere in the bb nrepl server task pipeline?

You need to be in the right namespace before you can evaluate a var that's defined in that namespace, but you could try to evaluate the fully qualified symbol

so if my scittle cljs ns is playground , then the fully qualified symbol would be playground/test-trace ?

if that also fails, try something like inc or whatever is defined in clojure.core

Ok, will try.

How can i “be” in the right namespace to use unqualified symbols? Like how it works when I jack in with Calva first? Maybe using :preloads in bp/start! ?

add (in-ns 'playground) to your expression?

I don't remember what preloads does in bp/start, been a while

but sounds relevant

Hoping to initialize this in the task, so I dont have to add it to every call. Seems like I could add it to :expr (first *command-line-args*)

also perhaps you can provide :ns in the nrepl client? if not, we could probably add that

this would likely solve it as well

I think that would be the proper solution tbh

will try this also:

:expr (do (in-ns 'playground) (first *command-line-args*))

yep that's good, expect that the last thing is a string

so make the whole thing a string

Oh right, thanks!

> provide :ns in the nrepl client you mean babashka/nrepl-client ?

yes, but it first needs to support it, currently it doesn't I think

issue welcome + PR, you can just try this locally I guess until it works. sending the `"ns" "playground" in the bencode message should make this work

Ok will try :

:expr (str "(do (in-ns 'playground) " (first *command-line-args*) ")")

well actually it doesn't support this in the sci nrepl server either yet

both sides should support this, it's a common nrepl option

Works!! 🙌 Thank you!

This is for my cljs in Photoshop project I’ve been toying with for a few years. If i can flesh out a meaningful api and reproducible setup I look forward to publishing it sometime.

I’m using the BB task to send commands to repl from Talon voice (python shelling out). So voice-activated clj functions in Photoshop, while otherwise working manually.

And no jvm process overhead!