$ show babashka/babashka
Babashka is a native Clojure interpreter for scripting, compiled with GraalVM native-image to produce a self-contained, fast-starting binary (`bb`). In production, it serves as a replacement for bash or Python scripting in Clojure, offering a REPL, task runner, nREPL server, HTTP client/server, process spawning, file I/O, database access via JDBC, and foreign function interface (FFI) to C libraries. The architecture is a monolith with modular feature flags: environment variables such as `BABASHKA_FEATURE_CSV` or `BABASHKA_FEATURE_JDBC` control which optional libraries (XML, YAML, CSV, Transit, http-kit, spec, logging, etc.) are compiled into the binary. The core interpreter is SCI (Small Clojure Interpreter), extended with a rich set of built-in namespaces that wrap popular Clojure libraries. Build scripts and CI pipelines automate testing on Linux, macOS, and Windows, and the project maintains an extensive library compatibility test suite with over 100 third-party Clojure libraries pinned to specific git SHAs. The codebase demonstrates exceptional craftsmanship: the JLine-based REPL with inline autosuggestion and eldoc, the FFI trampoline dispatch, the custom GraalVM features for binary size optimization, and the deftype map interface support are all non-obvious solutions to real problems in building a scripting runtime on the JVM. While primarily an application, the repository also contains a valuable data asset in `test-resources/lib_tests/bb-tested-libs.edn`, a curated registry of library compatibility that could support research on Clojure library portability.
The LLM identified 5 files worth highlighting for reuse:
Provides an interactive REPL using JLine 3, with features such as tab completion, doc-at-point (Ctrl-X Ctrl-D), eldoc (inline parameter hints), inline ghost text (tail tip), multi-line editing (Alt-Enter), and Ctrl-C/Ctrl-D exit. The implementation wraps JLine widgets by reimplementing `self-insert` and `backward-delete-char` to inject eldoc and tail-tip updates. This component is self-contained and could be extracted into a library for any SCI-based REPL, demonstrating non-obvious skill in bridging an interpreter with a terminal UI library.
A Java class implementing `APersistentMap` with method delegation and reflection-based map interface support, used as a superclass for SCI `deftype` instances that need to behave as Clojure maps. This enables libraries like `core.cache`, `clerk`, and `linked` to work with babashka's `deftype`. The pattern demonstrates how to make a GraalVM-compiled type satisfy the full Clojure map protocol, and could be reused in any Clojure runtime that needs to implement custom map types.
A custom GraalVM `Feature` that selectively registers only the `cp437` charset (and a few required ones) to avoid including the full charset support (~5MB binary bloat). This is a reusable pattern for any GraalVM native-image project that needs to reduce binary size by only including necessary charsets. The component is small, self-contained, and demonstrates understanding of the GraalVM native-image internals.
Provides context-aware error reporting for the SCI interpreter, capturing source snippets, stack traces, and user-friendly error messages. It is designed to be decoupled from the rest of babashka and could be used in any SCI-based project to improve error diagnostics. The component implements non-obvious patterns like extracting source lines from the evaluated string and computing a context window around the error location.
A full port of Clojure's `clojure.spec.alpha` library adapted to run under SCI. It includes the spec registry, macro-based spec definitions (`def`, `keys`, `cat`, `alt`, `*`, `+`, `?`), protocols (`Spec`, `Specize`), explanation (`explain`), and integration with test.check generators (`gen`, `fspec`). This is a self-contained implementation of one of Clojure's most complex namespaces, demonstrating deep understanding of Clojure's spec internals and the patience to port it for a different runtime. It is reusable in any SCI-based environment that needs spec validation.