0318.
Implicit Cache-Backed gen/ Derive Materialization
(F47)
- Status: Accepted (2026-11-28)
- Date: 2026-11-28
- Plan: M28.1 (F47; extends ADR-0295)
Context
ADR-0295
introduced two-tier implicit cached derive
materialization (in-memory BTreeMap + package-local
.tenon/cache/gen/<sha256>/<Target>.<Gen>.tn)
for packages with a tenon.toml.
Two remaining gaps blocked zero-friction workflows for standalone scripts and agent inspection:
- Standalone scripts without
tenon.toml:gen::cachefell back to<script_dir>/.tenon/cache/gen/..., cluttering the script's directory with.tenon/artifacts. - Ergonomic inspection and explicit write
flags: Agents and users expect
tenon view <file.tn> --generatedalongside--expanded,tenon gen --print <file.tn>to inspect materialized derived code on demand without writinggen/, andtenon gen --writeas an explicit counterpart totenon gen --check.
Decision
Package-Local and Standalone Global Gen Cache (
crates/tenon-compiler/src/gen/cache.rs,gen.rs):- When the deriving module belongs to a package with
tenon.toml, Tier 2 disk caching uses<package_dir>/.tenon/cache/gen/<job.key>/<Target>.<Gen>.tn. - When the deriving module has no enclosing
tenon.toml(such as a standalone#!script under ADR-0319), Tier 2 disk caching routes to$TENON_CACHE_DIR/gen/<job.key>/<Target>.<Gen>.tn(falling back to$XDG_CACHE_HOME/tenon/genor~/.cache/tenon/gen), leaving zero.tenon/orgen/files in the script's directory. - Every read is verified via
gen::verify(job, &text);TENON_NO_CACHE=1disables disk caching cleanly.
- When the deriving module belongs to a package with
Full Backward Compatibility with Committed
gen/:- Existing on-disk
gen/*.tnfiles remain Priority 1 whenever fresh (gen::verifypasses). tenon gen [path]andtenon gen --write [path]publish fresh companions togen/.tenon gen --check [path]verifies on-diskgen/freshness;TENON_STRICT_GEN=1disables implicit fallback during loads.
- Existing on-disk
On-Demand Derived Code Inspection (
crates/tenon/src/surface_cmd.rs,crates/tenon/src/cli/pkg.rs):tenon view <file.tn> --generatedis accepted as an alias fortenon view <file.tn> --expanded.tenon gen --print <file.tn>(with optional--json) materializes and prints derived companions in readable ordinary Tenon syntax without modifyinggen/.
Consequences
tenon check,tenon test,tenon run,tenon interp,tenon build, andtenon doc --cardmaterialize derives automatically for both packages and manifestless scripts with zero trackedgen/boilerplate.- Agents can inspect exact derived code on demand via
tenon view <file.tn> --generatedortenon gen --print <file.tn>. - Existing packages committing
gen/*.tnand runningtenon gen --checkkeep 100% identical behavior.