MoonshotAI / MoonshotAI/kimi-code

Grep passes an empty file type to ripgrep

Open
#3,243 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
7.5k
Forks
1.2k
Avg merge
11h 53m
Merged PRs (30d)
350

Description

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?
  1. Run Kimi Code 0.38.0 in a workspace where rg is available.

  2. Have the model call the built-in Grep tool with input equivalent to:

    {
      "pattern": "example",
      "type": ""
    }
    
  3. Observe that Kimi Code executes ripgrep with --type followed by an empty argument.

  4. 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:

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the argument-building logic in packages/agent-core/src/tools/builtin/file/grep.ts and packages/agent-core-v2/src/agent/tools/os/grep/grepTool.ts, then inspect the corresponding schemas. Run the existing Grep tests if available and add regression coverage for empty and whitespace-only glob and type values while preserving valid filters.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
cli, testing-qa
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.