Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/core/tools/ExecuteCommandTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,10 @@ function formatExitStatus(exitDetails: ExitCodeDetails | undefined): string {
return "Exit code: <undefined, notify user>"
}

if (exitDetails.aborted) {
return "Command was aborted by the user."
}

if (exitDetails.signalName) {
let status = `Process terminated by signal ${exitDetails.signalName}`
if (exitDetails.coreDumpPossible) {
Expand Down
6 changes: 3 additions & 3 deletions src/integrations/terminal/ExecaTerminalProcess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,17 +130,17 @@ export class ExecaTerminalProcess extends BaseTerminalProcess {
}
}

this.emit("shell_execution_complete", { exitCode: 0 })
this.emit("shell_execution_complete", { exitCode: 0, aborted: this.aborted })
} catch (error) {
if (error instanceof ExecaError) {
console.error(`[ExecaTerminalProcess#run] shell execution error: ${error.message}`)
this.emit("shell_execution_complete", { exitCode: error.exitCode ?? 0, signalName: error.signal })
this.emit("shell_execution_complete", { exitCode: error.exitCode ?? 0, signalName: error.signal, aborted: this.aborted })
} else {
console.error(
`[ExecaTerminalProcess#run] shell execution error: ${error instanceof Error ? error.message : String(error)}`,
)

this.emit("shell_execution_complete", { exitCode: 1 })
this.emit("shell_execution_complete", { exitCode: 1, aborted: this.aborted })
}
this.subprocess = undefined
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ describe("ExecaTerminalProcess", () => {
const spy = vitest.fn()
terminalProcess.on("shell_execution_complete", spy)
await terminalProcess.run("echo test")
expect(spy).toHaveBeenCalledWith({ exitCode: 0 })
expect(spy).toHaveBeenCalledWith({ exitCode: 0, aborted: false })

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add one regression case for the actual abort path? This assertion covers normal completion with aborted: false, but it would not catch dropping the aborted: true propagation or the model-facing Command was aborted by the user. formatting branch.

})

it("should emit completed event with full output", async () => {
Expand Down
6 changes: 6 additions & 0 deletions src/integrations/terminal/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,10 @@ export interface ExitCodeDetails {
signal?: number | undefined
signalName?: string
coreDumpPossible?: boolean
/**
* Set to true when the user explicitly pressed the Abort button

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this wording be a little less user-specific? abort() is also used by timeout and task teardown paths, so this flag seems to mean the process was intentionally aborted rather than necessarily that the user clicked Abort.

* to terminate the command, as opposed to the process exiting on its own
* or being killed by the OS (e.g., OOM-killer).
*/
aborted?: boolean
}
Loading