-
Notifications
You must be signed in to change notification settings - Fork 2.2k
feat: add taskCommandExecuted event to track command execution results #6375
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have reviewed this PR and found it to be a solid implementation of the taskCommandExecuted event. The feature adds valuable observability for command execution results, which will help API consumers track and debug command failures.
Critical Issues (Must Fix)
1. Inconsistent output data in event emission
The event uses different output sources across execution paths:
- Timeout/user feedback scenarios use accumulatedOutput
- Completed commands use result (compressed output)
This inconsistency could confuse API consumers. Consider standardizing on one approach, likely result since it is the processed/compressed version.
Files affected: src/core/tools/executeCommandTool.ts lines 281, 327, 377
Important Suggestions (Should Consider)
2. Missing JSDoc documentation
The new taskCommandExecuted event type lacks documentation. Consider adding JSDoc comments explaining:
- Purpose and use cases
- Payload structure and field meanings
- Example usage for API consumers
File: src/core/task/Task.ts lines 111-121
3. Event emission timing concerns
Events are emitted before some async operations complete (like task.say()). This could cause race conditions where listeners receive events before related UI updates finish.
4. Test coverage gaps
While test coverage is comprehensive, consider adding tests for:
- Shell integration error scenarios
- Interaction between timeout and user feedback
- Edge cases with undefined exit codes
Minor Improvements (Nice to Have)
5. Type safety enhancement
The failureReason field could use a union type of specific failure reasons rather than a generic string for better type safety.
6. Event payload consistency
Consider aligning the event payload structure with other task events in the codebase for consistency.
Overall Assessment
This is a well-implemented feature with excellent test coverage. The event provides valuable functionality for API consumers to track command execution results. The main concern is the output data inconsistency, which should be addressed to ensure reliable API behavior.
The comprehensive test suite demonstrates good engineering practices, and the feature addresses a real need mentioned in the Slack request.
src/core/tools/executeCommandTool.ts
Outdated
@@ -274,6 +274,15 @@ export async function executeCommand( | |||
await task.say("error", t("common:errors:command_timeout", { seconds: commandExecutionTimeoutSeconds })) | |||
task.terminalProcess = undefined | |||
|
|||
// Emit taskCommandExecuted event for timeout | |||
task.emit("taskCommandExecuted", task.taskId, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The task.emit('taskCommandExecuted', …) calls are repeated in several branches (e.g. timeout, user feedback, and completion). Consider refactoring these event emissions into a helper function to promote consistency and reduce duplication.
@roomote-agent use pr-fixer on this PR |
Hi @daniel-lxs! I see your request to fix this PR. I notice the integration tests are failing. Let me investigate and fix the issues. I'll keep you updated on my progress. |
✅ Fixed the failing integration tests! The issue was that the I've added the missing event definition to maintain consistency between the interfaces. The fix has been committed and pushed to this PR branch. Changes made:
The integration tests should now pass once the CI runs. |
@roomote-agent use the switch_mode to switch to pr-fixer and fix this PR |
Hi @daniel-lxs! I see your request to switch to pr-fixer mode. Switching now to fix this PR. |
- Added new event type to ClineEvents for tracking command execution completion - Event includes command, exit code, output, success status, and failure reason - Emits event in executeCommandTool for all execution paths (success, failure, timeout, user feedback) - Added comprehensive tests for the new event emission - Updated mock tasks in tests to include emit method This allows API consumers to listen for command execution events and surface failures for easier debugging.
- Added taskCommandExecuted event definition to TaskEvents in packages/types/src/task.ts - Added taskCommandExecuted event to rooCodeEventsSchema in packages/types/src/events.ts - This fixes the TypeScript errors where emit() was called with an event not defined in TaskEvents
0fa93ef
to
f4c1717
Compare
packages/types/src/events.ts
Outdated
@@ -77,6 +77,18 @@ export const rooCodeEventsSchema = z.object({ | |||
|
|||
[RooCodeEventName.TaskToolFailed]: z.tuple([z.string(), toolNamesSchema, z.string()]), | |||
[RooCodeEventName.TaskTokenUsageUpdated]: z.tuple([z.string(), tokenUsageSchema]), | |||
|
|||
// Command Execution | |||
taskCommandExecuted: z.tuple([ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new 'taskCommandExecuted' event is defined here but isn’t added to the RooCodeEventName enum nor included in the taskEventSchema discriminated union. Consistency between runtime validation and enum usage is crucial. Consider adding a corresponding enum entry (e.g. TaskCommandExecuted) and including it in the union.
packages/types/src/task.ts
Outdated
@@ -96,4 +96,16 @@ export type TaskEvents = { | |||
// Task Analytics | |||
[RooCodeEventName.TaskToolFailed]: [taskId: string, tool: ToolName, error: string] | |||
[RooCodeEventName.TaskTokenUsageUpdated]: [taskId: string, tokenUsage: TokenUsage] | |||
|
|||
// Command Execution | |||
taskCommandExecuted: [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In TaskEvents, the 'taskCommandExecuted' event is added directly. For consistency and strong typing, consider referencing a centralized enum value (e.g. from RooCodeEventName) and ensuring that any runtime validation (like in taskEventSchema) includes this event.
taskCommandExecuted: [ | |
\t[RooCodeEventName.TaskCommandExecuted]: [ |
✅ PR Fixed Successfully! Hi @daniel-lxs, I have successfully fixed PR #6375. Here is a summary of what was done: Issues Resolved:
Changes Made:
CI Status:✅ All checks are now passing:
The PR is now ready for review and merge! |
@roomote-agent address the reviews and suggestions from ellipsis, pull the comments of this PR |
Hi @daniel-lxs! I see your request to address the Ellipsis review comments. I have identified the following suggestions from Ellipsis:
I will now implement these improvements. Working on it! |
- 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.
✅ All Ellipsis review comments have been successfully addressed! Hi @daniel-lxs, I have completed all the requested changes from the Ellipsis review. Here is a summary of what was done: Changes Made:1. ✅ Refactored repeated event emissions (Ellipsis comment #1)
2. ✅ Added TaskCommandExecuted to RooCodeEventName enum (Ellipsis comment #2)
3. ✅ Used enum reference instead of string literal (Ellipsis comment #3)
CI Status:✅ All checks are passing:
The PR is now ready for review and merge! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This PR adds a new event
taskCommandExecuted
to theClineEvents
type that is fired when a command execution completes. This allows API consumers to listen for command execution events and surface failures for easier debugging.Changes
Event Definition
taskCommandExecuted
toClineEvents
interface insrc/core/task/Task.ts
TaskEvents
interface inpackages/types/src/task.ts
rooCodeEventsSchema
inpackages/types/src/events.ts
RooCodeAPIEvents
inpackages/types/src/api.ts
(via type alias)Event Payload
The event payload includes:
command
: The command that was executedexitCode
: The exit code (undefined if terminated by signal)output
: The terminal outputsucceeded
: Boolean indicating if command succeeded (exit code 0)failureReason
: Optional string with failure detailsEvent Emission
The event is emitted in
src/core/tools/executeCommandTool.ts
for all execution paths:Testing
All tests pass successfully:
taskCommandExecuted
event emissionemit
methodUse Case
As mentioned in the Slack request, this event allows Roo Code API consumers to:
Implementation Details
The event is emitted at the appropriate points in the command execution flow:
The event provides comprehensive information about the command execution result, making it easy for API consumers to understand what happened and take appropriate action.
Important
Introduces
taskCommandExecuted
event to track command execution results, including success, failure, signal termination, timeout, and user feedback, with comprehensive testing.taskCommandExecuted
toClineEvents
inTask.ts
andTaskEvents
intask.ts
.rooCodeEventsSchema
inevents.ts
.RooCodeAPIEvents
inapi.ts
.command
,exitCode
,output
,succeeded
, andfailureReason
.executeCommandTool.ts
for all execution paths: success, failure, signal termination, timeout, and user feedback.taskCommandExecuted
event inexecuteCommand.spec.ts
andexecuteCommandTimeout.integration.spec.ts
.emitCommandExecutedEvent()
inexecuteCommandTool.ts
.This description was created by
for 92f3f9a. You can customize this summary. It will automatically update as commits are pushed.