@@ -125,6 +125,8 @@ Rules are graphs. Systems are graphs. The whole runtime is a graph. This gives y
125125
126126## Architecture
127127
128+ > _ “Roads? Where we’re going, we don’t need roads.” — Doc Brown, Back to the Future_
129+
128130Echo is a Rust workspace organized into a multi-crate setup. The core engine is pure, dependency-free Rust (#![ no_std] capable) with I/O isolated to adapter crates.
129131
130132``` bash
@@ -140,124 +142,164 @@ echo/
140142└── scripts/ (Build automation, benchmarking)
141143```
142144
143- ### Core Layers (inside ` rmg-core ` )
145+ ### Core Architectural Layers
144146
145- ** ECS** : Archetype-based Entity-Component-System storage.
146- ** Scheduler** : Deterministic $O(n)$ radix-sort-based rule scheduler.
147- ** GraphStore** : In-memory BTreeMap-based graph storage (ensures deterministic iteration).
148- ** Transaction Model** : The ` begin() ` , ` apply() ` , ` commit() ` lifecycle for graph rewrites.
149- ** Snapshotting** : ` state_root ` and ` commit_id ` (Merkle commit) computation.
150- ** Footprints** : Independence checks for Multi-Writer-Multi-Read (MWMR) concurrency.
151- ** Deterministic Math** : safe Vec3, Mat4, Quat, and PRNG.
147+ 1 . ECS (Entity-Component-System): Type-safe components with archetype-based storage
148+ 2 . Scheduler: Deterministic DAG ordering via O(n) radix sort
149+ 3 . Event Bus: Command buffering for deterministic event handling
150+ 4 . Timeline Tree: Branching/merging with temporal mechanics (Chronos, Kairos, Aion)
151+ 5 . Ports & Adapters: Renderer, Input, Physics, Networking, Audio, Persistence
152+ 6 . Deterministic Math: Vec3, Mat4, Quat, PRNG with reproducible operations
152153
153- ---
154+ ### Key Technical Concepts
154155
155- ## Project Status: Phase 1 MVP (Active Development)
156+ #### Recursive Meta Graph Core
156157
157- The project is currently focused on proving the core determinism and performance of the RMG model.
158+ The engine operates on typed, directed graphs:
158159
159- ✅ Formal proofs of confluence (tick-level determinism proven).
160- ✅ C implementation of independence checks and footprint calculus.
161- ✅ Rust core runtime (` rmg-core ` ) with the transaction model and $O(n)$ scheduler.
162- ✅ Comprehensive property-based test suite (200+ iterations validating commutativity).
163- ✅ Benchmark infrastructure (` rmg-benches ` ) with a D3 visualization dashboard.
164- 🚧 Performance optimization (subgraph matching, spatial indexing).
165- 🚧 Temporal mechanics (Aion integration for significance/agency).
166- 🚧 Radix sort micro-tuning for scheduler.
167- ☑️ (not yet started) Lua scripting integration (via ` rmg-ffi ` ).
168- ☑️ (not yet started) Rendering backend (adapters planned).
169- ☑️ (not yet started) Full physics engine integration.
170- ☑️ (not yet started) Inspector tooling (via rmg-wasm).
160+ - Nodes = typed entities with component data
161+ - Edges = typed relationships between nodes
162+ - Rules = deterministic transformations that match patterns and rewrite subgraphs
171163
172- ## Learning the Vision
164+ All identifiers are 256-bit BLAKE3 hashes with domain separation:
173165
174- > _ “Roads? Where we’re going, we don’t need roads.” — Doc Brown, Back to the Future_
166+ ``` rust
167+ pub type Hash = [u8 ; 32 ];
168+ pub struct NodeId (pub Hash ); // Entities
169+ pub struct TypeId (pub Hash ); // Type descriptors
170+ pub struct EdgeId (pub Hash ); // Relationships
171+ ```
175172
176- - Read [ docs/architecture-outline.md] ( ./docs/architecture-outline.md ) for the full spec.
177- - Explore [ docs/diagrams.md] ( ./docs/diagrams.md ) for Mermaid visuals.
178- - Track active work in [ docs/execution-plan.md] ( ./docs/execution-plan.md ) .
173+ #### Deterministic Rewriting
179174
180- ---
175+ Each tick follows a transaction model:
181176
182- ### The Math Checks Out
177+ 1 . begin() → Create new transaction
178+ 2 . apply(tx, rule) → Enqueue pending rewrites
179+ 3 . commit(tx) → Execute in deterministic order, emit snapshot
183180
184- The mathematical properties of RMGs offer:
181+ #### $O(n)$ Deterministic Scheduler
185182
186- - ** Folds (catamorphisms)** : there is a guaranteed, one-true way to “walk” the graph.
187- - That’s how rendering, physics, and serialization all stay consistent: they’re just different folds over the same data.
188- - ** Double-Pushout (DPO) rewriting** : a safe, proven way to modify graphs.
189- - Instead of ad-hoc mutation, every change is a rewrite rule with an explicit match and replacement, so the engine can reason about merges, rollbacks, and conflicts.
190- - ** Confluence** – when two people or two threads make compatible edits, they deterministically converge to the same state.
191- - That’s the key to multiplayer sync, time-travel debugging, and collaborative editing.
183+ Rewrites are ordered using stable radix sort (not comparison-based):
192184
193- There's a ton of other advanced reasons why it's cool, but that's nerd stuff. Let's just say that the RMG is weird, and ** extremely powerful.**
185+ - Order: (` scope_hash ` , ` rule_id ` , ` nonce ` ) lexicographically
186+ - Time: $O(n)$ with 20 passes of 16-bit radix digits
194187
195- ---
188+ This ensures identical initial state + rules = identical execution order and final snapshot.
196189
197- ### Learning the Vision
190+ #### Snapshot Hashing (Merkle Commits)
198191
199- > * “Roads? Where we’re going, we don’t need roads.” — Doc Brown, Back to the Future *
192+ Two hashes per commit:
200193
201- - Read [ ` docs/architecture-outline.md ` ] ( docs/architecture-outline.md ) for the full spec (storage, scheduler, ports, timelines).
202- - Explore [ ` docs/diagrams.md ` ] ( docs/diagrams.md ) for Mermaid visuals of system constellations and the Chronos loop.
203- - Honor Caverns with [ ` docs/memorial.md ` ] ( docs/memorial.md ) —we carry the torch forward.
204- - Peek at [ ` docs/legacy-excavation.md ` ] ( docs/legacy-excavation.md ) to see which ideas survived the archaeological roast.
205- - Track active work in [ ` docs/execution-plan.md ` ] ( docs/execution-plan.md ) ; update it every session.
194+ - ` state_root ` : BLAKE3 of canonical graph encoding (sorted nodes/edges)
195+ - ` commit_id ` : BLAKE3 of commit header (` state_root ` + parent + plan + decisions + rewrites)
206196
207- ### Docs
197+ ### Footprints & Independence (MWMR)
208198
209- - Dev server: ` make docs ` (opens browser; uses ` PORT ` env var, default 5173)
210- - Static build: ` make docs-build `
211- - Single-file rollup: ` make echo-total ` (generates ` docs/echo-total.md ` from top‑level docs; commit the result if it changes)
199+ For parallel rewriting:
212200
213- ### CI Tips
201+ ``` rust
202+ struct Footprint {
203+ n_read , n_write : IdSet , // Node reads/writes
204+ e_read , e_write : IdSet , // Edge reads/writes
205+ b_in , b_out : PortSet , // Boundary ports
206+ factor_mask : u64 , // Spatial partitioning hint
207+ }
208+ ```
214209
215- - Manual macOS run: trigger the "CI (macOS — manual)" workflow from the Actions tab to run fmt/clippy/tests on macOS on demand.
216- - Reproduce CI locally:
217- - Format: ` cargo fmt --all -- --check `
218- - Clippy: ` cargo clippy --all-targets -- -D warnings -D missing_docs `
219- - Tests: ` cargo test --workspace `
220- - Rustdoc (warnings as errors): ` RUSTDOCFLAGS="-D warnings" cargo doc -p rmg-core --no-deps ` (repeat for other crates)
221- - Security: ` cargo install cargo-audit --locked && cargo audit --deny warnings `
222- - Dependency policy: ` cargo deny check ` (requires ` cargo-deny ` )
210+ Disjoint footprints = independent rewrites = safe parallel execution.
223211
224- ---
212+ ### Component Interaction
225213
226- ## Contributing
214+ #### ` rmg-core ` ( ` crates/rmg-core/src/ ` )
227215
228- > *** WANTED:** Somebody to go back in time with me. This is not a joke.*
229- > * P.O. Box 91, Ocean View, WA 99393.*
230- > * You’ll get paid after we get back. Must bring your own weapons.*
231- > * I have only done this once before. ** Safety not guaranteed.***
216+ - ` engine_impl.rs ` : Transaction lifecycle, rewrite application
217+ - ` scheduler.rs ` : $O(n)$ radix drain, conflict detection
218+ - ` graph.rs ` : BTreeMap-based node/edge storage
219+ - ` snapshot.rs ` : State root and commit ID computation
220+ - ` rule.rs ` : Rewrite rule definitions with pattern matching
221+ - ` footprint.rs ` : Independence checks for concurrent execution
222+ - ` math/ ` : Deterministic Vec3, Mat4, Quat, PRNG
232223
233- - Start each task by verifying a clean git state and branching (` echo/<feature> ` recommended).
234- - Tests go in ` packages/echo-core/test/ ` (fixtures in ` test/fixtures/ ` ). End-to-end scenarios will eventually live under ` apps/playground ` .
235- - Use expressive commits (` subject ` / ` body ` / optional ` trailer ` ). Tell future us the * why* , not just the * what* .
236- - Treat determinism as sacred: use Echo’s PRNG, avoid non-deterministic APIs without wrapping them.
224+ ## Execution Flow
237225
238- ### Running Benchmarks
226+ ``` c
227+ loop {
228+ let tx = engine.begin();
239229
240- Echo takes performance and determinism seriously. The ` rmg-benches ` crate provides detailed microbenchmarks.
230+ // Application phase
231+ for rule in rules_to_apply {
232+ engine.apply(tx, rule, &scope)?;
233+ }
241234
242- ** Command (live dashboard):**
235+ // Deterministic execution
236+ let snapshot = engine.commit(tx)?;
243237
244- ``` bash
245- make bench-report
238+ // Emit to networking, tools, etc.
239+ publish_snapshot (snapshot);
240+ }
246241```
247242
248- - Runs ` cargo bench -p rmg-benches ` , starts a local server, and opens the dashboard at ` http://localhost:8000/docs/benchmarks/ ` .
243+ ## Design Principles
249244
250- ** Command (offline static file): **
245+ 1 . Determinism as Foundation: Every operation must produce identical results given identical input
246+ 2 . Snapshot Isolation: State captured as immutable graph hashes (not event logs)
247+ 3 . Hexagonal Architecture: Core never touches I/O directly; all flows through ports
248+ 4 . Dependency Injection: Services wired at bootstrap for hot-reload support
249+ 5 . Property-Based Testing: Extensive use of proptest for mathematical invariants
251250
252- ``` bash
253- make bench-bake
254- ```
251+ ## Current Status
252+
253+ Phase 1 MVP (active development on echo/pr-12-snapshot-bench):
254+
255+ ✅ Completed:
256+ - Formal confluence proofs (tick-level determinism proven)
257+ - Rust core runtime with transaction model
258+ - 200+ property tests validating commutativity
259+ - Benchmark infrastructure with D3 dashboard
255260
256- - Runs benches and bakes ` docs/benchmarks/report-inline.html ` with results injected so it works over ` file:// ` (no server required).
261+ 🚧 In Progress:
262+ - Performance optimization (subgraph matching, spatial indexing)
263+ - Temporal mechanics integration
257264
258- ** Docs: **
265+ ## Key Files to Explore
259266
260- See [ ` crates/rmg-benches/benches/README.md ` ] ( ./crates/rmg-benches/benches/README.md ) for details.
267+ ### Documentation
268+
269+ - ` README.md ` — Project vision
270+ - ` docs/architecture-outline.md ` — Full system design
271+ - ` docs/spec-rmg-core.md ` — RMG Core spec v2
272+ - ` docs/spec-merkle-commit.md ` — Snapshot hashing spec
273+ - ` docs/spec-scheduler.md ` — Deterministic scheduler design
274+
275+ ### Core Implementation
276+
277+ - ` crates/rmg-core/src/engine_impl.rs ` — Engine core
278+ - ` crates/rmg-core/src/scheduler.rs ` — O(n) scheduler
279+ - ` crates/rmg-core/src/snapshot.rs ` — Merkle hashing
280+ - ` crates/rmg-core/src/demo/motion.rs ` — Example rewrite rule
281+
282+ ### Tests & Benchmarks:
283+
284+ - ` crates/rmg-core/tests/permutation_commute_tests.rs ` — Determinism proofs
285+ - ` crates/rmg-benches/benches/snapshot_hash.rs ` — Hashing throughput
286+
287+ Echo is a mathematically rigorous game engine that replaces traditional OOP with deterministic graph rewriting—enabling time-travel debugging, perfect
288+ replay, and Git-like branching for game states.
289+
290+ ---
291+
292+ ## Contributing
293+
294+ > *** WANTED:** Somebody to go back in time with me. This is not a joke.*
295+ > * P.O. Box 91, Ocean View, WA 99393.*
296+ > * You’ll get paid after we get back. Must bring your own weapons.*
297+ > * I have only done this once before. ** Safety not guaranteed.***
298+
299+ - Start each task by verifying a clean git state and branching (` echo/<feature> ` recommended).
300+ - Tests go in ` packages/echo-core/test/ ` (fixtures in ` test/fixtures/ ` ). End-to-end scenarios will eventually live under ` apps/playground ` .
301+ - Use expressive commits (` subject ` / ` body ` / optional ` trailer ` ). Tell future us the * why* , not just the * what* .
302+ - Treat determinism as sacred: use Echo’s PRNG, avoid non-deterministic APIs without wrapping them.
261303
262304### Git Hooks
263305
@@ -267,15 +309,6 @@ Install the repo’s hooks so formatting and quick checks run before commits:
267309make hooks
268310```
269311
270- - The pre-commit hook auto-fixes formatting by default (runs ` cargo fmt --all ` ).
271- - To switch to check-only mode for a commit, set ` ECHO_AUTO_FMT=0 `
272-
273- ```
274- ECHO_AUTO_FMT=0 git commit -m "your message"
275- ```
276-
277- You can also export ` ECHO_AUTO_FMT=0 ` in your shell rc if you prefer check-only always.
278-
279312### Development Principles
280313
2813141 . ** Tests First** – Write failing unit/integration/branch tests before new engine work.
@@ -285,10 +318,10 @@ You can also export `ECHO_AUTO_FMT=0` in your shell rc if you prefer check-only
285318
286319### Roadmap Highlights
287320
288- - [x] ** Phase 0** – Finalize specs and design.
289- - [ ⏳ ] ** Phase 1** – Ship Echo Core MVP with tests and headless harness.
290- - [ ] ** Phase 2** – Deliver reference render/input adapters and ** the playground** .
291- - [ ] ** Phase 3+** – Physics, WebGPU, audio, inspector, and full temporal tooling.
321+ ✅ ** Phase 0** – Finalize specs and design.
322+ ⏳ ** Phase 1** – Ship Echo Core MVP with tests and headless harness.
323+ ☑️ ** Phase 2** – Deliver reference render/input adapters and ** the playground** .
324+ ☑️ ** Phase 3+** – Physics, WebGPU, audio, inspector, and full temporal tooling.
292325
293326** Chrononauts welcome.** Strap in, branch responsibly, and leave the timeline cleaner than you found it.
294327
0 commit comments