Skip to main content

Crate mmz

Crate mmz 

Source
Expand description

mmz is a memoized command runner.

Prefix any command with mmz. A .mmz/config.yaml manifest declares named input scopes and command rules that reference them. When the invoked command matches a rule and that rule’s inputs are byte-for-byte unchanged since the command last succeeded, mmz skips execution and exits 0; otherwise it runs the command, streams its output, and records the new state on success. A rule may also declare outputs — literal artifact paths whose absence voids the record, however the inputs hash (see outputs) — and draw an input from a named command’s stdout rather than a file (see probe).

The cache identity is the matched rule, so the operator controls granularity through how specifically rules are written. State lives in a gitignored cache directory (.mmz/cache by default) and is throwaway.

§Use as a library

The binary is a thin wrapper over this crate; the same entry points are public. run memoizes one invocation against the nearest manifest, returning the exit code to propagate:

use std::path::Path;

let argv = vec!["cargo".to_owned(), "test".to_owned()];
let exit_code: u8 = mmz::run(&argv, Path::new("."))?;

status::report_json renders the freshness report, freshness::evaluate gates a rule’s freshness without running it, prune::prune sweeps orphaned records, and Manifest loads and validates a .mmz/config.yaml for callers that want the parsed model directly.

Modules: the manifest (manifest), fragment import resolution and merge (compose), imports: path resolution (import_paths), the source of every scope, probe and command a merge produces (provenance), pattern resolution (resolve), content hashing (hashing), command-driven inputs (probe), in-process AST matching (ast), declared artifact outputs (outputs), rule matching (matcher), glob-fanned parametric rules (parametric), the cache (cache), cache-hit notices (notice), the process clock (clock), record expiry (ttl), and the orchestration engine (engine). The mmz --… actions live in init, schema, status, freshness, prune, import_records, and dump.

§Reproducible output

Anything mmz prints or stamps with a time reads one clock, resolved once per invocation and threaded down. Set MMZ_NOW to a Unix epoch in seconds and a record’s ran_at and mmz --status’s ages become facts a build can capture; leave it unset and mmz reads the system clock. A rule’s ttl is aged against the same clock, so the pin also decides which records have expired. See clock.

Re-exports§

pub use engine::run;
pub use error::Error;
pub use error::Result;
pub use manifest::Manifest;

Modules§

ast
The in-process AST matcher a probe’s ast: key selects with, and the failure type probe::ProbeFailure::Ast carries. Public because a missing grammar is answered by a build flag, and a library caller matching on that case needs the variant rather than a rendered string. In-process AST matching: the engine behind a probe’s ast: key.
cache
Per-rule cache records under a gitignored cache directory (.mmz/cache by default; see cache_dir in the manifest).
clock
The process clock: one resolved “now”, pinnable through MMZ_NOW.
compose
Import resolution, cycle detection and merge for manifest composition.
dump
mmz --dump-config: print the merged manifest with the source file of every scope, probe and command.
engine
Orchestration: discover the manifest, match the command, and either skip a fresh command or run it and record the outcome.
error
Error types for the mmz library.
freshness
mmz --is-fresh: assert a rule’s cache is fresh without running it.
hashing
Content hashing of inputs using blake3.
import_paths
Resolves one imports: entry to the concrete manifest file paths it names.
import_records
mmz --import <dir>: carry cache records over from another checkout.
init
mmz --init: scaffold a starter .mmz/config.yaml in the working directory, alongside a .mmz/.gitignore so the cache self-ignores without the consumer touching their root .gitignore.
manifest
The mmz manifest (.mmz/config.yaml): named input scopes and the command rules that reference them.
matcher
Maps an invoked command to the rule that memoizes it.
notice
Cache-hit notices: expand a user template into the line printed when a command is skipped.
outputs
Declared outputs: the literal artifact paths a rule’s run is expected to produce.
parametric
Glob-fanned parametric rules.
probe
Narrowed inputs: named probes whose value joins a rule’s input digest.
provenance
Which file contributed each scope, probe and command in a composed manifest.
prune
mmz --prune: delete cache records whose rule no longer exists.
resolve
Expansion of scope patterns into concrete input paths.
schema
The JSON Schemas for .mmz/config.yaml and for a fragment it imports:, emitted by mmz --schema and mmz --schema=fragment.
status
mmz --status: report each rule’s current freshness against its cache.
ttl
A rule’s ttl: how long a successful record stays fresh once its inputs stop being the whole story.