Skip to content

Add system.fs_file_edit script for file splice operations with comprehensive benchmarks #1880

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 5 commits into
base: dev
Choose a base branch
from

Conversation

Copilot
Copy link

@Copilot Copilot AI commented Aug 19, 2025

Implements a new system script system.fs_file_edit that provides file editing capabilities through a splice operation, similar to JavaScript's Array.splice() but for file lines.

What this adds

The new fs_file_edit tool allows AI agents to precisely edit files by:

  • Inserting lines at a specific position without deleting existing content
  • Deleting lines from a specific position without inserting new content
  • Replacing lines by deleting and inserting in one operation

Usage

// Insert lines at position 3 without deleting
await runTool("fs_file_edit", {
    filename: "example.txt",
    insertLine: 3,
    deleteCount: 0,
    lines: ["new line 1", "new line 2"]
})

// Delete 2 lines starting at position 5
await runTool("fs_file_edit", {
    filename: "example.txt", 
    insertLine: 5,
    deleteCount: 2,
    lines: []
})

// Replace 1 line at position 2 with 3 new lines
await runTool("fs_file_edit", {
    filename: "example.txt",
    insertLine: 2, 
    deleteCount: 1,
    lines: ["replacement 1", "replacement 2", "replacement 3"]
})

Implementation details

  • File: /packages/core/genaisrc/system.fs_file_edit.genai.mts
  • Tool name: fs_file_edit (follows established fs_ naming convention)
  • Parameters:
    • filename: Path relative to workspace root
    • insertLine: 1-based line number where to start the edit
    • deleteCount: Number of lines to delete (default: 0)
    • lines: Array of lines to insert (default: [])
  • Validation: Comprehensive error handling for invalid line numbers, file boundaries, and missing files
  • Security: Respects workspace boundaries like other file system tools

Testing & Benchmarks

  • Added comprehensive test suite covering insert, delete, and replace operations
  • Manual testing confirms tool loads correctly with CLI
  • Integrates seamlessly with existing system (now 60 total tools)
  • NEW: Added fs-file-edit-benchmark.genai.mts in samples/sample that provides comprehensive benchmarking with:
    • 10 test scenarios covering all file edit operations
    • Performance testing with large files
    • Error handling validation for edge cases
    • Structured test setup with sample files for reproducible testing

The benchmark script demonstrates proper usage patterns and validates tool reliability across different file editing scenarios, making it easier for developers to understand and test the fs_file_edit capabilities.

This enables more precise file editing for AI agents compared to full file rewrites, making it easier to implement targeted code changes and content modifications.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@Copilot Copilot AI changed the title [WIP] Add system script "system.files.edit" that acts as a splice on a file. It takes filename, inserline number, number of deleted lines and lines to insert and applies the transformation to the file. Add system.files.edit script for file splice operations Aug 19, 2025
@Copilot Copilot AI requested a review from pelikhan August 19, 2025 12:05
Copilot finished work on behalf of pelikhan August 19, 2025 12:05
@pelikhan
Copy link
Member

@copilot rename tool to "fs_file_edit"

Copy link
Author

Copilot AI commented Aug 19, 2025

@copilot rename tool to "fs_file_edit"

Done! Renamed the tool from "files_edit" to "fs_file_edit" to follow the established fs_ naming convention. Updated the script file, test file, and documentation. Commit: 13a038f

@Copilot Copilot AI changed the title Add system.files.edit script for file splice operations Add system.fs_file_edit script for file splice operations Aug 19, 2025
Copilot finished work on behalf of pelikhan August 19, 2025 12:15
@pelikhan
Copy link
Member

@copilot add genaiscript script in samples/sample that runs tests against file edit benchmarks

Copy link
Author

Copilot AI commented Aug 19, 2025

@copilot add genaiscript script in samples/sample that runs tests against file edit benchmarks

Created fs-file-edit-benchmark.genai.mts in samples/sample/genaisrc that comprehensively tests the fs_file_edit tool with 10 benchmark scenarios covering insert, delete, replace, error handling, and performance testing. The script sets up test files and provides structured validation of all file splice operations. Commit: 7fb0fcc

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • cdn.sheetjs.com
    • Triggering command: node /home/REDACTED/.local/share/pnpm/.tools/pnpm/10.12.3/bin/pnpm install (dns block)
  • esm.ubuntu.com
    • Triggering command: /usr/lib/apt/methods/https (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@Copilot Copilot AI changed the title Add system.fs_file_edit script for file splice operations Add system.fs_file_edit script for file splice operations with comprehensive benchmarks Aug 19, 2025
Copilot finished work on behalf of pelikhan August 19, 2025 12:52
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.

2 participants