Repository navigation
feat: add deslag fix for banned characters - #51
Merged
Merged
Conversation
explain turned a path given on the command line into a file in the repo. fix needs the same lookup, so it moves to glob::find, which says why a path names no file in the repo and leaves the error type to the caller.
An Edit replaces a range of a document's source. Document::apply makes an edit only when it can show that the file reads as before, apart from the text the edit changes: 1. The edit lies in prose as written: not in frontmatter, HTML, code, an entity, an escape or a URL. 2. It covers whole grapheme clusters, so it leaves no variation selector behind. 3. Its replacement holds no control character. 4. Reading the result again gives the same blocks, spans, line breaks and pieces, with the same text apart from the edits. The edits are tried all at once, then one at a time when that fails. Each edit it refuses gets a Refusal that says why. A document now keeps the function that read its first layer, so it can read an edited source the same way. It is no longer PartialEq, since comparing function pointers says nothing useful.
deslag fix makes the edits a lint names where the document proves them safe, then prints and exits as deslag check does. Only banned_chars names edits, and only where the replacement is exact: set for that character alone, with no letter or digit in it. A word such as "yes", or the default for a range of characters, is a guess at meaning, so it is left for the writer with the reason. Fix works in passes until one makes no edit, works out every file before it writes any, and writes through a temp file and a rename. It keeps a file's permissions, byte order mark and line endings. A file that is not UTF-8 is skipped. --dry-run writes nothing, and a path that deslag check would not read is an error. A ban value with a control character is now an invalid setting, and one that holds a character the file's settings ban is a contradiction. Both exit 2 for check too. Each case now runs in a fresh copy, so a case can run fix.
The overview gains the fix module, its subcommand and its tests. The lints doc says which lints name edits and why, the document doc describes Document::apply, and the config doc adds glob::find and the new checks on ban values.
6 tasks done
webern
added a commit
that referenced
this pull request
Sep 27, 2026
## Summary This grows the corpus's big tier from 1,200 fixtures to 21,891 live ones. It adds a second batch, `2026-09-27-02`, with 21,075 fixtures from a new harvest: 11,473 `human`, 9,003 `llm` and 599 `mixed`. The same batch excludes the 384 fixtures of the first batch that `recheck` (#46) no longer proves. The tree is resampled so each label still holds 400. To get there, `collect.py` changed in five places: - `discover` is now a list of named samplers. Each says whether it needs a `gh` login and skips itself without one. The new ones search Sourcegraph for agent files and for topics, some outside software, and search GitHub commits for the marks agents write. - `harvest` asks GitHub's GraphQL API about every candidate first, 100 at a time, so forks, bad licences and huge histories are never cloned. It clones in parallel, reads each history in one pass, checks a nearer `LICENSE` than the root one, logs failures and retries them on the next run, and asks GitHub about squash-merges as `recheck` does. It keeps up to 50 files of each label from a repository, at random, and always keeps a `mixed` file's `human` twin. `--limit` and `--deadline` bound a run. - `stage` is new, and it is the one writer of sidecars. It writes version 3 sidecars and the batch's `repos.jsonl`, the ledger of every repository the harvest tried. - `pack` checks that every `before` names a live `human` twin. - `select` samples the tree from the big tier, keeps what is still live, and refills each label. Sidecar version 3 adds the raw evidence behind a label: each mark as written (`text`, `tool`, `kind`, `place`, `commits`), each marked commit's change to the file with its blob ids (`edits`), `truncated`, and the committer dates. A `mixed` sidecar may add `before`, which names its `human` twin (the same file at the last commit before 2022) and the commits between that are not an agent's. The loaders accept versions 2 and 3, check the ledger against the manifest, and check that every `before` names a live `human` fixture. The big tier now holds files of 128KB at most; the tree stays at 64KB. `docs/design/corpus.md` has a new Register section (there is no `baseline` label; register is a facet of `human`, tagged `sg-register:`), the twin rule, and the per-repository cap. `docs/design/corpus.asbuilt.md` and `scripts/blobstore/blobs.md` describe the new batch, the ledger and the discovery samplers. `blobs.md` now gives the image a budget of 250MB unpacked. ## Discovery `discover` found 70,418 distinct repositories, 67,878 of them on GitHub. A repository found by several samplers counts once in the total and once for each sampler below. | Sampler | Token | Repositories | Seconds | Notes | | --- | --- | --- | --- | --- | | `sourcegraph-agent-files` | no | 31,390 | about 900 | 8 patterns: `CLAUDE.md`, `AGENTS.md`, `GEMINI.md`, `.github/copilot-instructions.md`, `.claude/` commands, agents and skills, `.cursor/rules/`, `.kiro/`, `.windsurfrules` | | `sourcegraph-topics` | no | 21,510 software, 4,510 register | 11,320 | about a minute per query | | `github-commit-marks` | yes | 11,695 | 2,215 | 18 searches, each on 20 random days | | `crates.io` | no | 2,645 | 113 | by downloads | | `gitlab-stars` | no | 1,000 | 16 | | | `huggingface` | no | 1,000 | 3 | | | `codeberg-stars` | no | 497 | 59 | | | `npm` | no | 244 | 33 | | Limits: - Sourcegraph searches only the repositories it indexes, a slice of public GitHub, and each query asks only for repositories with a permissive licence file at the root. A topic query takes the first 300 or 500 results. It needs no token, which is why it leads. - GitHub commit search returns at most 1,000 results per query, so each search is cut into single days. Its secondary rate limit fired at 3 seconds between searches, so the pace is now 6 seconds. It interleaves the searches by day, in random order, so a run cut short still covers every tool. - The topic search is slow and coarse. The register topics (books, courses, essays, law, recipes, wikis, curated lists and the like) gave 337 repositories that the harvest tried. - GitLab, Codeberg and Hugging Face gave almost nothing: under one `human` file per repository, and no `llm`. - crates.io failed at page 215 with HTTP 400, so it now reads pages under 200. ## Pilot 200 repositories in `sources` order took 127 seconds. 39 more were skipped on GitHub's metadata before any clone. They gave 724 `human`, 116 `llm` and 13 `mixed` files, 11 of the `mixed` with their twin. - Repositories with agent files took 8.6 seconds each and gave 6.0 `human`, 2.9 `llm` and 0.38 `mixed` each. - 24 of 30 commit-search repositories were skipped for having no licence GitHub recognises. - Topic repositories gave 8.6 `human` files each; Hugging Face nearly none. - A fixture came to about 6.2KB of Markdown and 2.5KB of sidecar. The pilot showed that time would not bind the run; bytes would. At the rate the whole run went, 4 to 6 hours of harvest would have come to 350 to 500MB, well past the 250MB budget. ## The run The harvest ran in legs, to steer toward the rarer sources, and one leg was a retry: | Leg | Order and filter | Limit | Seconds | human | llm | mixed | | --- | --- | --- | --- | --- | --- | --- | | pilot | sources | 200 | 127 | 724 | 116 | 13 | | 1 | priority | 500 | 1,019 | 5,726 | 1,234 | 343 | | 2 | priority | 250 | 441 | 2,720 | 518 | 79 | | 3 | priority, commit search for every tool but Claude Code | 1,000 | 621 | 905 | 3,586 | 74 | | 3b | the same, the 309 that failed in leg 3 | 309 | 5,072 | 673 | 3,418 | 108 | | 4 | priority, register topics | 150 | 1,056 | 432 | 619 | 14 | | 5 | sources, register topics | 150 | 165 | 631 | 284 | 7 | | all | | | 8,501 | 11,811 | 9,775 | 638 | `priority` order takes first the repositories an agent was found in that began before 2022, since only they can give `mixed` files; then the other agent repositories; then the rest. Within each, the sources take turns, a repository standing for the rarest source that found it. Discovery ran for about 4 hours alongside the legs. Leg 3b was slow because its repositories lean on squash-merges, and the harvest asks GitHub about those at most 4,800 times an hour, under its limit. What the ledger says about the 3,232 repositories tried: - 2,238 harvested, 989 skipped on GitHub's metadata (801 with no licence GitHub recognises, 67 GPL-3.0, 27 AGPL-3.0, and so on), 4 gone, and 1 with 60,361 commits, past the limit. - 4 more failed on network errors and are left for the next run. - 1,388 gave a fixture to the batch. - Files that qualified: 59,724 `human`, 64,039 `llm` and 739 `mixed`. Kept: 11,473, 9,003 and 599. Past the cap of 50, 3,938 `llm` files were not asked about. - Dropped while reading: 12,692 whose text may be older than their history (8,565 of those from one repository, `tmorin/plantuml-libs`), 2,879 under a nearer licence that is not allowed, and 1,792 whose bytes a merge commit changed. `stage` then left out 1,022 files whose bytes another fixture already has, 68 whose origin the first batch holds, and 59 over 128KB. ### The batch | | human | llm | mixed | | --- | --- | --- | --- | | Fixtures | 11,473 | 9,003 | 599 | | Repositories | 873 | 677 | 238 | - 474 `mixed` fixtures have their `human` twin. 6 lost it in `stage`, where the twin was left out, and 119 never had one: no `human` revision of the file qualified at the cutoff. For most of those, the repository had no licence GitHub recognises at the cutoff. - `llm` by tool: Claude Code 5,254, Copilot 1,516, Cursor 752, Codex 620, Amp 352, Devin 331, Jules 205, OpenHands 190, opencode 136, Kiro 77, Aider 48. Six tools have 300 or more. - `mixed` by tool: Claude Code 412, Copilot 116, Cursor 73, Codex 20, and 4 each for Jules, Amp and Devin. - By first source: agent files 13,592, commit search 6,165, software topics 680, register topics 263, crates.io 210, npm 127, GitLab 22, Codeberg 16. Counted by any source in the ledger, register repositories gave 1,545 `human`, 967 `llm` and 81 `mixed`. - 17,834 in English, 3,108 in another language, 133 with no prose to tell. - 21,037 from GitHub, 22 from GitLab, 16 from Codeberg. Bytes: 142,677,577 of Markdown and 203,442,958 in all (sidecars about 50MB, the manifest 9.3MB, the ledger 1.2MB). With the first batch the image is 215MB of its 250MB budget. ### Sizes and the cap Every file the harvest read has its size recorded, 22,261 in all: median 3,305 bytes, p90 15,551, p99 77,728, p99.9 367,767, largest 2,574,278. | Cap | Files over it | Their share of bytes | | --- | --- | --- | | 64KB | 1.31% | 27.1% | | 128KB | 0.43% | 17.6% | | 256KB | 0.17% | 11.9% | By label at 128KB: `human` 0.57% of files and 24.7% of bytes, `llm` 0.15% and 7.4%, `mixed` 2.18% and 37.4%. At 64KB, `mixed` would lose 5.3% of its files. So the cap is 128KB: it costs few files, and `mixed` files, which tend to be long, keep most of theirs. Many of the files over it are changelogs and link lists. ## Exclusions The batch excludes the 384 fixtures `recheck` found in #46: 204 `llm` and 180 `mixed`, none `human`. 339 of them rest on a squash of several commits, which cannot say who wrote one file. Most of the other 45 rest on a commit whose mark the rules of section 3 no longer accept, 2 on a bot's commit and 3 on text older than its history. Each line of `exclude.jsonl` gives the reason. ## The tree | | human | llm | mixed | | --- | --- | --- | --- | | Before | 400 | 400 | 400 | | Dropped | 0 | 204 | 180 | | Added | 0 | 204 | 180 | | After | 400 | 400 | 400 | `select` kept every fixture still live and filled from the big tier. `select --check` passes. The floors hold: 400 in each label (the floor is 350), 18 layouts (the floor is 10), and the character test's `llm >= 4 * human` at 248 against 4 * 57 = 228 (it was 241 before). The tree now holds 204 `llm` and 180 `mixed` sidecars at version 3, and 147 of those `mixed` name a twin. ## Golden files `make fix-golden` moved only `llm` and `mixed` lines. Every changed line is a fixture dropped or added; no fixture that stayed changed its measurement, and `core` and `human` did not move. | Lint | Fails before | Fails after | | --- | --- | --- | | `banned_chars` | 469 (llm 241, mixed 165) | 494 (llm 248, mixed 183) | | `banned_phrases` | 221 (llm 29, mixed 121) | 207 (llm 32, mixed 104) | | `density` | 279 (llm 92, mixed 126) | 294 (llm 104, mixed 129) | | `max_emphasis` | 491 (llm 230, mixed 173) | 499 (llm 244, mixed 167) | | `max_size_bytes` | 166 (llm 25, mixed 106) | 173 (llm 31, mixed 107) | | `repo_layout` | 2 (mixed 1) | 3 (mixed 2) | ## The `deslag fix` tally `tests/corpus.rs` pins what `deslag fix` does to the tree (#51), so the numbers are pinned again: | | Before | After | | --- | --- | --- | | Banned characters | 6,399 in 469 fixtures | 7,423 in 494 fixtures | | Fixed | 5,400 | 6,443 | | Fixtures fixed whole | 350 | 358 | | Left: replacement holds letters or digits | 737 | 732 | | Left: the edit changes how the file reads | 153 | 143 | | Left: in HTML | 71 | 56 | | Left: in frontmatter | 23 | 40 | | Left: default for a range of characters | 14 | 6 | | Left: in a URL | 1 | 1 | | Left: drawn as one with the character beside it | 0 | 2 | The last row is new: a corpus edit now reaches the grapheme check and is refused there. ## Precision A sample of the batch was checked against GitHub's own record, not the clone the harvest read. For each fixture: GitHub's list of the commits that touched the file up to the quoted commit, labelled again from their authors, committers and messages with the same rules and the same squash-merge questions; the bytes GitHub serves at that commit; for `human`, that no commit is late or marked; and for `llm`, that GitHub says the oldest commit added the file rather than renamed it. One fixture per repository in each stratum, 30 where there were 30 repositories. `human` is split by register, and `llm` and `mixed` by the kind of evidence: an agent's identity, a session trailer only, or a squash-merge GitHub proved. | Stratum | Checked | Label wrong | Precision, 95% Wilson | Commit list differs | | --- | --- | --- | --- | --- | | human, register | 30 | 0 | 1.000 [0.886, 1.000] | 0 | | human, software | 30 | 0 | 1.000 [0.886, 1.000] | 0 | | llm, identity | 30 | 0 | 1.000 [0.886, 1.000] | 0 | | llm, session | 30 | 0 | 1.000 [0.886, 1.000] | 1 | | llm, squash-merge | 30 | 0 | 1.000 [0.886, 1.000] | 0 | | mixed, identity | 30 | 0 | 1.000 [0.886, 1.000] | 5 | | mixed, session | 9 | 0 | 1.000 [0.701, 1.000] | 2 | | mixed, squash-merge | 30 | 0 | 1.000 [0.886, 1.000] | 3 | All 239 labels hold, and GitHub serves the same bytes for every one. In 11 the commits differ, though the label GitHub's list gives is the same: - In 9, GitHub lists fewer commits than the sidecar counts (for example 129 against 784 for `cksystemsteaching/selfie/README.md`). The harvest reads the whole history in one pass, so a file's history holds every commit that changed it on any branch. GitHub's list for a path leaves out a side branch whose changes a merge did not take. - In 2, a marked commit of the sidecar is not in GitHub's list. In `valve-tech/reth`, GitHub lists a copy of it instead, with the same change, author date and message under another hash; in `tui-cs/Terminal.Gui`, it is an ancestor of the quoted commit that changed the file, on a branch GitHub's list leaves out. ## The image v2 is published and pinned: `ghcr.io/webern/deslag-blobs:v2@sha256:33d0d99e2d588f31d7d69563d62599486bcd1e89fe8efcfed6fcdf047d6fca00`. It reuses the first batch's layer as it is, and adds one layer, `corpus/batches/2026-09-27-02`, which holds only the batch's 21,075 fixtures, their 21,075 sidecars, and its `manifest.jsonl`, `exclude.jsonl` and `repos.jsonl`. From a cold cache (`.blobs/` moved aside), `make fetch-blobs` unpacked v2 in 26 seconds, the unpacked tree was identical to the one published, and `make test-blobs` passed. ## Other changes - The corpus tests place fixtures at their real paths, and the walk honours the global git excludes file. A new fixture sits under `.vscode/`, which some machines' global excludes ignore, so those machines walked a different corpus. `place_real` now writes a `.ignore` of `!*`, which takes precedence over the global file, so every machine walks the same files. - `tests/blobs.rs` builds its small batches from fixtures with no `before`, since the tree now holds some, and turns a sidecar into version 2 where a test needs one. - The pace file that the harvest's processes share for GitHub questions could be left holding two times run together, since a write was flushed after its lock was let go. It is now flushed first, and a bad value is read as "now". - In `corpus.md`, the example commit links in the marks table are cut to 10 hex characters, to keep the doc in its 16384-byte budget. ## Deviations - The run was 7 legs, not one command, and it stopped at 8,501 seconds of harvest, not 4 to 6 hours. Bytes bound it, not time. - 474 `mixed` fixtures have a twin, a little under the 500 hoped for. The last `priority` leg gave 79 `mixed` files along with about 3,200 others, some 30MB, so more would have spent the budget's headroom. - 309 repositories of leg 3 failed on the pace-file bug above. They were retried in leg 3b, and 3 of them failed again on the network. - `qualified` in the ledger counts, for `llm` and `mixed`, the files whose commits prove the label. The check for text older than its history runs only on files that are read, so `qualified` overstates `llm` by what that check would drop. - A sidecar's `found_by` is the repository's first source only; the ledger lists all of them. So a register analysis should read the ledger: 263 fixtures carry `sg-register:` in their sidecar, while register repositories gave 2,593. - The full-history reading above means a `mixed` label may rest on an agent's commit on a side branch whose change a merge did not take. GitHub's list agreed on the label for all 69 `mixed` fixtures checked, but a later change could read the history as the file's own line of descent instead. ## Left for later - A byte budget for a harvest run, in place of `--deadline`, and maybe a lower cap for `human`: it has 11,473 fixtures, well past the 3,000 to 5,000 hoped for, and the image has 35MB of budget left. - The 4 repositories that failed on the network are retried on the next run. - 3,938 `llm` files past the cap were not asked about. A later run can take them if a repository is worth more than 50. ## Testing - [x] `make ci`: exit 0 - [x] From a cold cache: `make fetch-blobs` unpacks v2 byte for byte as published, then `make test-blobs` passes - [x] `make test-blobs`: every fetched batch keeps the rules, every tree fixture is in the big tier with the same sidecar - [x] `collect.py select --check`: the tree is the sample it would take - [x] `scripts/blobstore/blobs.sh plan`: the first batch is the same layer, the second is new; it took 10 seconds over both batches - [x] Precision against GitHub's own record, per stratum (above) ## References - Related: #16, #18, #33
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
This adds
deslag fix [PATH].... It writes the replacements thatbanned_charsalready names in its report, such as-for an em dash or"for a curly quote, but only where it can prove the edit changes nothing else about the file. Everything it cannot prove, it leaves alone and reports with the reason, so the agent can fix it by hand.Fix never guesses. It does not reword, it never touches frontmatter, HTML, code or URLs, and it never writes a replacement that holds a letter or a digit.
Why a proof, and not just find and replace
Before building this, we applied every replacement the report names to the corpus (1230 fixtures), blindly. It changed how 17 fixtures parse, through 153 edits:
-(llm/xyTom--coding-tools-mcp/docs__plan-v0.5.md, and 123 lines of dialogue inhuman/barumau--pandunia/english__109_jumla_bina.md).> — @someonebecame a list inside a block quote (llm/corazawaf--coraza/...).human/Chef5--PopRun/README.md).mixed/ad-si--awesome-sheet-music/README.md).33 more edits would have replaced a character and left its variation selector (U+FE0F) behind.
The proof
Document::apply(insrc/document/edit.rs) takes a list ofEdits, each a byte range and a replacement, and makes one only when all four of these hold:It tries all the edits at once. If step 4 fails, it tries them one at a time, keeping each one that passes together with those kept before it. Every refused edit gets a reason. A document now keeps the function that read it, so step 4 reads the edited text exactly as the original was read. Because a function pointer cannot be compared in a useful way,
Documentis no longerPartialEq; nothing compared documents.Which replacements are fixable
Violation::editssits besideViolation::marksand gives each mark either an edit or the lint's reason for none. It is an exhaustive match, so a new lint has to decide. Today onlybanned_charsnames edits, and only when its replacement is exact:banor by a group rule for a single character. The default of a rule that covers a range of characters is a guess at what one of them means, so it is left. This also means fix never writes the wrong-direction arrow advice from banned_chars advises -> for arrows that point the other way #48.yes,no,uporsectionare a guess at meaning, and they can run into the text beside them: 193 of the 201 section signs (U+00A7) in the corpus sit right against a digit, wheresectionwould writesection3. This rule applies to abanvalue from the config too, so(R)for U+00AE is left for the writer.banned_phrasesstays unfixable: its values are advice, not replacements, and a match can cross markup.Config validation
Fix must never write a character it would then report. So:
banvalue with a control character in it is an invalid setting.banvalue that holds a character the file's merged settings ban (such as"—" = "–"with the dashes group on) is a contradiction, reported for the file. This is exit 2 fordeslag checktoo, since the report would advise writing a character it then reports.No existing case changes. There are new cases for both.
What it prints, and exit codes
For each file with something to say, fix prints a preface: the characters it fixed, by line, and the ones it could not fix, each with its reason. If a fix deleted a character, it says so, since the spaces around it may need a look. Then it prints exactly what
deslag checkprints for the tree after fixing, honoring--format, and exits as check would: 0 when every file passes, 1 when one fails. Exit 2 is for a run that cannot happen, as before.--dry-runprints the same preface with "would", then check's output for the tree as it is. It writes nothing.[md]is exit 2, and nothing is written. Path lookup moved fromexplainintoglob::findso both commands share it.banvalues above mean the bound can never be reached, so the error for passes that do not settle has no test. Fix works out every file before it writes any, so an error part way writes nothing.Corpus results
tests/corpus.rsruns fix over the whole corpus with the default groups. It checks that every changed byte is a banned character replaced exactly as reported, that what is left is exactly what check still finds, each with a reason, and that a second fix changes nothing. The numbers are pinned:There are 153 structure refusals, as many as the edits that broke parsing when applied blindly. No corpus edit reached the grapheme or markup checks and failed them;
tests/fix.rspins those refusals instead. The golden set does not change.Other changes
fixand the--format jsonrun does not see the first run's writes.tests/fix.rspins each refusal throughDocument::applyand the exact bytes the binary writes.Research
Two MIT-licensed tools were studied for ideas; no code was ported. Both are in
ACKNOWLEDGEMENTS.md.Violation::editsis the data, and fix ends by running check.Left for later
yes,section, and so on) need a way to prove the word does not run into its neighbors.->as advice; fix leaves them because that advice is a range default.Testing
make ci: exit 0tests/fix.rs: refusals for frontmatter, HTML blocks, inline HTML, bare URLs, autolinks, link destinations, code, entities, graphemes, control characters, and six kinds of structure change; exact bytes with CRLF and a byte order mark; a file that is not UTF-8; dry runs; permissions; an unchanged file not rewritten;banvalues; every path errorfix_some,fix_all,fix_dry_run,ban_value_banned,ban_value_controlReferences
banned_charsnames