Skip to content

Commit 5c5ee8c

Browse files
feifei325yansheng3
andauthored
Fix/4100 subtask completion mismatch (#4738)
Co-authored-by: yansheng3 <[email protected]>
1 parent 80dd3b8 commit 5c5ee8c

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

packages/types/src/api.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { RooCodeSettings } from "./global-settings.js"
55
import type { ProviderSettingsEntry, ProviderSettings } from "./provider-settings.js"
66
import type { ClineMessage, TokenUsage } from "./message.js"
77
import type { ToolUsage, ToolName } from "./tool.js"
8-
import type { IpcMessage, IpcServerEvents } from "./ipc.js"
8+
import type { IpcMessage, IpcServerEvents, IsSubtask } from "./ipc.js"
99

1010
// TODO: Make sure this matches `RooCodeEvents` from `@roo-code/types`.
1111
export interface RooCodeAPIEvents {
@@ -18,7 +18,7 @@ export interface RooCodeAPIEvents {
1818
taskAskResponded: [taskId: string]
1919
taskAborted: [taskId: string]
2020
taskSpawned: [parentTaskId: string, childTaskId: string]
21-
taskCompleted: [taskId: string, tokenUsage: TokenUsage, toolUsage: ToolUsage]
21+
taskCompleted: [taskId: string, tokenUsage: TokenUsage, toolUsage: ToolUsage, isSubtask: IsSubtask]
2222
taskTokenUsageUpdated: [taskId: string, tokenUsage: TokenUsage]
2323
taskToolFailed: [taskId: string, toolName: ToolName, error: string]
2424
}

packages/types/src/ipc.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ import { clineMessageSchema, tokenUsageSchema } from "./message.js"
44
import { toolNamesSchema, toolUsageSchema } from "./tool.js"
55
import { rooCodeSettingsSchema } from "./global-settings.js"
66

7+
/**
8+
* isSubtaskSchema
9+
*/
10+
export const isSubtaskSchema = z.object({
11+
isSubtask: z.boolean(),
12+
})
13+
export type IsSubtask = z.infer<typeof isSubtaskSchema>
14+
715
/**
816
* RooCodeEvent
917
*/
@@ -41,7 +49,7 @@ export const rooCodeEventsSchema = z.object({
4149
[RooCodeEventName.TaskAskResponded]: z.tuple([z.string()]),
4250
[RooCodeEventName.TaskAborted]: z.tuple([z.string()]),
4351
[RooCodeEventName.TaskSpawned]: z.tuple([z.string(), z.string()]),
44-
[RooCodeEventName.TaskCompleted]: z.tuple([z.string(), tokenUsageSchema, toolUsageSchema]),
52+
[RooCodeEventName.TaskCompleted]: z.tuple([z.string(), tokenUsageSchema, toolUsageSchema, isSubtaskSchema]),
4553
[RooCodeEventName.TaskTokenUsageUpdated]: z.tuple([z.string(), tokenUsageSchema]),
4654
[RooCodeEventName.TaskToolFailed]: z.tuple([z.string(), toolNamesSchema, z.string()]),
4755
})

src/extension/api.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,11 @@ export class API extends EventEmitter<RooCodeEvents> implements RooCodeAPI {
222222
})
223223

224224
cline.on("taskCompleted", async (_, tokenUsage, toolUsage) => {
225-
this.emit(RooCodeEventName.TaskCompleted, cline.taskId, tokenUsage, toolUsage)
225+
let isSubtask = false
226+
if (cline.rootTask != undefined) {
227+
isSubtask = true
228+
}
229+
this.emit(RooCodeEventName.TaskCompleted, cline.taskId, tokenUsage, toolUsage, { isSubtask: isSubtask })
226230
this.taskMap.delete(cline.taskId)
227231

228232
await this.fileLog(

0 commit comments

Comments
 (0)