Programmatic API
The workspace exposes the Rust facade crate as formasl.
Its public operations are deliberately small:
check(CheckRequest)turns explicit source inputs into aCheckOutcome.inspect(&CheckedProgram, InspectRequest)returns a structure-onlyInspectOutcome.run(&CheckedProgram, RunRequest)returns a typedRunOutcome.realize(&CheckedProgram, RealizeRequest)validates and binds an explicit realization plan.
The CheckedProgram carrier is produced by check; callers do not construct
one from fields. Diagnostics remain typed values rather than display strings.
Check a source set
Each source has a caller-chosen reference and revision. Imports resolve only
against the complete sources vector, so add every imported module explicitly.
#![allow(unused)]
fn main() {
use formasl::{
check, CheckOutcome, CheckRequest, CheckedProgram, Diagnostic, SourceInput,
};
fn source(reference: &str, text: &str) -> SourceInput {
SourceInput {
reference: reference.to_owned(),
revision: 1,
text: text.to_owned(),
}
}
fn checked(text: &str) -> Result<CheckedProgram, Vec<Diagnostic>> {
match check(CheckRequest {
sources: vec![source("memory:main.fsl", text)],
}) {
CheckOutcome::Accepted { program } => Ok(program),
CheckOutcome::Rejected { diagnostics } => Err(diagnostics),
}
}
}
CheckOutcome::Rejected is a normal result, not a panic condition. Match the
diagnostic code, class, and optional locus when a caller needs to make a
policy decision.
Inspect without running
Inspection does not evaluate applications. It exposes the checked summary or a selected structural view.
#![allow(unused)]
fn main() {
use formasl::{inspect, InspectRequest, InspectView};
let program = checked(r#"
module api_example {
type Entity
relation Seen { role subject: Entity }
assert claim c1 : Seen(subject: $alice) { by: $source }
}
"#)?;
let summary = inspect(&program, InspectRequest { view: InspectView::Summary });
assert_eq!(summary.items.len(), 1);
}
Available views are Summary, Declarations, Claims, Applications, and
Subtypes. The CLI inspect --view exposes the same five public categories.
Run an application
A run request is explicit about gas, optional application selection, and an
optional realization input. Passing application: None selects every runnable
application; Some(name) selects that exact name.
#![allow(unused)]
fn main() {
use formasl::{run, RunAggregateStatus, RunApplicationOutcome, RunRequest};
let program = checked(r#"
module api_run {
type Entity
relation Seen { role subject: Entity }
assert claim c1 : Seen(subject: $alice) { by: $source }
match Find() { pattern ?s: Seen(subject: ?who) }
}
"#)?;
let outcome = run(
&program,
RunRequest {
application: Some("Find".to_owned()),
gas: 1_000,
realization: None,
},
);
assert_eq!(outcome.aggregate_status, RunAggregateStatus::Complete);
// Match applications route through the engine-backed query bridge and report
// `QueryComplete` (the legacy pattern-only counterbridge was eradicated in
// QEC-FINAL-01 — the bridge is the single productive Match route).
assert!(matches!(
outcome.applications.as_slice(),
[RunApplicationOutcome::QueryComplete(_)]
));
}
gas is required because R1/R2/R3 reasoning consumes it. The runtime reports
ResourceExhausted instead of inventing a result when a reasoning run reaches
the supplied budget. Other application families can declare gas
not-applicable; see Support and limitations.
Realize a checked application
A realization plan is separate .fsp text. The operation binds the plan to
the checked program; it does not invoke an external capability merely because
the plan names one.
#![allow(unused)]
fn main() {
use formasl::{
realize, RealizationInput, RealizeOutcome, RealizeRequest,
};
let program = checked(r#"
module api_realize {
type Entity
relation Seen { role subject: Entity }
assert claim c1 : Seen(subject: $alice) { by: $source }
match Find() { pattern ?s: Seen(subject: ?who) }
}
"#)?;
let plan = RealizationInput {
reference: "memory:plan.fsp".to_owned(),
revision: 1,
text: r#"
realization Local {
app Find {
bind capability to external "example-capability"
}
}
"#
.to_owned(),
};
match realize(&program, RealizeRequest { plan }) {
RealizeOutcome::Bound { bindings } => assert!(!bindings.is_empty()),
RealizeOutcome::Rejected { diagnostics } => return Err(diagnostics),
}
}
If the same plan is intended to constrain a later run, pass an equivalent
RealizationInput in RunRequest::realization. The run outcome then carries
the bindings it admitted; it does not substitute a default plan.
Machine JSON
The facade exposes structured machine projections. Prefer revision 1 for a new integration: revision 0 is frozen and deliberately refuses run outcomes whose families it cannot represent. Do not treat the text renderer as a machine protocol.
#![allow(unused)]
fn main() {
use formasl::{machine_run_rev1, program_subject};
let (_program_identity, subject) = program_subject(&program);
let document = machine_run_rev1(&outcome, subject)?;
// `document` is the facade's canonical JsonValue carrier.
}
Every machine document is an envelope. A schematic successful run projection has this shape (the identities and outcomes are produced by the facade, not caller-supplied defaults):
{
"schema": "formasl.machine",
"schema_version": 1,
"schema_revision": 1,
"operation": "run",
"subject": {},
"outcome": {
"aggregate_status": "COMPLETE",
"applications": [],
"diagnostics": []
}
}
The CLI’s --format json --schema-revision 1 uses the same projection family.
Select the revision explicitly in an integration and validate both the envelope
and the operation-specific outcome; do not infer success only from a process
exit code.
Boundary of this API
The facade is the implemented product boundary, not a claim that every parsed surface form has a complete external effect. It does not expose a persistence transaction, a network provider, or an implicit source loader. In particular:
checkreports source/product diagnostics; it does not certify a claim true.runreports typed per-application outcomes and aggregate precedence.realizebinds an explicit plan; it does not itself call a bound provider.- canonical projections fail closed when a requested frozen revision lacks a representation for the observed result.
For current family-by-family execution support, use Support and limitations. For CLI option and exit semantics, use Toolchain and CLI.