Tenon Mental Model & Concepts
A 1-page guide to how Tenon projects, files, capabilities, and modern (M26–M30) language features fit together.
Project lifecycle & directory layout
A Tenon project is a directory with a tenon.toml
manifest and one or more .tn source modules (entry
point main.tn by default):
| Path | Committed? | Purpose |
|---|---|---|
tenon.toml |
Yes | Package manifest: [package]
name/version/platform, [capabilities] ceiling,
[dependencies], and [embed.*]
assets. |
tenon.lock |
Yes | Deterministic lockfile written by tenon add /
tenon fetch. Pins bundled edition plugins, git
commits, registry packs, and process-plugin executable SHA-256
hashes. |
.tenon/ |
No (.gitignored) |
Local toolchain state: offline materialized dependencies
(.tenon/deps/), implicit derive companion cache
(.tenon/cache/gen/), fetch lock, and local
vc store. Safe to delete and recreate via
tenon fetch. |
gen/ |
Optional | Explicit checked-in output directory for
derive G for T generators. By default, derives
materialize implicitly in memory and
.tenon/cache/gen/; use tenon gen --eject
to write gen/ to disk, tenon gen --print
to inspect, or TENON_STRICT_GEN=1 to require
checked-in gen/ files. |
Editions & bundled plugins
Edition "2026" ships a curated catalog of
first-party plugins embedded directly inside the
tenon binary so projects build offline:
- Tier 1 (
--core): 9 core plugins kept within a tight prompt budget. - Tier 2 (
--all): the full 105-plugin bundled catalog acrosscore,cli,tui,agent,mcp,proc,web,system, andvccategories — including 15std_*domain facades and standard packages (std_core,std_data,std_formats,std_cli,std_tui,std_web,std_agent,std_mcp, etc.). - Browse with
tenon plugins index --allor--category <cat>, install intotenon.toml+tenon.lockwithtenon add <plugin>, and read compact API cards withtenon doc --card <plugin>.
Capabilities (explicit authority)
Tenon has no ambient I/O. Programs receive authority through
explicit capability values (Cli, Fs,
Net, Env, Process,
Clock, Stdin, Stdout,
Stderr, Traps) passed from
fn main(cli: Cli) -> result<unit, CliError>:
- Declare the package's ceiling in
tenon.tomlunder[capabilities]. - Narrow authority before passing it into helpers or child
processes (
cli.fs.restrict(p),.read_only(),.no_follow();cli.net.restrict(hosts),.none();cli.process.sandbox(fs, net)). - Inspect reachable authority statically with
tenon check --report=authority.
Modern Tenon ergonomics (M26–M30)
Canonical Tenon source is readable UTF-8 (.tn).
The compiler still dual-reads legacy ~1 compact
syntax; convert older files with
tenon fmt --migrate-utf8.
- Expression bodies & tail returns:
Functions, methods, and closures return their final expression
implicitly without a trailing
return. Single-expression functions can use= expr:fn double(x: i64) -> i64 = x * 2 - Compound assignment & deep
withlenses: Mutable locals (var) support+=,-=,*=,/=,%=(and+=concatenation onstr,bytes,vec<T>). Immutable records update cleanly viawithlenses, including nested paths and compound updates:
On alet next = state with { pane.scroll: 0, stats.hits += 1 }varlocal,state.pane.scroll = 0desugars tostate = state with { pane.scroll: 0 }. - Null-coalescing
??&let ... else: Unwrapoption<T>lazily withopt ?? fallback(evaluatesfallbackonly onnone), or unwrapoption<T>,result<T, E>, and enum variants early with a divergingelseblock:let some(port) = raw.parse_i64() else { return err(CliError.Failed("bad port")) } - Typed holes (
todo()): Leave typed placeholders during incremental drafting and inspect every hole's expected type and in-scope bindings withtenon holes [path] [--json]. - Executable contracts (
requires/ensures): Attach preconditions and postconditions (ensures res => <bool-expr>) directly to functions. Verify purity or totality statically withtenon check --assert-pure <fn>andtenon check --assert-total <fn>. - Single-file
#!scripts: Run standalone.tnscripts with notenon.toml,gen/, or.tenon/clutter in the script directory. Declare edition, capabilities (default:stdin,stdout,stderr), and bundled dependencies with top-of-file//!directives:
Scripts compile into the build cache and execute via a warm cached binary on subsequent runs.#!/usr/bin/env tenon //! edition = "2026" //! capabilities = ["stdin", "stdout", "stderr", "fs"] //! deps = ["std_formats"] - Explicit state machines
(
derive StateMachine): Model multi-step workflows, UI modals, and protocols declaratively withfsm+fsm_gen(@initial,@terminal,@on("ev[(T)] -> target")) and exhaustively test transitions withfsm_test.
Profiling:
tenon profile vs
tenon build --profile
Tenon has two distinct profiling tools that serve different layers:
| Command | What it does | When to use it |
|---|---|---|
tenon profile [--dev] [path] [--json] [-- args...] |
Built-in runtime profiler. Compiles with
runtime instrumentation (TRT_PROFILE=1,
TRT_STATS=1), runs the program, and prints wall time,
arena allocations/copies/peak bytes, top function hotspots, and
static copy/check summaries. |
First stop for optimizing Tenon code, arena churn, copies, or runtime checks. |
tenon build --profile /
tenon run --profile |
Build optimization flag (mutually exclusive
with --debug). Compiles native C with
-g -O2 and frame pointers so external OS profilers
(perf, Instruments, addr2line) can
sample tn_* symbols. |
Native CPU flamegraphs and low-level C/kernel profiling (debugging guide). |
Where to go next
- 60-Second Quickstart — scaffold CLI, TUI, MCP, and plugin projects
- Language Reference — full syntax, types, and runtime rules
- Diagnostics & Command Reference — error codes, reports, and toolchain details
- Native Debugging & Profiling — DWARF line maps and external profiler workflows
- Extension Points — plugin
kinds and canonical
std_*/*_gennaming