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 wholeRun, synchronously and runtime-agnostic, returning one flatRunReport. ItsProgramis either source text or a registered hook applied to first-order arguments —Shell::register_hookstores 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:
protocolis the frame algebra (Attach/Dispatch/Event/Control) a front-end speaks, run in-process as the identity transport or across a socket to theenginechild (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::runtimeowns runtime values and interpreter state; static types stay intyand inference intypecheck.shell::evaluatoris the CBPV machine;shell::execowns command dispatch, pipelines and sink scopes. The evaluator passespipeline::StageEvalcallbacks intoexec, so stage threads re-enter evaluation without importing the machine.shell::grantdecodes runtime grant values and adapts spawn grants; substantive freezing and authored resolution stay inauthority::grant.shell::builtins,shell::run,shell::bootandshell::loadown primitives, the framed entry (includingshell/run/report.rs), boot and loading;shell/prelude.ralis the embedded library.marshal,role,protocol,carrierandenginestay 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::bootembeds aShellin a host process.Shell::root(runtime)constructs over aRuntime, the surface a host chooses throughHostSurface::runtimeorboot_runtime, so every shell chooses its surface through one of two constructors:HostSurface::shell(core’sCORE_SETS, then the host’s sets, no env, no prelude: a loader’s scaffold) orboot_shell, which adds the host env and seats aBakedPreludewhole (BakedPrelude::seat). A half-dressed production shell is unrepresentable, andHostSurface::manifesthands the checker the same list. The prelude is baked ahead of time into a schema-lesspostcardblob 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 toral-corereruns the bake, so the schema-evolution hazard has one guard rather than three that must agree (host-embedding-api, evaluator-runtime-split).hostreports the process’s facts:cwd,user,home,layout_home,home_dot, and on macOSuser_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-onlyhost/test_support.rsserialises temporary host-environment mutations.environholds ral’s rules over the host’s variables: the overlayEnvVars, shared by shell state, paths and grants; theReservednamesPWDandOLDPWD, which no overlay binds and no read returns; the view theenvbuiltin shows (EnvVars::visible); andChildEnv, a child’s cwd and environment edits (EnvVars::for_child), whichLaunch::situateapplies. exarch’s host snapshot is a formatter overEnvVars.fact/fs.rsowns the typedDirEntryandFileInfoquery records and their pure construction from metadata; builtins and the checker share these schemas.fact/observation.rsowns observation data, includingAuditIo, the captured byte prefixes and totals a command fact consumes; collection belongs to runtime.ownis 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-namedread_named,open_named,kind_namedandcreate_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/Compintermediate 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) andrefusal(core/src/egress.rs); policy loading belongs to exarch’snet_policy::{load, for_base}.- capabilities — the dynamic capability stack and the OS process
sandbox (
core/src/authority/: resolved policy and judgments inpolicy/, authored resolution and host system-read discovery ingrant/, enforcement inguard/andsandbox/; runtime decoding and spawn adaptation inshell/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
Shellinterpreter 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
Errorvalue, 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.ralstandard 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.