Editor
Overview
The editor feature is a collection of headless, pure-function primitives that give attune-rag IDEs and CLI tools schema validation, linting, autocomplete, reference lookup, and cross-template rename refactoring — all operating against a CorpusProtocol without coupling to any specific UI layer.
The five capabilities form a pipeline that mirrors what a language server does for source code:
-
Schema validation —
load_schemaloads the JSON Schema for template frontmatter.parse_frontmatterparses a raw YAML block and validates it in one step, raisingSchemaErroron malformed YAML and returning a list ofFrontmatterIssueobjects for any schema violations.validate_frontmatterhandles the validation step alone when the YAML has already been parsed. -
Linting —
lint_templateruns all checks against a template's text and returns a list ofDiagnosticobjects. EachDiagnosticcarries aseverity, an errorcode, a human-readablemessage, and 1-indexedline/col/end_line/end_colspan fields. -
Autocomplete —
autocomplete_tagsandautocomplete_aliasesprefix-match against the corpus and return up tolimitsuggestions (default 50). Tags are returned as plain strings; aliases are returned asAliasInfoobjects. -
Reference lookup —
find_referencessearches every file in the corpus for occurrences of a given alias, tag, or template path (selected byReferenceKind) and returns a list ofReferenceobjects. EachReferencerecords thetemplate_path,line,col, and aReferenceContextdescribing how the name is used. -
Rename refactoring —
plan_renamecomputes aRenamePlanthat collects all necessaryFileEditandFileMoveoperations without touching disk. EachFileEditbreaks its changes intoHunkobjects in unified-diff format so callers can preview the diff before committing.apply_renamethen executes the plan atomically, refreshes the corpus, and raises aRenameCollisionErrorif the proposed new name already exists, or aRenameErrorsubclass for problems such as a missing move source or a file that has drifted from the planned base.
Integration points
Other parts of the codebase consume the editor feature through these public interfaces:
| Interface | Role | Source file |
|---|---|---|
Diagnostic |
Lint result with location and severity | src/attune_rag/editor/lint.py |
Reference |
Single corpus-wide reference to a name | src/attune_rag/editor/references.py |
RenamePlan |
Diff preview before writing to disk | src/attune_rag/editor/rename.py |
RenameError / RenameCollisionError |
Failure signals from apply_rename |
src/attune_rag/editor/rename.py |
Hunk |
Unified-diff fragment within a FileEdit |
src/attune_rag/editor/rename.py |
The attune-gui editor and the attune-author edit CLI are the primary consumers. Because every function accepts a CorpusProtocol value rather than a concrete corpus type, any component that satisfies the protocol can use the full feature set without additional glue code.