Skip to content

Commit 92f3f9a

Browse files
committed
refactor: address Ellipsis review comments for taskCommandExecuted event
- Added TaskCommandExecuted to RooCodeEventName enum for consistency - Refactored repeated event emissions into emitCommandExecutedEvent helper function - Updated TaskEvents and ClineEvents to use enum reference instead of string literal - Updated taskEventSchema to include TaskCommandExecuted in discriminated union These changes improve code maintainability and consistency across the codebase.
1 parent f4c1717 commit 92f3f9a

File tree

4 files changed

+49
-23
lines changed

4 files changed

+49
-23
lines changed

packages/types/src/events.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ export enum RooCodeEventName {
3434
TaskTokenUsageUpdated = "taskTokenUsageUpdated",
3535
TaskToolFailed = "taskToolFailed",
3636

37+
// Command Execution
38+
TaskCommandExecuted = "taskCommandExecuted",
39+
3740
// Evals
3841
EvalPass = "evalPass",
3942
EvalFail = "evalFail",
@@ -79,7 +82,7 @@ export const rooCodeEventsSchema = z.object({
7982
[RooCodeEventName.TaskTokenUsageUpdated]: z.tuple([z.string(), tokenUsageSchema]),
8083

8184
// Command Execution
82-
taskCommandExecuted: z.tuple([
85+
[RooCodeEventName.TaskCommandExecuted]: z.tuple([
8386
z.string(),
8487
z.object({
8588
command: z.string(),
@@ -188,6 +191,13 @@ export const taskEventSchema = z.discriminatedUnion("eventName", [
188191
taskId: z.number().optional(),
189192
}),
190193

194+
// Command Execution
195+
z.object({
196+
eventName: z.literal(RooCodeEventName.TaskCommandExecuted),
197+
payload: rooCodeEventsSchema.shape[RooCodeEventName.TaskCommandExecuted],
198+
taskId: z.number().optional(),
199+
}),
200+
191201
// Evals
192202
z.object({
193203
eventName: z.literal(RooCodeEventName.EvalPass),

packages/types/src/task.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export type TaskEvents = {
9898
[RooCodeEventName.TaskTokenUsageUpdated]: [taskId: string, tokenUsage: TokenUsage]
9999

100100
// Command Execution
101-
taskCommandExecuted: [
101+
[RooCodeEventName.TaskCommandExecuted]: [
102102
taskId: string,
103103
details: {
104104
command: string

src/core/task/Task.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ export type ClineEvents = {
114114
taskCompleted: [taskId: string, tokenUsage: TokenUsage, toolUsage: ToolUsage]
115115
taskTokenUsageUpdated: [taskId: string, tokenUsage: TokenUsage]
116116
taskToolFailed: [taskId: string, tool: ToolName, error: string]
117-
taskCommandExecuted: [
117+
[RooCodeEventName.TaskCommandExecuted]: [
118118
taskId: string,
119119
details: {
120120
command: string

src/core/tools/executeCommandTool.ts

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as vscode from "vscode"
44

55
import delay from "delay"
66

7-
import { CommandExecutionStatus, DEFAULT_TERMINAL_OUTPUT_CHARACTER_LIMIT } from "@roo-code/types"
7+
import { CommandExecutionStatus, DEFAULT_TERMINAL_OUTPUT_CHARACTER_LIMIT, RooCodeEventName } from "@roo-code/types"
88
import { TelemetryService } from "@roo-code/telemetry"
99

1010
import { Task } from "../task/Task"
@@ -143,6 +143,26 @@ export type ExecuteCommandOptions = {
143143
commandExecutionTimeout?: number
144144
}
145145

146+
/**
147+
* Helper function to emit taskCommandExecuted event with consistent payload
148+
*/
149+
function emitCommandExecutedEvent(
150+
task: Task,
151+
command: string,
152+
exitCode: number | undefined,
153+
output: string,
154+
succeeded: boolean,
155+
failureReason?: string,
156+
) {
157+
task.emit(RooCodeEventName.TaskCommandExecuted, task.taskId, {
158+
command,
159+
exitCode,
160+
output,
161+
succeeded,
162+
failureReason,
163+
})
164+
}
165+
146166
export async function executeCommand(
147167
task: Task,
148168
{
@@ -275,13 +295,14 @@ export async function executeCommand(
275295
task.terminalProcess = undefined
276296

277297
// Emit taskCommandExecuted event for timeout
278-
task.emit("taskCommandExecuted", task.taskId, {
298+
emitCommandExecutedEvent(
299+
task,
279300
command,
280-
exitCode: undefined,
281-
output: accumulatedOutput, // Use accumulatedOutput instead of result
282-
succeeded: false,
283-
failureReason: `Command timed out after ${commandExecutionTimeoutSeconds}s`,
284-
})
301+
undefined,
302+
accumulatedOutput,
303+
false,
304+
`Command timed out after ${commandExecutionTimeoutSeconds}s`,
305+
)
285306

286307
return [
287308
false,
@@ -321,13 +342,14 @@ export async function executeCommand(
321342
await task.say("user_feedback", text, images)
322343

323344
// Emit taskCommandExecuted event for running command with user feedback
324-
task.emit("taskCommandExecuted", task.taskId, {
345+
emitCommandExecutedEvent(
346+
task,
325347
command,
326-
exitCode: undefined,
327-
output: accumulatedOutput, // Use accumulatedOutput instead of result
328-
succeeded: false,
329-
failureReason: "Command is still running (user provided feedback)",
330-
})
348+
undefined,
349+
accumulatedOutput,
350+
false,
351+
"Command is still running (user provided feedback)",
352+
)
331353

332354
return [
333355
true,
@@ -371,13 +393,7 @@ export async function executeCommand(
371393

372394
// Emit taskCommandExecuted event
373395
const succeeded = exitCode === 0
374-
task.emit("taskCommandExecuted", task.taskId, {
375-
command,
376-
exitCode,
377-
output: result,
378-
succeeded,
379-
failureReason: succeeded ? undefined : exitStatus,
380-
})
396+
emitCommandExecutedEvent(task, command, exitCode, result, succeeded, succeeded ? undefined : exitStatus)
381397

382398
return [false, `Command executed in terminal ${workingDirInfo}. ${exitStatus}\nOutput:\n${result}`]
383399
} else {

0 commit comments

Comments
 (0)