@@ -29,7 +29,7 @@ import {
2929 everyLineHasLineNumbers ,
3030} from "../integrations/misc/extract-text"
3131import { countFileLines } from "../integrations/misc/line-counter"
32- import { fetchInstructions } from "./prompts/instructions/instructions "
32+ import { fetchInstructionsTool } from "./tools/fetchInstructionsTool "
3333import { ExitCodeDetails } from "../integrations/terminal/TerminalProcess"
3434import { Terminal } from "../integrations/terminal/Terminal"
3535import { TerminalRegistry } from "../integrations/terminal/TerminalRegistry"
@@ -86,7 +86,7 @@ import { readLines } from "../integrations/misc/read-lines"
8686import { getWorkspacePath } from "../utils/path"
8787import { isBinaryFile } from "isbinaryfile"
8888
89- type ToolResponse = string | Array < Anthropic . TextBlockParam | Anthropic . ImageBlockParam >
89+ export type ToolResponse = string | Array < Anthropic . TextBlockParam | Anthropic . ImageBlockParam >
9090type UserContent = Array < Anthropic . Messages . ContentBlockParam >
9191
9292export type ClineEvents = {
@@ -148,9 +148,11 @@ export class Cline extends EventEmitter<ClineEvents> {
148148 private askResponseText ?: string
149149 private askResponseImages ?: string [ ]
150150 private lastMessageTs ?: number
151- private consecutiveMistakeCount : number = 0
151+ // Not private since it needs to be accessible by tools
152+ consecutiveMistakeCount : number = 0
152153 private consecutiveMistakeCountForApplyDiff : Map < string , number > = new Map ( )
153- private providerRef : WeakRef < ClineProvider >
154+ // Not private since it needs to be accessible by tools
155+ providerRef : WeakRef < ClineProvider >
154156 private abort : boolean = false
155157 didFinishAbortingStream = false
156158 abandoned = false
@@ -2402,59 +2404,8 @@ export class Cline extends EventEmitter<ClineEvents> {
24022404 }
24032405
24042406 case "fetch_instructions" : {
2405- const task : string | undefined = block . params . task
2406- const sharedMessageProps : ClineSayTool = {
2407- tool : "fetchInstructions" ,
2408- content : task ,
2409- }
2410- try {
2411- if ( block . partial ) {
2412- const partialMessage = JSON . stringify ( {
2413- ...sharedMessageProps ,
2414- content : undefined ,
2415- } satisfies ClineSayTool )
2416- await this . ask ( "tool" , partialMessage , block . partial ) . catch ( ( ) => { } )
2417- break
2418- } else {
2419- if ( ! task ) {
2420- this . consecutiveMistakeCount ++
2421- pushToolResult (
2422- await this . sayAndCreateMissingParamError ( "fetch_instructions" , "task" ) ,
2423- )
2424- break
2425- }
2426-
2427- this . consecutiveMistakeCount = 0
2428- const completeMessage = JSON . stringify ( {
2429- ...sharedMessageProps ,
2430- content : task ,
2431- } satisfies ClineSayTool )
2432-
2433- const didApprove = await askApproval ( "tool" , completeMessage )
2434- if ( ! didApprove ) {
2435- break
2436- }
2437-
2438- // now fetch the content and provide it to the agent.
2439- const provider = this . providerRef . deref ( )
2440- const mcpHub = provider ?. getMcpHub ( )
2441- if ( ! mcpHub ) {
2442- throw new Error ( "MCP hub not available" )
2443- }
2444- const diffStrategy = this . diffStrategy
2445- const context = provider ?. context
2446- const content = await fetchInstructions ( task , { mcpHub, diffStrategy, context } )
2447- if ( ! content ) {
2448- pushToolResult ( formatResponse . toolError ( `Invalid instructions request: ${ task } ` ) )
2449- break
2450- }
2451- pushToolResult ( content )
2452- break
2453- }
2454- } catch ( error ) {
2455- await handleError ( "fetch instructions" , error )
2456- break
2457- }
2407+ fetchInstructionsTool ( this , block , askApproval , handleError , pushToolResult )
2408+ break
24582409 }
24592410
24602411 case "list_files" : {
0 commit comments