Skip to content

fix(filetools): follow-up correctness and performance fixes - #160

Merged
w0wl0lxd merged 9 commits into
mainfrom
fix/filetools-followup
Jul 28, 2026
Merged

w0wl0lxd merged 9 commits into
mainfrom
fix/filetools-followup

Conversation

@w0wl0lxd

@w0wl0lxd w0wl0lxd commented Jul 27, 2026 •

Copy link
Copy Markdown
Owner

Summary

Follow-up to #152. Adds streaming line-limited reads, fixes long-line truncation and quote handling, and replaces ToolRegistry linear scans with a HashMap-backed snapshot.

Changes

  • n00n-lua/src/api/fs.rs: add n00n.fs.read_lines for offset/limit streaming reads with a 256-line prefix window.
  • plugins/read/init.lua: use read_lines, fix truncate_bytes with utf8.offset, and correct line-number width.
  • plugins/lib/n00n/truncate.lua: truncate long lines instead of dropping them, respect byte budgets, and strip \r.
  • plugins/grep/init.lua: strip leading/trailing quotes from patterns and fix line-number width.
  • n00n-agent/src/tools/registry.rs: O(1) get/has with ToolsSnapshot, batch duplicate detection.
  • n00n-ui/src/agent/agent_loop.rs: update ToolsCache to hold Arc<ToolsSnapshot>.

Verification

  • cargo fmt --all
  • cargo clippy --all --tests -- -D warnings
  • cargo nextest run --workspace

All green.

Risk

Low; bug fixes and performance improvements stacked on #152.


Note

Low Risk
Targeted file-tool and registry improvements with tests; no auth, security, or breaking API surface beyond new read_lines.

Overview
Follow-up correctness and performance work on file tools and the tool registry.

Streaming reads: Adds n00n.fs.read_lines for offset/limit line reads without loading whole files, with a 256-line prefix for UI context. The read plugin switches from read + manual splitting to read_lines, and line truncation uses utf8.offset so multibyte characters are not split mid-codepoint.

Truncation and grep UX: n00n.truncate keeps long lines (with ellipsis) within byte/line budgets instead of dropping them, and handles CRLF. The grep plugin strips wrapping quotes from patterns and fixes line-number column width; Rust grep collects parallel results via a channel, errors on missing paths, and logs walk/search failures.

Registry and JSON: ToolRegistry stores a ToolsSnapshot with a name → index HashMap for O(1) get/has (agent loop cache updated accordingly). tool_search / load_namespace emit JSON via serde_json instead of hand-built strings (with escaping tests).

FS helpers: glob validates the search root is a directory, improves walk error handling, and stabilizes mtime sorting; dir validates depth and logs directory walk issues.

Reviewed by Cursor Bugbot for commit 8842041. Bugbot is set up for automated code reviews on this repo. Configure here.

w0wl0lxd added 3 commits July 27, 2026 05:46
…and channels

- Fix manual JSON construction in tool_search.rs to use serde_json::json! macro
  for proper escaping of backslashes, quotes, and newlines in descriptions
- Fix UTF-8 over-truncation in plugins/read/init.lua by using utf8_boundary
  from tool_view.lua instead of naive byte-based truncation
- Do not ignore grep search errors in n00n-agent/src/tools/grep.rs; log warnings
- Warn on/propagate walk errors in grep.rs instead of silently continuing
- Add path existence check before building walker in grep.rs
- Replace Arc<Mutex<Vec<GrepFileEntry>>> with flume channel in grep.rs to remove
  Mutex hot-path contention
- Fix n00n-lua/src/api/fs.rs glob: add root validation, log walk errors,
  warn on non-UTF-8 paths, and use bounded sort for mtime with BinaryHeap
- Fix collect_dir_entries silent error swallowing with explicit warn logging
- Fix dir silent default for depth parameter to return error on wrong type
- Add streaming n00n.fs.read_lines with offset/limit and a 256-line
  prefix window for syntax highlighting context, avoiding full-file loads.
- Fix plugins/lib/n00n/truncate.lua to truncate over-long lines instead
  of dropping them, respect byte budgets, and strip CR line endings.
- Fix plugins/read/init.lua to use read_lines, use utf8.offset for
  byte-safe truncation, and correct line-number width formatting.
- Fix plugins/grep/init.lua to strip leading/trailing quotes from
  patterns and correct line-number width formatting.
- Replace ToolRegistry linear scans with an Arc-swapped ToolsSnapshot
  backed by a HashMap, and update n00n-ui's ToolsCache accordingly.
@coderabbitai

coderabbitai Bot commented Jul 27, 2026 •

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: f72e5faf-4813-4370-9254-3487975a1155

📥 Commits

Reviewing files that changed from the base of the PR and between effc288 and 8842041.

📒 Files selected for processing (12)
  • changelog.d/160.fixed.md
  • changelog.d/160.performance.md
  • n00n-agent/src/tools/grep.rs
  • n00n-agent/src/tools/mod.rs
  • n00n-agent/src/tools/registry.rs
  • n00n-agent/src/tools/tool_search.rs
  • n00n-lua/src/api/fs.rs
  • n00n-ui/src/agent/agent_loop.rs
  • plugins/grep/init.lua
  • plugins/lib/n00n/truncate.lua
  • plugins/read/init.lua
  • site/docs/content/lua-api/_index.md

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Added line-range file reading with total line counts and surrounding context.
    • Improved handling of UTF-8 text, long lines, CRLF endings, and truncation boundaries.
    • Tool searches now return reliably formatted JSON, including descriptions with special characters.
  • Bug Fixes

    • Improved errors for missing search paths and invalid directory options.
    • Fixed quoted grep patterns and line-number alignment.
    • Improved resilience when scanning directories and processing very long files.
  • Performance

    • Faster tool lookup and registry access.
  • Documentation

    • Documented the new line-reading filesystem API.

Walkthrough

The changes add streaming filesystem line reads, UTF-8-safe truncation, stricter grep handling, JSON-based tool output, and HashMap-indexed tool registry snapshots. Related tests, exports, documentation, and changelog entries were updated.

Changes

File tool correctness

Layer / File(s) Summary
Streaming file reads and UTF-8 output
n00n-lua/src/api/fs.rs, plugins/read/init.lua, plugins/lib/n00n/truncate.lua, site/docs/content/lua-api/_index.md
n00n.fs.read_lines streams UTF-8 lines with offsets, limits, prefixes, totals, CRLF handling, and deterministic errors. Read and truncation plugins use UTF-8-safe byte limits and the new response shape.
Grep validation and result collection
n00n-agent/src/tools/grep.rs, plugins/grep/init.lua
Grep validates paths, logs traversal and search failures, collects parallel results through a channel, strips only surrounding quotes, and derives line-number width from digit count.

Tool registry and output

Layer / File(s) Summary
Indexed registry snapshots
n00n-agent/src/tools/registry.rs, n00n-agent/src/tools/mod.rs, n00n-ui/src/agent/agent_loop.rs
ToolsSnapshot stores ordered tools with a name index, and registry mutations rebuild atomic snapshots consumed by the UI cache.
JSON tool responses
n00n-agent/src/tools/tool_search.rs
Tool search and namespace responses are serialized through JSON values, with escaping round-trip coverage.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant ReadTool
  participant n00n.fs.read_lines
  participant File
  ReadTool->>n00n.fs.read_lines: request offset and limit
  n00n.fs.read_lines->>File: stream buffered UTF-8 lines
  File-->>n00n.fs.read_lines: lines and total_lines
  n00n.fs.read_lines-->>ReadTool: lines, prefix, total_lines
Loading

Possibly related PRs

  • w0wl0lxd/n00n#12: Related to the registry snapshot API and downstream snapshot caching.

Poem

A rabbit hops through lines so bright,
UTF-8 curls all come out right.
Snapshots index tools in rows,
Grep sends matches where it goes.
“JSON!” the bunny cheers tonight.

✨ 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 fix/filetools-followup

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.

@github-actions

Copy link
Copy Markdown

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@codecov

codecov Bot commented Jul 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 79.12371% with 81 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
n00n-lua/src/api/fs.rs 85.82% 37 Missing ⚠️
n00n-agent/src/tools/registry.rs 66.26% 28 Missing ⚠️
n00n-agent/src/tools/tool_search.rs 60.00% 10 Missing ⚠️
n00n-agent/src/tools/grep.rs 68.42% 6 Missing ⚠️

📢 Thoughts on this report? Let us know!

@github-actions github-actions Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Criterion

Details
Benchmark suite Current: 8842041 Previous: effc288 Ratio
fib/jit_mlua_hook 5308303 ns/iter (± 168566) 6481806 ns/iter (± 170017) 0.82
fib/jit_watchdog 1898583 ns/iter (± 10237) 2442795 ns/iter (± 6390) 0.78
fib/jit_none 1896915 ns/iter (± 30292) 2443849 ns/iter (± 31481) 0.78
fib/interp_mlua_hook 5955194 ns/iter (± 236981) 7687393 ns/iter (± 21353) 0.77
fib/interp_watchdog 3027951 ns/iter (± 84255) 3890031 ns/iter (± 13264) 0.78
fib/interp_none 3031976 ns/iter (± 8454) 3872294 ns/iter (± 17252) 0.78
buffer_rw/jit_mlua_hook 430990 ns/iter (± 10695) 554028 ns/iter (± 11300) 0.78
buffer_rw/jit_watchdog 130482 ns/iter (± 443) 167820 ns/iter (± 287) 0.78
buffer_rw/jit_none 130474 ns/iter (± 3716) 167957 ns/iter (± 1691) 0.78
buffer_rw/interp_mlua_hook 821292 ns/iter (± 9107) 1047403 ns/iter (± 3919) 0.78
buffer_rw/interp_watchdog 499312 ns/iter (± 5537) 646436 ns/iter (± 10073) 0.77
buffer_rw/interp_none 499452 ns/iter (± 5224) 647732 ns/iter (± 12756) 0.77
splash_render_120x40 47903 ns/iter (± 7808) 73489 ns/iter (± 4090) 0.65
splash_render_200x60 143000 ns/iter (± 4938) 178968 ns/iter (± 12812) 0.80

This comment was automatically generated by workflow using github-action-benchmark.

@cursor

cursor Bot commented Jul 28, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: serverGenReqId_5eefe5ec-7fa7-42da-9b6d-af2190e1daee)

@w0wl0lxd

Copy link
Copy Markdown
Owner Author

cursor review

@cursor

cursor Bot commented Jul 28, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: serverGenReqId_da39bc1d-ef7e-479e-8b20-af737a59c1f6)

@w0wl0lxd
w0wl0lxd marked this pull request as ready for review July 28, 2026 05:29
@w0wl0lxd
w0wl0lxd merged commit 8d0865e into main Jul 28, 2026
34 checks passed
@cursor

cursor Bot commented Jul 28, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: serverGenReqId_efdd555a-cfbe-46b2-94db-1ff151449f5b)

@linear-code

linear-code Bot commented Jul 28, 2026

Copy link
Copy Markdown

N00N-88

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