Scrai/sbt-console-ai: standard REPL and sbt plugin with lightweight AI code generation

Hi, I recently started this small project for my own Scala teaching efforts and would like to share it with the community.

Motivation: When using the Scala REPL to demo something in class, I can’t always remember the exact import required or correct API usage. To address those moments, I thought it would be helpful to integrate AI code generation directly into the REPL.

scrai (pronounced “scry”) is a lightweight AI input widget for the native Scala 3 REPL (standalone CLI) and sbt console plugin (sbt-console-ai). It lets you type an AI prompt as a // inline comment, press Ctrl-G, review the generated Scala, then press Enter to evaluate it. Generation never submits the code automatically, so you’re in control of what runs.

scala> val words = List("pear", "apple", "plum", "apricot")
scala> // group words by their first letter ───[ Type prompt & press Ctrl-G ]───►
scala> words.groupBy(_.head)               ◀───[ Generated code inserted inline ]

Source, instructions, standalone release, and artifacts are available here:

Requirements and build matrix: JDK 17 or newer, a real interactive terminal, and a Groq API key. Supported combinations: sbt 1.13.x and sbt 2.0.x, each with Scala 3.3.x through 3.10.x projects (scrai drives the compiler’s REPL internals and ships one runtime variant per Scala minor line; the dev build itself uses sbt 1.13.0).

Feedback and contributions are welcome!

Acknowledgment: The project was heavily inspired by the elegant, distraction-free terminal workflow of the fish-ai shell extension.

2 Likes

As a former student, if my teacher (looked like) he didn’t know the syntax/api of the thing he is teaching, it would have made me feel like either:

  • I’m not being taken seriously (why bother learning something my teacher himself seemingly does not know)
  • The thing being thought is simply too confusing to remember (and then again, why bother learning it)

There is nothing wrong with copy-pasting the import from something you prepared in advance, and checking the api a bit before the course so you have it fresh in your mind
Or even making mistakes in front of your students, that’s an opportunity to teach them how to solve these kinds of issues !
For example you could show them going on List and searching for a group method

And maybe I’m wrong and that is not how your students are feeling, in which case simply keep going, that’s what matters in the end

1 Like

As a lifelong student, I endorse forgetting as much as possible, so I think this is a great idea.

An early discussion about the Scala 2 REPL was that, aspirationally, it should offer much more help. In particular, much specialized knowledge is locked away in other contexts (tickets, forums, or at the time it was email lists). The REPL should offer help with head-scratchers that might even be FAQs.

This feature could fulfill that need.

It could also leverage spec strings. That might be too verbose, despite its appeal as a mechanism.

2 Likes