Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/globstar-zero-directories.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@moonshot-ai/kimi-code": patch
---

Fix glob patterns with `**/` so they also match files in the starting directory.
5 changes: 5 additions & 0 deletions packages/kaos/src/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,11 @@ export function globPatternToRegex(pattern: string, caseSensitive: boolean): Reg
if (ch === undefined) break;
switch (ch) {
case '*':
if (pattern[i + 1] === '*' && pattern[i + 2] === '/') {
regex += '(?:[^/]+/)*';
i += 2;
Comment on lines +193 to +195

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Treat globstar only as a full path segment

When callers pass a full pattern containing a path component like ***/foo.txt or a**/foo.txt, this branch fires on the last two * characters and turns that non-globstar component into (?:[^/]+/)*, so it can match zero or multiple directories. In Python-style glob semantics only a component that is exactly ** is recursive; these patterns should stay within a single path segment. Please require the **/ to start a segment, e.g. at index 0 or immediately after /, before applying the recursive rewrite.

Useful? React with 👍 / 👎.

break;
}
regex += '[^/]*';
break;
case '?':
Expand Down
11 changes: 10 additions & 1 deletion packages/kaos/test/internal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,14 +264,23 @@ describe('globPatternToRegex', () => {
expect(regex.test('.config')).toBe(true);
});

it.skip('Python treats **/foo.txt as recursive; current helper is segment-based and does not implement zero-or-more directories', () => {
it('treats **/foo.txt as recursive with zero-or-more directories', () => {
const regex = globPatternToRegex('**/foo.txt', true);

expect(regex.test('foo.txt')).toBe(true);
expect(regex.test('a/foo.txt')).toBe(true);
expect(regex.test('a/b/foo.txt')).toBe(true);
});

it('treats middle ** segments as zero-or-more directories', () => {
const regex = globPatternToRegex('root/**/foo.txt', true);

expect(regex.test('root/foo.txt')).toBe(true);
expect(regex.test('root/a/foo.txt')).toBe(true);
expect(regex.test('root/a/b/foo.txt')).toBe(true);
expect(regex.test('other/a/foo.txt')).toBe(false);
});

it('keeps single-star matching to a single path segment', () => {
const regex = globPatternToRegex('*/foo.txt', true);

Expand Down