Traits — Kernel
A Rust-native trait platform. Traits are typed, composable function objects defined in .trait.toml files with companion Rust source. All 26 traits compile directly into a single traits binary — zero worker processes, zero HTTP overhead for inter-trait calls. Every trait is callable via CLI, REST API, or internal dispatch.
Live: traits.build
Repo: github.com/kilian-ai/traits.build
Traits (26)
kernel.* — Core runtime (11)
| Trait | Description |
|---|---|
kernel.call |
Call another trait by dot-notation path (dispatch mechanism) |
kernel.config |
Configuration loader: traits.toml parsing, env var overrides |
kernel.dispatcher |
Core trait execution engine: path resolution, arg validation, dispatch, handle management |
kernel.dylib_loader |
Dynamic shared-library loader for trait cdylib plugins |
kernel.globals |
Global OnceLock statics: REGISTRY, CONFIG, TRAITS_DIR, HANDLES, START_TIME |
kernel.main |
Binary entry point, system bootstrap, compiled module list introspection |
kernel.plugin_api |
C ABI export macro for cdylib trait plugins. Returns ABI contract + installed plugins |
kernel.registry |
Trait registry: loading, lookup, interface resolution, bindings |
kernel.reload |
Reload trait registry from disk |
kernel.serve |
Start the HTTP API server (actix-web, background trait) |
kernel.types |
Cross-language type system: TraitType, TraitValue, wire protocol types |
sys.* — System utilities (9)
| Trait | Description |
|---|---|
sys.checksum |
Deterministic SHA-256 checksums (hash values, I/O pairs, trait signatures) |
sys.cli |
CLI bootstrap, trait dispatch, stdin injection, arg parsing, result formatting |
sys.info |
Show detailed trait info (delegates to sys.registry info) |
sys.list |
List all registered traits (delegates to sys.registry list) |
sys.ps |
List running background traits with process details |
sys.registry |
Registry read API — list, info, tree, namespaces, count, get, search |
sys.snapshot |
Snapshot a trait version (YYMMDD, or YYMMDD.HHMMSS for same-day) |
sys.test_runner |
Run .features.json tests — example dispatch + shell commands |
sys.version |
Show trait system version, or generate YYMMDD version strings |
www.* — Web interface (6)
| Trait | Description |
|---|---|
www.traits.build |
Landing page for traits.build |
www.admin |
Admin dashboard (Basic Auth protected) |
www.admin.deploy |
Deploy latest version to Fly.io |
www.admin.fast_deploy |
Fast deploy: build amd64 binary in Docker + upload via sftp + restart |
www.admin.scale |
Scale Fly.io machines (0 = stop all, 1+ = start) |
www.admin.destroy |
Destroy all Fly.io machines for the app |
Architecture
┌──────────────┐ ┌──────────────┐ ┌──────────────┐
│ CLI (main) │────▶│ Dispatcher │────▶│ Compiled │
│ call/serve │ │ resolve + │ │ trait fns │
│ list/info │ │ coerce args │ │ (Rust) │
└──────────────┘ └──────────────┘ └──────────────┘
│
┌──────▼──────┐
│ Registry │
│ (DashMap) │
└─────────────┘
- Entry point (
src/main.rs=traits/kernel/main/main.rs) — binary entry,bootstrap()loads config → registry → dylibs → resolves interfaces → creates Dispatcher. Declares[requires]for dispatcher, registry, config, globals, dylib_loader — all resolved through the interface system - CLI (
traits/sys/cli/cli.rs) — clap parsing, trait dispatch, arg coercion, result formatting. Any unknown subcommand is tried assys.{name}thenkernel.{name} - Dispatcher (
traits/kernel/dispatcher/) — resolves trait paths, validates/coerces arguments, dispatches to compiled modules - Registry (
traits/kernel/registry/) — loads.trait.tomldefinitions from disk + compiled builtins, concurrent DashMap storage, interface resolution - Serve (
traits/kernel/serve/) — actix-web HTTP server, runs as a background trait. Routes URL paths towww/webpageinterface providers via keyed bindings - Dylib loader (
traits/kernel/dylib_loader/) — optional dynamic library loading for external trait plugins - Types (
traits/kernel/types/) —TraitValue,TraitEntry,TraitSignature, wire protocol types
CLI
Every sys.* trait is available as a direct subcommand — no call sys. prefix needed:
# Start the server (default when no subcommand given)
# List all traits
# Show trait info
# Run tests
# Compute a checksum
# Snapshot a trait version
The call subcommand dispatches any trait by full path (useful for non-sys namespaces):
Arguments are positional and mapped to params via the CLI's inline arg parser. Pipe input is supported for params with pipe = true:
|
REST API
All traits are callable over HTTP when the server is running:
# Call a trait
# List traits
# Reload registry
# SSE streaming
# Health check
Testing
Every trait has a .features.json file with example tests (internal dispatch) and command tests (shell):
# Run all tests
# Run tests for a specific trait
# Verbose output
Trait Definition Format
Each trait lives in traits/{namespace}/<name>/ with:
<name>.trait.toml— metadata, params, returns, implementation pointer, interfaces<name>.rs— Rust source (compiled into the binary viabuild.rs)<name>.features.json— test cases (optional)<name>.md— documentation (optional)
Example call.trait.toml:
[]
= "Call another trait by dot-notation path"
= "v260322"
= "system"
= ["system", "meta", "dispatch"]
= ["kernel/call"]
[]
= [
{ = "trait_path", = "string", = "Dot-notation trait path" },
{ = "args", = "list<any>", = "Arguments forwarded to the target trait", = true }
]
[]
= "any"
= "Result from the called trait"
[]
= "rust"
= "builtin"
= "call"
File Layout
src/
main.rs # Binary entry point (Cargo.toml target)
main.trait.toml # Trait definition for kernel.main
traits/kernel/
main/ # Bootstrap, trait_exists(), introspection
call/ # Inter-trait dispatch by dot-notation path
config/ # Server configuration (traits.toml + env vars)
dispatcher/ # Path resolution, arg validation, compiled dispatch
dylib_loader/ # Dynamic library trait plugins
globals/ # Global state (OnceLock registry, config, traits dir)
plugin_api/ # C ABI export macro for cdylib plugins
registry/ # Trait registry (load, store, lookup, interface resolution)
reload/ # Hot-reload registry from disk
serve/ # HTTP API server (actix-web)
types/ # Core types (TraitValue, TraitEntry, signatures)
traits/sys/
checksum/ # SHA-256 hashing primitives
cli/ # CLI clap parsing, dispatch routing
info/ # Trait introspection (delegates to registry)
list/ # Trait listing (delegates to registry)
ps/ # Background trait process listing
registry/ # Registry read API (list, info, tree, search)
snapshot/ # YYMMDD version snapshots
test_runner/ # Test discovery and execution
version/ # Version generation
traits/www/
traits/build/ # Landing page (www.traits.build)
admin/ # Admin dashboard
deploy/ # Fly.io deployment
fast_deploy/ # Fast binary deploy via sftp
scale/ # Fly.io machine scaling
destroy/ # Fly.io machine destruction
Interface System
Traits declare dependencies through interfaces — named contracts that are provided, required, and bound entirely within .trait.toml files. There are no separate interface definition files.
How it works
-
Provide — a trait declares what interfaces it satisfies via
providesin[trait]:[] = ["kernel/dispatcher"] -
Require — a consuming trait declares
[requires]with a logical key mapped to an interface name:[] = "kernel/dispatcher" -
Bind — the same trait provides default wiring in
[bindings], mapping the key to a concrete trait:[] = "kernel.dispatcher" -
Resolve at runtime — the registry resolves interfaces through a priority chain:
- Per-call overrides (highest priority)
- Global bindings
- Caller's
[bindings] - Auto-discover (find providers, pick by priority)
URL-keyed bindings
kernel.serve uses interface keys as URL paths, binding each route to a www/webpage provider:
[]
= "www/webpage"
= "www/webpage"
= "kernel/dispatcher"
[]
= "www.traits.build"
= "www.admin"
= "kernel.dispatcher"
Current interfaces
| Interface | Providers | Required by |
|---|---|---|
kernel/dispatcher |
kernel.dispatcher |
kernel.main, kernel.serve |
kernel/registry |
kernel.registry |
kernel.main |
kernel/config |
kernel.config |
kernel.main |
kernel/globals |
kernel.globals |
kernel.main |
kernel/dylib_loader |
kernel.dylib_loader |
kernel.main |
www/webpage |
www.traits.build, www.admin |
kernel.serve (keyed by URL path) |
Build System
build.rs auto-discovers all traits and generates Rust code at compile time:
builtin_traits.rs— embeds all.trait.tomldefinitions viainclude_str!compiled_traits.rs— module declarations +dispatch_compiled()match tablekernel_modules.rs— crate-levelpub moddeclarations for kernel subdirectoriescli_formatters.rs— optional CLI output formatters from*_cli.rscompanion files
Version is auto-computed as vYYMMDD (or vYYMMDD.HHMMSS for same-day rebuilds). Source file checksums are computed and written back to each .trait.toml.
Deployment
Deployed on Fly.io:
See docs/deploy.md for details, docs/release.md for GitHub releases.