Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

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

Abierto Apto para principiantes
#4,146 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@chenqing0106 ya está trabajando en esto.

Desde el 18/10/2026.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
85/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
node.js, typescript
Área
backend

Línea de trabajo

Empieza en packages/agent-core-v2/src/workspace/workspaceFs/fsService.ts, líneas 1257-1284, donde el analizador de flujo de ripgrep acumula líneas de contexto en un array pending y lo vacía en cada coincidencia, y en las líneas 1312-1323, donde finalize solo rellena after para la última coincidencia. Usa el helper makeSession de fsService.test.ts para ejecutar los cuatro fixtures descritos (separated, overlapping, adjacent, single) con ambos backends. La corrección debería conservar las líneas coincidentes en el contexto pending entre coincidencias consecutivas, para que los arrays before y after estén completos para cada coincidencia.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.
Lenguaje dominante
TypeScript
Estrellas
8k
Forks
1.3k
Merge medio
17 h 52 min
PR fusionados (30 d)
163

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de MoonshotAI/kimi-code

Todos los issues de MoonshotAI/kimi-code

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.