What version of Kimi Code is running?
0.38.0
Which open platform/subscription were you using?
OpenAI-compatible provider
Which model were you using?
gpt-5.6-sol
What platform is your computer?
Linux 7.0.0-30-generic x86_64 x86_64
What issue are you seeing?
When the model invokes the built-in Grep tool with an empty optional file type, Kimi Code forwards the empty string to ripgrep:
Grep input: { "pattern": "example", "type": "" }
Failed to grep: rg: unrecognized file type:
This can repeat within a session as the agent retries the same tool call. It creates avoidable tool failures and consumes context even though no file-type filter was requested.
The current schemas accept any string, including an empty one:
packages/agent-core/src/tools/builtin/file/grep.ts
packages/agent-core-v2/src/agent/tools/os/grep/grep.ts
Both implementations then check only whether the value is undefined:
if (args.glob !== undefined) cmd.push('--glob', args.glob);
if (args.type !== undefined) cmd.push('--type', args.type);
Consequently, type: "" becomes rg --type ''. Running that command directly reproduces the same error with ripgrep exit code 2:
$ rg --type '' anything .
rg: unrecognized file type:
$ echo $?
2
The same boundary issue applies to an empty glob, although ripgrep does not necessarily report it in the same way.
What steps can reproduce the bug?
-
Run Kimi Code 0.38.0 in a workspace where rg is available.
-
Have the model call the built-in Grep tool with input equivalent to:
{
"pattern": "example",
"type": ""
}
-
Observe that Kimi Code executes ripgrep with --type followed by an empty argument.
-
Observe rg: unrecognized file type: and a failed Grep tool result.
The implementation-level reproduction is deterministic because the argument builder appends --type whenever args.type !== undefined.
What is the expected behavior?
Optional string filters containing only whitespace should be treated as omitted after trimming. Kimi Code should not pass an empty --type or --glob value to ripgrep.
A focused fix could normalize the optional arguments at the tool boundary, for example:
const glob = args.glob?.trim();
const type = args.type?.trim();
if (glob) cmd.push('--glob', glob);
if (type) cmd.push('--type', type);
Regression tests should cover empty and whitespace-only values in both agent-core implementations, while preserving valid trimmed values.
Additional information
Confirmed against current main at commit e6a302b310a78fb0c09ea20169c52541980a9a87:
- v1 schema:
|
glob: z |
|
.string() |
|
.optional() |
|
.describe( |
|
"Optional glob filter for which files to search, e.g. `*.ts`. Matched against each file's full absolute path, so a path-anchored pattern like `src/**/*.ts` silently matches nothing — use a basename pattern (`*.ts`), or anchor with `**/` (`**/src/**/*.ts`). To scope the search to a directory, use `path` instead.", |
|
), |
|
type: z |
|
.string() |
|
.optional() |
|
.describe( |
|
'Optional ripgrep file type filter, such as ts or py. Prefer this over `glob` when filtering by language or file kind: it is more efficient and less error-prone than an equivalent glob pattern.', |
|
), |
|
output_mode: z |
- v1 argument builder:
|
if (args.glob !== undefined) cmd.push('--glob', args.glob); |
|
if (args.type !== undefined) cmd.push('--type', args.type); |
- v2 schema:
|
glob: z |
|
.string() |
|
.optional() |
|
.describe( |
|
"Optional glob filter for which files to search, e.g. `*.ts`. Matched against each file's full absolute path, so a path-anchored pattern like `src/**/*.ts` silently matches nothing — use a basename pattern (`*.ts`), or anchor with `**/` (`**/src/**/*.ts`). To scope the search to a directory, use `path` instead.", |
|
), |
|
type: z |
|
.string() |
|
.optional() |
|
.describe( |
|
'Optional ripgrep file type filter, such as ts or py. Prefer this over `glob` when filtering by language or file kind: it is more efficient and less error-prone than an equivalent glob pattern.', |
|
), |
|
output_mode: z |
- v2 argument builder:
|
if (args.glob !== undefined) cmd.push('--glob', args.glob); |
|
if (args.type !== undefined) cmd.push('--type', args.type); |
I searched existing open issues for the exact ripgrep error and did not find a matching report.
I am willing to submit a focused PR with regression tests after a maintainer approves this bug with /approve, as required by CONTRIBUTING.md.
What version of Kimi Code is running?
0.38.0
Which open platform/subscription were you using?
OpenAI-compatible provider
Which model were you using?
gpt-5.6-sol
What platform is your computer?
Linux 7.0.0-30-generic x86_64 x86_64
What issue are you seeing?
When the model invokes the built-in
Greptool with an empty optional file type, Kimi Code forwards the empty string to ripgrep:This can repeat within a session as the agent retries the same tool call. It creates avoidable tool failures and consumes context even though no file-type filter was requested.
The current schemas accept any string, including an empty one:
packages/agent-core/src/tools/builtin/file/grep.tspackages/agent-core-v2/src/agent/tools/os/grep/grep.tsBoth implementations then check only whether the value is
undefined:Consequently,
type: ""becomesrg --type ''. Running that command directly reproduces the same error with ripgrep exit code 2:The same boundary issue applies to an empty
glob, although ripgrep does not necessarily report it in the same way.What steps can reproduce the bug?
Run Kimi Code 0.38.0 in a workspace where
rgis available.Have the model call the built-in
Greptool with input equivalent to:{ "pattern": "example", "type": "" }Observe that Kimi Code executes ripgrep with
--typefollowed by an empty argument.Observe
rg: unrecognized file type:and a failed Grep tool result.The implementation-level reproduction is deterministic because the argument builder appends
--typewheneverargs.type !== undefined.What is the expected behavior?
Optional string filters containing only whitespace should be treated as omitted after trimming. Kimi Code should not pass an empty
--typeor--globvalue to ripgrep.A focused fix could normalize the optional arguments at the tool boundary, for example:
Regression tests should cover empty and whitespace-only values in both agent-core implementations, while preserving valid trimmed values.
Additional information
Confirmed against current
mainat commite6a302b310a78fb0c09ea20169c52541980a9a87:kimi-code/packages/agent-core/src/tools/builtin/file/grep.ts
Lines 55 to 67 in e6a302b
kimi-code/packages/agent-core/src/tools/builtin/file/grep.ts
Lines 486 to 487 in e6a302b
kimi-code/packages/agent-core-v2/src/agent/tools/os/grep/grep.ts
Lines 14 to 26 in e6a302b
kimi-code/packages/agent-core-v2/src/agent/tools/os/grep/grepTool.ts
Lines 457 to 458 in e6a302b
I searched existing open issues for the exact ripgrep error and did not find a matching report.
I am willing to submit a focused PR with regression tests after a maintainer approves this bug with
/approve, as required byCONTRIBUTING.md.