Skip to content

Commit 9a1a527

Browse files
committed
fix: type tool alias originalName and correct alias comments
1 parent 9509b6c commit 9a1a527

File tree

5 files changed

+12
-6
lines changed

5 files changed

+12
-6
lines changed

src/core/assistant-message/NativeToolCallParser.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ export class NativeToolCallParser {
537537

538538
// Preserve original name for API history when an alias was used
539539
if (originalName) {
540-
;(result as any).originalName = originalName
540+
result.originalName = originalName
541541
}
542542

543543
return result
@@ -559,7 +559,7 @@ export class NativeToolCallParser {
559559
return this.parseDynamicMcpTool(toolCall)
560560
}
561561

562-
// Resolve tool alias to canonical name (e.g., "edit_file" -> "search_and_replace")
562+
// Resolve tool alias to canonical name (e.g., "edit_file" -> "apply_diff", "temp_edit_file" -> "search_and_replace")
563563
const resolvedName = resolveToolAlias(toolCall.name as string) as TName
564564

565565
// Validate tool name (after alias resolution)
@@ -796,7 +796,7 @@ export class NativeToolCallParser {
796796

797797
// Preserve original name for API history when an alias was used
798798
if (toolCall.name !== resolvedName) {
799-
;(result as any).originalName = toolCall.name
799+
result.originalName = toolCall.name
800800
}
801801

802802
return result

src/core/assistant-message/presentAssistantMessage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ export async function presentAssistantMessage(cline: Task) {
696696
if (!block.partial) {
697697
const modelInfo = cline.api.getModel()
698698
// Resolve aliases in includedTools before validation
699-
// e.g., "edit_file" should resolve to "search_and_replace"
699+
// e.g., "edit_file" should resolve to "apply_diff"
700700
const rawIncludedTools = modelInfo?.info?.includedTools
701701
const { resolveToolAlias } = await import("../prompts/tools/filter-tools-for-mode")
702702
const includedTools = rawIncludedTools?.map((tool) => resolveToolAlias(tool))

src/core/prompts/tools/filter-tools-for-mode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ export function filterNativeToolsForMode(
218218
)
219219
allowedToolNames = customizedTools
220220

221-
// Apply tool aliases - if one tool in an alias group is allowed, all aliases are allowed
221+
// Resolve any aliases to canonical tool names for execution-time filtering
222222
allowedToolNames = applyToolAliases(allowedToolNames)
223223

224224
// Conditionally exclude codebase_search if feature is disabled or not configured

src/core/task/Task.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3110,7 +3110,7 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
31103110
// When tool aliases are used (e.g., "edit_file" -> "search_and_replace"),
31113111
// we want the alias name in the conversation history to match what the model
31123112
// was told the tool was named, preventing confusion in multi-turn conversations.
3113-
const toolNameForHistory = (toolUse as any).originalName || toolUse.name
3113+
const toolNameForHistory = toolUse.originalName ?? toolUse.name
31143114

31153115
assistantContent.push({
31163116
type: "tool_use" as const,

src/shared/tools.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,12 @@ export interface ToolUse<TName extends ToolName = ToolName> {
120120
type: "tool_use"
121121
id?: string // Optional ID to track tool calls
122122
name: TName
123+
/**
124+
* The original tool name as called by the model (e.g. an alias like "edit_file"),
125+
* if it differs from the canonical tool name used for execution.
126+
* Used to preserve tool names in API conversation history.
127+
*/
128+
originalName?: string
123129
// params is a partial record, allowing only some or none of the possible parameters to be used
124130
params: Partial<Record<ToolParamName, string>>
125131
partial: boolean

0 commit comments

Comments
 (0)