0319.
Single-File Manifestless #! Scripts (B10)
- Status: Accepted (2026-11-28)
- Date: 2026-11-28
- Plan: M28.2 (B10; builds on ADR-0318)
Context
Tenon packages require a tenon.toml manifest and
tenon.lock lockfile before they can import
edition-2026 plugins or use derive. For quick
operational scripts, CI glue, data-wrangling one-offs, and
agent-authored executables, creating a full package directory with
tenon.toml, tenon.lock,
.tenon/, and gen/ is unnecessary
ceremony.
Developers and AI agents need to write a single executable
.tn file with #!/usr/bin/env tenon,
optionally declare its edition, capability ceiling, and embedded
edition-2026 dependencies via //! header directives,
and run it directly (./script.tn args...,
tenon run script.tn,
tenon interp script.tn,
tenon check script.tn,
tenon test script.tn) with zero disk clutter in the
script's directory and ~1–3 ms warm native startup.
Decision
Line-1
#!Shebang Tolerance (crates/tenon-frontend/src/source.rs):- A leading
#!...line on line 1 is neutralized in-place to//...(identical 2-byte length) during script parsing so ordinary lexing and span computation preserve 100% exact 1-based line numbers, column numbers, and byte offsets.
- A leading
Top-of-File
//!Script Header Directives (crates/tenon-compiler/src/packages/script.rs):- Optional directives before imports (after optional
#!and blank lines)://! edition = "2026"(defaults to"2026")//! capabilities = ["fs", "process", "stdout"](defaults to["stdin", "stdout", "stderr"]when#!or//!is present)//! deps = ["std_data", "std_validate", "std_regex", "json"]
- Standalone scripts may be authored in either readable ordinary
Tenon syntax or canonical compact
~1syntax.
- Optional directives before imports (after optional
Deterministic Offline Synthetic Manifest & Global Cache (
$TENON_CACHE_DIR/scripts/<digest>/):- Keyed by SHA-256 of
(format version, toolchain VERSION, script bytes). - Synthesizes an offline
tenon.tomlagainst embeddededition = "2026"plugins and materializestenon.lock/.tenon/strictly inside$TENON_CACHE_DIR/scripts/<digest>/(default~/.cache/tenon/scripts/<digest>/), leaving zero files in the script's own directory. derivecompanions inside standalone scripts are materialized implicitly via ADR-0318 with zerogen/directory in the script's directory.- Compiled native executables are cached at
$TENON_CACHE_DIR/scripts/<digest>/bin-<mode>so warm#!/tenon runinvocations skip parsing, typechecking, and C compilation entirely (~1–3 ms).
- Keyed by SHA-256 of
CLI & Direct Shebang Invocation (
crates/tenon/src/):- Direct invocation
tenon <script.tn> [args...](triggered by#!/usr/bin/env tenon) intercepts.tnscript paths before CLI flag parsing so all trailing arguments (including--help,--json,-v, etc.) pass verbatim to the script. tenon run <script.tn> [-- args...],tenon interp <script.tn> [-- args...],tenon check <script.tn>, andtenon test <script.tn>all transparently detect standalone scripts (no enclosingtenon.toml+#!or//!header or ordinary syntax) and run them against the cached synthetic workspace.
- Direct invocation
Fail-Closed Diagnostics (
E1230–E1249):E1230: Malformed//!script header directive (syntax error, duplicate key, or unknown key).E1231://!script header directive appears after code or imports.E1232: Unknown or invalid capability in//! capabilities.E1233: Unsupported edition in//! edition.E1234: Unknown plugin in//! deps(not in embedded edition catalog).E1235: Dependency in//! depsrequires a capability not declared in//! capabilities.E1236: Standalone script cache or materialization I/O error.
Consequences
- Single-file
.tnscripts run directly viachmod +x script.tn && ./script.tn ...with 100% offline embeddededition = "2026"batteries and implicitderive. - Zero
tenon.toml,tenon.lock,.tenon/, orgen/files are ever created in the script's directory. - Warm
#!script executions hit the cached native binary in ~1–3 ms. - Existing packages with
tenon.tomland existing manifestless.tnfiles without#!or//!headers retain 100% backward compatibility.