PR: se refactoriza grep.ts para mejorar la compatibilidad multiplataforma de la herramienta#11
Conversation
…en entorno windows La tool grep es una herramienta de línea de comandos que permite buscar patrones en archivos y directorios. Se ha refactorizado para mejorar su compatibilidad con entornos Windows, corrigiendo el uso de funciones específicas de Unix que causaban errores en sistemas Windows. Ahora, la herramienta utiliza métodos más universales para manejar rutas y archivos, asegurando un funcionamiento correcto en ambos entornos.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughWalkthroughThe PR updates package scripts and schema metadata, changes server startup to use Bun, rewrites bash execution to resolve the shell per OS, and rewrites grep to scan files in-process with Bun APIs. ChangesTooling and command execution
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant Caller
participant createBashTool
participant Shell
participant Process
Caller->>createBashTool: command
createBashTool->>Shell: resolve shell for OS
createBashTool->>Process: spawn command through shell
Process-->>createBashTool: stdout, stderr, exitCode
createBashTool-->>Caller: result or timeout error
sequenceDiagram
participant Caller
participant execute
participant walkFiles
participant FileSystem
Caller->>execute: pattern, include
execute->>execute: build RegExp
execute->>walkFiles: enumerate candidate files
walkFiles-->>execute: sorted relative paths
loop each file
execute->>FileSystem: read file text
FileSystem-->>execute: contents
execute->>execute: test lines against RegExp
end
execute-->>Caller: matches, no matches, or error
Related Issues: None specified. Related PRs: None specified. Suggested labels: enhancement, tooling Suggested reviewers: MarceM1 Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
packages/server/src/tools/grep.ts (1)
116-118: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick winUnbounded
file.text()reads the whole file into memory.A large text file without a binary extension (generated bundles, minified assets, logs) is fully materialized as a string and then split. The surrounding
try/catchwon't gracefully handle an out-of-memory condition. Consider skipping files above a size threshold before reading.🛡️ Size guard before reading
try { const file = Bun.file(absolutePath); + if (file.size > 1_000_000) continue; // skip files > ~1MB text = await file.text(); } catch {🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/server/src/tools/grep.ts` around lines 116 - 118, The file-reading path in grep.ts loads the entire file via Bun.file(...).text() without any size check, which can blow up memory on large non-binary files. Add a pre-read guard in the same try/catch flow around the Bun.file/text logic to skip files above a reasonable size threshold before materializing them as a string, and keep the change localized to the file processing code in the grep implementation.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/server/src/tools/grep.ts`:
- Around line 110-141: The grep loop in the search routine undercounts
`totalMatches` once `MAX_MATCHES` is reached, so the truncation summary is
misleading. In `grep.ts`, update the logic around the `filePaths` scan and the
`matches.length < MAX_MATCHES` / `truncated` checks so `totalMatches` reflects
the intended contract: either continue scanning all files to compute the true
total, or rename/repurpose the returned count to clearly indicate it is only a
partial lower-bound value. Ensure the behavior in the `grep` function remains
consistent with the returned `matches`, `truncated`, and `totalMatches` fields.
- Around line 94-102: The glob scan in the grep tool is still descending into
node_modules before shouldSkip filters entries, so the exclusion needs to happen
during traversal instead of after. Update the scan logic in scanGlob.scan to
prune node_modules up front, or switch to a walker that supports directory-level
ignore/exclude pruning, and keep the existing shouldSkip, isHiddenPath, and
isBinaryPath checks for any remaining per-entry filtering.
---
Nitpick comments:
In `@packages/server/src/tools/grep.ts`:
- Around line 116-118: The file-reading path in grep.ts loads the entire file
via Bun.file(...).text() without any size check, which can blow up memory on
large non-binary files. Add a pre-read guard in the same try/catch flow around
the Bun.file/text logic to skip files above a reasonable size threshold before
materializing them as a string, and keep the change localized to the file
processing code in the grep implementation.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: a6b9e37f-69d4-40ec-b846-f8e9fac5b6d4
📒 Files selected for processing (2)
package.jsonpackages/server/src/tools/grep.ts
…lataforma. Agrego comando start en server y root package.json para deploy
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/server/src/tools/bash.ts`:
- Line 57: The bash tool has a dead `response` variable in the `bash.ts` flow:
`new Response(proc.stdout)` is created but never used, since the later `.text()`
calls already instantiate fresh `Response` objects from the same streams. Remove
the unused `response` creation in the `bash`-related logic and keep the existing
stream reads intact so the control flow remains unchanged.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: df8ac6c7-5060-42f1-a8db-76af2f447376
📒 Files selected for processing (3)
package.jsonpackages/server/package.jsonpackages/server/src/tools/bash.ts
✅ Files skipped from review due to trivial changes (1)
- packages/server/package.json
| proc.kill(); | ||
| }, timeout); | ||
|
|
||
| const response = new Response(proc.stdout); |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win
Remove unused Response wrapper.
response at Line 57 is never read; lines 60-61 already construct fresh Response objects over the same streams for the actual .text() calls. This is dead code, likely a leftover from refactoring.
🧹 Proposed fix
- const response = new Response(proc.stdout);
-
const [stdout, stderr] = await Promise.all([📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| const response = new Response(proc.stdout); |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@packages/server/src/tools/bash.ts` at line 57, The bash tool has a dead
`response` variable in the `bash.ts` flow: `new Response(proc.stdout)` is
created but never used, since the later `.text()` calls already instantiate
fresh `Response` objects from the same streams. Remove the unused `response`
creation in the `bash`-related logic and keep the existing stream reads intact
so the control flow remains unchanged.
Summary by CodeRabbit