Fix aborted tool display when continuing sessions

Two fixes for rendering aborted tools in --continue mode:

1. In renderInitialMessages: Check if assistant message was aborted/errored
   and immediately mark tool execution components as failed instead of
   leaving them in pending state.

2. In AssistantMessageComponent: Don't show "Aborted" text when there are
   tool calls in the message, since the tool execution components will
   show the error state themselves. This prevents duplicate error messages.

Now aborted tools show properly as red with "Operation aborted" message,
without the duplicate "Aborted" text above them.
This commit is contained in:
Mario Zechner 2025-11-11 23:39:00 +01:00
parent 2fdd304fbf
commit 1e857e0a6a
2 changed files with 24 additions and 7 deletions

View file

@ -49,11 +49,15 @@ export class AssistantMessageComponent extends Container {
}
// Check if aborted - show after partial content
if (message.stopReason === "aborted") {
this.contentContainer.addChild(new Text(chalk.red("Aborted")));
} else if (message.stopReason === "error") {
const errorMsg = message.errorMessage || "Unknown error";
this.contentContainer.addChild(new Text(chalk.red(`Error: ${errorMsg}`)));
// But only if there are no tool calls (tool execution components will show the error)
const hasToolCalls = message.content.some((c) => c.type === "toolCall");
if (!hasToolCalls) {
if (message.stopReason === "aborted") {
this.contentContainer.addChild(new Text(chalk.red("Aborted")));
} else if (message.stopReason === "error") {
const errorMsg = message.errorMessage || "Unknown error";
this.contentContainer.addChild(new Text(chalk.red(`Error: ${errorMsg}`)));
}
}
}
}

View file

@ -327,8 +327,21 @@ export class TuiRenderer {
if (content.type === "toolCall") {
const component = new ToolExecutionComponent(content.name, content.arguments);
this.chatContainer.addChild(component);
// Store in map so we can update with results later
this.pendingTools.set(content.id, component);
// If message was aborted/errored, immediately mark tool as failed
if (assistantMsg.stopReason === "aborted" || assistantMsg.stopReason === "error") {
const errorMessage =
assistantMsg.stopReason === "aborted"
? "Operation aborted"
: assistantMsg.errorMessage || "Error";
component.updateResult({
output: errorMessage,
isError: true,
});
} else {
// Store in map so we can update with results later
this.pendingTools.set(content.id, component);
}
}
}
} else if (message.role === "toolResult") {