Skip to content

feat: fail walls of text - #23

Merged
webern merged 1 commit into
m/banned-charsfrom
m/density
Sep 24, 2026
Merged

webern merged 1 commit into
m/banned-charsfrom
m/density

Conversation

@webern

@webern webern commented Sep 24, 2026 •

Copy link
Copy Markdown
Owner

Human Summary

We'll see how well this works, but the agent did a nice job with it. I want my Markdown files to breathe, and that's what we are going for here.

Summary

Adds the density lint. It fails a Markdown file that holds a wall of text: a paragraph longer than max_paragraph_chars (default 600), or a list item longer than max_item_chars (default 300). The report lists each dense block with its line and length, and the advice tells the agent to split paragraphs, cut, and use short lists where the text walks through steps.

[md.lints.density]          # the table alone turns it on
max_paragraph_chars = 600
max_item_chars = 300

Like every other lint, it is off until the config has a density table. Each limit defaults on its own, an override sets only the limits it names, a limit of 0 is a config error, and message replaces the advice with {path}, {max_paragraph_chars} and {max_item_chars}.

What is measured

A block is a paragraph, or the text of a tight list item. Its length is the characters a reader sees: text, code spans, and one per line break. Markup, link targets, HTML tags and image alt text are not counted, so a paragraph full of links is not punished for its URLs. Headings, tables, code blocks and frontmatter are not blocks. A paragraph inside a loose list item is held to the item limit, because a long item is the same problem whether or not it has a blank line inside it. A blank line ends a paragraph; a line break does not, and the advice says so, since an agent's first move is often to add line breaks.

Why not the ratio in the issue

The issue asks for a ratio of non-whitespace to whitespace over the whole file. I measured it on the 1200 corpus fixtures, bucketed by each file's longest paragraph or item:

Longest block (chars) Files Ratio p10 p50 p90
0-200 262 4.0 5.2 7.9
200-400 457 4.2 5.5 7.6
400-800 372 4.2 5.4 7.5
800+ 109 4.0 5.6 9.0

The ratio barely moves between files of short paragraphs and files with walls of text. Most whitespace is the single space between words, so the ratio stays close to the average word length whatever the layout. A limit per block measures what the issue is after and tells the agent exactly which paragraph to fix.

The defaults

The defaults are loose ceilings that most files pass. Under them, the corpus fails:

Corpus Paragraph > 600 Item > 300 Either
human (400) 25 31 53
llm (400) 31 69 84
mixed (400) 40 101 122

Long list items separate agent text from human text better than long paragraphs do. Unlike banned_chars, this lint is not a detector; it is a readability limit, and a repo that wants terse agents should tighten it. This repo turns it on for AGENTS.md and the skills with 500 per paragraph.

This PR is stacked on #22.

Testing

  • make ci: exit 0
  • tests/density.rs: what a block is, what is counted, chars not bytes, hidden blocks, list items, quotes and footnotes, the defaults at and over the limits, one limit at a time, zero refused, override merge
  • tests/cases/density/: broken, clean, limits in an override, custom message, zero limit
  • tests/corpus.rs: every block starts on a line of text, and the binary reports exactly the blocks the library finds across the corpus

References

@webern webern added enhancement New feature or request area/lint Deals with the linting algorithms themselves, how they work. labels Sep 24, 2026
@webern
webern added this pull request to stack #24 September 24, 2026 15:01
@webern webern mentioned this pull request Sep 24, 2026
4 tasks done
Add the density lint. A file fails when a paragraph is longer than
max_paragraph_chars (default 600) or a list item is longer than
max_item_chars (default 300). The report lists each one with its
line and length.

Length is the characters a reader sees: text, code spans, and one
for each line break. Markup, link targets, HTML and image text are
not counted. Headings, tables, code blocks and frontmatter are not
checked. A paragraph inside a list item is held to the item limit.

Issue #10 asked for a whitespace ratio over the whole file. The
corpus shows the ratio barely moves between a file of short
paragraphs and a wall of text, so the limit is per block instead.
The defaults are loose: they fail 53 of 400 human fixtures and 84 of
400 llm ones.

Turn the lint on for this repo's AGENTS.md and skills, with 500
characters per paragraph.
@webern
webern merged commit 19874b1 into main Sep 24, 2026
2 checks passed
@webern
webern deleted the m/density branch September 24, 2026 17:39
webern added a commit that referenced this pull request Sep 24, 2026
## Human Summary

The idea here is that the agent itself can use the `deslag instructions`
command to understand how to set up a repo with deslag.

## Summary

Adds `deslag instructions`, a command whose output is written for an
agent rather than a person. Onboarding becomes: `cargo install deslag`,
then tell your agent to run `deslag instructions` and follow them. The
README says so in two lines.

This one is a command, not a lint, so there is nothing to configure. The
configurability work here is in the schema.

### The guide

`deslag instructions` prints a Markdown guide to standard output. It
walks the agent through:

1. finding the config, or choosing where to put one;
2. choosing which files to lint, and asking before linting files a human
writes, such as README.md;
3. writing a config, from an example that turns on every lint;
4. running `deslag check`, then proposing limits to the human with what
each would fail;
5. fixing the files an agent wrote, and asking about the ones a human
wrote;
6. wiring `deslag check` into CI;
7. if it suits the project and the human agrees, adding a note about
`deslag check` to AGENTS.md.

The rule running through it: the human owns the limits. The agent
proposes them and never raises one, or adds an override or a frontmatter
budget, just to get past a check.

The guide lives in `src/instructions/guide.md` and is compiled in with
`include_str!`, so `Cargo.toml`'s `include` now takes `/src/**/*.md`
too. The config paths, extensions, schema version and deslag version are
filled in from the code. This repo's own deslag config lints the guide,
with a 5000 byte budget, so it cannot bloat.

### The schema

`deslag instructions config-schema` prints the JSON schema of the
config, draft 7. It comes from `schemars` (a new dependency, 1.2.2,
which brings in 5 small crates) deriving `JsonSchema` on the same types
the config is read into, so a new lint or setting shows up in the schema
without anyone remembering to add it. It serves TOML and YAML configs
too, and editors can use it: taplo for TOML, yaml-language-server for
YAML.

What the derive does not know, I added by hand:

- the real defaults, taken from the code's constants (600 and 300 for
`density`, the `repo_layout` defaults, `["*.md"]` for `globs`), instead
of the `null` that `#[serde(default)]` produces;
- each `banned_chars` group's default, which a test ties to the `GROUPS`
table;
- the ranges deslag enforces: `max_percent` 0 to 100, `density` limits
at least 1, `schema_version` at most the version this build reads.

Doc comments on the config types become the schema's descriptions, so I
removed the rustdoc links and the "On by default" wording that the
`default` keyword now carries.

### Room for #17

`instructions` takes an optional topic as a subcommand. #17's `deslag
instructions --from 2 --to 6` can be added as flags on `instructions`
without changing what exists. I have not built any of it.

### A small fix along the way

`deslag instructions | head` panicked on the closed pipe. The command
now writes to stdout and treats a broken pipe as success, since agents
pipe output into `head` all the time.

This PR is stacked on #23.

## Testing

- [x] `make ci`: exit 0
- [x] `make check-publish`: exit 0, and the package lists
`src/instructions/guide.md`
- [x] `tests/instructions.rs`, 9 tests:
  - the command prints the guide, and `config-schema` prints the schema;
  - no placeholder is left in the guide, and it names every lint;
- the example config names every lint, passes `deslag check`, and fits
the schema;
  - every config in `tests/cases` that deslag accepts fits the schema;
  - nine configs deslag refuses are refused by the schema too;
  - every table in the schema refuses unknown keys;
  - each group's default in the schema matches `GROUPS`.
- [x] Mutations, each caught by a test:
  - dropping a range;
  - flipping a group default;
  - loosening `max_percent`;
  - dropping the schema version maximum;
  - dropping a lint from the guide or the example;
  - leaving a placeholder unfilled.

## References

- Closes #13
- Related to #17
- Stacked on #23
webern added a commit that referenced this pull request Sep 27, 2026
## Summary

`docs/design/deslag.asbuilt.md` describes the code as it is. At a2d8ea1
it is 16378 bytes of its 16384 `max_size_bytes`, and it has been within
180 bytes of that budget since #23 (16352). Each of #44, #45 and #47
made room for its new paragraphs by cutting others, and #45 moved the
corpus text out to `corpus.asbuilt.md`. The `deslag-design-docs` skill
says a budget is not raised without the owner, so every change to the
code has had to squeeze the doc.

The budget was also kept by hand: `.agents/deslag.toml` did not select
the doc. Selected at a2d8ea1, it fails `max_emphasis` (20 bold spans,
1.24% of its prose) and `density` (8 paragraphs over 500 characters).

This PR splits the doc the way `corpus.asbuilt.md` already is: one
as-built doc per subsystem, each with its own budget, and every one of
them linted.

- `deslag.asbuilt.md` is now the overview: what deslag is, a run, the
modules at directory level and what calls what, an index of the
subsystem docs, the command line and exit codes, other files, the tests
and the build. Its budget drops from 16384 to 8192, so it cannot grow
back into the place every detail goes.
- `config.asbuilt.md`: the config, glob patterns, the walk and `deslag
explain`.
- `document.asbuilt.md`: the `Document` and frontmatter. It is named for
`src/document/`, the module it holds.
- `lints.asbuilt.md`: checking, marks, one section per lint in
`Lint::ALL` order, reports and `--format`. A new lint is one new
section.

Each subsystem doc opens with its entry points and callers, then its
`src/` tree, then one section per concern. `subsystems:` in each doc's
frontmatter holds `src/` module names, each in exactly one doc: the one
with its detail.

| Doc | Bytes | Budget | `subsystems:` |
|---|---|---|---|
| `deslag.asbuilt.md` | 6786 | 8192 (was 16384) | `cli`, `instructions`
|
| `config.asbuilt.md` | 3889 | 5000 | `config`, `glob`, `explain` |
| `document.asbuilt.md` | 2194 | 3000 | `document`, `parse` |
| `lints.asbuilt.md` | 5884 | 7500 | `lint`, `output` |
| `corpus.asbuilt.md` | 5998 | 8192 | `corpus` (unchanged) |

### Where each old section went

| Section at a2d8ea1 | Now |
|---|---|
| intro, A run | `deslag.asbuilt.md`, as they were |
| Modules | `deslag.asbuilt.md` keeps the tree at directory level and
the paragraph on what calls what; each subsystem doc takes its
file-level lines |
| The document | `document.asbuilt.md`: Blocks; Tokens, sentences and
locations |
| Where a file's budget comes from | `lints.asbuilt.md`: max_size_bytes
|
| The config | `config.asbuilt.md`: The config, and Glob patterns for
the `glob::Pattern` paragraph |
| Frontmatter | `document.asbuilt.md`: Frontmatter |
| Explaining a file | `config.asbuilt.md`: Explaining a file |
| Walking the repo | `config.asbuilt.md`: Walking the repo |
| Checking and reporting | `lints.asbuilt.md`: Checking, Marks, a
section per lint, Reports, --format |
| The command line, Other files, Tests, Build | `deslag.asbuilt.md`, as
they were |

### Commits

1. `docs: split the as-built doc by subsystem`: the text moves as it
was. New text is limited to each subsystem doc's opening sentences, the
overview's index, the section headings, and short descriptions for the
directories in the overview's tree, worded after the layout in
`AGENTS.md`. `README.md` says the overview indexes the subsystem docs.
2. `docs: fix the lint findings in the as-built docs`: 8 paragraphs
split at a sentence end, and 13 of 20 bold spans un-bolded. Each doc
keeps its first two; the sentence that defines each of the others stays.
No sentence is reworded.
3. `docs: correct the as-built docs against the code`: an ellipsis,
U+2026, also ends a sentence (`src/document/sentences.rs:113`); `make
clean` also runs `cargo clean` (`Makefile:98-99`); the trees now name
`parse/mod.rs`, `ACKNOWLEDGEMENTS.md` and `.agents/skills/`; `explain`
is in `subsystems:`, where no doc named it (`src/lib.rs:27`).
4. `test: lint every as-built doc and its subsystems`:
- `.agents/deslag.toml` selects `/docs/design/*.asbuilt.md` in place of
`corpus.asbuilt.md` alone. The glob does not select `deslag.desired.md`,
which is written by hand and stays unlinted, and topic docs stay listed
one by one.
- A selected file with no budget is counted but never size-checked
(`src/lint/max_size_bytes.rs:35-38`). An override on the same glob with
`value = 4096` closes that: a frontmatter budget wins over it, and a doc
that declares none fails at 4 KB.
- `tests/asbuilt.rs` fails when a module under `src/` is named in no
as-built doc's `subsystems:`, or in more than one, so a new module gets
its doc on purpose. It finds the frontmatter with `Document` and reads
it with `serde-saphyr`; no new dependency.

### Nothing lost in the move

A script outside the repo cuts the a2d8ea1 doc into 177 units (each
sentence, code line and heading) and 166 backticked names, and looks for
each in the four new docs, with whitespace and bold markers ignored.
After each commit:

| After commit | Units missing | Names missing |
|---|---|---|
| 1 | 4 | 0 |
| 2 | 4 | 0 |
| 3 | 6 | 0 |
| 4 | 6 | 0 |

The six, each on purpose:

- Three headings, `The document`, `Where a file's budget comes from` and
`Checking and reporting`, replaced by the sections in the table above.
- "Most specific first: the `max_size_bytes` key ..." now opens "A
file's budget comes from, most specific first: ...". Its heading used to
say what it was about; the section is now named for the lint.
- The sentence rule now names the ellipsis (commit 3).
- "`make clean` removes both directories" now adds "and runs `cargo
clean`" (commit 3).

The script proves each unit is somewhere, not that it is in the right
place, so the trees were read by eye.

### Left as it was

- The overview's paragraph on what calls what does not say that
`explain` calls `config`, `glob` and `parse` too. It is not wrong, so it
was not rewritten.
- The tests stay in the overview; no doc owns them yet.
- `corpus.asbuilt.md`, `corpus.md` and their lines in
`.agents/deslag.toml` are untouched; the glob now selects
`corpus.asbuilt.md` in place of its own line.

## Testing

- [x] `make ci`: exit 0
- [x] `deslag check` on the repo: exit 0 with all five as-built docs
selected; `deslag explain docs/design/deslag.desired.md` says it is not
selected.
- [x] A 5149-byte `docs/design/nofm.asbuilt.md` with no frontmatter
fails at 4096 bytes; `deslag explain` shows the frontmatter budget
winning over the override for `lints.asbuilt.md`. File removed after.
- [x] `tests/asbuilt.rs` fails with `parse: in no doc` when `parse` is
dropped from `document.asbuilt.md`, and with `lint: in
corpus.asbuilt.md, lints.asbuilt.md` when `lint` is added to
`corpus.asbuilt.md`, which also shows it reads a YAML block list. Both
reverted.
- [x] The residue script after each commit, as above.

## References

- No issue. Related to #23, #44, #45 and #47, each of which squeezed the
old doc.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/lint Deals with the linting algorithms themselves, how they work. enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

White space density lint.

1 participant