Skip to content
This repository was archived by the owner on May 15, 2026. It is now read-only.

Commit ff22942

Browse files
committed
More progress
1 parent 24baf36 commit ff22942

5 files changed

Lines changed: 20 additions & 39 deletions

File tree

packages/evals/src/cli/runTaskInCli.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ export const runTaskWithCli = async ({ run, task, publish, logger, jobToken }: R
264264

265265
if (rooTaskId && !isClientDisconnected) {
266266
logger.info("cancelling task")
267-
client.sendCommand({ commandName: TaskCommandName.CancelTask, data: rooTaskId })
267+
client.sendCommand({ commandName: TaskCommandName.CancelTask })
268268
await new Promise((resolve) => setTimeout(resolve, 5_000))
269269
}
270270

@@ -289,7 +289,7 @@ export const runTaskWithCli = async ({ run, task, publish, logger, jobToken }: R
289289

290290
if (rooTaskId && !isClientDisconnected) {
291291
logger.info("closing task")
292-
client.sendCommand({ commandName: TaskCommandName.CloseTask, data: rooTaskId })
292+
client.sendCommand({ commandName: TaskCommandName.CloseTask })
293293
await new Promise((resolve) => setTimeout(resolve, 2_000))
294294
}
295295

packages/evals/src/cli/runTaskInVscode.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ export const runTaskInVscode = async ({ run, task, publish, logger, jobToken }:
270270

271271
if (rooTaskId && !isClientDisconnected) {
272272
logger.info("cancelling task")
273-
client.sendCommand({ commandName: TaskCommandName.CancelTask, data: rooTaskId })
273+
client.sendCommand({ commandName: TaskCommandName.CancelTask })
274274
await new Promise((resolve) => setTimeout(resolve, 5_000)) // Allow some time for the task to cancel.
275275
}
276276

@@ -289,7 +289,7 @@ export const runTaskInVscode = async ({ run, task, publish, logger, jobToken }:
289289

290290
if (rooTaskId && !isClientDisconnected) {
291291
logger.info("closing task")
292-
client.sendCommand({ commandName: TaskCommandName.CloseTask, data: rooTaskId })
292+
client.sendCommand({ commandName: TaskCommandName.CloseTask })
293293
await new Promise((resolve) => setTimeout(resolve, 2_000)) // Allow some time for the window to close.
294294
}
295295

packages/types/src/__tests__/ipc.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ describe("IPC Types", () => {
2727
const result = taskCommandSchema.safeParse(resumeTaskCommand)
2828
expect(result.success).toBe(true)
2929

30-
if (result.success) {
30+
if (result.success && result.data.commandName === TaskCommandName.ResumeTask) {
3131
expect(result.data.commandName).toBe("ResumeTask")
3232
expect(result.data.data).toBe("non-existent-task-id")
3333
}
@@ -45,7 +45,7 @@ describe("IPC Types", () => {
4545
const result = taskCommandSchema.safeParse(resumeTaskCommand)
4646
expect(result.success).toBe(true)
4747

48-
if (result.success) {
48+
if (result.success && result.data.commandName === TaskCommandName.ResumeTask) {
4949
expect(result.data.commandName).toBe("ResumeTask")
5050
expect(result.data.data).toBe("task-123")
5151
}

packages/types/src/ipc.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,9 @@ export const taskCommandSchema = z.discriminatedUnion("commandName", [
6464
}),
6565
z.object({
6666
commandName: z.literal(TaskCommandName.CancelTask),
67-
data: z.string(),
6867
}),
6968
z.object({
7069
commandName: z.literal(TaskCommandName.CloseTask),
71-
data: z.string(),
7270
}),
7371
z.object({
7472
commandName: z.literal(TaskCommandName.ResumeTask),

src/extension/api.ts

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ export class API extends EventEmitter<RooCodeEvents> implements RooCodeAPI {
3030
private readonly sidebarProvider: ClineProvider
3131
private readonly context: vscode.ExtensionContext
3232
private readonly ipc?: IpcServer
33-
private readonly taskMap = new Map<string, ClineProvider>()
3433
private readonly log: (...args: unknown[]) => void
3534
private logfile?: string
3635

@@ -65,35 +64,37 @@ export class API extends EventEmitter<RooCodeEvents> implements RooCodeAPI {
6564
ipc.listen()
6665
this.log(`[API] ipc server started: socketPath=${socketPath}, pid=${process.pid}, ppid=${process.ppid}`)
6766

68-
ipc.on(IpcMessageType.TaskCommand, async (_clientId, { commandName, data }) => {
69-
switch (commandName) {
67+
ipc.on(IpcMessageType.TaskCommand, async (_clientId, command) => {
68+
switch (command.commandName) {
7069
case TaskCommandName.StartNewTask:
71-
this.log(`[API] StartNewTask -> ${data.text}, ${JSON.stringify(data.configuration)}`)
72-
await this.startNewTask(data)
70+
this.log(
71+
`[API] StartNewTask -> ${command.data.text}, ${JSON.stringify(command.data.configuration)}`,
72+
)
73+
await this.startNewTask(command.data)
7374
break
7475
case TaskCommandName.CancelTask:
75-
this.log(`[API] CancelTask -> ${data}`)
76-
await this.cancelTask(data)
76+
this.log(`[API] CancelTask`)
77+
await this.cancelCurrentTask()
7778
break
7879
case TaskCommandName.CloseTask:
79-
this.log(`[API] CloseTask -> ${data}`)
80+
this.log(`[API] CloseTask`)
8081
await vscode.commands.executeCommand("workbench.action.files.saveFiles")
8182
await vscode.commands.executeCommand("workbench.action.closeWindow")
8283
break
8384
case TaskCommandName.ResumeTask:
84-
this.log(`[API] ResumeTask -> ${data}`)
85+
this.log(`[API] ResumeTask -> ${command.data}`)
8586
try {
86-
await this.resumeTask(data)
87+
await this.resumeTask(command.data)
8788
} catch (error) {
8889
const errorMessage = error instanceof Error ? error.message : String(error)
89-
this.log(`[API] ResumeTask failed for taskId ${data}: ${errorMessage}`)
90+
this.log(`[API] ResumeTask failed for taskId ${command.data}: ${errorMessage}`)
9091
// Don't rethrow - we want to prevent IPC server crashes
9192
// The error is logged for debugging purposes
9293
}
9394
break
9495
case TaskCommandName.SendMessage:
95-
this.log(`[API] SendMessage -> ${data.text}`)
96-
await this.sendMessage(data.text, data.images)
96+
this.log(`[API] SendMessage -> ${command.data.text}`)
97+
await this.sendMessage(command.data.text, command.data.images)
9798
break
9899
}
99100
})
@@ -181,20 +182,6 @@ export class API extends EventEmitter<RooCodeEvents> implements RooCodeAPI {
181182
await this.sidebarProvider.cancelTask()
182183
}
183184

184-
public async cancelTask(taskId: string) {
185-
const provider = this.taskMap.get(taskId)
186-
187-
if (provider) {
188-
await provider.cancelTask()
189-
this.taskMap.delete(taskId)
190-
} else {
191-
// Fallback: taskMap entry may have been removed on TaskCompleted
192-
// but the task is still the current task on the provider's stack
193-
// (e.g. after SendMessage resumed a completed task).
194-
await this.sidebarProvider.cancelTask()
195-
}
196-
}
197-
198185
public async sendMessage(text?: string, images?: string[]) {
199186
await this.sidebarProvider.postMessageToWebview({ type: "invoke", invoke: "sendMessage", text, images })
200187
}
@@ -217,7 +204,6 @@ export class API extends EventEmitter<RooCodeEvents> implements RooCodeAPI {
217204

218205
task.on(RooCodeEventName.TaskStarted, async () => {
219206
this.emit(RooCodeEventName.TaskStarted, task.taskId)
220-
this.taskMap.set(task.taskId, provider)
221207
await this.fileLog(`[${new Date().toISOString()}] taskStarted -> ${task.taskId}\n`)
222208
})
223209

@@ -226,16 +212,13 @@ export class API extends EventEmitter<RooCodeEvents> implements RooCodeAPI {
226212
isSubtask: !!task.parentTaskId,
227213
})
228214

229-
this.taskMap.delete(task.taskId)
230-
231215
await this.fileLog(
232216
`[${new Date().toISOString()}] taskCompleted -> ${task.taskId} | ${JSON.stringify(tokenUsage, null, 2)} | ${JSON.stringify(toolUsage, null, 2)}\n`,
233217
)
234218
})
235219

236220
task.on(RooCodeEventName.TaskAborted, () => {
237221
this.emit(RooCodeEventName.TaskAborted, task.taskId)
238-
this.taskMap.delete(task.taskId)
239222
})
240223

241224
task.on(RooCodeEventName.TaskFocused, () => {

0 commit comments

Comments
 (0)