Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Workspace fs:grep loses surrounding lines for multiple matches with ripgrep

Open Beginner friendly
#4,146 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
85/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
node.js, typescript
Domain
backend

Research direction

Start from packages/agent-core-v2/src/workspace/workspaceFs/fsService.ts lines 1257-1284 where the ripgrep stream parser accumulates context lines in a pending array and clears it on each match, and lines 1312-1323 where finalize only populates after for the last match. Use the makeSession helper in fsService.test.ts to run the four described fixtures (separated, overlapping, adjacent, single) against both backends. The fix should preserve matching lines in the pending context across consecutive matches so that before and after arrays are complete for every match.

Written by the indexing model from the issue text.

Description

Version and environment

Current main: 5b936697670ed15444bcb4720bd91e6ee776a941 (@moonshot-ai/agent-core-v2 0.4.3).
Windows x64, Node 24.19.0, pnpm 10.33.0, ripgrep 15.1.0.
No model/subscription is involved in this file-service reproduction.

Actual behavior

WorkspaceFsService.grep drops surrounding lines when ripgrep reports multiple matches in one file. For separated matches, the first match's after is empty. For adjacent/overlapping matches, the later match's before also omits nearby matching lines. The response reports truncated: false.

This concerns the workspace file service exposed through the server's fs:grep route; I have not reproduced it through the model-facing Grep tool or a running HTTP server.

Reproduction

Create src/a.ts with:

a
hit
b
c
d
hit
e
f

Run WorkspaceFsService.grep with this request (the existing makeSession helper in fsService.test.ts can exercise it):

{
  "pattern": "hit",
  "regex": false,
  "case_sensitive": true,
  "follow_gitignore": false,
  "max_files": 200,
  "max_matches_per_file": 50,
  "max_total_matches": 5000,
  "context_lines": 2
}

The stream used by the test was captured from actual ripgrep:

rg --json --context 2 --fixed-strings hit src/a.ts

The real WorkspaceFsService parses that stream through its existing process-service test seam. Its match results are:

[
  {"line":2,"col":1,"text":"hit","before":["a"],"after":[]},
  {"line":6,"col":1,"text":"hit","before":["c","d"],"after":["e","f"]}
]
Expected behavior

The first match should have after: ["b", "c"]. Removing ripgrep and exercising the Node fallback on identical content returns this expected context for both matches.

With a\nhit\nb\nhit\nc\nd\n, the second match should have before: ["hit", "b"], but the rg path returns ["b"]. With adjacent hits, its before is empty instead of ["a", "hit"].

Investigation and focused validation

The context/match handling accumulates context in one pending array and clears it on every match. finalize fills after only for the last match. Matching lines are not retained for neighboring matches' context.

Four fixtures (separated, overlapping, adjacent, single), each tested through both real service backends: 3 rg multi-match failures; 5 passing controls (all four Node cases and the single-match rg case). Production code was unchanged. These are focused service tests, not a claim that the full Windows suite passes.

Contribution
  • I am willing to submit a focused fix and regression tests after a maintainer's /approve.
Dominant language
TypeScript
Stars
7.8k
Forks
1.3k
Avg merge
17h 23m
Merged PRs (30d)
157

Getting set up

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.

More from MoonshotAI/kimi-code

All issues in MoonshotAI/kimi-code

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.