Skip to content

Commit 32f6deb

Browse files
committed
Add tool failed event
1 parent 0508a61 commit 32f6deb

File tree

9 files changed

+77
-6
lines changed

9 files changed

+77
-6
lines changed

evals/packages/types/src/ipc.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@ export const taskEventSchema = z.discriminatedUnion("eventName", [
111111
payload: rooCodeEventsSchema.shape[RooCodeEventName.TaskTokenUsageUpdated],
112112
taskId: z.number().optional(),
113113
}),
114+
z.object({
115+
eventName: z.literal(RooCodeEventName.TaskToolFailed),
116+
payload: rooCodeEventsSchema.shape[RooCodeEventName.TaskToolFailed],
117+
taskId: z.number().optional(),
118+
}),
114119
z.object({
115120
eventName: z.literal(EvalEventName.Pass),
116121
payload: z.undefined(),

evals/packages/types/src/roo-code.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,7 @@ export enum RooCodeEventName {
862862
TaskSpawned = "taskSpawned",
863863
TaskCompleted = "taskCompleted",
864864
TaskTokenUsageUpdated = "taskTokenUsageUpdated",
865+
TaskToolFailed = "taskToolFailed",
865866
}
866867

867868
export const rooCodeEventsSchema = z.object({
@@ -882,6 +883,7 @@ export const rooCodeEventsSchema = z.object({
882883
[RooCodeEventName.TaskSpawned]: z.tuple([z.string(), z.string()]),
883884
[RooCodeEventName.TaskCompleted]: z.tuple([z.string(), tokenUsageSchema, toolUsageSchema]),
884885
[RooCodeEventName.TaskTokenUsageUpdated]: z.tuple([z.string(), tokenUsageSchema]),
886+
[RooCodeEventName.TaskToolFailed]: z.tuple([z.string(), toolNamesSchema, z.string()]),
885887
})
886888

887889
export type RooCodeEvents = z.infer<typeof rooCodeEventsSchema>

package-lock.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/core/Cline.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ export type ClineEvents = {
107107
taskSpawned: [taskId: string]
108108
taskCompleted: [taskId: string, tokenUsage: TokenUsage, toolUsage: ToolUsage]
109109
taskTokenUsageUpdated: [taskId: string, tokenUsage: TokenUsage]
110+
taskToolFailed: [taskId: string, tool: ToolName, error: string]
110111
}
111112

112113
export type ClineOptions = {
@@ -340,6 +341,7 @@ export class Cline extends EventEmitter<ClineEvents> {
340341
return data
341342
}
342343
}
344+
343345
return []
344346
}
345347

@@ -2541,12 +2543,17 @@ export class Cline extends EventEmitter<ClineEvents> {
25412543

25422544
this.toolUsage[toolName].attempts++
25432545
}
2544-
public recordToolError(toolName: ToolName) {
2546+
2547+
public recordToolError(toolName: ToolName, error?: string) {
25452548
if (!this.toolUsage[toolName]) {
25462549
this.toolUsage[toolName] = { attempts: 0, failures: 0 }
25472550
}
25482551

25492552
this.toolUsage[toolName].failures++
2553+
2554+
if (error) {
2555+
this.emit("taskToolFailed", this.taskId, toolName, error)
2556+
}
25502557
}
25512558

25522559
public getToolUsage() {

src/core/tools/applyDiffTool.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ export async function applyDiffTool(
9696

9797
if (!diffResult.success) {
9898
cline.consecutiveMistakeCount++
99-
cline.recordToolError("apply_diff")
10099
const currentCount = (cline.consecutiveMistakeCountForApplyDiff.get(relPath) || 0) + 1
101100
cline.consecutiveMistakeCountForApplyDiff.set(relPath, currentCount)
102101
let formattedError = ""
@@ -128,6 +127,8 @@ export async function applyDiffTool(
128127
await cline.say("diff_error", formattedError)
129128
}
130129

130+
cline.recordToolError("apply_diff", formattedError)
131+
131132
pushToolResult(formattedError)
132133
return
133134
}

src/exports/api.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -285,10 +285,6 @@ export class API extends EventEmitter<RooCodeEvents> implements RooCodeAPI {
285285

286286
cline.on("taskModeSwitched", (taskId, mode) => this.emit(RooCodeEventName.TaskModeSwitched, taskId, mode))
287287

288-
cline.on("taskTokenUsageUpdated", (_, usage) =>
289-
this.emit(RooCodeEventName.TaskTokenUsageUpdated, cline.taskId, usage),
290-
)
291-
292288
cline.on("taskAskResponded", () => this.emit(RooCodeEventName.TaskAskResponded, cline.taskId))
293289

294290
cline.on("taskAborted", () => {
@@ -309,6 +305,14 @@ export class API extends EventEmitter<RooCodeEvents> implements RooCodeAPI {
309305
cline.on("taskPaused", () => this.emit(RooCodeEventName.TaskPaused, cline.taskId))
310306
cline.on("taskUnpaused", () => this.emit(RooCodeEventName.TaskUnpaused, cline.taskId))
311307

308+
cline.on("taskTokenUsageUpdated", (_, usage) =>
309+
this.emit(RooCodeEventName.TaskTokenUsageUpdated, cline.taskId, usage),
310+
)
311+
312+
cline.on("taskToolFailed", (taskId, tool, error) =>
313+
this.emit(RooCodeEventName.TaskToolFailed, taskId, tool, error),
314+
)
315+
312316
this.emit(RooCodeEventName.TaskCreated, cline.taskId)
313317
})
314318
}

src/exports/roo-code.d.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,30 @@ type RooCodeEvents = {
543543
contextTokens: number
544544
},
545545
]
546+
taskToolFailed: [
547+
string,
548+
(
549+
| "execute_command"
550+
| "read_file"
551+
| "write_to_file"
552+
| "append_to_file"
553+
| "apply_diff"
554+
| "insert_content"
555+
| "search_and_replace"
556+
| "search_files"
557+
| "list_files"
558+
| "list_code_definition_names"
559+
| "browser_action"
560+
| "use_mcp_tool"
561+
| "access_mcp_resource"
562+
| "ask_followup_question"
563+
| "attempt_completion"
564+
| "switch_mode"
565+
| "new_task"
566+
| "fetch_instructions"
567+
),
568+
string,
569+
]
546570
}
547571

548572
/**
@@ -560,6 +584,7 @@ declare enum RooCodeEventName {
560584
TaskSpawned = "taskSpawned",
561585
TaskCompleted = "taskCompleted",
562586
TaskTokenUsageUpdated = "taskTokenUsageUpdated",
587+
TaskToolFailed = "taskToolFailed",
563588
}
564589

565590
type RooCodeSettings = GlobalSettings & ProviderSettings

src/exports/types.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,30 @@ type RooCodeEvents = {
552552
contextTokens: number
553553
},
554554
]
555+
taskToolFailed: [
556+
string,
557+
(
558+
| "execute_command"
559+
| "read_file"
560+
| "write_to_file"
561+
| "append_to_file"
562+
| "apply_diff"
563+
| "insert_content"
564+
| "search_and_replace"
565+
| "search_files"
566+
| "list_files"
567+
| "list_code_definition_names"
568+
| "browser_action"
569+
| "use_mcp_tool"
570+
| "access_mcp_resource"
571+
| "ask_followup_question"
572+
| "attempt_completion"
573+
| "switch_mode"
574+
| "new_task"
575+
| "fetch_instructions"
576+
),
577+
string,
578+
]
555579
}
556580

557581
export type { RooCodeEvents }

src/schemas/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -873,6 +873,7 @@ export enum RooCodeEventName {
873873
TaskSpawned = "taskSpawned",
874874
TaskCompleted = "taskCompleted",
875875
TaskTokenUsageUpdated = "taskTokenUsageUpdated",
876+
TaskToolFailed = "taskToolFailed",
876877
}
877878

878879
export const rooCodeEventsSchema = z.object({
@@ -893,6 +894,7 @@ export const rooCodeEventsSchema = z.object({
893894
[RooCodeEventName.TaskSpawned]: z.tuple([z.string(), z.string()]),
894895
[RooCodeEventName.TaskCompleted]: z.tuple([z.string(), tokenUsageSchema, toolUsageSchema]),
895896
[RooCodeEventName.TaskTokenUsageUpdated]: z.tuple([z.string(), tokenUsageSchema]),
897+
[RooCodeEventName.TaskToolFailed]: z.tuple([z.string(), toolNamesSchema, z.string()]),
896898
})
897899

898900
export type RooCodeEvents = z.infer<typeof rooCodeEventsSchema>

0 commit comments

Comments
 (0)