Skip to content

feat: delete_range — reliable large text deletion with anchor-based range matching | 大块文本删除工具#2190

Merged
esengine merged 1 commit into
esengine:mainfrom
SivanCola:pr/3-delete-range
May 29, 2026
Merged

feat: delete_range — reliable large text deletion with anchor-based range matching | 大块文本删除工具#2190
esengine merged 1 commit into
esengine:mainfrom
SivanCola:pr/3-delete-range

Conversation

@SivanCola

Copy link
Copy Markdown
Collaborator

Summary

Adds a delete_range tool that deletes a contiguous text range from a file using exact start/end text anchors. Parameters: path, start_anchor, end_anchor, inclusive. Requires read_file first (enforced via ReadTracker). No-op on missing/duplicate anchors or reversed ranges. Returns unified diff on success. Integrated into the edit review/auto/yolo gate with CRLF line ending normalization and path traversal protection.

概述

新增 delete_range 工具,使用精确的开始/结束文本锚点删除文件中的连续文本范围。参数:path、start_anchor、end_anchor、inclusive。要求先 read_file(通过 ReadTracker 强制执行)。缺失/重复锚点或反转范围时 no-op。成功时返回 unified diff。集成到 edit review/auto/yolo 门禁,支持 CRLF 换行符自适应和路径穿越防护。

Key Files

  • src/tools/filesystem.tsdelete_range tool registration
  • src/tools/fs/edit.tsapplyDeleteRange(), computeDeleteRangePatchFromText()
  • src/tools.ts — gate rejection patterns
  • src/cli/ui/edit-tool-gate.ts — review/auto gate integration
  • src/code/prompt.ts — recommend delete_range for large deletions
  • src/code/lifecycle-policy.ts — high-risk classification
  • tests/delete-tools.test.ts (new) — unit tests

Depends On / 依赖

This PR is #3 in a 5-PR series:

Test Plan

  • Unread file refusal (read-before-edit enforcement)
  • Duplicate anchor no-op
  • CRLF line ending normalization in review preview
  • Path traversal protection (../ outside workspace)
  • Review/auto gate integration

Verification

npm run lint      → 0 errors
npx vitest run tests/delete-tools.test.ts tests/review-edit-gate.test.ts → all passed

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f520f05495

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/tools/filesystem.ts Outdated
@SivanCola SivanCola changed the title feat: delete_range — reliable large text deletion with anchor-based range matching feat: delete_range — reliable large text deletion with anchor-based range matching | 大块文本删除工具 May 28, 2026
@SivanCola

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6426b6823f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/cli/ui/edit-tool-gate.ts Outdated
@SivanCola

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6212f5e0ea

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/cli/ui/edit-tool-gate.ts
@esengine

Copy link
Copy Markdown
Owner

Part of the #2188#2192 stack that currently shows the same cumulative +1740/-39 diff on all five PRs (all based on main but stacked on each other). See my comment on #2188 for the fix — please split into independent single-feature branches off main so each PR contains only its own change. I'll review this one (and especially the file-deleting / RFC ones) properly once it's isolated.

@esengine esengine left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Reviewed the now-split, independent PR — this is a well-built, safety-first tool. computeDeleteRangePatchFromText requires exactly one occurrence of each anchor (0 → 'not found', >1 → 'appears N times', both no-op), rejects reversed/empty ranges, and inclusive defaults sensibly. And it's wired into every existing edit-safety layer: safePath(..., "write") for traversal protection, readTracker.hasRead enforcement (anchors must match on-disk bytes), prepareAutoGitRollback for the pre-edit checkpoint, and ReviewGatedEditTool so it routes through the review/auto gate like edit_file. Returns a unified diff, tests in delete-tools.test.ts, CI green. The exactly-one-anchor rule + review gate make accidental/ambiguous deletion essentially impossible. Merging.

@esengine esengine merged commit 7cf0195 into esengine:main May 29, 2026
4 checks passed
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