Skip to content

Commit 72894c2

Browse files
authored
Remove switch from tools (#2091)
* HandleError returns a promise * Remove unnecessary switch from tools
1 parent e95afc2 commit 72894c2

File tree

4 files changed

+193
-205
lines changed

4 files changed

+193
-205
lines changed

src/core/tools/fetchInstructionsTool.ts

Lines changed: 43 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -12,58 +12,53 @@ export async function fetchInstructionsTool(
1212
handleError: HandleError,
1313
pushToolResult: PushToolResult,
1414
) {
15-
switch (true) {
16-
default:
17-
const task: string | undefined = block.params.task
18-
const sharedMessageProps: ClineSayTool = {
19-
tool: "fetchInstructions",
20-
content: task,
15+
const task: string | undefined = block.params.task
16+
const sharedMessageProps: ClineSayTool = {
17+
tool: "fetchInstructions",
18+
content: task,
19+
}
20+
try {
21+
if (block.partial) {
22+
const partialMessage = JSON.stringify({
23+
...sharedMessageProps,
24+
content: undefined,
25+
} satisfies ClineSayTool)
26+
await cline.ask("tool", partialMessage, block.partial).catch(() => {})
27+
return
28+
} else {
29+
if (!task) {
30+
cline.consecutiveMistakeCount++
31+
pushToolResult(await cline.sayAndCreateMissingParamError("fetch_instructions", "task"))
32+
return
2133
}
22-
try {
23-
if (block.partial) {
24-
const partialMessage = JSON.stringify({
25-
...sharedMessageProps,
26-
content: undefined,
27-
} satisfies ClineSayTool)
28-
await cline.ask("tool", partialMessage, block.partial).catch(() => {})
29-
break
30-
} else {
31-
if (!task) {
32-
cline.consecutiveMistakeCount++
33-
pushToolResult(await cline.sayAndCreateMissingParamError("fetch_instructions", "task"))
34-
break
35-
}
3634

37-
cline.consecutiveMistakeCount = 0
38-
const completeMessage = JSON.stringify({
39-
...sharedMessageProps,
40-
content: task,
41-
} satisfies ClineSayTool)
35+
cline.consecutiveMistakeCount = 0
36+
const completeMessage = JSON.stringify({
37+
...sharedMessageProps,
38+
content: task,
39+
} satisfies ClineSayTool)
4240

43-
const didApprove = await askApproval("tool", completeMessage)
44-
if (!didApprove) {
45-
break
46-
}
41+
const didApprove = await askApproval("tool", completeMessage)
42+
if (!didApprove) {
43+
return
44+
}
4745

48-
// now fetch the content and provide it to the agent.
49-
const provider = cline.providerRef.deref()
50-
const mcpHub = provider?.getMcpHub()
51-
if (!mcpHub) {
52-
throw new Error("MCP hub not available")
53-
}
54-
const diffStrategy = cline.diffStrategy
55-
const context = provider?.context
56-
const content = await fetchInstructions(task, { mcpHub, diffStrategy, context })
57-
if (!content) {
58-
pushToolResult(formatResponse.toolError(`Invalid instructions request: ${task}`))
59-
break
60-
}
61-
pushToolResult(content)
62-
break
63-
}
64-
} catch (error) {
65-
await handleError("fetch instructions", error)
66-
break
46+
// now fetch the content and provide it to the agent.
47+
const provider = cline.providerRef.deref()
48+
const mcpHub = provider?.getMcpHub()
49+
if (!mcpHub) {
50+
throw new Error("MCP hub not available")
51+
}
52+
const diffStrategy = cline.diffStrategy
53+
const context = provider?.context
54+
const content = await fetchInstructions(task, { mcpHub, diffStrategy, context })
55+
if (!content) {
56+
pushToolResult(formatResponse.toolError(`Invalid instructions request: ${task}`))
57+
return
6758
}
59+
pushToolResult(content)
60+
}
61+
} catch (error) {
62+
await handleError("fetch instructions", error)
6863
}
6964
}

src/core/tools/listFilesTool.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,8 @@ export async function listFilesTool(
6969
return
7070
}
7171
pushToolResult(result)
72-
return
7372
}
7473
} catch (error) {
7574
await handleError("listing files", error)
76-
return
7775
}
7876
}

0 commit comments

Comments
 (0)