Skip to content

PR: se refactoriza grep.ts para mejorar la compatibilidad multiplataforma de la herramienta#11

Merged
MarceM1 merged 3 commits into
mainfrom
debug/grep-tool
Jul 5, 2026
Merged

PR: se refactoriza grep.ts para mejorar la compatibilidad multiplataforma de la herramienta#11
MarceM1 merged 3 commits into
mainfrom
debug/grep-tool

Conversation

@MarceM1

@MarceM1 MarceM1 commented Jul 4, 2026

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • New Features
    • Enhanced file search: scans files in-process with improved skipping of hidden/binary/unwanted directories and optional include pattern filtering.
    • Improved handling of large searches with clearer truncation behavior and reporting.
  • Bug Fixes
    • Invalid search regex patterns now return a clearer “Invalid regex pattern” error.
    • When no results are found, the search tool returns a dedicated “No matches found” response.
    • Command timeout handling now reports timeouts via an explicit error while still truncating output.
  • Chores
    • Added JSON schema metadata to package manifests and expanded type-checking scripts; updated server start command.

…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.
@vercel

vercel Bot commented Jul 4, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
whalin-code-server Error Error Jul 5, 2026 6:09pm

@coderabbitai

coderabbitai Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The 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.

Changes

Tooling and command execution

Layer / File(s) Summary
Package scripts and schema
package.json, packages/server/package.json
package.json gains a top-level $schema and new start/typecheck* scripts, and the server package start script points to bun run src/index.ts.
OS-aware shell execution
packages/server/src/tools/bash.ts
The bash tool resolves the shell from the host environment, spawns commands through that shell, and returns an explicit timeout error when execution exceeds the limit.
In-process grep scan
packages/server/src/tools/grep.ts
The grep tool walks files with Bun APIs, filters hidden and binary paths, scans matching files line by line with regex matching, and returns structured results for matches, truncation, no-match, and invalid regex cases.

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
Loading
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
Loading

Related Issues: None specified.

Related PRs: None specified.

Suggested labels: enhancement, tooling

Suggested reviewers: MarceM1

Poem

A shell now bends to OS terrain,
While grep scans files without restraint,
Scripts learned new paths to run and check,
And schema tags keep package in spec,
With Bun, the tools now stay more plain.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main grep.ts refactor and its cross-platform compatibility goal.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch debug/grep-tool

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
packages/server/src/tools/grep.ts (1)

116-118: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Unbounded 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/catch won'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

📥 Commits

Reviewing files that changed from the base of the PR and between 17fb715 and e022135.

📒 Files selected for processing (2)
  • package.json
  • packages/server/src/tools/grep.ts

Comment thread packages/server/src/tools/grep.ts Outdated
Comment thread packages/server/src/tools/grep.ts
…lataforma. Agrego comando start en server y root package.json para deploy
@railway-app railway-app Bot temporarily deployed to charming-blessing / production July 5, 2026 18:10 Inactive

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1ebaf83 and 78849f5.

📒 Files selected for processing (3)
  • package.json
  • packages/server/package.json
  • packages/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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 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.

Suggested change
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.

@MarceM1 MarceM1 merged commit b5b6c33 into main Jul 5, 2026
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant