mirror of
https://github.com/RooVetGit/Roo-Code.git
synced 2026-08-28 05:27:24 +00:00
Co-authored-by: daniel-lxs <ricciodaniel98@gmail.com> Co-authored-by: Matt Rubens <mrubens@users.noreply.github.com>
75 lines
2.3 KiB
TypeScript
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()
|