#19125: fix(edit): allow empty string newText for line deletion
agents
size: XS
trusted-contributor
Cluster:
TUI and Tool Execution Fixes
## Summary
Fixes #19085 — the edit tool rejects empty string `newText` as a missing required parameter, preventing line deletion via `newText: ""`.
## Root Cause
The `assertRequiredParams` validation uses `value.trim().length > 0` for the newText parameter group, which treats empty strings and whitespace-only strings as missing. The `allowEmpty` guard exists but wasn't set for newText.
## Fix
Add `allowEmpty: true` to the newText/new_string parameter group in `CLAUDE_PARAM_GROUPS.edit`. This is the same pattern used elsewhere (e.g., in common.ts line 190).
## Changes
- `src/agents/pi-tools.read.ts`: Add `allowEmpty: true` to newText param group
- `src/agents/pi-tools.read.edit-empty-newtext.test.ts`: 4 unit tests covering empty string, whitespace, missing newText, and missing oldText
## Testing
- [x] All 4 new tests pass
- [x] `pnpm build` succeeds
- [x] Lint passes (0 warnings, 0 errors)
AI-assisted (Claude/HAL). Fully tested locally.
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Fixed validation to allow empty string `newText` in the edit tool for line deletion. Previously, `assertRequiredParams` rejected empty strings using `value.trim().length > 0`, preventing deletion via `newText: ""`. Added `allowEmpty: true` to the newText parameter group, matching the pattern used elsewhere in the codebase (e.g., `src/agents/tools/common.ts:190`).
- Added `allowEmpty: true` to newText parameter validation in `CLAUDE_PARAM_GROUPS.edit`
- Added comprehensive test coverage with 4 unit tests covering empty strings, whitespace, and missing parameter validation
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge with minimal risk
- The fix is minimal, well-targeted, and follows existing patterns. It adds a single boolean flag to enable empty strings for a specific use case. The change is covered by comprehensive unit tests that verify both the new behavior (allowing empty strings) and the existing behavior (rejecting missing parameters). The implementation matches the same pattern used elsewhere in the codebase for similar validation scenarios.
- No files require special attention
<sub>Last reviewed commit: e52c834</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#23381: fix(tools): allow empty newText in edit tool for text deletion
by SidQin-cyber · 2026-02-22
92.1%
#22778: fix: allow empty string for edit tool newText parameter
by miloudbelarebia · 2026-02-21
90.2%
#21695: fix(edit): include line numbers in duplicate match errors
by lbo728 · 2026-02-20
73.4%
#16733: fix(ui): avoid injected newlines when tool output is hidden
by jp117 · 2026-02-15
72.5%
#18464: fix(web-search): handle empty query gracefully instead of crashing
by Clawborn · 2026-02-16
72.2%
#12325: fix: trim leading/trailing whitespace from outbound messages
by jordanstern · 2026-02-09
70.5%
#6502: fix(tui): skip empty text for tool-only assistant turns
by douvy · 2026-02-01
70.4%
#14470: fix(agents): unescape newlines in write and edit tool content
by VintLin · 2026-02-12
69.9%
#17070: fix(telegram): Outbound: ignore empty legacy target fields
by yhw2003 · 2026-02-15
69.9%
#22198: fix(skills): treat empty allowBundled array as block-all
by haitao-sjsu · 2026-02-20
68.8%