Expand description
§mant-engine
mant-engine is ManT’s document execution layer. It resolves local documents
through mant-sources, lowers every source into the semantic center in
mant-ir, builds in-memory and versioned protocol projections, and produces
deterministic output without owning a terminal or command-line process.
§What this crate provides
- Registered Markdown lookup through the read-only
mant-sourcesboundary. - A conservative, source-positioned Markdown parser with explicit loss diagnostics and optional embedded tldr content.
- Bounded native manual loading, explicit leaf-file symlink support,
root-constrained
.soalias resolution, andman(7)/mdoc(7)lowering on every supported platform. - Semantic outlines containing addressable sections and role-aware entries.
- Excerpt selection and literal or regular-expression search with generated Markdown coordinates.
- Markdown, text, man-style text, and JSON renderers over one normalized IR.
- Installed-client and private tldr cache discovery. Explicit subprocess-backed
updates are available only with the opt-in
tldr-updatefeature.
Process argument parsing, MCP transport, and interactive presentation remain outside this crate.
The default feature set is read-only with respect to tldr data. The native
mant composition root enables tldr-update; library consumers, renderers,
and MCP-oriented embeddings do not receive subprocess update authority unless
they request it explicitly.
§Execution pipeline
logical selector / physical input
│
v
DocumentResolver ──> Markdown parser or libmandoc lowering
│
v
mant_ir::ResolvedContent
├─> outline / excerpt / search projections
├─> Markdown / text / man-style renderers
└─> versioned mant-protocol responses| Need | Preferred API |
|---|---|
| Reuse one stable discovery snapshot | DocumentResolver |
| Resolve a complete typed request | resolve_query_with_policy |
| Resolve and project its requested view | execute_query |
| Parse in-memory Markdown without discovery | parse_markdown or query_markdown_text |
| Parse in-memory roff without discovery | parse_manual_bytes or query_roff_bytes |
| Build a focused result from existing content | build_outline_with_detail, select_excerpt, search_query |
| Produce human or JSON output | The render_* functions |
§Basic use
The in-memory Markdown path is deterministic and works on every supported platform:
use mant_protocol::OutlineDetail;
use mant_engine::{
build_outline_with_detail, query_markdown_text, render_outline_text,
};
let query = query_markdown_text(
"# Demo\n\n## Options\n\n- `--verbose`: Show more detail.\n",
Some("demo.md".to_owned()),
)?;
let outline = build_outline_with_detail(&query, OutlineDetail::Entries)?;
println!("{}", render_outline_text(&outline));Use resolve_query or resolve_query_with_policy when a caller needs the full
document bundle. Use execute_query to validate, resolve, and materialize the
request’s view through one engine boundary. Use parse_markdown when the
caller needs the parsed document and tldr preface without query composition.
DocumentResolver can be reused when several operations must share one lazy
filesystem snapshot; constructing a new resolver refreshes discovery.
Named resolution treats the full document and command quick reference as two
orthogonal facets. A manual section selects an exact native full document; it
does not by itself disable a compatible section 1 or 8 tldr attachment.
QueryPolicy::ManualOnly excludes that facet, while TldrOnly requests it
without requiring a full document. Dotted names are never split heuristically.
The engine returns mant_ir::ResolvedContent to direct semantic consumers and
creates mant-protocol projections for every structured host or process
boundary. A projection can stay in memory for a TUI callback or be serialized
for CLI JSON and compact MCP presentation. Serializing the IR directly is not a supported substitute
for those versioned DTOs.
§Platform behavior
| Platform | Markdown engine | Native man/mdoc engine |
|---|---|---|
| Linux with glibc | Yes | Bundled libmandoc-rs |
| macOS | Yes | Bundled libmandoc-rs |
| Windows | Yes | Bundled libmandoc-rs |
Every supported target compiles libmandoc-rs. Windows uses its memory-only C
transport while Rust owns file I/O, decompression, paths, and .so redirects.
Native root discovery is also Rust-owned: Linux reads man-db mappings or
mandoc man.conf, macOS reads its PATH, active developer selection, and
MANPATH/MANCONFIG configuration, and Windows optionally reads ManT’s own
man.conf, all without spawning a host manual utility.
§Layering
mant-engine returns an owned mant_ir::ResolvedContent for direct semantic
use and owned mant-protocol values at versioned integration boundaries. It does not expose
libmandoc C structures. Applications that only need raw roff syntax should use
libmandoc-rs directly. Applications
that need the complete command or reader should install
mant.
Architecture and source-resolution details are documented in the ManT native-engine reference.
§License
Apache-2.0. Native builds also contain the separately attributed vendored mandoc
sources supplied by libmandoc-rs.
Structs§
- Available
Document - One document discoverable by name through the ordinary query boundary.
- Document
Resolver - One explicit local document-environment snapshot.
- Loaded
Document Scope - A logical scope together with the loaded documents in matching order.
- Manual
Index - Immutable index shared by discovery and exact manual lookup.
- Manual
Page - One effective local manual page after path and locale precedence.
- Manual
Request - One validated manual lookup independent from CLI token syntax.
- Markdown
Options - Markdown serialization controls that do not alter the query IR.
- Parsed
Markdown - Complete result of parsing one
ManT-flavoured Markdown input. - Resolved
Content - One materialized document query before any versioned process projection.
- Selector
Candidate - One stable qualification offered when a semantic alias is ambiguous.
- Tldr
Page Location - Source identity attached to a parsed tldr page.
Enums§
- Available
Document Kind - Source family used to resolve one available document.
- Available
Document Origin - Precedence class and storage family for one available document.
- Catalog
Error - Invalid document-catalog filter or regular expression.
- Host
Platform - Native host families supported by
ManTdistributions. - Locate
Error - Expected source-discovery failures suitable for a user-facing CLI error.
- Manual
Error - Failure produced by
ManT’s source policy or by the underlying roff parser. - Manual
Error Kind - Stable category for a native manual failure.
- Manual
Load Error - Native-manual resolution or lowering failed after candidate selection.
- Markdown
Parse Error - Invalid structure in
ManT’s optional top-level Markdown extension. - Projection
Error - Failure to derive an addressable view from a complete query.
- Query
Error - A query cannot produce either authoritative manual content or a quick reference.
- Query
Execution Error - A valid request could not be loaded or projected.
- Query
Policy - Closed content-resolution policy kept outside the serialized request contract.
- Query
View Result - Materialized result of the view carried by a
QueryRequest. - Scope
Query Error - Invalid scope configuration or failure to resolve any initial document.
- Search
Error - Invalid search input or matcher construction.
- Search
Text Role - Semantic roles in the grep-like search presentation.
- Tldr
Cache Error - Offline cache discovery or page-read failure.
- Tldr
Directive Error - Invalid structure in a document-owned tldr directive.
- Tldr
Parse Error - A tldr page lacks the minimum structure required by the contract.
- Tldr
Update Error - Failure to refresh an installed client or
ManT’s private checkout.
Constants§
- MAX_
MANUAL_ BYTES - Upper bound on both the stored and decoded form of one manual source chain.
- MAX_
MARKDOWN_ BYTES - Upper bound on a single Markdown source, shared by every input path.
Functions§
- build_
outline - Build a block-free, addressable outline for one complete query.
- build_
outline_ with_ detail - Build an outline with optional semantic definition entries.
- discover_
documents - Load and query the current local document catalog.
- discover_
manual_ roots - Discover effective manual hierarchy roots for the current host.
- execute_
query - Load and materialize the view encoded in one native request.
- find_
host_ executable - Locate one directly runnable program using the current host’s
PATHand native executable-suffix rules without spawning it. - get_
system_ tldr_ cache_ dirs - Return known installed-client cache roots in priority order.
- get_
tldr_ cache_ dir - Resolve the
ManT-owned fallback checkout for an explicit environment. - get_
tldr_ languages - Resolve locale candidates, retaining first occurrence priority.
- get_
tldr_ platforms - Resolve host, common, then cross-platform fallback page directories.
- get_
tldr_ read_ cache_ dirs - Select installed-client caches followed by
ManT’s private fallback. - is_
command_ manual_ section - Return whether a manual section belongs to a command-page family.
- is_
manual_ section - Return whether a value is a conventional native manual section.
- list_
available_ documents - List every registered document candidate and locally indexed manual page.
- locate_
manual_ source_ in - Locate a manual in an explicit immutable index.
- lower_
mandoc_ document - Convert a completed low-level parse into the stable document contract.
- native_
api_ version - Reports the native contract version through the engine layer.
- normalize_
tldr_ topic - Convert a multi-word query to the tldr filename convention.
- parenthesized_
manual_ reference - Split the
name(section)spelling accepted by manual readers. - parse_
manual_ bytes - Parse one already bounded, uncompressed standalone roff input.
- parse_
manual_ page - Parse an indexed manual, resolving
.soredirects against its discovered manual hierarchy without falling back to the process working directory. - parse_
manual_ source - Parse and normalize one standalone man or mdoc source file.
- parse_
markdown - Split
ManT’s optional leading tldr preface from the Markdown document. - parse_
tldr_ command - Parse the tldr placeholder extension and choose the long option variant.
- parse_
tldr_ page - Parse one tldr Markdown page without performing any I/O.
- project_
query_ view - Materialize one view from an already loaded query.
- query_
available_ documents - Filter the unified local catalog using one shared CLI, TUI, and MCP policy.
- query_
markdown_ text - Parse in-memory Markdown for the direct
mant -command. - query_
roff_ bytes - Parse one bounded roff stream without consulting MANPATH or following
.so. - read_
cached_ tldr_ page - Read one cached tldr page using current host conventions; never updates it.
- render_
excerpt_ json - Serialize selected query nodes in compact or human-readable form.
- render_
excerpt_ markdown - Render selected query nodes with their outline context.
- render_
excerpt_ markdown_ with_ options - Render selected nodes using explicit presentation-only options.
- render_
excerpt_ text - Render selected query nodes as unstyled text with outline context.
- render_
markdown - Render a complete query as clean Markdown without a trailing newline.
- render_
markdown_ with_ options - Render a complete query using explicit presentation-only options.
- render_
outline_ json - Serialize a complete query outline in compact or human-readable form.
- render_
outline_ markdown - Render a complete query outline as a nested
CommonMarklist. - render_
outline_ text - Render a complete query outline as a copyable Unicode tree.
- render_
query_ json - Serialize a query contract in compact or human-readable form.
- render_
query_ man - Render the manual as
man(1)-faithful plain text. - render_
query_ text - Render a complete query without Markdown or terminal escape sequences.
- render_
search_ json - Serialize structure-aware search results in compact or human-readable form.
- render_
search_ markdown - Render a readable Markdown report whose coordinates target the full page.
- render_
search_ text - Render grep-like results with stable Markdown coordinates and node paths.
- render_
search_ text_ with - Render grep-like search text through a semantic span decorator.
- render_
update_ json - Serialize the explicit tldr update result for a process boundary.
- resolve_
query - Query the local man database and optional offline tldr caches.
- resolve_
query_ with_ policy - Query with an explicit input-resolution policy.
- search_
query - Search one complete query and report coordinates in its canonical Markdown.
- select_
excerpt - Select tldr, document-root content, or complete section subtrees by path or ID.
- select_
explanation - Select exactly one semantic entry by stable path, ID, or alias.
- update_
tldr_ cache - Refresh tldr through an installed client or
ManT’s private Git checkout. - validate_
query_ request - Validate all request and policy invariants before local I/O.
- validate_
scope_ query_ request - Validate the closed scope-query contract before document I/O.
- validate_
search_ query - Validate search limits and compile its matcher without loading a manual.