On this page

0314. Dual-Read .tn Source and Canonical Terse UTF-8 Surface

Context

ADR-0268 established versioned compact source (~1) as Tenon's sole .tn authoring and interchange representation, causing the compiler loader to reject ordinary UTF-8 .tn files with E0120. While ~1 (and generated ~1g) remains compact and well-suited for generated companions and existing corpus files, requiring every authoring and editing flow to read or round-trip ~1 adds friction compared to clean, terse UTF-8 Tenon source.

Decision

  1. Dual-Read .tn Loader: Keep the .tn extension and inspect the file header on load. Files starting with ~1 or ~1g continue to decode through the compact codec; ordinary UTF-8 .tn files parse directly through the ordinary parser without triggering E0120.
  2. Canonical Terse UTF-8 Formatter (tenon fmt, tenon write): Ordinary UTF-8 .tn files format idempotently as canonical terse UTF-8 Tenon. Existing ~1 files preserve ~1 formatting by default unless explicitly converted via --utf8 or tenon fmt --migrate-utf8 <paths...>. Generated ~1g files are never rewritten by migration.
  3. Unified Tooling Surface: tenon view, tenon outline, tenon edit, and tenon hashes operate seamlessly on both UTF-8 .tn and ~1 .tn files, yielding identical ASTs and semantic item hashes regardless of surface encoding.
  4. Atomic Corpus Migration Script: Provide scripts/migrate_utf8_corpus.sh to atomically convert non-generated ~1 .tn files in a target tree to canonical UTF-8 Tenon while verifying byte-identical item hashes and lossless AST round-trips. Existing tracked plugins/**/*.tn and examples/**/*.tn remain ~1 until a dedicated corpus migration step.

Consequences