Skip to content

feat: replace pi-mono filesystem tools with native implementation#366

Merged
shadowfax92 merged 2 commits intomainfrom
feat/remove-pi-mono-tools
Feb 26, 2026
Merged

feat: replace pi-mono filesystem tools with native implementation#366
shadowfax92 merged 2 commits intomainfrom
feat/remove-pi-mono-tools

Conversation

@shadowfax92
Copy link
Contributor

Summary

  • Removed @mariozechner/pi-coding-agent and @mariozechner/pi-agent-core dependencies that caused bun compile issues (tree traversal looking for package.json creates complexity during compilation)
  • Reimplemented all 7 filesystem tools (read, write, edit, bash, grep, find, ls) using only Bun/Node.js built-in libraries
  • No external binary dependencies (ripgrep, fd, etc.) — everything is pure TypeScript
  • 107 new tests across 8 test files

Changes

Added (apps/server/src/tools/filesystem/)

File Purpose
utils.ts Shared utilities — truncation, path resolution, binary detection, walkFiles, toModelOutput
read.ts Read files with line numbers, offset/limit pagination, image base64
write.ts Create/overwrite files with auto parent directory creation
edit.ts Exact string replacement with fuzzy whitespace-tolerant fallback
bash.ts Shell command execution via Bun.spawn (sh on Unix, cmd on Windows)
grep.ts Pure JS regex search across files (replaces ripgrep dependency)
find.ts Glob-based file search using Bun.Glob (replaces fd dependency)
ls.ts Directory listing with sizes, dirs-first sorting
build-toolset.ts Assembles all tools into ai-sdk ToolSet

Modified

  • apps/server/package.json — removed pi-mono dependencies
  • apps/server/src/agent/tool-loop/ai-sdk-agent.ts — import changed to new build-toolset
  • bun.lock — updated

Deleted

  • apps/server/src/agent/tool-loop/filesystem-tools/pi-tool-adapter.ts

Test plan

  • 107 new tests across 8 test files — all passing
  • Server typecheck passes
  • Lint passes (9 warnings — all expected as any in test helpers)
  • Manual: verify agent tool loop works end-to-end with new tools
  • Manual: verify bun run dist:server compile succeeds without pi-mono tree issues

🤖 Generated with Claude Code

…entation

Remove @mariozechner/pi-coding-agent and @mariozechner/pi-agent-core
dependencies that caused bun compile issues (tree traversal, package.json
resolution). Reimplement all 7 filesystem tools (read, write, edit, bash,
grep, find, ls) using only Bun and Node.js built-in libraries.

- No external binary dependencies (no ripgrep, fd, etc.)
- Cross-platform: Linux, macOS, Windows
- 107 tests covering all tools and utilities
- Pure JS grep/find using Bun.Glob and async directory walking

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 26, 2026

Greptile Summary

Replaced external @mariozechner/pi-mono dependencies with native Bun/Node.js implementations to fix bun compile issues. All 7 filesystem tools (read, write, edit, bash, grep, find, ls) reimplemented using only built-in libraries with no external binary dependencies.

Key changes:

  • Implemented pure TypeScript replacements for all filesystem operations
  • Added comprehensive error handling with try-catch blocks for file operations (including previous ENOENT issue)
  • Preserved line ending detection and BOM handling for cross-platform compatibility
  • Implemented whitespace-tolerant fuzzy matching in edit tool as fallback
  • Added proper timeout and output truncation for bash tool
  • Comprehensive test coverage with 107 tests across 8 test files

Technical improvements:

  • walkFiles generator properly handles errors and skips ignored directories
  • Binary file detection prevents reading non-text files in grep/find
  • All tools properly resolve paths using resolve(cwd, path) for consistent behavior
  • Metrics logging integrated for tool execution tracking

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • Score reflects well-structured implementation with comprehensive test coverage (107 tests), proper error handling throughout, no security issues introduced, and the previous stat() ENOENT issue has been properly addressed with try-catch blocks
  • No files require special attention - all implementations follow best practices with proper error handling and comprehensive test coverage

Important Files Changed

Filename Overview
apps/server/src/tools/filesystem/utils.ts Added shared utilities for filesystem tools including truncation, path helpers, binary detection, and file walking
apps/server/src/tools/filesystem/read.ts Implemented file reading with line numbers, pagination, and image base64 encoding support
apps/server/src/tools/filesystem/edit.ts Implemented exact string replacement with whitespace-tolerant fallback and line ending preservation
apps/server/src/tools/filesystem/bash.ts Implemented shell command execution via Bun.spawn with timeout support and output truncation
apps/server/src/tools/filesystem/grep.ts Implemented pure JavaScript regex search across files with glob filtering and context lines
apps/server/src/agent/tool-loop/ai-sdk-agent.ts Updated import path to use new native filesystem tools implementation
apps/server/package.json Removed pi-mono dependencies that caused bun compile issues

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[AI Agent] -->|requests filesystem operation| B[ai-sdk-agent.ts]
    B -->|builds toolset| C[buildFilesystemToolSet]
    C -->|creates tools| D[Individual Tool Creators]
    
    D --> E[createReadTool]
    D --> F[createWriteTool]
    D --> G[createEditTool]
    D --> H[createBashTool]
    D --> I[createGrepTool]
    D --> J[createFindTool]
    D --> K[createLsTool]
    
    E -->|uses| L[utils.ts]
    F -->|uses| L
    G -->|uses| L
    H -->|uses| L
    I -->|uses| L
    J -->|uses| L
    K -->|uses| L
    
    L -->|provides| M[truncation]
    L -->|provides| N[walkFiles]
    L -->|provides| O[path helpers]
    L -->|provides| P[binary detection]
    
    E -->|reads via| Q[Node fs/promises]
    F -->|writes via| Q
    G -->|edits via| Q
    I -->|searches via| Q
    J -->|finds via| Q
    K -->|lists via| Q
    H -->|executes via| R[Bun.spawn]
Loading

Last reviewed commit: 3a3ba57

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

21 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

}

// Check if searching a single file
const pathStat = await stat(searchPath)
Copy link
Contributor

Choose a reason for hiding this comment

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

wrap stat() in try-catch to handle ENOENT

Suggested change
const pathStat = await stat(searchPath)
let pathStat: Awaited<ReturnType<typeof stat>>
try {
pathStat = await stat(searchPath)
} catch (err) {
return {
text: `Path not found: ${params.path || '.'}`,
isError: true,
}
}
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/server/src/tools/filesystem/grep.ts
Line: 150

Comment:
wrap `stat()` in try-catch to handle ENOENT

```suggestion
        let pathStat: Awaited<ReturnType<typeof stat>>
        try {
          pathStat = await stat(searchPath)
        } catch (err) {
          return {
            text: `Path not found: ${params.path || '.'}`,
            isError: true,
          }
        }
```

How can I resolve this? If you propose a fix, please make it concise.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@shadowfax92 shadowfax92 merged commit 19c4175 into main Feb 26, 2026
5 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant