Repository navigation
fix(repos): a {a,b} brace in a manifest glob lists alternatives - #1613
antonwolfy wants to merge 5 commits into
Conversation
…l#1484) `match_posix_glob`, the one match behind `guidance.globs`, `guidance.also_scan` and `useful.edit`, escaped the `{`, `,` and `}` of `**/{AGENTS,CLAUDE}.md` or `src/{a,b}.h` as literal characters, so such a glob matched no file and `repo scan` warned that it matched nothing. It now matches when any alternative of a closed comma brace does (nested braces and an empty alternative `a{,b}` too). A brace with no comma or no closing `}` stays literal, and a glob that would spell more than 16 alternatives reads each such brace as `*`, as the repository scan reads a code span. The expansion moved from `repos/l0/braces.py` to the new `brace_alternatives.py`, a foundation module both import. `glob_paths` is left as it is: no documented manifest field reaches it. Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
There was a problem hiding this comment.
🟡 Changes recommended
The brace-cap fallback can turn adjacent wildcard replacements into recursive matches, violating single-segment behavior and selecting unintended files.
1 open issue
What changed in this PR
1 new finding.
This PR adds brace alternatives to manifest glob matching, sharing expansion logic with repository code-span scanning.
Changes:
- Supports nested and empty alternatives, with capped expansion and cached matching.
- Extracts shared brace utilities into a foundation module.
- Adds regression tests and documents the matching rules.
| File | Description |
|---|---|
dokimi/tests/test_pattern_glob_braces.py |
Tests alternatives, literal braces, and cap fallback. |
dokimi/tests/test_import_architecture.py |
Registers the shared foundation module. |
dokimi/dokimi/repos/l0/braces.py |
Reuses extracted brace utilities. |
dokimi/dokimi/pattern_glob.py |
Adds brace-aware matching and regex caching. |
dokimi/dokimi/brace_alternatives.py |
Provides shared, bounded brace expansion. |
dokimi/docs/repo-evaluation-contract.md |
Defines manifest glob behavior. |
dokimi/docs/architecture.md |
Documents the shared module. |
dokimi/changelog.d/20261204_100000_manifest-glob-braces.md |
Records the matching fix. |
Review effort: Balanced
|
✅ OpenCodeReview: Review complete: 0 finding(s) across 2 selected item(s). CI at Test notes (2)
Review details
|
Mutation of changed linesAt 98833fe: 69 caught · 10 missed · 1 waived Each row is a small deliberate break (a mutant) of a line this PR changes that every test reaching that line still passes. Add a test that fails on it or, if it cannot change behaviour, put
Not checked:
Marked harmless with
Warning only: a missed break does not fail the job. Updated on every push; the full report is in the ci run summary. |
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1613 +/- ##
==========================================
- Coverage 96.46% 96.45% -0.01%
==========================================
Files 561 567 +6
Lines 74345 75066 +721
Branches 12840 12964 +124
==========================================
+ Hits 71716 72404 +688
- Misses 1609 1632 +23
- Partials 1020 1030 +10
🚀 New features to boost your workflow:
|
…e a star or brace Settles review thread 4801928326: the cap fallback wrote each replaced brace as `*`, so a brace next to another brace or a `*` formed `**` and matched across directories. The fallback now marks a replaced brace with a placeholder that compiles to `[^/]*` on its own. Tests cover adjacent braces and neighbouring stars. Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
The _STAR constant sat between the `#:` comment and _ABSENT, so the comment documented _STAR. Move _STAR above the comment. Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
A comma brace nested deeper than MAX_DEPTH made expand return None, and match_posix_glob then starred the whole pattern, so a 33-deep brace matched any root file. The depth limit is now told apart from the alternative count (brace_alternatives.too_deep): a too-deep pattern is read with its braces literal, as MAX_DEPTH documents ("not expanded"). Settles the review thread on pattern_glob.py:157.
Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
…he alternative cap Settles review thread 4806007759: too_deep stopped at the alternative-count overflow raised before the depth check, so a pattern with 33 nested braces and 17 alternatives was read as a star and matched unrelated files. too_deep now measures the nesting of matched braces on its own, independent of the capped expansion; a test combines both limits, also with an overflowing brace before the deep one. Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
napetrov
left a comment
There was a problem hiding this comment.
Change class: CONTRACT (head 98833fe)
- Contract: changed. dispatch dokimi/dokimi/brace_alternatives.py:44; errors dokimi/dokimi/brace_alternatives.py:73
- Responsibility: candidate. delegate _glob_regex in dokimi/dokimi/pattern_glob.py; policy dokimi/docs/architecture.md
- Dependency: none
- Review depth: check the changed surface: callers, docs, tests pin new behaviour
- Coverage gaps: none
No new blocking findings on 98833fe7.
Reviewed the diff, edge cases and prior threads. Focused tests: 25 passed on head. The full local suite was outside coverage.

Summary
A glob of a repo manifest (
guidance.globs,guidance.also_scan,useful.edit) with a{a,b}brace matches no file onmain:match_posix_glob(imported asmatch_globinrepos/manifest.py) escapes every character but*,?and**/, so{,,and}are literal. The issue namesmatch_globinrepos/manifest.py:483, whichmainno longer defines, but the bug is the same inpattern_glob.py.mainmatch_glob('src/{a,b}.h', 'src/a.h')Falsematch_glob('**/{AGENTS,CLAUDE}.md', 'AGENTS.md')Falsematch_glob('**/{AGENTS,CLAUDE}.md', 'x/CLAUDE.md')Falsematch_glob('a{,b}', 'ab')FalseSo
repo scanwarns that such a glob matches no file, and the guidance arms anduseful.editnever see the files it names. The code-span side of the repository scan already reads a brace as alternatives (#1485,repos/l0/braces.py).The issue's first option is taken: expand a comma brace into alternatives before matching, in the one function every manifest glob goes through. The other option (document braces as literal) would leave
**/{AGENTS,CLAUDE}.mdunusable, though the scan already reads that spelling in a code span.Past 16 alternatives (the cap
l0uses) each outermost comma brace is read as*, asl0reads a code span past its cap; the replacement stays inside one path segment, also beside another brace or a*(src/{a,b,c,d,e}{f,g,h,i}.hdoes not matchsrc/deep/x.h). This over-matches rather than dropping the glob, so a manifest with a long brace list still finds its files.glob_paths(repo_glob.py) is left alone. Its only callers arerepo_config.py(thedefaults.skillspatterns and the suite patterns, where{skill}is already a placeholder replaced before matching), and no page ofdokimi/docsdescribes those fields, so no documented manifest or config glob reaches it.Closes #1484
Changes
dokimi/brace_alternatives.py(new, foundation layer):expand,over_cap,pairsand the caps, moved out ofrepos/l0/braces.pysincepattern_globsits belowrepos.l0and cannot import it.braces.pyimports them and keeps the code-span parts (pathlike,starred,judge,defined_in).pattern_glob.match_posix_glob: a closed brace with a comma lists alternatives (nested braces and an empty alternativea{,b}too); a brace with no comma or no}stays literal; past the cap each outermost comma brace is a single-segment wildcard of its own, never merged with a neighbouring*or brace into**. Braces nested deeper thanMAX_DEPTH(32) are not expanded and the glob matches only its own literal text (brace_alternatives.too_deepmeasures the nesting of matched braces on its own, so it tells that case apart whatever the alternative count, also when a pattern exceeds both caps). The compiled pattern is cached per glob, since the expansion would otherwise run on every path.dokimi/docs/repo-evaluation-contract.md(manifest rules) anddokimi/docs/architecture.md(module list) say a{a,b}brace lists alternatives.tests/test_import_architecture.py: the new module is in the foundation layer.tests/test_pattern_glob_braces.py(new): the alternatives, the literal cases, the cap.Risk
A manifest glob that held a literal
{a,b}(a directory named{a,b}) now matchesaandbinstead. A glob with no comma brace matches exactly as before; the existingmatch_globandmatch_posix_globtests pass unchanged. A glob past the cap matches more than before (it matched nothing). The user-given CLI patterns (pattern_glob.expand) are not changed.Open PRs that change the same files: #1576 changes one line of the
LAYERStuple indokimi/tests/test_import_architecture.pyright next to the line this PR changes (it addsdokimi.spend_preview), so the two conflict textually in that line, and whichever merges second takes a one-line rebase. The other open PRs that touchdokimi/docs/repo-evaluation-contract.mdordokimi/docs/architecture.mdmerge cleanly.Testing
On a Linux review host, at
98833fe7(onmain01ff2d6):make ci-local: 36 passed, 2 failed, 16 skipped (docker and network steps, jobs that do not run on a PR, matrix legs of other platforms, semgrep, micromamba). The 2 failures areci.yml:test / Run testsandRepeat changed tests, both ontests/test_import_architecture.py::test_package_uses_the_new_modules(dokimi.runs.resolveimportsdokimi.utils). That one test fails on this branch's base (01ff2d6) and is fixed by the merged fix(runs): import InputError from dokimi.files, not dokimi.utils #1609; this PR does not touch it. The run: 35430 tests passed, 1 failed, 28 skipped; changed-line coverage 100% (99 lines).main's codetests/test_pattern_glob_braces.pygives10 failed, 12 passed, first onmatch_glob('**/{AGENTS,CLAUDE}.md', 'AGENTS.md')returningFalse(the test's import ofMAX_ALTERNATIVESis replaced by16in that copy).*,test_a_brace_past_the_cap_next_to_a_brace_or_a_star_stays_within_one_segmentfails (src/{a,b,c,d,e}{f,g,h,i}.hmatchedsrc/deep/x.h).*crossing a/, every brace starred, an unclosed{paired, no nesting, an empty alternative dropped, the character after a starred brace skipped).{* 33 +a,b+}* 33) are read with their braces literal, not as a wildcard:test_braces_nested_past_the_depth_cap_stay_literal_not_a_starchecks the pattern matches only itself and notunrelated.md, and that 32 levels still expand. It fails on the previous head's code (the glob matchedunrelated.md) and with thetoo_deepbranch removed.{* 33 + 17 alternatives +}* 33, also with an overflowing{...}brace before it) is read with its braces literal:test_braces_nested_past_the_depth_cap_stay_literal_also_past_the_alternative_capchecks it matches only itself and notunrelated.md. Withtoo_deepback to reading the depth from the capped expansion, that test fails.ci-locallists 13 survivors, all in the moved code ofbrace_alternatives.py, whichtests/test_repo_l0_braces.pyexercises and the job does not run for that module; none is inpattern_glob.py.fix/pinned-manifest-identifieronmain0eeae5f:pytest -n auto35684 passed, 28 skipped,mypyclean,ruff checkclean.19e8d60a, which only moves one constant above a comment inpattern_glob.py:tests/test_pattern_glob.py53 passed;make ci-localwas not rerun for it.Open questions
None.
Revert
A plain revert restores the old behaviour: a brace in a manifest glob is literal again, and
repos/l0/braces.pyholds the expansion. Nothing is stored.Checklist
pytestpasses (the full run has 1 failure,test_package_uses_the_new_modules, which fails on the base and is fixed by the merged fix(runs): import InputError from dokimi.files, not dokimi.utils #1609)ruff,mypy, and schema checks passAGENTS.mdraise/exit and test names the doc, contract or issue it traces to.github/.licenserc.yaml)