Here is the English version of your instruction.md. It has been translated to maintain the authoritative, "blacksmithing-inspired" tone of the Mumei project.
Mumei is a protocol designed to transform the uncertain code generated by AI agents (the result of "probabilistic inference") into verified, reliable assets. Developers and AI agents must define Immutable Truths (requires/ensures) before writing any algorithmic logic.
All logic must be encapsulated within an atom.
- requires: Conditions that must be satisfied before execution.
- ensures: Outcomes that are guaranteed after execution. Use
result == exprfor precise equality propagation across chained calls. - body: The implementation of the algorithm. Using
{}block syntax andletvariable bindings is highly recommended. - consume: Declares ownership transfer.
consume x;marks parameterxas consumed — it cannot be used after the atom returns. - ref: Declares read-only borrowing.
ref v: Tallows access without taking ownership. The owner cannotconsumeduring the borrow.
- if-else: An
elseblock must always be included to ensure mathematical totality (exhaustiveness). - let: Variables must be treated as immutable. Re-assignment is not permitted.
- Block Evaluation: The final expression in a block
{ ... }is treated as the return value of that block.
When performing division, you must either explicitly state in the requires clause that the divisor is non-zero or implement a dynamic guard using an if statement.
Bad:
body: a / b;Good:body: if b != 0 { a / b } else { 0 };
When handling arrays or ranges, use forall to define boundary conditions.
Example: requires: forall(i, 0, len, arr[i] > 0);
When working with heap-allocated resources (Vector<T>, HashMap<K, V>), follow these rules:
- consume: Use
consume x;to declare that a parameter's ownership is transferred. After consumption, the variable is dead — any subsequent access is a compile-time error. - ref: Use
ref v: Tfor read-only access. The caller retains ownership, and the callee cannot free or consume the resource. - No double-free: The compiler's
LinearityCtxtracks liveness via Z3 symbolic Bools. Consuming an already-consumed variable triggers:Double-free detected. - No use-after-free: Accessing a consumed variable triggers:
Use-after-free detected. - No consume during borrow: Attempting to consume a borrowed variable triggers:
Cannot consume: currently borrowed.
Bad:
atom drop(ref v: i64) consume v;— ref and consume conflict Good:atom drop(v: i64) consume v;— ownership transfer without borrow
When defining traits with law clauses, the compiler expands method calls using impl bodies and verifies with Z3:
law commutative_add: add(a, b) == add(b, a)→ expanded to(a + b) == (b + a)→ Z3 proves directly.- Use
whereconstraints on trait method parameters:fn div(a: Self, b: Self where v != 0) -> Self;
When defining atoms that accept function parameters via atom_ref, use the contract() clause to declare the expected preconditions and postconditions of the function parameter. This enables Z3 to verify the atom's body without relying on trusted.
Syntax:
atom apply(x: i64, f: atom_ref(i64) -> i64)
requires: x >= 0;
ensures: result >= 0;
contract(f): ensures: result >= 0;
body: call(f, x);
contract(f): ensures: <expr>;— declares the postcondition thatf's result must satisfy.contract(f): requires: <expr>, ensures: <expr>;— declares both precondition and postcondition.- In contract expressions,
x/arg0refer to the first call-site argument (not the atom's own parameter),y/arg1to the second call-site argument, andresultto the call's return value. Note: if the atom has a parameter namedx, the contract'sxwill shadow it with the call-site argument value.
How it works: When the verifier encounters call(f, args...) and f is a parametric function parameter with a declared contract, it:
- Checks the
requiresclause (if any) holds at the call site — fails verification if the precondition may be violated. - Asserts the
ensuresclause as a fact in the Z3 solver — constraining the symbolic result of the call.
This mechanism replaces the need for trusted on higher-order functions like map, fold_left, and result_map.
Subsumption warning: When calling apply(5, atom_ref(increment)), the verifier now performs a subsumption check: it verifies that increment's actual ensures clause, under its requires precondition, implies the declared contract(f): ensures. Formally: (concrete.requires ∧ concrete.ensures) ⇒ contract.ensures. If the implication does not hold, a warning is emitted to stderr (not a hard error, to maintain backward compatibility). For example, if increment has requires: x >= 0 and ensures: result == x + 1 and the contract declares ensures: result >= 0, no warning is emitted because x >= 0 ∧ result == x + 1 implies result >= 0. However, if the concrete atom's ensures does not imply the contract's ensures (even under its precondition), a warning like ⚠️ Subsumption warning: atom_ref(foo) passed to apply.f — concrete ensures '...' may not imply contract ensures '...' will be printed.
When defining atoms that are generic over effect sets, use <E: Effect> type parameter bounds and with E on function parameter types:
Syntax:
atom pipe<E: Effect>(f: atom_ref(i64) -> i64 with E)
effects: [E];
requires: true;
ensures: true;
body: call(f, 42);
<E: Effect>— declaresEas an effect type parameter. The compiler verifies that the concrete type argument is a known effect definition.with E— annotates the function parameter's effect set. After monomorphization,Eis replaced with the concrete effect (e.g.,FileWrite).effects: [E]— the atom's own effect set includes the effect variable. After monomorphization, this becomeseffects: [FileWrite].
How it works: Effect polymorphism is resolved through monomorphization (same as type polymorphism):
pipe<FileWrite>(atom_ref(writer))triggers monomorphization ofpipewithE = FileWrite- A concrete
pipe<FileWrite>atom is generated witheffects: [FileWrite]andwith [FileWrite] - The concrete atom is verified by Z3 using the standard effect containment check
Multiple effect parameters:
atom transform<E1: Effect, E2: Effect>(
r: atom_ref(i64) -> i64 with E1,
w: atom_ref(i64) -> i64 with E2
)
effects: [E1, E2];
requires: true;
ensures: true;
body: { let x = call(r, 1); call(w, x) };
- Prelude (
std/prelude.mm): Auto-imported. ProvidesEq,Ord,Numeric,Option<T>,Result<T, E>. - Alloc (
std/alloc.mm): Import withimport "std/alloc" as alloc;. ProvidesVector<T>,HashMap<K, V>,alloc_raw,dealloc_raw. - FQN dot-notation:
math.add(x, y)is equivalent tomath::add(x, y).
If verification is marked as Failed, the developer or AI agent should follow these steps:
- Analyze the Counter-example: Refer to the Visualizer or
report.jsonto identify which input values caused the logic to fail. - Strengthen Requirements (
requires): Re-evaluate if the input constraints are too loose. - Repair the Body: Add
ifguards or implement proper edge-case handling. - Re-forge: Run
cargo runagain to confirm that the mathematical contradiction has been resolved.
Understand the following characteristics of the code exported by Mumei:
| Language | Characteristics | Ownership Mapping | Primary Use Case |
|---|---|---|---|
| LLVM IR | Fast, Native Execution | alloc_raw → malloc, dealloc_raw → free |
Performance-critical core logic |
- Optimization for i64: The current verification engine is optimized for
i64(Int64).u64andf64are also supported. - Overflow Responsibility: If there is a risk of overflow in arithmetic operations, limit the value range in the
requiresclause. - Float Verification:
f64is supported with sign propagation (pos×pos→pos, etc.). Usetype Pos = f64 where v > 0.0;for positive-only floats. - Zero-Division Prevention: The
Numerictrait'sdivmethod carrieswhere v != 0on the divisor. Z3 checks this at every call site automatically.
- Introducing Side Effects: Mumei focuses on pure functional verification. Modifying global variables or performing undefined external I/O within the
bodyis strictly prohibited. Atoms without aneffects:annotation are treated as pure — calling effectful atoms from a pure atom is a verification error. - Ignoring Type Constraints: Treat numbers as
i64by default and always account for potential overflows.
Mumei serves as a bridge between heavyweight formal proof assistants and modern application development.
| Item | Lean 4 | Coq / Rocq | Mumei (無銘) |
|---|---|---|---|
| Primary Use | General math proofs, SW verification | Mathematical theorems, high-trust systems | Secure code generation for AI agents |
| Difficulty | Very High (Requires learning tactics) | Very High (Requires math background) | Moderate (Close to standard coding) |
| Verif. Engine | Custom Kernel / Lean Checker | Coq Kernel | Z3 SMT Solver (Automated priority) |
| Automation | Partially automated, mainly manual | Mainly manual (via Ltac, etc.) | Fully Automated (requires/ensures) |
| Target Output | Lean runtime, C | OCaml, Haskell, Scheme, etc. | LLVM IR (native binary) |
| Memory Safety | GC / managed | GC / extracted | Ownership + Borrowing (Z3-verified) |
| AI Synergy | Research stage (LLM tactics) | Research stage | Native (JSON reports / Self-healing) |
| Design Logic | Expressing math through code | Building proofs as programs | Preventing "unforged" (unsafe) code |
Mumei caches verification results per-atom in .mumei/cache/verification_cache.json:
- Each atom's proof hash is computed from
name | requires | ensures | body_expr | consume | ref | effects | trust level | callee signatures | type predicates. - The proof hash includes transitive callee signatures — if a callee's contract changes, all callers are automatically re-verified.
- If the hash matches the cached value, Z3 verification is skipped — significantly reducing build times.
- If verification fails, the atom is removed from cache and will be re-verified next time.
- Old
.mumei_build_cachefiles are automatically migrated to the new format.
On the second run:
✅ Verification passed: 2 verified, 6 skipped (unchanged) ⚡
| Document | Purpose |
|---|---|
README.md |
Language overview, features, quickstart |
docs/LANGUAGE.md |
Language reference — types, generics, traits, ownership, async |
docs/ROADMAP.md |
Strategic roadmap v0.3.0+ — 3 priorities, phases, dependencies, timeline |
docs/CROSS_PROJECT_ROADMAP.md |
Cross-project roadmap (mumei + mumei-agent + mumei-lean + mumei-demo) |
docs/ARCHITECTURE.md |
Compiler internals, pipeline, ModuleEnv, LinearityCtx |
docs/STDLIB.md |
Standard library reference (all modules + atoms + planned std.json/std.http) |
docs/EXAMPLES.md |
Verification suite, pattern matching, negative tests |
docs/CHANGELOG.md |
Change history |
docs/CAPABILITY_SECURITY.md |
Effect-based capability security evaluation |
docs/DIAGNOSTICS.md |
Span-based diagnostics design and implementation status |
docs/FFI.md |
FFI extern block design, implementation status, and bridge completion plan |
docs/CONCURRENCY.md |
Structured concurrency (task/task_group) design, implementation status, and std.http integration plan |
docs/TOOLCHAIN.md |
CLI commands, distribution, and future roadmap (3 priorities) |
docs/PATTERNS.md |
Verification patterns — Verified Configuration, Verified State Machine |
docs/CROSS_SPEC_GUIDE.md |
System-wide contract consistency, invariants, dependency cycles |
docs/PLUGIN_GUIDE.md |
Emitter plugin architecture and external plugin development |
docs/SPEC_GUIDE.md |
Decidable fragment guide, spec validation, property-based testing |
docs/EDITORS.md |
Editor configuration (Neovim, Helix, Emacs, Sublime Text, Zed) |
docs/LSP_INTEGRATION.md |
LSP CodeLens, intent drift, spec-code mapping |
docs/PROOF_CERTIFICATE.md |
Proof certificate format and verification |
docs/REPORT_SCHEMA.md |
report.json output schema for AI agent consumption |
docs/STDLIB_METRICS.md |
Standard library proof health metrics (auto-updated by CI) |
docs/STRUCTURED_FEEDBACK_SCHEMA.md |
Structured semantic feedback schema |
docs/TRUSTED_ATOMS.md |
Trusted atom reduction roadmap and FFI contract test harness |
docs/ZERO_HUMAN_CHALLENGE.md |
Zero-Human Challenge analysis and results |
docs/META_ARCHITECT.md |
Meta-architect design notes |
docs/SESSION_PLANS.md |
Detailed session plans for implementation priorities |
docs/CLI.md |
CLI command reference |
docs/CLAUDE_CODE_QUICKSTART.md |
Claude Code + mumei setup and workflow guide |
mumei-agent/docs/VERIFICATION_WORKFLOW_GUIDE.md |
End-to-end verification workflows — NL spec validation, foreign-code verification, spec↔code alignment, cross-spec, MCP usage, self-healing loop |
instruction.md |
This file — forging guidelines, development phase, coding conventions |
Details:
docs/ROADMAP.md
The LSP server (mumei lsp) has the following features implemented:
textDocument/didOpen/textDocument/didChange→ parse error diagnosticstextDocument/hover→ atom requires/ensures display- Z3 verification error diagnostics (with Span-based position info)
- Real-time
/// spec:natural-language comment validation viamumei-agent validate-spec - Inline contract diagnostics for opened
.py/.rs/.ts/.tsx/.gofiles viamumei-agent validate-code textDocument/completion→ keyword, atom, effect, type/struct/enum completion (trigger characters:.,:)textDocument/definition→ jump to atom, type, struct, enum, effect, trait, and resource definitionsshutdown/exithandling- Parsed items cache for efficient completion and definition lookups
Editor configuration examples: docs/EDITORS.md
Deferred items:
- Counter-example highlighting in editors
VS Code Marketplace publishing→ ✅ Published (see editors/vscode/README.md)
Mumei's differentiators:
- Rust-level safety (Z3 formal verification) combined with
- Go-level simplicity for concurrent programming
Three strategic priorities to transform Mumei from an experimental language into a practical tool:
Goal: Build a compelling demo: "API scripting is this simple and safe in Mumei."
Phases:
- P1-A: FFI Bridge Completion — extern → trusted atom auto-registration in ModuleEnv (prerequisite for all FFI-backed stdlib)
- P1-B: std.json —
json.parse(str)/json.stringify(obj)/json.get_string()/json.get_int()(serde_json backend) - P1-C: std.http —
http.get(url)/http.post(url, body)→ Response (reqwest FFI backend) - P1-D: Integration Demo —
task_group:all+ concurrent HTTP requests example
Target API:
import "std/http" as http;
import "std/json" as json;
// Simple GET — extreme simplicity
let response = await http.get("https://api.example.com/users");
let data = json.parse(http.body(response));
let name = json.get_string(data, "name");
// Concurrent requests — Mumei's killer feature
task_group:all {
task { http.get("https://api.example.com/users") };
task { http.get("https://api.example.com/orders") };
task { http.get("https://api.example.com/products") }
}
Goal: "Install in 30 seconds, run anywhere."
Phases:
- P2-A: Static Linking — musl target for fully static Linux binaries + Windows support
- P2-B: Homebrew Tap —
brew install mumei-lang/mumei - P2-C: WebInstall —
curl -fsSL https://mumei-lang.github.io/install.sh | sh
Goal: "Best-in-class CLI development experience, no IDE required."
Phases:
- P3-A: mumei repl — Interactive REPL with incremental definition, verification feedback, and
:verify-spec/:verify-codehandoff tomumei-agent(spec_health_issues/verification_violations/cross_validation_gaps/next_steps) - P3-B: mumei doc — rustdoc-style HTML documentation generation from
///comments - P3-C: REPL + HTTP Integration — Try HTTP requests interactively in REPL
Improve the practicality of task / task_group introduced in PR-C.
Implemented (Plan 8):
- Task return type inference — type checker infers return type from
task { expr }block's final expression;awaityields the correct type from the task handle - Syntax for binding
task_groupresults to variables —let results = task_group { ... }binds the collection of individual task return types - Task cancellation semantics —
cancel group_name;statement cancels pending tasks in a task_group; task_group scope exit implicitly cancels all pending tasks via cancellation token mechanism - Channel type (
chan<T>) — built-in generic type withsend(ch, value)andrecv(ch)operations; requiresChaneffect annotation; implemented in parser (send/recvkeywords), AST (ChanSend/ChanRecv), HIR, MIR, codegen, and Z3 verification (channel and value sub-expressions are fully traversed)
- Always run
cargo fmtbefore committing. - When adding a new
Exprvariant, add match arms in all of these locations:mumei-core/src/verification.rs:expr_to_z3,stmt_to_z3,collect_callees_expr,collect_callees_stmt,count_self_calls_expr,count_self_calls_stmt,collect_acquire_resources_expr,collect_acquire_resources_stmt,expr_has_symbolic_perform_args,body_has_symbolic_perform_args,has_acquire_in_while_exprmumei-core/src/ast.rs:collect_from_expr,collect_from_stmtmumei-core/src/hir.rs:collect_free_variables_expr,collect_free_variables_stmtmumei-emit-llvm/src/codegen.rs:compile_hir_expr,compile_hir_stmtmumei-core/src/mir.rs:lower_expr,lower_stmt
- When adding a new
Itemvariant, add match arms in all of these locations:src/main.rs:load_and_prepare,cmd_check,cmd_buildmumei-core/src/resolver.rs:resolve_imports_recursive,register_imported_itemssrc/lsp.rs:verify_source_for_lsp
- When adding
Item::EffectDef, ensure match arms exist in all locations listed above. - When constructing
Atominstances (including extern → atom conversion), always includeeffects: vec![]as default. Also includeeffect_pre: std::collections::HashMap::new(), effect_post: std::collections::HashMap::new()for modular verification fields. - The
effect_pre/effect_postsyntax in.mmfiles:effect_pre: { EffectName: StateName };effect_post: { EffectName: StateName };— parsed asHashMap<String, String>. Default is empty HashMap if omitted. - When monomorphizing atoms with
effect_pre/effect_post, substitute effect type variable keys usingtype_map(same pattern aseffectssubstitution). Do not simply.clone()— generic keys likeEmust be replaced with concrete names likeFileWrite. - When using
#[allow(dead_code)], always add a NOTE comment explaining the reason.