Skip to content

Use AgentTool::NAME const instead of name() method and hardcoded strings#48506

Merged
rtfeldman merged 12 commits intomainfrom
const-tool-name
Feb 5, 2026
Merged

Use AgentTool::NAME const instead of name() method and hardcoded strings#48506
rtfeldman merged 12 commits intomainfrom
const-tool-name

Conversation

@rtfeldman
Copy link
Contributor

@rtfeldman rtfeldman commented Feb 5, 2026

This PR removes the fn name() default method from the AgentTool trait (which just returned Self::NAME) and replaces all call sites with direct use of the NAME associated constant. This lets us use it as a single source of truth in macros that want to access it at compile time.

This PR also replaces hardcoded tool name string literals throughout the codebase with the corresponding NAME constants, so tool name references stay in sync if a tool is renamed.

Intentionally not changed:

  • Display strings like "Thinking" and "Subagent" (user-facing UI labels)
  • Serde attributes like #[serde(rename = "thinking")] (wire format)
  • The test assertion assert_eq!(SubagentTool::NAME, "subagent") (replacing the literal would make it tautological)
  • MCP server names like "mcp:srv:terminal" (not tool identifiers)

Release Notes:

  • N/A

Add const NAME: &'static str to the AgentTool trait, replacing the
fn name() method with a default implementation that returns Self::NAME.
This allows tool names to be used in const contexts (e.g. const arrays).

Also adds ALL_TOOL_NAMES const array generated by the tools! macro,
providing a single source of truth for all built-in tool names.
Remove the fn name() default method from the AgentTool trait.
All call sites now use the NAME associated constant directly.
Replace hardcoded tool name string literals with Self::NAME.to_string()
(or EditFileTool::NAME for streaming_edit_file_tool) in all
ToolPermissionContext construction sites across tool implementations.
Replace hardcoded tool name strings with the corresponding NAME
associated constants in:
- has_tool() lookups (edit_file_tool, streaming_edit_file_tool)
- Tool routing in Thread::enabled_tools (streaming_edit_file/edit_file)
- Subagent telemetry ID
- Eval tool-use filtering
Replace hardcoded "terminal" and "edit_file" string literals with
TerminalTool::NAME and EditFileTool::NAME in the tool_permissions test
module.
Replace hardcoded tool name string literals in tests/mod.rs with the
corresponding NAME associated constants (TerminalTool::NAME,
EditFileTool::NAME, FetchTool::NAME, etc.) in ToolPermissionContext,
LanguageModelToolUse, settings inserts, and has_registered_tool calls.
Replace hardcoded "read_file" and "edit_file" string literals with
ReadFileTool::NAME and EditFileTool::NAME in LanguageModelToolUse
constructions, tools.insert() calls, and has_registered_tool() checks.
@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Feb 5, 2026
Fix cargo fmt violations in tests/mod.rs and replace ::name() calls
with ::NAME in the eval crate's planets example.
Remove the supported_built_in_tool_names function, making ALL_TOOL_NAMES
the single source of truth for built-in tool names. The one call site
now filters ALL_TOOL_NAMES directly using tool_supports_provider() and
the subagent feature flag check.
@rtfeldman rtfeldman marked this pull request as ready for review February 5, 2026 19:17
@rtfeldman rtfeldman enabled auto-merge (squash) February 5, 2026 19:20
@rtfeldman rtfeldman merged commit 65da2c2 into main Feb 5, 2026
27 checks passed
@rtfeldman rtfeldman deleted the const-tool-name branch February 5, 2026 19:28
naaiyy added a commit to Glass-HQ/Glass that referenced this pull request Feb 16, 2026
Key changes:
- Thermal state detection (zed-industries#45638) - GPUI detects system thermal state, throttles to ~60fps when overheating
- Checkerboard shader for side-by-side diff (zed-industries#48417) - visual pattern for diff backgrounds
- cosmic-text v0.17 (zed-industries#48504) - fixes font ligatures on Linux
- Middle click tab close (zed-industries#44916) - on_aux_click/is_middle_click API additions
- Soft wrap modes for wrap width (zed-industries#46422)
- Tab switcher mode similar to vim/helix buffer picker (zed-industries#47079)
- Multi_buffer optimization batch (zed-industries#48519)
- TreeMap for diagnostics (zed-industries#48482) - performance improvement
- Semantic token follow-up fixes (zed-industries#48485)
- Claude Opus 4.6 and 1M context window model variants (zed-industries#48508)
- Anthropic adaptive thinking types (zed-industries#48517)
- Side-by-side diff: hunk gutter highlights restored, toolbar buttons for SplittableEditor
- Shell quote bypass fix in terminal permission system (zed-industries#48436)
- Project panel: Collapse All improvements (zed-industries#47328, zed-industries#48443)
- Edit prediction: trailing newlines fix, cursor position in global coords
- Properly discard tokens on language server stop (zed-industries#48490)
- AgentTool::NAME const instead of hardcoded strings (zed-industries#48506)

Conflict resolution:
- collab/editor_tests.rs: deleted (collab removed)
- vim (helix, motion, increment): deleted (vim removed)
- GPUI (17 files): deleted from Glass (handled in Obsydian-HQ/gpui)
- editor/items.rs: merged imports (added BufferId, kept Theme)
- project_diff.rs: removed old native_button toggle (upstream uses toolbar buttons now)
- lsp_store.rs: added SemanticTokenConfig, removed GlobalLogStore/LanguageServerKind
- project_panel.rs: merged UI imports (added ContextMenuEntry, ScrollAxes)
- Keymaps: took upstream JetBrains bindings

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant