Skip to content

feat: delete_symbol — AST-aware symbol deletion via tree-sitter (6 languages) | AST 符号删除工具#2191

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

feat: delete_symbol — AST-aware symbol deletion via tree-sitter (6 languages) | AST 符号删除工具#2191
esengine merged 1 commit into
esengine:mainfrom
SivanCola:pr/4-delete-symbol

Conversation

@SivanCola

Copy link
Copy Markdown
Collaborator

Summary

Adds a delete_symbol tool that deletes one function/class/method/interface/type by exact name using tree-sitter AST parsing. Supports TS/TSX/JS/JSX/Python/Go/Rust/Java. Parameters: path, name, kind (optional filter), parent (optional parent class/namespace filter). Multi-match fails and returns candidates with kind/line/parent for the model to disambiguate. Integrated into the edit review/auto/yolo gate with read_file enforcement via ReadTracker. v1 is delete-only (no replace-symbol).

概述

新增 delete_symbol 工具,使用 tree-sitter AST 解析按精确名称删除函数/类/方法/接口/类型。支持 TS/TSX/JS/JSX/Python/Go/Rust/Java。参数:path、name、kind(可选过滤)、parent(可选父类/命名空间过滤)。多匹配时失败并返回候选项供模型消歧义。集成到 edit review/auto/yolo 门禁,通过 ReadTracker 强制执行 read_file。v1 仅做删除(无 replace-symbol)。

Key Files

  • src/tools/filesystem.tsdelete_symbol tool with tree-sitter integration
  • src/tools/fs/edit.tsapplyDeleteLineRange(), computeDeleteLineRangePatchFromText()
  • src/cli/ui/edit-tool-gate.tsbuildDeleteSymbolBlock(), review gate
  • src/cli/ui/App.tsx — ReadTracker in edit-gate interceptor
  • src/code/lifecycle-policy.ts — high-risk classification
  • tests/delete-tools.test.ts — AST deletion test

Depends On / 依赖

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

Test Plan

  • TypeScript function deletion via AST
  • Multi-language grammar support
  • Multi-match disambiguation with candidates
  • kind/parent filter parameters
  • read_file enforcement in review/auto gate

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
@SivanCola SivanCola changed the title feat: delete_symbol — AST-aware symbol deletion via tree-sitter (6 languages) feat: delete_symbol — AST-aware symbol deletion via tree-sitter (6 languages) | AST 符号删除工具 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.

@SivanCola SivanCola force-pushed the pr/4-delete-symbol branch from 6212f5e to e56eb2c Compare May 29, 2026 03:23

@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 — equally solid, and I like that it reuses the existing code-query/symbols tree-sitter extraction rather than adding a new parser dependency. Safety mirrors delete_range: exactly-one-match required (0 → no-op, >1 → error returning candidates with kind/line/parent to disambiguate), read_file enforced, ReviewGatedEditTool + auto-git-rollback wired, kind/parent filters for precision. Reusing proven symbol extraction is the right call.

Two notes:

  1. Will need a rebase — I just merged #2190 (delete_range), which touches the same registration points (tools.ts, edit.ts, filesystem.ts, edit-tool-gate.ts, auto-git-rollback.ts, prompt.ts). Quick rebase onto current main and it's good.
  2. Non-blocking: confirm the deleted node range covers leading decorators / preceding doc-comments (Python @decorator, TS decorators, JSDoc) — if the symbol's AST range starts at the function/class keyword, deleting it could orphan a decorator or leave a dangling doc-comment. The review gate catches it visually, but worth a test case (delete a decorated symbol, assert the decorator goes too) if extractSymbols includes them in range.

Approving the approach; rebase for the merge.

@SivanCola SivanCola force-pushed the pr/4-delete-symbol branch from e56eb2c to 8056d16 Compare May 29, 2026 04:30

@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.

Re-reviewed after the rebase — clean against current main now (the delete_range registration points it conflicted with are reconciled). My earlier approval stands: reuses the existing code-query/symbols tree-sitter extraction (no new parser dep), exactly-one-match safety (0 → no-op, >1 → error with candidates), read_file enforced, review-gated, auto-git-rollback wired. CLEAN + CI green. Merging.

@esengine esengine merged commit 0a5bc54 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