Skip to content

enhance: improve filesystem & shell tools with pagination, fallback matching, and smarter output#1895

Merged
Re-bin merged 1 commit intomainfrom
enhance-tools
Mar 11, 2026
Merged

enhance: improve filesystem & shell tools with pagination, fallback matching, and smarter output#1895
Re-bin merged 1 commit intomainfrom
enhance-tools

Conversation

@Re-bin
Copy link
Copy Markdown
Collaborator

@Re-bin Re-bin commented Mar 11, 2026

Summary

Enhance the core filesystem and shell tools to close feature gaps identified by comparing with opencode's tool implementations.

Changes

ReadFileTool

  • Added offset (1-indexed) and limit parameters for line-based pagination
  • Output now includes line numbers in {n}| {content} format
  • Character budget enforcement (_MAX_CHARS = 128K) trims from end when output is too large
  • Pagination hints guide the LLM to continue reading (Use offset=N to continue)

EditFileTool

  • Introduced progressive fallback matching via _find_match():
    1. Exact match
    2. Line-trimmed sliding window (handles indentation differences)
  • CRLF line endings are detected via raw bytes and preserved through edits
  • Added replace_all parameter for bulk replacements
  • Ambiguous matches (count > 1) return a warning instead of silently replacing the wrong one
  • "Not found" errors now show a diff against the best partial match (if >50% similar)

ListDirTool

  • Added recursive mode using rglob("*") for deep directory exploration
  • Added max_entries cap (default 200) with truncation message
  • Built-in _IGNORE_DIRS set auto-skips .git, node_modules, __pycache__, .venv, etc.

ExecTool

  • Output truncation changed from simple prefix cut to head + tail strategy, preserving both the beginning and end of long outputs
  • Exposed timeout parameter to the LLM (1–600s), capped at _MAX_TIMEOUT
  • Exit code is now always included in the output, not just on failure

Code quality

  • Extracted _FsTool base class to eliminate duplicated __init__ and path resolution across all 4 filesystem tool classes
  • Minor variable and naming cleanup for conciseness

Test plan

  • All 246 tests passing (no regressions)
  • New tests/test_filesystem_tools.py — 18 tests covering:
    • ReadFileTool: pagination, line numbers, offset bounds, empty file, char budget trimming
    • _find_match: exact, no-match, CRLF, line-trim fallback, multiple candidates
    • EditFileTool: exact edit, CRLF preservation, trim fallback, ambiguous warning, replace_all, not-found
    • ListDirTool: basic list, recursive, ignore dirs, max_entries truncation, empty dir, not-found
  • Updated tests/test_tool_validation.py — 4 new tests covering:
    • ExecTool always returns exit code
    • Head+tail truncation for large outputs
    • Timeout parameter acceptance
    • Timeout capped at _MAX_TIMEOUT
  • Zero lint errors on all modified files

@Re-bin Re-bin merged commit 214693c into main Mar 11, 2026
@Re-bin Re-bin deleted the enhance-tools branch March 11, 2026 16:22
sorker pushed a commit to sorker/nanobot that referenced this pull request Mar 24, 2026
…agination, fallback matching, and smarter output

enhance: improve filesystem & shell tools with pagination, fallback matching, and smarter output
Wattysaid pushed a commit to kieran-assistant/nanobot that referenced this pull request Apr 3, 2026
…agination, fallback matching, and smarter output

enhance: improve filesystem & shell tools with pagination, fallback matching, and smarter output
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