Skip to content

Changed: ToolContext::NAME from associated const to method#121

Merged
Sewer56 merged 1 commit into
mainfrom
change-tool-context-name-to-method
May 29, 2026
Merged

Changed: ToolContext::NAME from associated const to method#121
Sewer56 merged 1 commit into
mainfrom
change-tool-context-name-to-method

Conversation

@Sewer56
Copy link
Copy Markdown
Member

@Sewer56 Sewer56 commented May 29, 2026

ToolContext Object-Safety Migration

Summary

Migrate ToolContext::NAME from associated const to instance method for object-safety.
Required for future custom tool functionality.

Changes

  • ToolContext trait: const NAME -> fn name(&self) -> &'static str
  • Updated all tool implementations (read, write, edit, glob, grep, bash, webfetch, todo read/write, task)
  • Updated SystemPromptBuilder::track() to use tool.name()
  • Updated doc examples (README.md, custom-framework guide, mock tools)
  • Added test proving Box<dyn ToolContext> constructible

Breaking Change

Implementations must change from:

const NAME: &'static str = "mytool";

To:

fn name(&self) -> &'static str {
    "mytool"
}

- Replace `const NAME: &'static str` with `fn name(&self) -> &'static str` in the ToolContext trait
- Makes the trait object-safe, enabling `Box<dyn ToolContext>` for custom-tools feature
- Update all tool implementations: read, write, edit, glob, grep, bash, webfetch, todo read/write, task
- Update SystemPromptBuilder::track() to use tool.name() instead of T::NAME
- Update all doc examples and mock tools
- Add object-safety test proving Box<dyn ToolContext> construction works
- Silence doc lint warning on api_type field in provider-config
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 29, 2026

Review Change Stack

Warning

Review limit reached

@Sewer56, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 29 minutes and 8 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4bfc834e-1640-4a7a-a6f3-da20c0b706c0

📥 Commits

Reviewing files that changed from the base of the PR and between dee6897 and 0c7ac4e.

📒 Files selected for processing (1)
  • src/reloaded-code-serdesai/src/task/tool.rs

Walkthrough

This PR refactors the ToolContext trait to replace an associated constant NAME with an instance method name(&self) -> &'static str. The trait definition is updated in src/reloaded-code-core/src/context/mod.rs to require the new method signature and includes a test verifying object-safety. The SystemPromptBuilder integration point is updated to call tool.name() instead of reading the constant. All eleven tool implementations across the codebase—including Bash, Edit, Glob, Grep, Read, Todo (both variants), WebFetch, Write, and Task tools—are updated to provide naming via the instance method. Documentation examples, guide code snippets, and example mock tool implementations are revised to reflect the new API.

Possibly related PRs

  • Reloaded-Project/ReloadedCode#1: Initially introduced the ToolContext trait with the associated NAME constant, which this PR migrates to the instance method API.
  • Reloaded-Project/ReloadedCode#17: Adds mock ToolContext implementations using the old const NAME pattern, which would need updating to align with this refactoring's new name(&self) signature.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and clearly summarizes the main change: converting ToolContext::NAME from an associated constant to a method.
Description check ✅ Passed The description comprehensively covers the scope, implementation details, breaking changes, and includes code examples, though it could reference the contributing guidelines as per the template.
Docstring Coverage ✅ Passed Docstring coverage is 85.42% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch change-tool-context-name-to-method

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/reloaded-code-serdesai/src/task/tool.rs`:
- Around line 121-127: The test task_tool_name_matches_metadata should call the
ToolContext::name path on a real TaskTool instance rather than re-checking
task_tool_definition(...).name(); construct a TaskTool (or a minimal test double
implementing ToolContext) and assert that ToolContext::name(&tool) ==
task_meta::NAME, keeping or reusing the existing summary/targets setup as needed
and not relying on task_tool_definition to exercise TaskTool::name; reference
TaskTool and ToolContext::name in the test replacement so a broken impl
ToolContext for TaskTool<C> would be detected.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 93ee5612-42f5-45e1-9189-cd3db02676a7

📥 Commits

Reviewing files that changed from the base of the PR and between fab32c8 and dee6897.

📒 Files selected for processing (15)
  • docs/src/guides/custom-framework.md
  • src/reloaded-code-core/README.md
  • src/reloaded-code-core/examples/system_prompt/mock_tools.rs
  • src/reloaded-code-core/src/context/mod.rs
  • src/reloaded-code-core/src/system_prompt.rs
  • src/reloaded-code-provider-config/src/config.rs
  • src/reloaded-code-serdesai/src/task/tool.rs
  • src/reloaded-code-serdesai/src/tools/bash.rs
  • src/reloaded-code-serdesai/src/tools/edit.rs
  • src/reloaded-code-serdesai/src/tools/glob.rs
  • src/reloaded-code-serdesai/src/tools/grep.rs
  • src/reloaded-code-serdesai/src/tools/read.rs
  • src/reloaded-code-serdesai/src/tools/todo.rs
  • src/reloaded-code-serdesai/src/tools/webfetch.rs
  • src/reloaded-code-serdesai/src/tools/write.rs

Comment thread src/reloaded-code-serdesai/src/task/tool.rs
@Sewer56 Sewer56 force-pushed the change-tool-context-name-to-method branch from 0c7ac4e to dee6897 Compare May 29, 2026 16:05
@Sewer56 Sewer56 merged commit 72ff2b3 into main May 29, 2026
20 checks passed
@Sewer56 Sewer56 deleted the change-tool-context-name-to-method branch May 29, 2026 16:05
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