Roo-Code/src/core/tools/FetchInstructionsTool.ts
Hannes Rudolph 8de9337e63
chore: remove XML tool calling support (#10841)
Co-authored-by: daniel-lxs <ricciodaniel98@gmail.com>
Co-authored-by: Matt Rubens <mrubens@users.noreply.github.com>
2026-01-20 20:25:08 -05:00

75 lines
2.3 KiB
TypeScript

import { type ClineSayTool } from "@roo-code/types"
import { Task } from "../task/Task"
import { fetchInstructions } from "../prompts/instructions/instructions"
import { formatResponse } from "../prompts/responses"
import type { ToolUse } from "../../shared/tools"
import { BaseTool, ToolCallbacks } from "./BaseTool"
interface FetchInstructionsParams {
task: string
}
export class FetchInstructionsTool extends BaseTool<"fetch_instructions"> {
readonly name = "fetch_instructions" as const
async execute(params: FetchInstructionsParams, task: Task, callbacks: ToolCallbacks): Promise<void> {
const { handleError, pushToolResult, askApproval } = callbacks
const { task: taskParam } = params
try {
if (!taskParam) {
task.consecutiveMistakeCount++
task.recordToolError("fetch_instructions")
task.didToolFailInCurrentTurn = true
pushToolResult(await task.sayAndCreateMissingParamError("fetch_instructions", "task"))
return
}
task.consecutiveMistakeCount = 0
const completeMessage = JSON.stringify({
tool: "fetchInstructions",
content: taskParam,
} satisfies ClineSayTool)
const didApprove = await askApproval("tool", completeMessage)
if (!didApprove) {
return
}
// Now fetch the content and provide it to the agent.
const provider = task.providerRef.deref()
const mcpHub = provider?.getMcpHub()
if (!mcpHub) {
throw new Error("MCP hub not available")
}
const diffStrategy = task.diffStrategy
const context = provider?.context
const content = await fetchInstructions(taskParam, { mcpHub, diffStrategy, context })
if (!content) {
pushToolResult(formatResponse.toolError(`Invalid instructions request: ${taskParam}`))
return
}
pushToolResult(content)
} catch (error) {
await handleError("fetch instructions", error as Error)
}
}
override async handlePartial(task: Task, block: ToolUse<"fetch_instructions">): Promise<void> {
const taskParam: string | undefined = block.params.task
const sharedMessageProps: ClineSayTool = { tool: "fetchInstructions", content: taskParam }
const partialMessage = JSON.stringify({ ...sharedMessageProps, content: undefined } satisfies ClineSayTool)
await task.ask("tool", partialMessage, block.partial).catch(() => {})
}
}
export const fetchInstructionsTool = new FetchInstructionsTool()