Expand description
§mana-core Public API
Programmatic access to all mana unit operations. Use this module when embedding mana in another application — a GUI, MCP server, orchestration daemon, or custom tooling.
The API is organized into layers:
- Types — Core data structures re-exported from internal modules
- Discovery — Find
.mana/directories and unit files - Query — Read-only operations (list, get, tree, status, graph)
- Mutations — Write operations (create, update, close, delete)
- Orchestration — Agent dispatch, context assembly, and verification
- Facts — Verified project knowledge with TTL
§Quick Start
use mana_core::api::*;
use std::path::Path;
// Find the .mana/ directory
let mana_dir = find_mana_dir(Path::new(".")).unwrap();
// Load the index (cached, rebuilds if stale)
let index = load_index(&mana_dir).unwrap();
// Get a specific unit
let unit = get_unit(&mana_dir, "1").unwrap();
println!("{}: {}", unit.id, unit.title);§Design Principles
- No I/O side effects — Library functions never print to stdout/stderr. All output is returned as structured data.
- Structured params and results — Each mutation takes a
Paramsstruct and returns a typed result. No raw argument passing. &Pathas entry point — Every function takesmana_dir: &Path. No global state, no singletons, noArcrequired.- Serializable — All types derive
Serialize/Deserializefor easy IPC (Tauri, JSON-RPC, MCP). - Thread-safe — No interior mutability, no shared global state.
Modules§
Structs§
- Agent
Context - Fully assembled agent context for a unit.
- Attempt
Record - A single attempt record (claim→close cycle).
- Blocked
Unit - A unit that was excluded from dispatch.
- Config
- Project-level mana configuration, loaded from
.mana/config.yaml. - Dependency
Graph - A full dependency graph representation.
- Fact
Params - Parameters for creating a fact.
- Fact
Result - Result of creating a fact.
- Graph
Node - A node in the dependency graph.
- Index
- The in-memory and on-disk unit index.
- Index
Entry - A lightweight summary of a single unit, stored in the index cache.
- Ready
Queue - The result of computing the ready queue.
- Ready
Unit - A unit that is ready to be dispatched.
- RunPlan
- A full execution plan grouped into dependency-ordered waves.
- RunRecord
- A single verification run record.
- RunWave
- A wave of units that can run concurrently (no inter-wave dependencies).
- Stats
Result - Project statistics snapshot.
- Status
Summary - Categorized view of project status.
- Tree
Node - A node in the unit hierarchy tree, used by
get_tree. - Unit
- A single unit of work managed by mana.
- Verify
Facts Result - Aggregated result of verifying all facts.
- Verify
Result - Result of running a verify command.
Enums§
- Attempt
Outcome - Outcome of a claim→close cycle.
- Error
- Typed error for mana-core’s public API surface.
- OnClose
Action - Declarative actions to run when a unit is closed. Processed after the unit is archived and post-close hook fires.
- OnFail
Action - Declarative action to run when a unit’s verify command fails.
- RunResult
- Outcome of a verification run.
- Status
Functions§
- add_dep
- Add a dependency:
from_iddepends ondep_id. - assemble_
context - Assemble the full agent context for a unit.
- build_
dependency_ tree - Build a dependency tree rooted at
id. Returns a string representation with box-drawing characters. - build_
full_ graph - Build a project-wide dependency graph as a text tree. Shows all dependencies rooted at units with no parents.
- claim_
unit - Claim a unit for work.
- close_
unit - Close a unit — run verify, archive, and cascade to parents.
- compute_
ready_ queue - Compute which units are ready to dispatch.
- count_
subtree_ attempts - Count total verify attempts across all descendants of a unit.
- create_
fact - Create a verified fact — a unit that encodes checked project knowledge.
- create_
unit - Create a new unit.
- delete_
unit - Delete a unit and remove all references to it from other units’ dependencies.
- dependency_
graph - Build a dependency graph from the active index.
- detect_
cycle - Detect whether adding an edge from
from_idtoto_idwould create a cycle. - fail_
unit - Mark a unit as explicitly failed without closing it.
- find_
all_ cycles - Find all cycles in the dependency graph. Returns a list of cycle paths.
- find_
archived_ unit - Find an archived unit by ID within the
.mana/archive/directory tree. - find_
mana_ dir - Walk up from
startlooking for a.mana/directory. Returns the path to the.mana/directory if found. Errors if no.mana/directory exists in any ancestor. - find_
unit_ file - Find a unit file by ID, supporting both new and legacy naming conventions.
- get_
archived_ unit - Load a unit from the archive by ID.
- get_
stats - Get aggregate project statistics.
- get_
status - Get a categorized project status summary.
- get_
tree - Build a unit hierarchy tree rooted at the given unit ID.
- get_
unit - Load a unit by ID.
- list_
units - List units with optional filters.
- load_
index - Load the index, rebuilding from unit files if stale.
- ready_
units - Return units with all dependencies satisfied (ready to dispatch).
- record_
attempt - Record a verify attempt result on a unit.
- release_
unit - Release a claim on a unit.
- remove_
dep - Remove a dependency:
from_idno longer depends ondep_id. - reopen_
unit - Reopen a closed unit.
- run_
verify - Run the verify command for a unit without closing it.
- topological_
sort - Topologically sort all units by dependency order.
- update_
unit - Update a unit’s fields.
- validate_
priority - Validate that priority is in the valid range (0-4, P0-P4).
- verify_
facts - Verify all facts and report staleness and failures.