Skip to content

feat(gadgets): add multi-mode EditFile and line numbers to ReadFile#75

Merged
zbigniewsobiecki merged 1 commit intodevfrom
feat/editfile-multi-mode
Jan 18, 2026
Merged

feat(gadgets): add multi-mode EditFile and line numbers to ReadFile#75
zbigniewsobiecki merged 1 commit intodevfrom
feat/editfile-multi-mode

Conversation

@zbigniewsobiecki
Copy link
Copy Markdown
Member

Summary

  • EditFile multi-mode: Refactored to support 3 operation modes via discriminated union:

    • search_replace: Existing behavior with layered matching (exact → whitespace → indentation → fuzzy)
    • insert_at_line: Insert content at a specific line number (1-based, inserts BEFORE the specified line)
    • remove_lines: Remove a range of lines (1-based, inclusive)
  • ReadFile line numbers: Added optional showLineNumbers parameter that prefixes each line with its 1-based line number (e.g., 1 | content) for precise line-based editing

Changes

EditFile (src/gadgets/EditFile.ts)

  • Schema changed from flat object to z.discriminatedUnion('mode', [...])
  • Updated description documenting all three modes
  • Refactored execute() to dispatch to mode-specific handlers
  • Added 6 new examples (3 for insert_at_line, 3 for remove_lines)
  • All existing examples updated with mode: 'search_replace'

ReadFile (src/gadgets/ReadFile.ts)

  • Added showLineNumbers optional boolean parameter (default: false)
  • Added addLineNumbers() helper method
  • Added example showing line numbers output

Edge Cases Handled

Scenario Mode Handling
Empty file insert_at_line Insert at line 1
Empty file remove_lines Error: startLine beyond EOF
Line > EOF insert_at_line Append at end
startLine > endLine remove_lines Error
startLine > EOF remove_lines Error

Test plan

  • All existing tests pass (120 tests)
  • TypeScript type checking passes
  • Biome lint passes
  • Pre-commit and pre-push hooks pass

🤖 Generated with Claude Code

EditFile now supports 3 modes via discriminated union:
- search_replace: existing behavior with layered matching
- insert_at_line: insert content at specific line (1-based)
- remove_lines: remove range of lines (1-based, inclusive)

ReadFile now supports optional showLineNumbers parameter that
prefixes each line with its 1-based line number for precise editing.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@zbigniewsobiecki zbigniewsobiecki merged commit 27eeaff into dev Jan 18, 2026
3 checks passed
@zbigniewsobiecki zbigniewsobiecki deleted the feat/editfile-multi-mode branch January 18, 2026 10:55
This was referenced Jan 18, 2026
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