fix: trim whitespace from tool names to prevent invalid tool calls
Some models (e.g. kimi-k2.5) return tool names with leading spaces like ' delegate_task', causing tool matching to fail. Add .trim() in transformToolName() and defensive trim in claude-code-hooks. Fixes #1568
This commit is contained in:
@@ -13,14 +13,15 @@ function toPascalCase(str: string): string {
|
||||
}
|
||||
|
||||
export function transformToolName(toolName: string): string {
|
||||
const lower = toolName.toLowerCase()
|
||||
const trimmed = toolName.trim()
|
||||
const lower = trimmed.toLowerCase()
|
||||
if (lower in SPECIAL_TOOL_MAPPINGS) {
|
||||
return SPECIAL_TOOL_MAPPINGS[lower]
|
||||
}
|
||||
|
||||
if (toolName.includes("-") || toolName.includes("_")) {
|
||||
return toPascalCase(toolName)
|
||||
if (trimmed.includes("-") || trimmed.includes("_")) {
|
||||
return toPascalCase(trimmed)
|
||||
}
|
||||
|
||||
return toolName.charAt(0).toUpperCase() + toolName.slice(1)
|
||||
return trimmed.charAt(0).toUpperCase() + trimmed.slice(1)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user