Expand description
The trumly engine: parse, validate and run rules over a typed graph of markdown files.
A model is a folder of markdown files. Each file is a node: YAML front matter (an id, a type,
typed links and other fields) followed by a free-form body. This crate loads those files into a
model::Graph, checks its structure, and evaluates the rules the model carries. It is pure:
it never reads a file or touches the network, so the caller supplies (path, text) pairs. That
is what lets the same code run in the command line tool, the MCP server, and the browser (as WASM).
use trumly_core::report::check;
let files = vec![
("a.md".to_string(), "---\nid: a\ntype: note\n---\nHello.\n".to_string()),
("b.md".to_string(), "---\nid: b\ntype: note\nparent: missing\n---\n".to_string()),
];
let report = check(files);
assert_eq!(report.graph.len(), 2);
// `b` names a parent that does not exist, so the structure check reports it.
assert!(report.structure.errors.iter().any(|f| f.kind == "missing_parent"));
assert_ne!(report.exit_code(), 0);Where to start: report::check does the whole job; load, structure and rules are
its stages; ops holds edits such as renaming a node and rewriting every link to it.
Modules§
- format
- Writes a
Nodeback out as a markdown file. The one place that decides what a canonical node file looks like, so files written by the editor, the CLI and the server are all byte-identical. - load
- Builds a
Graphfrom a set of files. Still pure: the caller reads the files and hands us (path, text) pairs, so this works the same from the CLI, a test, or WASM in a browser. - model
- The in-memory shape of a model: nodes, links, and the graph that holds them. Mirrors spec/FORMAT.md section 2. Nothing here reads files; that is the parser’s job.
- ops
- Edits that must mean the same thing in every client (the editor, the CLI, an agent over MCP): renaming a node and
renaming a type or link type. Each takes the model and returns an
Edit: the nodes to write (new or changed files) and the ids whose files go. Nothing here touches the disk. - parse
- Turns the text of one node file into a
Node. Pure: takes a string, returns a value. Mirrorsparse_nodein reference/core.py and section 1 to 3 of spec/FORMAT.md. - report
- The result of checking a model, and how to show it. This is the one place that knows the shape
of
check --json, so the CLI, the WASM build and the tests all agree. - rules
- Runs the rules: which rule applies to which node, and does the node pass?
Mirrors
matches,run_checkandevaluatein reference/core.py and section 5 of the spec. - structure
- Structural checks: is the graph well-formed, before any rules run?
Mirrors
structurein reference/core.py and section 4 of spec/FORMAT.md.