Skip to content

feat: show the settings a file gets - #40

Merged
webern merged 1 commit into
mainfrom
m/explain
Sep 26, 2026
Merged

webern merged 1 commit into
mainfrom
m/explain

Conversation

@webern

@webern webern commented Sep 26, 2026 •

Copy link
Copy Markdown
Owner

Human Summary

Cool idea from Vale that would allow one to see what settings are in-effect for a given file.

Summary

Adds deslag explain <PATH>.... It runs from the repo root like deslag check and takes --config-path the same way. For each path it prints the config in use, whether [md] selects the file, the overrides that match it (by position in the config, in the order they merge), any max_size_bytes in the file's frontmatter, and the settings every lint ends up with, defaults filled in.

Each path gets one TOML document: the explanation is in comments, the settings are tables, and a lint that is off is a # <lint>: off comment. It is TOML whatever language the config is written in. From this repo:

$ deslag explain .agents/skills/deslag-commit/SKILL.md README.md
# .agents/skills/deslag-commit/SKILL.md
# config: .agents/deslag.toml
# selected by [md]: yes
# overrides, in the order they merge:
#   override 2: globs = ["/.agents/skills/**/*.md"]

[banned_chars.groups]
arrows = true
box_drawing = true
bullets = true
checks = true
dashes = true
ellipsis = true
emoji = true
invisible = true
math = true
quotes = true
section = true
spaces = true

[density]
max_item_chars = 300
max_paragraph_chars = 500

[max_emphasis]
free_spans = 2
max_percent = 1.0

[max_size_bytes]
value = 5000

# repo_layout: off

# README.md
# config: .agents/deslag.toml
# selected by [md]: no

How it works:

  • MdLints and each lint's settings now derive Serialize. MdLints::toml_tables serializes them, and takes the list of lints and their defaults from the config's JSON schema, the same schemars defaults that deslag instructions config-schema prints. The explain code never names a lint.
  • MdConfig::overrides_for returns the matching overrides with their positions, in merge order. lints_for now uses it, so explain and check cannot disagree on the order.
  • A path is named the way the walk names it, so ./, .., absolute paths and links all work. A path that does not exist, is not a file, or is outside the repo is a new Error::Explain. It goes out through run()'s Err like check's errors, so the exit code from Exit with 2 when deslag cannot run #28 applies to it. Every path is checked before anything is printed.
  • Which override set each field is not shown, as the issue allows.

Things to look at:

  • The frontmatter budget is shown as the last layer, because check uses it and it beats the config. The issue listed only the [md] table and the overrides.
  • Deriving Serialize makes schemars publish a default for every #[serde(default)] field. So that it is not a table of nulls, MdLints skips unset lints and Groups skips unset groups when serialized. The published schema gains exactly three "default": {} entries (md.lints, md.overrides[].lints, banned_chars.groups) and nothing else changes. A new test fails if a default in the schema holds a null.
  • A setting that TOML cannot hold, an integer above i64::MAX in a JSON or YAML config, is an error rather than a panic.
  • The as-built doc describes the command and shrinks from 16,247 to 16,233 bytes. To make room, the list of config stems and the lists of extensions, checks and published files give way to the names that hold them, and a few paragraphs are tighter.

For a new lint, such as the one in #32, to show up in explain:

  • derive Serialize on its settings (it will not compile otherwise, since MdLints derives it);
  • give its field in MdLints #[serde(default, skip_serializing_if = "Option::is_none")] like the others, or no_default_in_the_schema_is_a_table_of_nulls fails;
  • give each field that has a default #[schemars(extend("default" = ...))], as the other lints do, and explain fills it in;
  • add the lint's line to the pinned output in tests/explain.rs.

Testing

  • make ci: exit 0
  • tests/explain.rs: the four paths the issue names, pinned whole, under a config with two overlapping overrides; the same config in YAML and JSON prints the same; --config-path; a frontmatter budget; ./, .. and absolute paths; a missing path, a directory and a file outside the repo; no path; no default in the schema holding a null
  • Diffed deslag instructions config-schema against main: only the three "default": {} entries
  • Checked by hand that a multi-line message prints as valid TOML

References

@webern webern added enhancement New feature or request area/config Has to do with deslag configuration (deslag.yaml, etc.) area/cli Deals with the command line interface. ai Primarily authored by AI (whether PR, Issue, Whatever) labels Sep 26, 2026
`deslag explain <PATH>...` prints, for each file, the config in use,
whether [md] selects the file, the overrides that match it in the
order they merge, any budget in its frontmatter, and the settings
every lint ends up with. The settings are printed as TOML whatever
language the config is in, with each default filled in from the
config's JSON schema. A lint that is off is a comment.

The lint settings now derive Serialize. An unset lint or group is
left out when serialized, so the schema's default for a lints or
groups table is an empty table rather than a table of nulls.

MdConfig::overrides_for now holds the merge order that lints_for
worked out on its own, so explain and check agree on it.

A path that does not exist, is not a file, or is outside the repo is
an error.
@webern
webern merged commit a4c5be6 into main Sep 26, 2026
2 checks passed
@webern
webern deleted the m/explain branch September 26, 2026 14:24
@webern webern mentioned this pull request Sep 26, 2026
9 tasks done
webern added a commit that referenced this pull request Sep 26, 2026
## Human Summary

Seems like a pretty good feature that could go a long way toward solving
pet peeves.

## Summary

Adds `banned_phrases`, a lint that fails a Markdown file whose prose
holds a phrase the config lists. `ban` maps each phrase to the advice
its report shows, and `allow` exempts a longer phrase that holds a
banned one. deslag ships no phrases: with nothing in `ban`, the lint
checks nothing. `.agents/deslag.toml` is unchanged.

This config and report are the `broken` case in
`tests/cases/banned_phrases/`:

```toml
[md.lints.banned_phrases.ban]
"it's worth noting" = ""
"delve into" = "say what you found instead"
"in today's fast-paced world" = ""
"leverage" = "write `use`"
```

```
ERROR: deslag detected banned phrases!

README.md has 6 banned phrases.

This repo keeps these phrases out of its Markdown. Do what the advice with each one says, or reword the sentence; it often reads better with the phrase simply gone.

Do not hide a phrase in a code span or HTML, and do not change the config to get past this check. Only a human can tell you to do that, and I am a linter, not a human.

The phrases, and what to do about each:
  line 1: "Delve Into"; say what you found instead
  line 3: "In today's fast-paced world"; delete it
  line 3: "It's worth noting"; delete it
  line 4: "it's worth noting"; delete it
  line 6: "leverage"; write `use`
  line 11: "Leverage"; write `use`

deslag: 1 of 1 Markdown files with banned phrases.
```

The second match on line 3 runs onto line 4, and the one on line 4 is
written `**it's worth** noting`.

### How it matches

There are no regular expressions. A new `Token::split` in
`src/document/tokens.rs` splits a phrase with the same code that splits
a stretch of prose, so the config and the document agree on what a word
is. The phrase then matches the same tokens in one block, compared by
`Token::folded`: lower case, with a curly apostrophe made straight.
Whitespace, line breaks and formatting between tokens don't count. A
code span, HTML, an image, a URL or a footnote reference is a token no
phrase can hold, so it breaks a match. Phrases are indexed by their
first token, so each token of a file costs one lookup.

### Choices the issue left open

- **A phrase is plain text, not Markdown.** `Token::split` runs the
tokenizer on the raw string instead of parsing it with
`Document::markdown`. So `#` or `*` in a phrase stays a token instead of
turning into a heading or emphasis, and the phrase is compared with what
the file renders: `AT&amp;T rocks` in a file matches `AT&T rocks` in the
config.
- **Symbols match like words and marks.** The issue names word, number
and punctuation tokens. Without symbols (`+`, `>`, emoji), `C++ rules`
would pass validation and never match.
- **"No words" means no word and no number**, so `110%` is a valid
phrase.
- **Overlap is leftmost, then longest.** Scanning left to right, the
first match wins, and of matches that start at one token, the longest.
With `worth noting` and `noting that` banned, "Worth noting that"
reports `Worth noting` only.
- **`allow` is applied before overlap is settled.** A match inside an
allowed match is discarded first, so an allowed phrase hides only what
lies inside it. With `worth noting` and `noting that` banned and `well
worth noting` allowed, "well worth noting that" reports `noting that`.
- **A phrase in both `ban` and `allow` is an error within one table
only**, because `invalid()` runs per table. That lets an override allow
a phrase the section bans, and after the merge `allow` wins; the `allow`
case pins this. The check compares folded tokens, so `It's worth noting`
and `it's worth NOTING` count as one phrase.
- **An override replaces `ban` and `allow` whole**, as with
`banned_chars`.
- **The quote** is each matched token as written, with a space where
whitespace parts two of them and the markup between them left out.
Quoting the raw byte range gave `"it's** worth noting"`, and `"It's
worth > noting"` inside a block quote.
- **The advice is printed as written**, and an empty one prints `delete
it`. It is advice, not a replacement, so the report does not put it in a
`write ...` the way `banned_chars` does.
- **The guide's example config** turns the lint on with an empty table,
because its test requires every lint. The bullet tells the agent to ask
the human which phrases to ban.

### Corpus numbers

These are 22 phrases widely cited as LLM tells, run through the library
over `tests/corpus/{human,llm,mixed}` by a throwaway test that is not
committed:

`delve into`, `delves into`, `it's worth noting`, `it is worth noting`,
`it's important to note`, `in today's fast-paced world`, `in the realm
of`, `a testament to`, `tapestry`, `navigate the complexities`, `plays a
crucial role`, `seamlessly`, `harness the power of`, `unlock the power
of`, `game-changer`, `cutting-edge`, `ever-evolving`, `in conclusion`,
`embark on`, `let's dive in`, `deep dive`, `whether you're`

| label | files | flagged | rate | matches |
|---|---|---|---|---|
| human | 400 | 1 | 0.25% | 1 |
| llm | 400 | 5 | 1.25% | 7 |
| mixed | 400 | 13 | 3.25% | 20 |

The list barely fires on any label, so it does not separate them in any
useful way. Only 7 of the 22 phrases matched at all, mostly `seamlessly`
(7 files) and `whether you're` (5 files, one of them human). 19 flagged
files out of 1,200 is too few to tell the labels apart. The chatbot
phrases people cite are rare in the Markdown that agents write in
repositories.

For comparison, 12 single words that are also often cited
(`comprehensive`, `robust`, `seamless`, `leverage`, `crucial`,
`essential`, `ensure`, `enhance`, `streamline`, `utilize`, `powerful`,
`effortlessly`) flag human 55 (13.8%), llm 67 (16.8%) and mixed 142
(35.5%). They fire far more but hardly separate human from llm: `ensure`
alone flags 33 human files and 34 llm ones. `comprehensive` (4 / 14 / 25
files) and `leverage` (2 / 9 / 14) lean llm. Under both lists mixed
files are flagged most, and I did not correct for file length. None of
this makes a case for shipping a default list.

### Also in this PR

Fixes found while checking the README, in three commits of their own:

- **The README holds only what stays true.** It listed the lints,
spelled out each one's rules and quoted corpus counts, so it went stale
with every lint PR; one count was already wrong (the density defaults
fail 92 of the 400 agent-written files, not 84). It now says what deslag
is, how to install, set up and run it, and the config's general shape,
and points to `deslag instructions config-schema`, `deslag
instructions`, `deslag explain` and the as-built doc for the details.
This is also why the PR adds no README section for `banned_phrases`.
- **Install.** `cargo install deslag` fails: the crate is not on
crates.io. The README installs from a checkout, and the setup guide
tells the agent to ask the human how CI should install deslag instead of
writing `cargo install deslag --locked`. `deslag --help` and the crate
description said deslag only checks the byte budget; they now describe
the linter.
- **`deslag explain` on a file check skips.** `check` never reads a
git-ignored file or one inside `.git`, but `explain` printed its
settings as if `check` used them. It now prints `# ignored: yes, so
deslag check never reads it` and stops, as it does for a file `[md]`
does not select.
- **`every_lint_has_a_failing_case`** counted any case with a non-empty
`.stderr` file, so a case where deslag cannot run (exit 2) passed for a
case where the lint fails a file. It now counts only cases that exit 1.

## Testing

- [x] `make ci`: exit 0
- [x] `tests/phrases.rs`: case, curly apostrophes, soft and hard line
breaks, formatting, code spans, HTML, images, URLs, footnotes, two
blocks, blocks that are not read, `allow`, overlap, merging, each
validation error, and `Token::split` agreeing with `Document::markdown`
on sample text
- [x] `tests/cases/banned_phrases/`: `clean`, `broken`, `allow` (with an
override that allows a phrase the section bans), `custom_message`, and
`ban_and_allow` (an invalid config)
- [x] `deslag instructions config-schema` shows `BannedPhrases`
- [x] A throwaway corpus probe, not committed: every run of three prose
tokens in the corpus's prose blocks (319,722 of them), joined into a
phrase, split back into the same tokens and was found by the lint. No
tokenizer bug turned up.
- [x] `tests/explain.rs`: a file under a git-ignored directory, and one
inside `.git`, each say `# ignored: yes` and nothing more; without the
fix they print full settings
- [x] `tests/cases.rs`: a case with a `.exit` file holding 2 does not
count as failing a file; with the old rule it did
- [x] The README's example config, run with `deslag check` and `deslag
explain` in a scratch repo, and `cargo install --locked --path .` into a
scratch directory
- [x] `docs/design/deslag.asbuilt.md` is 16,379 bytes of its 16,384,
from 16,363 on `main`

## Notes

- The as-built doc's intro and its config paragraph now give examples
instead of listing every lint and every invalid setting, so a new lint
doesn't have to extend them.
- Rebased after #37 to #40 merged. `ban_and_allow` is a config error, so
it has a `.exit` file holding `2`, as #39 asks of such cases.
`BannedPhrases` derives `Serialize` like the other lints, so `deslag
explain` (#40) shows it, and explain's pinned output gains a `#
banned_phrases: off` line.

## References

- Closes #32
- Related to #34, which ruled out regular expressions over raw text;
this matches tokens
- Related to #39 and #40
- Related to #16, #18 (the README)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai Primarily authored by AI (whether PR, Issue, Whatever) area/cli Deals with the command line interface. area/config Has to do with deslag configuration (deslag.yaml, etc.) enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a command that shows the settings a file gets

1 participant