On this page

0049: Checked source edit tools

Context

Agents need compact outlines and checked replacements/renames without changing the language or either backend. The compiler currently checks one file at a time, and its name checker does not export declaration identities.

Decision

Outline parsed declarations in source order, with signatures, source lines and FNV-1a 64-bit hashes of exact AST item spans. Hashes are optimistic revision guards, not security primitives. Replace one free function or impl method by unqualified name; parse method replacements in their impl context. Preserve replacement comments and outside-span original comments. Check the whole spliced candidate, format it, check again, then write. Formatting is whole-file by design, so one replacement can change other items' outline hashes; agents must re-run outline after every replacement. CRLF files keep CRLF. Selectors are name, fn name, Type.name and Interface for Type.name; ambiguity lists them.

Build a tooling-only declaration/reference graph over the successfully checked AST using lexical scopes, separate function/type namespaces and the checker's method dispatch, instantiation and aggregate metadata. No compiler phase changes. Select a unique definition by bare name or qualified selector (fn f, type T, Type.field, Interface.method, item.local); a bare name matching several definitions refuses and lists the choices rather than preferring one. Interface methods include all impl definitions. Rename only linked spans and check again; reject any change in reference identities (silent capture). Keep rename byte-preserving outside selected identifier tokens.

Directories contain independent programs, not a synthetic merged module. Validate every original and candidate before staging all changes. Reject symlinks and nonregular sources. Preserve permissions, sync sibling temporary files, recheck contents and atomically rename per file. On commit-time failure attempt rollback; report failure explicitly. No multi-file crash atomicity or filesystem locking. Tool errors are plain stderr messages, exit 2; no new diagnostic codes.

Alternatives considered

Consequences

Tooling resolution must evolve with syntax and scope rules. Candidate checking, reference-identity comparison and scope/capture tests are the safety net. Bare names intentionally refuse ambiguity rather than guessing a declaration.