On this page

0161: vc storage unit is the formatted item

Status: Accepted — implementation authorized 2026-11-05

Context

Item-level history, merge and incremental gates need the program stored in units smaller than a file. The candidates are files, AST nodes, or item text. fmt is canonical (ADR-0018) and keeps comments in source order, but it drops blank lines and has no per-item printer. The ADR-0075 hashes ignore comments and layout, so they cannot be the stored identity. ADR-0075 canonical names need a package root, and they change when a file moves. ADR-0075 also has no per-method identity.

Decision

A .hn file whose bytes equal fmt output is stored as a module object, which holds:

A unit is one of:

Keys come from the parser alone. Splitting therefore needs no name resolution, and moving a file leaves its keys unchanged.

A chunk is the item's slice of the fmt output, including the comments before it. Join is concatenation with fixed separators, and join(split(f)) == f for every fmt-clean f. Exact grammar: FORMAT.md.

Files that do not parse, are not fmt-clean, or repeat a key are stored as raw blobs. They land like any other file: whether a .hn file must be fmt-clean is the gate's policy, not the store's, and about 20% of this repository's .hn files are deliberate parse-error or unformatted fixtures. Generated files, identified by the gen magic line, are plain blobs. Other files are whole-file blobs, and directories are tree objects.

The following are derived data, cached per (tree, toolchain) and never stored in objects:

Consequences

Comments survive, agents read stored text directly, and identical items deduplicate. Commits are independent of the toolchain.

The cost is that a change to the formatter's output rewrites every chunk. FMT_VERSION plus a digest test over the corpus turns each such change into an explicit, single vc reformat commit. Join must also be closed under merge: fmt(join(m)) == join(m) for reordered and merged modules. Both properties run in the gate.

Alternatives