Expand description
flux-lang — the pure Flux-Lang language core.
Flux-Lang is an authored workflow language: applications place deterministic control flow around typed model stages and registered operations, and a deterministic runtime runs the AST. This crate is the language half, deliberately separated from the engine that executes it:
ast— the Draft AST, typed HIR, physical plan, value model, the semanticast::FlowEffects, and the run-event trace.render— the AST pretty-printer (human-auditable projections).- [
format] /parse— the canonical compact text syntax (the round-trippable.fluxsurface):parse(&format(&ast)) == astfor everyDraftAst. Distinct fromrender(one-way). analyze— the validator, working against an abstractopspec::OpCatalog(no knowledge of any concrete tool registry).opspec— the typed operation spec/signature and theopspec::OpCatalogseam.prelude— the artifact-type ontology (claims, evidence, needs, context packs, …) ops declare their I/O against; a stdlib ofNamedschemas, not aValuechange.program— the multi-agentProgramlayer (agents/channels/triggers/journeys) + the key-sniffing module loader; pure-data decls the L6flux-apphost runs.effects— lowering of semantic effects onto hostflux_spec::Effect+ policy actions.schema— the single source of truth: a derived JSON Schema and the node-kind catalog that drives generated skill/docs and language tooling.context_slice— automatic context slicing (KF4/L-56): derive the minimum model-visible context for a model-op call or diagnostic UI from HIR reads, field access paths, op schemas, and diagnostics, gated by visibility/secret/policy and a token budget.
It is an L0 leaf: it depends only on other pure contracts (flux-core, flux-spec,
flux-policy) and has no IO, no provider, no runtime, and no dependency on concrete tools. The
engine crate flux-flow builds on top of it (analyze → execute) and re-exports it.
Re-exports§
Modules§
- analyze
- The analyzer. M1 validates the single-
callgrammar: the operation must be registered. Later milestones add full name / type / effect / bounded-loop checking over the whole AST, lowering aDraftAstinto a typedHirFlow. - ast
- The pure language contracts: the Draft AST the LLM emits, the typed HIR the analyzer produces, the physical plan the optimizer produces, the value model, semantic effects, and the run-event trace. No IO and no flux-runtime/provider dependency — these types are shared by every phase and by the UI projections.
- context_
slice context_slice— automatic context slicing for planner and model ops (KF4/L-56,docs/designs/flux-lang-agent-speed.md).- dsl
- A Rust embedded DSL for authoring Flux-Lang flows — builder primitives that compile straight
down to the
crate::asttree, so a Rust programmer can write a flow natively instead of emitting JSON or natural language. - effects
- Lowering of semantic
FlowEffects onto the host-resourceEffect+ policyActionthat the existing authorization bridge understands. This keepsflux_spec::Effecthost-resource-shaped while letting operations declare workflow meaning (sends mail, costs money, …). - error
- The crate error type. Library code returns
Result; the phases (parse/analyze/compile/runtime) each map onto a variant so diagnostics stay attributable. - expr
- The
exprevaluator — a safe, side-effect-free formula mini-language for conditional logic, arithmetic, string functions, and list operations. Used byNode::Exprin the runtime and by transform operations (filter,map, etc.) for predicate evaluation. Public soflux-toolscan reuse the exact semantics for op-side predicates (L-46). - format
format— the canonical compact text projection of aDraftAst, and the round-trip partner ofcrate::parse. Wherecrate::renderis a one-way box-drawing display tree, this module emits a re-parseable surface:parse(&format(&ast)) == astfor everyDraftAstwhose header names are spellable (see “The flow-header exception” below — node bodies are covered totally).- highlight
highlight— CST-classified highlight spans (the shared syntax-highlighting substrate).- host
- The execution host seam: the narrow interface the interpreter dispatches operations and
approvals through. The engine implements
OpHostover its real safety envelope (Executor::dispatch+ the approver); the language stays free of any concrete runtime or tool dependency — it knows only this trait. - lexer
lexer— the lossless, layout-aware lexer, stage one of the CST front-end.- lower_
cst lower_cst— strict lowering from the lossless rowan tree to the semanticDraftAst, plus the range side-map that gives the message-only analyzer diagnostics realTextRanges.- opspec
- The pure operation contracts: the typed
OpSpec(which lowers to aflux_spec::ToolSpec), theOpSignaturethe analyzer and model-stage catalog reason over, and the abstractOpCatalogthe analyzer validates against. - optimize
- The optimizer: lower a validated
HirFlowinto aPhysicalPlan— a schedule over the flow’s top-level body. The scheduler (L-53) builds a whole-node symbol dependency graph: every statement is summarized by walking its entire subtree — nested blocks,whenconditions, object/list templates, call arguments — into (reads, writes, class). Whole-node read-only statements (every reachable op registered with onlyReadeffects, no approval/durability construct) are placed into dependency levels between fences; each multi-node level becomes aStage::Parallel. An order floor keeps the emitted stage sequence in exact program order, so the replayed trace is identical to sequential execution while independent reads still overlap. - parse
parse— read canonical Flux-Lang text back into aDraftAst. The round-trip partner ofcrate::format:parse(&format(&ast)) == astfor everyDraftAst(the supported subset natively, everything else via the@jsonescape; the flow header is the one documented exception — seecrate::format’s “flow-header exception”). The accepting grammar is the lossless CST incrate::parser; this module is the strict public wrapper around structured CST lowering.- parser
parser— the tolerant, event-free recursive-descent parser that turns thecrate::lexertoken stream into a lossless rowan green tree (stage two of the CST front-end, L-58).- prelude
- The artifact-type prelude — the curated standard library of typed structures an agent task
manipulates (claims, evidence, needs, context packs, patches, …). These are not new
Valuevariants: every artifact is an ordinarycrate::ast::Value::StructwhoseNamedcrate::ast::TypeRefnames one of these schemas. The prelude ships with the language so ops can declare their inputs and outputs in these terms; an op’sNamed("Claim")input lowers to a#/$defs/Claim$ref(opspec::type_ref_to_schema) that resolves againstprelude_schema. - program
- The multi-agent Program layer: a
.fluxfile may declare a whole app — capability ceilings, agents, channels, datasources, triggers, and journeys — not just a single flow. These are pure-data declarations (L0, strings + an opaquesettingsJSON map); the L3 engine and the L6flux-apphost give them their runtime meaning (model/datasource/channel wiring, the event bus, the scheduler). This keeps the multi-agent vision coherent without expanding the language core: orchestration is an op-pack (ask/send/emit/spawn), so this layer needs zero new node kinds. - render
- Pretty-rendering of a
DraftAstas a human-readable execution-path tree — theprettyoutput of--plan/--compile-only, and the live plan view the engine surfaces before executing. - runtime
- The reference interpreter: execute a compiled Flux-Lang flow against an injected execution host.
execute_calldispatches one op (store the result as an immutable value, optionally bind a symbol, trace it);execute_flowwalks a whole graph —bind/call/returnpluswhen(typed branch) andrepeat(bounded loop) — resolving each$symbolargument to the value the store owns (awaitcross-turn suspend/resume is the next slice). - schema
- Schema generation — the single source of truth for the Flux-Lang AST surface.
- sink
- The observation sink the interpreter streams to as it executes — the language-level mirror of
the engine’s
AgentSink. Op results are reported asOpOutcomes (not the host’s tool result), keeping the trait free of any runtime type. The engine bridges this to its real sink. - skill
- The Flux-Lang language skill: a self-contained reference for authoring durable Flux-Lang
programs. It is generated — the node-kind table comes from
crate::schema::node_kind_catalog(theNodedoc-comments), so it can never drift from the types. Unlike the engine’s skill it carries no registered-ops table: operations are provided by the host runtime, not the language. - store
- The value/symbol/event store the interpreter reads and writes through. The engine backs it with
a durable SQLite store (
flux_flow::state::FlowStore); the language ships an in-memoryMemStoreso the interpreter can run standalone (CLI, tests) without a database. - syntax
syntax— theSyntaxKindalphabet for the lossless CST front-end and itsrowan::Languagebinding.