-
Notifications
You must be signed in to change notification settings - Fork 998
fix: improve converter tool mappings and drop redundant tool guidance #358
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
tmchow
wants to merge
1
commit into
main
Choose a base branch
from
fix/converter-tool-mappings
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+433
−58
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| export function composeAgentBody(options: { | ||
| body: string | ||
| fallback: string | ||
| capabilities?: string[] | ||
| }): string { | ||
| const sections: string[] = [] | ||
|
|
||
| if (options.capabilities && options.capabilities.length > 0) { | ||
| sections.push( | ||
| `## Capabilities\n${options.capabilities.map((capability) => `- ${capability}`).join("\n")}`, | ||
| ) | ||
| } | ||
|
|
||
| const body = options.body.trim() | ||
| sections.push(body.length > 0 ? body : options.fallback) | ||
|
|
||
| return sections.join("\n\n") | ||
| } | ||
|
|
||
| export function normalizeToolSpecifier(tool: string): string { | ||
| return tool.split("(", 1)[0]?.trim().toLowerCase() ?? "" | ||
| } | ||
|
|
||
| export function mapToolSpecifiers( | ||
| tools: string[] | undefined, | ||
| mapping: Record<string, string>, | ||
| ): { mappedTools: string[] | undefined; unmappedTools: string[] } { | ||
| if (!tools || tools.length === 0) { | ||
| return { mappedTools: undefined, unmappedTools: [] } | ||
| } | ||
|
|
||
| const mapped: string[] = [] | ||
| const unmapped: string[] = [] | ||
| for (const tool of tools) { | ||
| const mappedTool = mapping[normalizeToolSpecifier(tool)] | ||
| if (!mappedTool) { | ||
| if (!unmapped.includes(tool)) unmapped.push(tool) | ||
| continue | ||
| } | ||
| if (mapped.includes(mappedTool)) continue | ||
| mapped.push(mappedTool) | ||
| } | ||
|
|
||
| return { | ||
| mappedTools: mapped.length > 0 ? mapped : undefined, | ||
| unmappedTools: unmapped, | ||
| } | ||
| } | ||
|
|
||
| export function formatToolMappingWarning(options: { | ||
| sourceTools: string[] | ||
| unmappedTools: string[] | ||
| target: string | ||
| fallback: string | ||
| }): string { | ||
| if (options.unmappedTools.length === options.sourceTools.length) { | ||
| return `Warning: ${options.target} has no mapping for Claude agent tools [${options.sourceTools.join(", ")}]. ${options.fallback}` | ||
| } | ||
|
|
||
| return `Warning: ${options.target} cannot preserve Claude agent tools [${options.unmappedTools.join(", ")}] from [${options.sourceTools.join(", ")}]. ${options.fallback}` | ||
| } | ||
|
|
||
| export function resolveStructuredAgentTools(options: { | ||
| sourceTools: string[] | undefined | ||
| mappedTools: string[] | undefined | ||
| unmappedTools: string[] | ||
| target: string | ||
| }): string[] { | ||
| if (!options.sourceTools || options.sourceTools.length === 0) { | ||
| return ["*"] | ||
| } | ||
|
|
||
| if (options.unmappedTools.length === 0 && options.mappedTools && options.mappedTools.length > 0) { | ||
| return options.mappedTools | ||
| } | ||
|
|
||
| console.warn( | ||
| formatToolMappingWarning({ | ||
| sourceTools: options.sourceTools, | ||
| unmappedTools: options.unmappedTools, | ||
| target: options.target, | ||
| fallback: 'Falling back to ["*"] so the converted agent remains usable.', | ||
| }), | ||
| ) | ||
| return ["*"] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using a case-insensitive pattern here causes ordinary prose to be rewritten as if it were a tool reference, because
taskis now matched in any casing whenever it is followed byto. In converted prompts, sentences like "the next task to complete..." become "the next use_subagent to complete...", which corrupts instructions and can materially change agent behavior. This regression appears in the new lowercase mapping +giregex combination and should be constrained to explicit tool-invocation phrasing.Useful? React with 👍 / 👎.