Skip to content

glob: support brace alternatives in patterns #511

@justrach

Description

@justrach

Problem

codedb_glob treats brace alternatives literally, so agent-style patterns such as **/*.{yaml,yml} return no matches even when indexed .yaml and .yml files exist. This is confusing because users commonly use shell-style brace alternatives when surveying related extensions.

The same matcher backs MCP path filters, so path_glob has the same limitation.

Failing Test

test "issue-511: glob supports brace alternatives" {
    var explorer = Explorer.init(testing.allocator, Explorer.DEFAULT_CONTENT_CACHE_CAPACITY);
    defer explorer.deinit();

    try explorer.indexFile(".github/workflows/release.yml", "name: release");
    try explorer.indexFile("config.yaml", "name: app");
    try explorer.indexFile("docs/readme.md", "# docs");

    const matches = try explorer.globPaths(testing.allocator, "**/*.{yaml,yml}", 10);
    defer testing.allocator.free(matches);

    try testing.expectEqual(@as(usize, 2), matches.len);
    try testing.expectEqualStrings(".github/workflows/release.yml", matches[0]);
    try testing.expectEqualStrings("config.yaml", matches[1]);

    try testing.expect(mcp_mod.globMatch("src/{mcp,explore}.zig", "src/mcp.zig"));
    try testing.expect(mcp_mod.globMatch("src/{mcp,explore}.zig", "src/explore.zig"));
    try testing.expect(!mcp_mod.globMatch("src/{mcp,explore}.zig", "src/main.zig"));
}

Verification before the fix:

zig build test-query -Dtest-filter="issue-511"
expected 2, found 0

Expected

codedb_glob and MCP path_glob should support simple comma-separated brace alternatives such as **/*.{yaml,yml} without requiring multiple tool calls.

Fix

Teach the shared glob matcher to evaluate simple {a,b} alternatives while preserving existing *, **, and ? semantics. Malformed or non-alternative braces should continue to behave as literal characters.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpriority:p2Medium priority

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions