Map: core (ral-core)

core/ is the ral-core crate — the language engine — and a host reaches it through two narrow crate-root seams: a compile-then-typecheck pipeline that turns source into typed IR, and the framed run entry that is the only way into evaluation. It is the bulk of the codebase (~140k lines of Rust); both binaries, ral and exarch, embed it.

core/src/lib.rs is the crate root. The compilation ladder is source → tokens → flat AST → CBPV IR → typed IR, bundled as compile::compile_and_typecheck (parse → elaborate → typecheck, failing with a CompileError of Parse or Types), returning a Toplevel — a sequence of phrases (Define/Run) run by shell::evaluator::run_phrases. Evaluation is not on the crate root — parse, elaborate, and Toplevel are not re-exported there, reached by the owning module path when a host deliberately steps past the seam (after-turn-api-simplifications).

Reach is enforced rather than intended: an item is pub because something outside the crate names it, pub(crate) otherwise, so dead_code can name an internal whose last caller went away (pub-crate-by-default). Core’s own integration tests link ral-core as an external crate and reach internals through one gated module, core::test_access, for cross-component assertions. Representation-local tests live beside their implementations: builtin registry properties in shell/builtins/tests.rs, stored-scheme reseeding in typecheck/session_tests.rs, and scheme formatting in ty/fmt.rs. Integration tests’ engine reads go through IdentityTransport::inspect, the one test-util-only read of an identity engine’s shell; core’s unit tests boot engines through carrier::testkit and prelude shells through test_helper::fresh_shell.

The evaluation seam

Evaluation enters only through the framed run entry on Shell, never the reduction primitive behind it. A host states policy; core owns resources.

  • Shell::run(RunRequest) runs one whole Run, synchronously and runtime-agnostic, returning one flat RunReport. Its Program is either source text or a registered hook applied to first-order arguments — Shell::register_hook stores compiled hooks by name in the session-lived hook table (run-turn-is-host-api).
  • Completion is the call returning, never a channel disconnecting, so a deferred worker holding a surface clone cannot keep a run from ending (run-turn-host-loop).
  • The protocol itself is transport-parametric: protocol is the frame algebra (Attach/Dispatch/Event/Control) a front-end speaks, run in-process as the identity transport or across a socket to the engine child (engine-protocol).
  • The reduction host behind the entry is crate-private, so a host cannot start an unframed evaluation that would foreground or capture against a stale frame.

The shell subjects

core/src/shell.rs groups shell code by subject, not by dependency layer.

  • shell::runtime owns runtime values and interpreter state; static types stay in ty and inference in typecheck.
  • shell::evaluator is the CBPV machine; shell::exec owns command dispatch, pipelines and sink scopes. The evaluator passes pipeline::StageEval callbacks into exec, so stage threads re-enter evaluation without importing the machine.
  • shell::grant decodes runtime grant values and adapts spawn grants; substantive freezing and authored resolution stay in authority::grant.
  • shell::builtins, shell::run, shell::boot and shell::load own primitives, the framed entry (including shell/run/report.rs), boot and loading; shell/prelude.ral is the embedded library.
  • marshal, role, protocol, carrier and engine stay at the crate root, alongside the other non-shell subjects.

authority, egress, fact, host, io, own, path and process cannot reach shell, directly or transitively, in production. Their intentional lower cycles are permitted: this is a boundary, not a DAG.

host and boot

The crate splits driving a Shell from probing the machine it runs on.

  • shell::boot embeds a Shell in a host process. Shell::root(runtime) constructs over a Runtime, the surface a host chooses through HostSurface::runtime or boot_runtime, so every shell chooses its surface through one of two constructors: HostSurface::shell (core’s CORE_SETS, then the host’s sets, no env, no prelude: a loader’s scaffold) or boot_shell, which adds the host env and seats a BakedPrelude whole (BakedPrelude::seat). A half-dressed production shell is unrepresentable, and HostSurface::manifest hands the checker the same list. The prelude is baked ahead of time into a schema-less postcard blob whose single encode site (shell::boot::bake_prelude, returning the blob for a host’s build script to write) and single decode site (shell::boot::BakedPrelude) sit together, and the build-dependency edge from each host to ral-core reruns the bake, so the schema-evolution hazard has one guard rather than three that must agree (host-embedding-api, evaluator-runtime-split).
  • host reports the process’s facts: cwd, user, home, layout_home, home_dot, and on macOS user_cache_dir. It is also the one reader of the host’s environment (var, var_os, vars_os, temp_dir), and of the XDG bases (xdg, with the account’s home as the program’s own fallback). host/login_env.rs (Unix) writes and reads the POSIX login helper’s environment report. Its test-only host/test_support.rs serialises temporary host-environment mutations.
  • environ holds ral’s rules over the host’s variables: the overlay EnvVars, shared by shell state, paths and grants; the Reserved names PWD and OLDPWD, which no overlay binds and no read returns; the view the env builtin shows (EnvVars::visible); and ChildEnv, a child’s cwd and environment edits (EnvVars::for_child), which Launch::situate applies. exarch’s host snapshot is a formatter over EnvVars.
  • fact/fs.rs owns the typed DirEntry and FileInfo query records and their pure construction from metadata; builtins and the checker share these schemas.
  • fact/observation.rs owns observation data, including AuditIo, the captured byte prefixes and totals a command fact consumes; collection belongs to runtime.
  • own is the files a program touches on its own account, outside any shell: OwnDir (what it keeps), UserFile (what the user writes at its places) and the user-named read_named, open_named, kind_named and create_named (banned, so each caller is a typed site that says why the name is the user’s), over the walk and one authority, with three authority-mint sites but no syscall sites (capabilities, own-files).

The pipeline, by judgment

Source text flows down a fixed ladder; each rung is a subsystem page.

  • syntax — lexer and parser, producing the flat surface AST (core/src/syntax/).
  • elaboration — lowers surface forms into CBPV IR (core/src/elaborator.rs).
  • ir — the Val / Comp intermediate representation (core/src/ir.rs).
  • ty — the type language as data, below the IR (core/src/ty.rs, core/src/ty/).
  • typecheck — Hindley–Milner inference with row types (core/src/typecheck/), the sole inference engine, including the grade that places capture (CompTy::Return(Grade, _)).
  • evaluator — the CEK machine over computation closures: focus, frame stack, matching, audit (core/src/shell/evaluator/).
  • exec — command dispatch, pipelines and sink scopes the machine dispatches into (core/src/shell/exec/).

Authority, plumbing, surface

  • egress — pure CONNECT destination data and judgments: Host, NetPolicy, NetPolicy::admits, NetPolicy::offline (no host, no search) and refusal (core/src/egress.rs); policy loading belongs to exarch’s net_policy::{load, for_base}.
  • capabilities — the dynamic capability stack and the OS process sandbox (core/src/authority/: resolved policy and judgments in policy/, authored resolution and host system-read discovery in grant/, enforcement in guard/ and sandbox/; runtime decoding and spawn adaptation in shell/grant/).
  • io-process — byte streams, terminal, signals, process groups (core/src/io/, core/src/process/).
  • builtins — Rust-implemented commands and bundled coreutils/grep (core/src/shell/builtins/).
  • shell-state — runtime values and the Shell interpreter state (core/src/shell/runtime/).
  • transport — the image codec every helper session reads (core/src/marshal.rs, marshal/), first-order values and protocol framing (data/, io/frame.rs).
  • diagnostics — the runtime Error value, source locations and error rendering (core/src/error.rs, source.rs, diagnostic.rs, compile.rs, io/terminal.rs, io/ansi.rs).
  • prelude — the embedded prelude.ral standard library (core/src/shell/prelude.ral).

Beside these sit small shared leaves with no page of their own: text (byte↔char conversion, plurals, fuzzy ranking), sync (the workspace’s lock-poison policy, LockExt), site (the typed-site vocabulary), role and invocation (process-role classification and its dispatch), and external_editor (the editor contract the ral and exarch prompts share).

Siblings

repl is the ral binary over this engine; exarch is the agent embedding it.

The formal account is docs/SPEC.md; the design rationale lives in the durable layer. These pages point at code, they do not restate it.