System Architecture & Design Language

Selûne keeps Git and MoonBit 1.0 RC1 source code as the single source of truth. Every derived fact shard, context pack, evidence attestation, and optional export flows through explicit trust boundaries verified directly against moon.mod, moon.work, and host bridges.

On this page

Constellation Architecture

Five disciplined planes separate stateless agent access, compiler-backed reading, hermetic worktree cell execution, atomic object-store convergence, and offline formal verification.

Selûne Constellation Architecture star chart showing the five planes from stateless gateway to authoritative Git hub
Selûne Constellation Architecture: solid silver and aquamarine paths form the Trusted Commit Core; dotted amethyst paths denote optional fail-open overlays.

Verified MoonBit Module & Bridge Dependency DAG

Each library under libs/<name>/ is an independent MoonBit 1.0 RC1 module using moon.mod and module-local moon.work files so parallel workers never contend on a shared _build/ lock.

+=========================================================================================+
|                         SELÛNE — MODULE & BRIDGE DEPENDENCY GRAPH                       |
|                  (Exact DAG verified from moon.mod / moon.work / bridges)               |
+=========================================================================================+

  [EXTERNAL TOOLCHAIN & SYSTEM LAYER — pinned in toolchain.lock]
  +---------------------+  +----------------------+  +------------------+  +--------------+
  | MoonBit 1.0 RC1     |  | Git (Authoritative)  |  | Bubblewrap 0.13  |  | SQLite 3.54  |
  | moonc/moon/moon ide |  | worktree/merge-tree  |  | --unshare-all    |  | WAL + Shards |
  | moon prove + Why3   |  | CAS update-ref/hooks |  | --unshare-net    |  | Evidence DB  |
  +----------+----------+  +----------+-----------+  +--------+---------+  +------+-------+
             |                        |                       |                   |
  +----------+----------+  +----------+-----------+  +--------+---------+  +------+-------+
  | Z3 5.3.3 / CVC5 1.4 |  | Quint 0.35 + Veil 2  |  | Clang 23.1.3 +   |  | Node 26.13 + |
  | SMT Backends        |  | + Lean 4.35.0 Kernel |  | Tree-sitter 0.26 |  | Python 3.14  |
  +---------------------+  +----------------------+  +------------------+  +--------------+
                                          |
  [FOUNDATION LAYER — MoonBit 1.0 RC1 Standard Packages]
                  moonbitlang/core (1.0.0-rc1)    moonbitlang/x@0.5.9
                                    \                /
  -----------------------------------\--------------/--------------------------------------
  [TIER 1: ZERO-INTERNAL-DEP CORE LIBRARIES]
  -----------------------------------------------------------------------------------------
  +------------------+  +------------------+  +------------------+  +---------------------+
  | libs/toolchain   |  | libs/syntax      |  | libs/identity    |  | libs/crypto_ffi     |
  | agentic_toolchain|  | agentic_syntax   |  | agentic_identity |  | agentic_crypto_ffi  |
  | + moon_runner.py |  | + mbt_ts_bridge.c|  | + cli/ (SHA-256) |  | + csrc/mbcrypto.c   |
  +------------------+  |   -> vendor/ts   |  +------------------+  |   (native C FFI)    |
                        +------------------+                        +---------------------+

  +------------------+  +------------------+  +------------------+  +---------------------+
  | libs/facts       |  | libs/edit        |  | libs/evidence    |  | libs/runtime        |
  | agentic_facts    |  | agentic_edit     |  | agentic_evidence |  | agentic_runtime     |
  | + fact_store.py  |  | + cmd/           |  | (DSSE/SLSA/10st) |  | (Outcome/Cause/Exit |
  | + index_ws.py    |  | + edit_engine.py |  +--------+---------+  |  Scope/STM/Clock)   |
  +--------+---------+  +------------------+           |            | +- host_proc (C)    |
           |                                           |            | +- async_rt (exp)   |
           |                                           |            +----------+----------+
           v                                           v                       |
  -----------------------------------------------------|-----------------------|-----------
  [TIER 2: COMPOSED CORE LIBRARIES (moon.work local deps)]                     |
  -----------------------------------------------------|-----------------------|-----------
  +------------------+                        +--------+---------+             |
  | libs/export      |                        | libs/cache       |             v
  | agentic_export   |                        | agentic_cache    |  +---------------------+
  | + cmd/emit_ogs   |                        | (Drift-Failing   |  | libs/queue          |
  | + exporters.py   |                        |  Evidence Cache) |  | agentic_queue       |
  | (OGS/Cypher/SCIP)|                        +--------+---------+  | +- proofs/ (Why3)   |
  +------------------+                                 |            | +- git_e2e/ (CAS)   |
                                                       v            +----------+----------+
  +------------------+  +------------------+  +--------+---------+             |
  | libs/cells       |  | libs/policy      |  | libs/validate    |             v
  | agentic_cells    |  | agentic_policy   |  | agentic_validate |  +---------------------+
  | + cells_ctl.py   |  | + policy_engine  |  | (deps: evidence, |  | libs/sim            |
  | + verify_gates   |  | + mut_sample/    |  |  cache + bwrap)  |  | agentic_sim + cmd/  |
  | (6-Phase GC/Lock)|  +------------------+  +------------------+  | (deps: runtime,     |
  +------------------+                                              |  queue; 1M DST)     |
                                                                    +---------------------+

  +------------------+  +------------------+  +------------------+
  | libs/context     |  | libs/knowledge   |  | libs/telemetry   |
  | agentic_context  |  | agentic_knowledge|  | agentic_telemetry|
  | + context_engine |  | + graphify_adapt |  +--------+---------+
  | (Packs/Canaries) |  | + wiki.mbt ->    |           |
  +------------------+  |   llm-wiki/ + SIM|           v
                        | (OPT-IN/FAIL-OPEN)| +--------+---------+
                        +------------------+  |                  |
  --------------------------------------------|------------------|-------------------------
  [TIER 3: GATEWAY, PLUGINS & FORMAL VERIFICATION]               |
  ---------------------------------------------------------------|-------------------------
  +-------------------------------------+     +------------------+---+  +-----------------+
  | libs/cli (agentic_cli + bin/agentic)|<----| libs/mcp             |  | plugins/        |
  | (depends on libs/telemetry)         |     | agentic_mcp          |  | - agent-skill   |
  +------------------+------------------+     | + agentic-mcp.mjs    |  | - mcp-plugin    |
                     |                        | (20 tools incl.      |  | - wasm-guest    |
                     |  orchestrates via      |  agentic_wiki_*)     |  | - editor-ide    |
                     |  typed JSON schemas    +----------------------+  +-----------------+
                     v
  +---------------------------------------------------------------------------------------+
  | schemas/  (Draft 2020-12 v1 + fact_store.sql + OGS 1.1.0 YAML)                        |
  | spec/     (commit_queue.qnt + commit_queue_proofs.lean; cell_lifecycle.qnt + .lean)   |
  | llm-wiki/ (29 compiled wiki pages + 4 SIM root-cause entries; tools/{lint,sim}.py)    |
  | benchmark/(Paired A-G Runner + Bootstrap CI + e2e_beta_verify.py -> reports/)         |
  +---------------------------------------------------------------------------------------+

Five-Plane Infrastructure Topology

+=========================================================================================+
|                  SELÛNE — INFRASTRUCTURE & TRUST-BOUNDARY ARCHITECTURE                  |
+=========================================================================================+

  [CONCURRENT CODING AGENTS (Claude / Codex / Gemini / IDE)]
      |                     |                      |                       |
      v                     v                      v                       v
  +-------------------------------------------------------------------------------------+
  |  LAYER 0: STATELESS ACCESS PLANE ("Gates of the Moon")                              |
  |  Stateless MCP Replicas (libs/mcp/bin/agentic-mcp.mjs, HTTP Streamable + Stdio)     |
  |  agentic CLI (libs/cli/bin/agentic) · Editor/Wasm Plugins · OTel Traceparent        |
  +-----------------------------------------+-------------------------------------------+
                                            |
                                            v
  +=====================================================================================+
  |  LAYER 1: DETERMINISTIC READ & CONTEXT PLANE ("Eye of Selûne")                      |
  |  Compiler Core (.mbti / moon ide / Tree-sitter) -> Content-Addressed SQLite Shards  |
  |  -> Context Pack Engine (Held-Out Isolation + Prompt-Injection & Secret Quarantine) |
  | - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
  |  OPTIONAL OVERLAYS (Dotted = Fail-Open, Never Blocks Commits):                      |
  |  [Graphify 0.9.121 (doc/ADR edges)] [llm-wiki/ (29 pages) + SIM (4 entries)]        |
  |  [OGS 1.1.0 / Cypher / SCIP Exporters] [MCP: agentic_wiki_{index,lint,query}]       |
  +=====================================================================================+
                                            |
                                            v
  +=====================================================================================+
  |  LAYER 2: ISOLATED EXECUTION PLANE ("Tears of Selûne" — Worktree Cells)             |
  |  Locked detached git worktree + private GIT_OBJECT_DIRECTORY + bwrap --unshare-all  |
  |  --unshare-net + 6-Phase Lunar Single-Collector GC + Direct main push VETO          |
  +-----------------------------------------+-------------------------------------------+
                                            | Submit(CandidateTree + OpLog + ReadSet)
                                            v
  +=====================================================================================+
  |  LAYER 3: CONVERGENCE, VERIFICATION & COMMIT PLANE ("The Silver Path")              |
  |  Effect-Inspired Runtime + Speculative Commit Queue (git merge-tree --write-tree)   |
  |  -> Hermetic Sandbox (moon check/test/prove) + Anti-Cheat Policy + Drift Cache      |
  |  -> Single-Writer Authoritative Git Hub (Atomic CAS git update-ref refs/heads/...)  |
  +=====================================================================================+
                                            ^
                                            | Offline / CI Formal Verification Loop
  +=========================================+===========================================+
  |  LAYER 4: FORMAL ASSURANCE & DST PLANE ("Silver Fire")                              |
  |  libs/sim (1M DST + ITF Replay) · Quint 0.35 · Veil 2.0 MC · Lean 4.35 ProofAudit   |
  +=====================================================================================+

Trust Boundary Matrix

Solid silver and aquamarine paths belong to the fail-closed Trusted Commit Core; dotted amethyst paths belong to fail-open Optional Overlays.

Plane Components Boundary Failure & Security Posture
Access Plane libs/mcp, libs/cli, plugins/* Trusted Core Strictly stateless (N >= 2 replicas); validates Origin, bearer auth, MCP-Protocol-Version, and explicit repo allowlists before dispatch.
Read & Context Plane libs/toolchain, libs/syntax, libs/identity, libs/facts, libs/context Trusted Core Atomic private-tempfile shards, BEGIN IMMEDIATE SQLite WAL, HMAC-signed manifests, unified secret/injection quarantine (grants_permissions=false), and held_out_tests/ module isolation.
Execution Plane libs/cells, libs/edit, bwrap Trusted Core Private GIT_OBJECT_DIRECTORY per cell with read-only hub alternate; bwrap --unshare-all --unshare-net; supervisor-owned import; collector lease-version fencing + positive empty-cgroup confirmation.
Convergence Plane libs/runtime, libs/queue, libs/validate, libs/evidence, libs/cache, libs/policy Trusted Core Fail-closed on policy weakening, cache drift (CacheDriftError), sandbox escape, timeout (non-servable), or mismatched validated tree OID at atomic CAS git update-ref.
Optional Overlays libs/knowledge (Graphify + wiki.mbt / llm-wiki/ + SIM), libs/export (OGS 1.1.0, Cypher, SCIP), libs/crypto_ffi Optional Overlay Fail-open — missing, stale, or corrupt Graphify, llm-wiki/, SIM, or Neo4j projections never block commits (commit_path_affected=false); compiler-resolved facts always win (source_wins=true).

Knowledge & Self-Improvement Memory (llm-wiki/ + SIM)

Selûne maintains a persistent, repo-local Karpathy-style LLM knowledge base under llm-wiki/ paired with a typed Self-Improvement Memory (SIM.md). Like Graphify, it is strictly optional and fail-open with zero commit-path dependency: compiler-resolved facts and Git remain sole authorities (source_wins=true, commit_path_affected=false).

Compiled Wiki & SIM Ledger (llm-wiki/)

29 compiled pages across 12 sources, 7 entities, 7 concepts, and 3 syntheses backed by canonical repo-relative pointers in raw/SOURCES.tsv, an append-only wiki/log.md, and 4 SIM root-cause entries (moon-mod-manifest-syntax, veil-mc-state-explosion, wcag-contrast-drift, stale-metric-drift) audited via llm-wiki/tools/lint.py (0 failures, 0 orphans) and llm-wiki/tools/sim.py.

Governance · Off Commit Path

MoonBit Runtime, CLI & Stateless MCP Integration

libs/knowledge/wiki.mbt parses frontmatter, [[wikilink]] graphs, and logs with deterministic BM25-style ranking and fail-open fallback (provenance="llm_wiki_compiled"). Accessible via ./bin/selune wiki {status,lint,query,log,sim} and 3 read-only, repo-confined stateless MCP tools: agentic_wiki_index, agentic_wiki_lint, and agentic_wiki_query.

Optional Overlay
./bin/selune wiki status
./bin/selune wiki lint && ./bin/selune wiki sim
./bin/selune wiki query "MARS"

Six-Phase Lunar Worktree Cell Lifecycle

Every agent cell progresses monotonically through six CAS-versioned lifecycle states formally verified in spec/cell_lifecycle.qnt and spec/cell_lifecycle_proofs.lean.

Selûne 6-phase lunar worktree cell lifecycle from Created through Reclaimed with single-collector GC fencing
Six-phase lunar cell lifecycle: only the supervisor may transition to Submitted; only the fenced single collector may seal and reclaim.
State Lunar Phase Glyph Authority & Invariant
Created New Moon Supervisor leases CAS row, locks detached worktree, seeds CoW _build/ on btrfs, mounts private object store.
Running Waxing Crescent Agent executes inside bwrap --unshare-all --unshare-net; live-lease cells cannot be reclaimed.
Submitted Full Moon Supervisor imports candidate commit into hub refs/candidates/<cell>; convergence lands with zero live worktrees.
Abandoned Lunar Eclipse Lease expired or policy vetoed; collector claims and fences lease version in SQLite before terminating processes.
Sealed Waning Crescent Positive empty-cgroup termination confirmed; unsubmitted changes salvaged to refs/salvage/<cell>; worktree unlocked and quarantined.
Reclaimed Dark of the Moon Quarantine trash deleted, ephemeral refs dropped, disk freed, idempotent on repeat; hand-made non-cell worktrees untouched.

Effect v4-Inspired Concurrency in MoonBit 1.0 RC1

Auditing MoonBit's core/async/task_group.mbt exposed two constraints: TaskGroup::add_defer overwrites prior errors during cleanup, and diagnostic E4188 disallows combining raise? with async. libs/runtime resolves both:

Flat Multi-Reason Cause[E]

Preserves every Fail, Die, Interrupt, and CleanupFailure inside Exit[A, E] and Outcome[A, E] without losing earlier errors during teardown.

Pure Sync Layer 1

Keeps ValidationServices, Scope, TxRef STM, TestClock, Schedule, and Pool pure and synchronous so libs/sim runs 1M schedules natively without E4188.

Shielded async_rt

Isolates core/async in libs/runtime/async_rt with bracket_protected, LIFO/parallel exit-aware finalizers, Deferred, Latch, MultiSemaphore, and FiberMap.

Five-Pillar Technical Synthesis

Five pillars intersection: Unison identity, Quint/Lean proofs, Effect concurrency, bwrap isolation, and MoonBit 1.0 RC1
Five-pillar architectural convergence anchoring Selûne.
End-to-end change lifecycle from context pack and structured edit plan through speculative validation to CAS commit
End-to-end change lifecycle from context pack to atomic CAS commit.
Content-addressed identity prism separating InterfaceDigest, BodyDigest, and ClosureDigest alongside formal verification
Identity & assurance prism: separating interface, body, and closure invalidation.
Trust boundary matrix separating solid authoritative commit core from dotted optional overlays
Trust boundary matrix: fail-closed commit core vs fail-open optional overlays.

Selûne Design Language v2 Tokens

Use the theme toggle in the header to switch live between Astral Midnight (dark default) and Celestial Vellum (House of the Moon white marble light mode). All 162 token color pairs pass WCAG AA/AAA contrast audits.

Selûne Design System specimen sheet illustrating Astral Midnight and Celestial Vellum surfaces, semantic accents, and optical geometry
Selûne Design Language v2 specimen sheet: Astrolabe geometry, dual themes, and semantic verification accents.
Canvas --selune-bg-canvas
Surface --selune-bg-surface
Elevated --selune-bg-elevated
Argentum Silver --selune-silver
Moonglow (Proved / Sandbox) --selune-moonglow
Silverfire (Passed / Replay) --selune-silverfire
Amethyst (Formal / Optional) --selune-amethyst
Waxing Amber (Inconclusive) --selune-waxing
Shar's Umbra (Hard Veto) --selune-umbra