Expand description
§Module :: unilang
Zero-overhead command framework with compile-time command registration
unilang processes command definitions at compile-time, generating optimized static command registries with O(1) lookups (~80ns), zero runtime overhead, and SIMD-accelerated parsing. Commands are defined in YAML (default), JSON, or Rust DSL; the build system auto-discovers and validates them before your binary ships.
§Features
- 50x faster command resolution — static PHF map vs runtime HashMap (~80ns vs ~4,000ns)
- Compile-time validation — all command definitions checked before deployment
- SIMD parsing — 4-25x parsing performance improvement
- Multiple definition styles — YAML, JSON, Rust DSL (builder or const fn)
- Multi-file aggregation — auto-discover commands across files with conflict detection
- Hybrid mode — static base + runtime plugins in one registry
- Built-in REPL — interactive shell with history, completion, secure input
- CLI aggregation — unify multiple tools under one interface with namespace isolation
§Installation
[dependencies]
unilang = "0.49"The default configuration enables multi-YAML build-time static registration (Approach #2 — recommended for 95% of users).
§Minimal Example
Create unilang.commands.yaml:
- name: ".greet"
description: "Greeting command"
arguments:
- name: "name"
kind: "String"
attributes:
optional: true
default: "World"Use it in src/main.rs:
use unilang::prelude::*;
include!( concat!( env!( "OUT_DIR" ), "/static_commands.rs" ) );
fn main() -> Result< (), unilang::Error >
{
let registry = StaticCommandRegistry::from_commands( &STATIC_COMMANDS );
let pipeline = Pipeline::new( registry );
let result = pipeline.process_command_simple( ".greet name::Alice" );
println!( "{}", result.outputs[ 0 ].content );
Ok( () )
}cargo run # Builds, generates static registry, runs§Parameter Syntax
Named parameters use name::value — double colon is required. The :: operator
activates value context, preserving special characters (/, ., #, ?) until
whitespace:
.greet name::Alice
.run file::./examples/plan.md # file paths — fully supported
.fetch url::https://example.com/path # URLs — fully supported
.find pattern::"multi word value" # spaces → quote the valueSingle colon (name:value) is not valid syntax and produces a parse error.
See docs/parameter_syntax.md for the full reference.
§Documentation
| Document | Contents |
|---|---|
| docs/quick_start.md | Step-by-step setup guide |
| docs/parameter_syntax.md | :: operator, value context, file paths, quoting |
| docs/cli_definition_approaches.md | All 21 approaches (YAML/JSON/DSL, build/runtime) |
| docs/cli_aggregation.md | CLI aggregation with namespace isolation |
| docs/migration.md | Runtime → build-time migration (50x speedup) |
| docs/troubleshooting.md | Common errors and solutions |
| docs/features.md | Full feature tracking table |
| docs/optimization_guide.md | Performance tuning guidelines |
| docs/phf_reexport.md | PHF re-export for static_registry users |
| spec/ | Requirements and specification |
| examples/ | Runnable examples with learning path |
§Approach Selection
| # | Approach | Feature Flag | Default | Lookup |
|---|---|---|---|---|
| 2 | Multi-YAML → Build-time static | approach_yaml_multi_build | ✅ | ~80ns |
| 1 | Single YAML → Build-time static | approach_yaml_single_build | ❌ | ~80ns |
| 3 | YAML → Runtime loading | approach_yaml_runtime | ❌ | ~4,200ns |
| 4–6 | JSON variants (same as 1–3) | approach_json_* | ❌ | 80/4,200ns |
| 7 | Rust DSL builder API | (always available) | ✅ | ~4,200ns |
| 8 | Rust DSL const fn static | approach_rust_dsl_const | ❌ | ~80ns |
| 18 | Hybrid (static + runtime) | approach_hybrid | ❌ | Mixed |
See docs/cli_definition_approaches.md for all 21 approaches.
§Design Rules Compliance Notice
CRITICAL: This codebase must follow strict design rules. Before making changes, review:
$PRO/genai/code/rules/code_design.rulebook.md- Core design patterns and architecture rules$PRO/genai/code/rules/code_style.rulebook.md- Code formatting and style requirements
Key Rules Summary:
- Testing: All tests MUST be in
tests/directory, NOT insrc/asmod tests - Benchmarking: Use
benchkitframework ONLY - no custom timing code in tests - Performance Tests: NEVER mix benchmarks with unit tests - separate concerns
- Test Documentation: Every test file MUST have Test Matrix documentation
- Directory Structure:
tests/for tests,benches/for benchmarks (if using benchkit)
Common Violations to Avoid:
❌ Custom std::time::Instant timing code in test files
❌ Performance/benchmark tests in tests/ directory
❌ Missing file-level documentation with Test Matrix in test files
❌ Using anything other than benchkit for performance measurement
§Feature Flags
Unilang supports multiple feature flags to customize functionality and dependencies:
§Core Features
enabled- Core functionality (included indefault)full- All features enabled for maximum functionality
§REPL Features
-
repl- Basic REPL functionality with standard I/O- Provides interactive command execution
- Basic command history tracking
- Cross-platform compatibility
- No additional dependencies
-
enhanced_repl⭐ Enabled by Default - Advanced REPL with rustyline integration- Enables: All features from
replplus: - Arrow Key Navigation: ↑/↓ for command history browsing
- Tab Auto-completion: Command and argument completion
- Interactive Prompts: Secure password input with masking
- Session Persistence: History saved across sessions
- Terminal Detection: Auto-fallback to basic REPL in non-interactive environments
- Dependencies:
rustyline,std::io::IsTerminal
- Enables: All features from
§Performance Features
simd- SIMD optimizations for parsing and JSON processing- Enables:
simd-json(4-25x faster JSON), SIMD string operations - Automatic: Included in
defaultfor maximum performance - Disable with:
cargo build --no-default-features --features enabled
- Enables:
§Optional Features
on_unknown_suggest- Fuzzy command suggestions (requirestextdistance)
Note: Benchmarking tools are available in the separate unilang_benchmarks workspace crate
§Usage Examples
Basic REPL (minimal dependencies):
[dependencies]
unilang = { version = "0.10", features = ["repl"] }Default (Enhanced REPL included):
[dependencies]
unilang = "0.10" # Enhanced REPL enabled by defaultPerformance-optimized CLI:
[dependencies]
unilang = { version = "0.10", features = ["enhanced_repl", "simd", "on_unknown_suggest"] }Embedded/minimal:
[dependencies]
unilang = { version = "0.10", default-features = false, features = ["enabled"] }§Feature Compatibility
enhanced_replautomatically includesreplfullincludes all features except development-only ones- All features work together without conflicts
- Enhanced REPL gracefully falls back to basic REPL when needed
Re-exports§
pub use super::private::TypeAnalyzer;pub use super::private::TypeHint;pub use super::private::Severity;pub use super::private::HintGenerator;pub use super::aggregator;pub use super::builder;pub use super::type_analyzer;pub use super::hint_generator;pub use super::private::TypeAnalyzer;pub use super::private::TypeHint;pub use super::private::Severity;pub use super::private::HintGenerator;pub use unilang_parser as parser;pub use phf;pub use super::prelude::*;pub use super::prelude::*;
Modules§
- build_
helpers - Build-time helper utilities for type analysis and hint generation.
Provides tools for detecting type issues in YAML command definitions during build.
Requires feature:
yaml_parserBuild-time helper utilities for static registry generation - command_
validation - Command validation utilities. Command registration validation and utilities.
- config_
extraction - Config value extraction utilities.
Generic extractors for
HashMap<String, (JsonValue, S)>config maps. Requires feature:json_parser - data
- Core data structures and types.
- error
- Error handling utilities.
- exposed
- Exposed namespace of the module.
- help
- Help generation system.
- interner
- String interning system for performance optimization. String Interning System
- interpreter
- Command execution interpreter.
- loader
- Configuration loading from YAML/JSON.
Functions gated by
yaml_parserandjson_parserfeatures. - multi_
yaml - Multi-YAML build system for compile-time aggregation.
Requires feature:
multi_fileMulti-YAML Build System and Ergonomic Aggregation APIs - orphan
- Orphan namespace of the module.
- own
- Own namespace of the module.
- pipeline
- High-level pipeline API.
- prelude
- Prelude to use essentials:
use my_module ::prelude :: *. - registry
- Command registry management. Some functions gated by approach features.
- semantic
- Semantic analysis and validation.
- simd_
json_ parser - SIMD-optimized JSON parsing for 4-25x performance improvements.
Requires features:
simd-jsonANDjson_parser - simd_
tokenizer - SIMD-optimized tokenization for 3-6x performance improvements. SIMD-optimized tokenization for high-performance string processing.
- static_
data - Static data structures for compile-time commands.
Requires feature:
static_registry - types
- Value types and type system.
- validation_
core - Core validation logic shared between runtime and build.rs. This module can be included in build.rs via include!() since it has no dependencies. Core validation logic shared between runtime and build.rs.
Structs§
- Aggregation
Config - Re-export key aggregator types Re-export key aggregator types Configuration for multi-YAML aggregation
- Argument
Attributes - Holds attributes and configuration for a specific argument within a command.
- Argument
Definition - Defines an argument within a command, including its name, type, and constraints.
- Batch
Result - Result of processing multiple commands through the pipeline.
- CliBuilder
- Re-export key builder types Re-export key builder types Ergonomic CLI builder for simple and complex aggregation scenarios
- CliConfig
- Re-export key builder types Re-export key builder types Global CLI configuration
- Command
Definition - Type-safe command definition with validated newtypes and private fields.
- Command
Definition Builder - Type-state builder for
CommandDefinitionthat enforces required fields at compile time. - Command
Name - A validated command name that guarantees the dot prefix convention.
- Command
Registry - Runtime command registration. Consider compile-time alternatives for better performance. Runtime command registration. Consider compile-time alternatives for better performance. Runtime command registration. Consider compile-time alternatives for better performance.
- Command
Registry Builder - A builder for constructing
CommandRegistryinstances with a fluent API. - Command
Result - Result of processing a single command through the pipeline.
- Conditional
Module - Re-export key builder types Re-export key builder types Conditional module based on feature flags
- Conflict
Report - Re-export key aggregator types Re-export key aggregator types Report of detected conflicts
- Dynamic
Command Map - Optimized dynamic command storage with intelligent caching
- Dynamic
Module - Re-export key builder types Re-export key builder types Dynamic YAML module configuration for ergonomic APIs
- EnvConfig
Parser - Re-export key aggregator types Re-export key aggregator types Environment variable configuration parser
- Error
Data - Represents an error that occurred during command execution
- Execution
Context - The execution context for a command.
- Fast
Json Value - Performance-optimized JSON value for applications that need maximum parsing speed with minimal allocations.
- Help
Display Options - Global configuration for help output display.
- Help
Generator - Generates help information for commands.
- Interner
Stats - Statistics about the string interner’s current state.
- Interpreter
- The interpreter for Unilang commands.
- Module
Config - Re-export key aggregator types Re-export key aggregator types Configuration for a single module
- Multi
Yaml Aggregator - Re-export key aggregator types Re-export key aggregator types Multi-YAML aggregation system for compile-time command processing
- Namespace
- Represents a namespace within the command system.
- Namespace
Isolation - Re-export key aggregator types Re-export key aggregator types Namespace isolation configuration
- Namespace
Type - A validated namespace that guarantees correct naming conventions.
- NotSet
- Marker type indicating a required field has not been set.
- Output
Data - Represents the output of a successfully executed command.
- Performance
Metrics - Performance metrics for command registry operations.
- Pipeline
- A high-level pipeline processor that combines parsing, semantic analysis, and execution.
- SIMD
Json Parser - High-performance JSON parser using SIMD optimizations.
- SIMD
Tokenizer - SIMD-optimized tokenizer for splitting strings by delimiters. SIMD-optimized tokenizer for splitting strings by delimiters.
- Semantic
Analyzer - The semantic analyzer, responsible for validating the parsed program.
- Set
- Marker type indicating a required field has been set.
- Static
Argument Attributes - Static, const-compatible version of
ArgumentAttributes. - Static
Argument Definition - Static, const-compatible version of
ArgumentDefinition. - Static
Command Definition - Static, const-compatible version of
CommandDefinition. - Static
Command Map - Wrapper for static command maps with zero-overhead compile-time lookup.
- Static
Command Registry - High-performance static command registry with zero-cost compile-time lookup. High-performance static command registry with zero-cost compile-time lookup. High-performance static command registry with zero-cost compile-time lookup.
- Static
Module - Re-export key builder types Re-export key builder types Static module configuration for ergonomic APIs
- String
Interner - Thread-safe string interner that caches strings and returns ’static references.
- Type
Error - An error that can occur during type parsing or validation.
- Verified
Command - Represents a command that has been verified against the command registry.
- Version
Type - A validated version string.
Enums§
- Aggregation
Mode - Re-export key builder types Re-export key builder types Ergonomic CLI aggregation modes
- Command
Status - Command status indicating lifecycle stage and availability.
- Conflict
Resolution Strategy - Re-export key aggregator types Re-export key aggregator types Conflict resolution strategies for handling duplicate commands
- Conflict
Type - Re-export key aggregator types Re-export key aggregator types Types of conflicts that can be detected
- Error
- The main error type for the Unilang framework.
- Error
Code - Standard error codes for command execution failures
- Help
Verbosity - Help verbosity levels controlling output detail.
- Kind
- Represents the data type and structure of an argument or value.
- Module
Source - Re-export key builder types Re-export key builder types Module source type for aggregation
- Registry
Mode - Registry operation mode for hybrid command lookup optimization
- Static
Kind - Static, const-compatible version of Kind.
- Static
Validation Rule - Static, const-compatible version of
ValidationRule. - Unilang
Error - Structured error types for better API consistency and error handling.
- Validation
Rule - Validation rule for argument values.
- Value
- Represents a parsed and validated value of a specific kind.
Traits§
- Command
Registry Trait - Common trait for command registries to enable interoperability.
Functions§
- aggregate_
cli_ complex - Re-export key aggregator types Re-export key aggregator types More complex aggregate_cli simulation
- aggregate_
cli_ simple - Re-export key aggregator types Re-export key aggregator types Convenience function for zero-boilerplate static aggregation (aggregate_cli! macro simulation)
- compute_
full_ name_ core - Computes full command name from namespace and name.
- create_
aggregated_ registry - Re-export key aggregator types Re-export key aggregator types Runtime multi-YAML aggregation with environment variable support.
- extract_
bool - Extract
boolvalue from config. - extract_
f64 - Extract
f64value from config. - extract_
i32 - Extract
i32value from config. - extract_
i64 - Extract
i64value from config. - extract_
string - Extract
Stringvalue from config. - extract_
string_ array - Extract array of strings from config.
- extract_
u8 - Extract
u8value from config. - extract_
u16 - Extract
u16value from config. - extract_
u32 - Extract
u32value from config. - extract_
u64 - Extract
u64value from config. - global_
interner - Returns a reference to the global string interner instance.
- intern
- Convenience function to intern a string using the global interner.
- intern_
command_ name - Convenience function to intern command names using the global interner.
- is_
help_ command - Checks if command name ends with “.help” suffix.
- is_
simd_ enabled - Returns true if SIMD optimizations are available and enabled. Returns true if SIMD optimizations are available and enabled.
- load_
command_ definitions_ from_ json_ str - Loads command definitions from a JSON string.
- load_
command_ definitions_ from_ yaml_ str - Loads command definitions from a YAML string.
- make_
help_ command_ name - Builds help command name from command name.
- parse_
cargo_ metadata - Re-export key aggregator types Re-export key aggregator types Parse Cargo.toml metadata for build configuration
- parse_
value - Parses a raw string input into a
Valuebased on the specifiedKind. - process_
single_ command - Convenience function to process a single command with a registry.
- resolve_
routine_ link - Resolves a routine link string to a
CommandRoutine. - simd_
support_ info - CPU feature detection for SIMD optimization selection. CPU feature detection for SIMD optimization selection.
- validate_
command_ definition_ core - Validates a complete command definition at build time.
- validate_
command_ for_ registration - Validates entire command definition for registration.
- validate_
command_ name - Validates command name follows dot-prefix naming convention.
- validate_
command_ name_ core - Validates command name follows dot-prefix naming convention.
- validate_
full_ name_ core - Validates the full name (namespace + name combination).
- validate_
namespace - Validates namespace follows dot-prefix naming convention.
- validate_
namespace_ core - Validates namespace follows dot-prefix naming convention.
- validate_
parameter_ storage_ types - Validates parameter storage types match their multiple attribute.
- validate_
single_ command - Convenience function to validate a single command with a registry.
- validate_
version_ core - Validates version string is non-empty.
Type Aliases§
- Command
Routine - Type alias for a command routine.
A routine takes a
VerifiedCommandand anExecutionContext, and returns aResultofOutputDataorErrorData. - Config
Map - Type alias for configuration maps with any source type.