Repository navigation
feat: lint the repository layout section - #19
Merged
Merged
Conversation
Add a repo_layout lint. A file it applies to must have a section, "Repository layout" by default, whose first code block lists the paths that matter most, one per line, as `path <- description`, with every path and every `<-` in one column. The lint fails the file when the section or the block is missing, when the number of entries is outside min_entries to max_entries (5 to 15 by default), when a line is out of format, or when a listed path does not exist relative to the Markdown file. The report lists every problem with its line. Turn it on for this repo's AGENTS.md with 5 to 12 entries, and trim the layout there from 16 entries to 12. Move the pulldown-cmark options and the line lookup into parse/markdown.rs so both Markdown lints share them.
Split repo_layout into read, which finds the section and reads the layout from the text alone, and check, which adds the limits and looks the paths up on disk. The corpus has none of the repos its fixtures describe, so it can run only the part that needs no disk. Add a corpus test that reads the layout of every fixture under a few headings real repos use. The lines it reports must fall in the section, an entry's line must hold its path, and core/rt-agents.md, the one fixture in deslag's format, must read with no malformed line. The as-built doc now says each lint keeps what it decides from the text alone in a function of the text, so the corpus can run it.
3 tasks done
webern
commented
Sep 24, 2026
An agent told only the rules of the layout format can guess wrong and keep guessing. The default advice now shows a layout to copy, under the configured heading, and the prose around it is shorter. A test renders the report, reads it as Markdown, and checks that the example in it passes the lint, so the example cannot drift out of format.
webern
commented
Sep 24, 2026
The example in the advice wrapped a description onto a second line, which shows an agent that wrapping is a fine way to say more. Drop the wrap. A continuation still passes, but the advice no longer shows one. No line of the layout may be wider than 100 characters now, not counting trailing whitespace. A wider line is malformed, and its problem asks for it to be shortened. The advice, the README and the as-built doc state the limit.
The widest line a layout may have is now the max_width setting, 100
by default, and a config message can name it with {max_width}.
read still works from the text alone. It returns the width of each
line, and check compares them with the setting, as it does the entry
count. A line that is too wide is now its own problem rather than a
format problem, since whether it fails depends on the settings.
webern
added a commit
that referenced
this pull request
Sep 24, 2026
## Summary
Adds a second kind of test data next to the corpus: cases, written for
one lint and shipped with whatever they need on disk.
The corpus can't do this job. Its fixtures are quoted from other repos
and never edited, and the repos they describe aren't there. A lint like
`repo_layout` needs a directory tree to check paths against, and its
report is only worth pinning on a document written to break it in known
ways.
A case is a directory under `tests/cases/<lint>/` that is a whole repo
root: the Markdown, a `deslag.toml`, and any files the lint looks for.
Beside it, `<case>.stderr` holds exactly what `deslag check` prints
there:
```
tests/cases/repo_layout/
broken/
deslag.toml
AGENTS.md
Makefile
src/lib.rs
...
broken.stderr <- the exact report
clean/
...
clean.stderr <- empty: the run must pass
```
`tests/cases.rs` copies each case to a temp directory, runs the binary
there, and compares its stderr with the file. Some other details:
- The exit code isn't stored. An empty `.stderr` means the run must exit
0, and any other means exit 1. That is the contract the binary already
has.
- Config errors print absolute paths, so the temp root is written as
`[ROOT]`.
- A `.stderr` file with no case beside it, or any other stray file,
fails the test, so renaming a case can't leave a stale file behind.
- On a mismatch, the test prints the first line that differs, both
outputs, and the command to accept the new output.
Accepting new output is `make fix-test-output`, which runs the test with
`DESLAG_FIX_TEST_OUTPUT=1`. It is part of `make fix`, and the build
doctrine's definition of `fix` now says so. It accepts whatever deslag
prints, so the diff has to be read.
The first cases replace the tests in `tests/layout.rs` that ran the
binary. Those tests checked pieces of the report with `contains`, while
the cases pin all of it:
- `broken`: one layout with every kind of problem, so every message's
wording is pinned. It sets `max_width = 80`, so the advice and the width
problem must both show the configured width.
- `clean`: a good layout passes on the default limits
- `no_section`, `no_block`: the short report, and a heading with no code
block (not covered before)
- `custom_message`: a config `message` replaces the advice, with every
placeholder filled in
- `nested`: paths are relative to `src/AGENTS.md`, not the repo root
- `min_over_max`, `min_over_default_max`: the two ways the limits can
contradict each other
The tests of `read` and `check` stay in `tests/layout.rs`.
`tests/cases/` isn't excluded from the spell check: cases are ours,
unlike the corpus. The self-lint globs are anchored, so the cases'
`AGENTS.md` files aren't linted as this repo's own.
A case can't hold a `.git` directory, or a `.gitignore` that ignores its
own files, because git would apply it to this repo too. The harness's
doc comment says so.
`AGENTS.md` and the as-built doc are updated.
## Testing
- [x] `make ci`: exit 0
- [x] Ran the harness before any `.stderr` existed: every case reported
its file as missing. Then ran `make fix-test-output` and checked each
`.stderr` line by line against its source: line numbers, columns, entry
counts and file counts.
- [x] Changed one line of `nested.stderr` and added a stray
`orphan.stderr`: the test failed on both, naming line 10 as the first
difference. Restored both.
## References
- Stacked on #19. The cases use the `repo_layout` lint it adds.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a third lint,
repo_layout. It checks that a Markdown file, usually AGENTS.md, has a short index of the repo whose paths all exist.The index is the first code block in the
## Repository layoutsection. The heading can be changed in the config, and it matches at any level and in any case. The section ends at the next heading of the same level or higher. Each line of the block is an entry: a path, then<-and a description.The format is strict so that it stays tidy:
deslag/). It is not an entry.<-sits in the same column as the first entry's.max_widthcharacters, 100 by default, not counting trailing whitespace./must be a directory.A file fails when the section or its code block is missing, when the number of entries is outside
min_entriestomax_entries, when a line is too wide or breaks the format, or when a path does not exist. The report lists every problem with its line number, so an agent can fix them one by one. The advice shows an example layout under the configured heading, so an agent that has never seen the format has one to copy instead of guessing from a description:The config:
The defaults are 5 to 15 entries, and
max_widthdefaults to 100. The other lints only run when one of their limits is set, but for this one the table alone turns it on, because requiring the section is the point. Overrides andmessagework as they do for the other lints.Because of the defaults,
min_entriesandmax_entriescan contradict each other only once they are merged for a particular file. For example,min_entries = 20alone conflicts with the default maximum of 15, and so does a section-wide minimum paired with a smaller maximum in an override. The run checks each file's merged settings and stops with a config error that names the file. It does not produce a report the agent could never satisfy.This repo's config turns the lint on for AGENTS.md with 5 to 12 entries. I cut the layout there from 16 entries to 12:
AGENTS.md <- you are hereand_typos.toml;src/main.rsinto the description ofsrc/lib.rs;.claude/skillsinto the description of.agents/skills/.As the issue suggested, the lint uses the Markdown parser.
pulldown-cmarkwas already a dependency. The options it is set up with, and the lookup from byte offset to line number, move out ofmax_emphasisintosrc/parse/markdown.rs, so both Markdown lints share them.The lint is in two parts.
repo_layout::readworks from the text alone: it finds the section, and returns the entries, any lines that break the format, and the width of each line.repo_layout::checkadds the entry limits and the width limit, and looks the paths up on disk. The split exists so the test corpus can exercise the lint. The corpus has none of the repos its fixtures describe, so the parts that need the disk are tested on small directory trees the tests create. The as-built doc now states this as a rule for every lint: whatever a lint decides from the text alone lives in a function of the text, so the corpus can run it.max_emphasis::measurealready works this way.There is one limitation. Paths are looked up on disk, so a path that git ignores, such as a build directory, passes on a machine that has built it and fails on a clean checkout.
README and
deslag.asbuilt.mdare updated.Testing
make ci: exit 0tests/corpus.rs: a new test runsreadon every fixture, under eight headings real repos use for a layout. It reads 12 real layouts: lists,treedrawings and prose. Every line it reports must fall inside the section, and an entry's line must hold its path.core/rt-agents.mdis the one fixture written in deslag's format, and it must read with no format problems.tests/layout.rs: 22 new tests covering:readworking from the text alone, with no files on disk;max_width, and its default of 100;message, and both kinds of contradictory limits;<-in the example fails it.make check-deslagon this repo: it failed on the 16-entry AGENTS.md and passes after the trimReferences
max_entriescaps how far the layout can grow, but it does not stop descriptions from turning into lists.