Skip to content

πŸ™Œ OpenHands: AI-Driven Development

Fix issue #6262: Add success/failure indicators for file read/edit operations (#6653)

Graham Neubig6c88b10c5933
diff --git a/frontend/__tests__/components/chat/chat-interface.test.tsx b/frontend/__tests__/components/chat/chat-interface.test.tsx
index 168715f219..9411ec473d 100644
--- a/frontend/__tests__/components/chat/chat-interface.test.tsx
+++ b/frontend/__tests__/components/chat/chat-interface.test.tsx
@@ -1,4 +1,5 @@
import { afterEach, beforeAll, describe, expect, it, vi } from "vitest";
+import type { Message } from "#/message";
import { act, screen, waitFor, within } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { renderWithProviders } from "test-utils";
diff --git a/frontend/__tests__/components/file-operations.test.tsx b/frontend/__tests__/components/file-operations.test.tsx
new file mode 100644
index 0000000000..2d2018df90
--- /dev/null
+++ b/frontend/__tests__/components/file-operations.test.tsx
@@ -0,0 +1,82 @@
+import { render, screen } from "@testing-library/react";
+import { describe, it, expect } from "vitest";
+import { Messages } from "#/components/features/chat/messages";
+import type { Message } from "#/message";
+
+describe("File Operations Messages", () => {
+ it("should show success indicator for successful file read operation", () => {
+ const messages: Message[] = [
+ {
+ type: "action",
+ translationID: "read_file_contents",
+ content: "Successfully read file contents",
+ success: true,
+ sender: "assistant",
+ timestamp: new Date().toISOString(),
+ },
+ ];
+
+ render(<Messages messages={messages} isAwaitingUserConfirmation={false} />);
+
+ const statusIcon = screen.getByTestId("status-icon");
+ expect(statusIcon).toBeInTheDocument();
+ expect(statusIcon.closest("svg")).toHaveClass("fill-success");
+ });
+
+ it("should show failure indicator for failed file read operation", () => {
+ const messages: Message[] = [
+ {
+ type: "action",
+ translationID: "read_file_contents",
+ content: "Failed to read file contents",
+ success: false,
+ sender: "assistant",
+ timestamp: new Date().toISOString(),
+ },
+ ];
+
+ render(<Messages messages={messages} isAwaitingUserConfirmation={false} />);
+
+ const statusIcon = screen.getByTestId("status-icon");
+ expect(statusIcon).toBeInTheDocument();
+ expect(statusIcon.closest("svg")).toHaveClass("fill-danger");
+ });
+
+ it("should show success indicator for successful file edit operation", () => {
+ const messages: Message[] = [
+ {
+ type: "action",
+ translationID: "edit_file_contents",
+ content: "Successfully edited file contents",
+ success: true,
+ sender: "assistant",
+ timestamp: new Date().toISOString(),
+ },
+ ];
+
+ render(<Messages messages={messages} isAwaitingUserConfirmation={false} />);
+
+ const statusIcon = screen.getByTestId("status-icon");
+ expect(statusIcon).toBeInTheDocument();
+ expect(statusIcon.closest("svg")).toHaveClass("fill-success");
+ });
+
+ it("should show failure indicator for failed file edit operation", () => {
+ const messages: Message[] = [
+ {
+ type: "action",
+ translationID: "edit_file_contents",
+ content: "Failed to edit file contents",
+ success: false,
+ sender: "assistant",
+ timestamp: new Date().toISOString(),
+ },
+ ];
+
+ render(<Messages messages={messages} isAwaitingUserConfirmation={false} />);
+
+ const statusIcon = screen.getByTestId("status-icon");
+ expect(statusIcon).toBeInTheDocument();
+ expect(statusIcon.closest("svg")).toHaveClass("fill-danger");
+ });
+});
diff --git a/frontend/package.json b/frontend/package.json
index cbb81f68bc..7be3f89cbc 100644
--- a/frontend/package.json
+++ b/frontend/package.json
@@ -7,8 +7,8 @@
"node": ">=20.0.0"
},
"dependencies": {
- "@monaco-editor/react": "^4.7.0-rc.0",
"@heroui/react": "2.6.14",
+ "@monaco-editor/react": "^4.7.0-rc.0",
"@react-router/node": "^7.1.5",
"@react-router/serve": "^7.1.5",
"@react-types/shared": "^3.27.0",
diff --git a/frontend/src/components/features/chat/expandable-message.tsx b/frontend/src/components/features/chat/expandable-message.tsx
index f04c9c4283..036ad9ce66 100644
--- a/frontend/src/components/features/chat/expandable-message.tsx
+++ b/frontend/src/components/features/chat/expandable-message.tsx
@@ -46,55 +46,57 @@ export function ExpandableMessage({
)}
>
<div className="text-sm w-full">
- {headline && (
- <div className="flex flex-row justify-between items-center w-full">
- <span
- className={cn(
- "font-bold",
- type === "error" ? "text-danger" : "text-neutral-300",
+ <div className="flex flex-row justify-between items-center w-full">
+ <span
+ className={cn(
+ headline ? "font-bold" : "",
+ type === "error" ? "text-danger" : "text-neutral-300",
+ )}
+ >
+ {headline && (
+ <>
+ {headline}
+ <button
+ type="button"
+ onClick={() => setShowDetails(!showDetails)}
+ className="cursor-pointer text-left"
+ >
+ {showDetails ? (
+ <ArrowUp
+ className={cn(
+ "h-4 w-4 ml-2 inline",
+ type === "error" ? "fill-danger" : "fill-neutral-300",
+ )}
+ />
+ ) : (
+ <ArrowDown
+ className={cn(
+ "h-4 w-4 ml-2 inline",
+ type === "error" ? "fill-danger" : "fill-neutral-300",
+ )}
+ />
+ )}
+ </button>
+ </>
+ )}
+ </span>
+ {type === "action" && success !== undefined && (
+ <span className="flex-shrink-0">
+ {success ? (
+ <CheckCircle
+ data-testid="status-icon"
+ className={cn(statusIconClasses, "fill-success")}
+ />
+ ) : (
+ <XCircle
+ data-testid="status-icon"
+ className={cn(statusIconClasses, "fill-danger")}
+ />
)}
- >
- {headline}
- <button
- type="button"
- onClick={() => setShowDetails(!showDetails)}
- className="cursor-pointer text-left"
- >
- {showDetails ? (
- <ArrowUp
- className={cn(
- "h-4 w-4 ml-2 inline",
- type === "error" ? "fill-danger" : "fill-neutral-300",
- )}
- />
- ) : (
- <ArrowDown
- className={cn(
- "h-4 w-4 ml-2 inline",
- type === "error" ? "fill-danger" : "fill-neutral-300",
- )}
- />
- )}
- </button>
</span>
- {type === "action" && success !== undefined && (
- <span className="flex-shrink-0">
- {success ? (
- <CheckCircle
- data-testid="status-icon"
- className={cn(statusIconClasses, "fill-success")}
- />
- ) : (
- <XCircle
- data-testid="status-icon"
- className={cn(statusIconClasses, "fill-danger")}
- />
- )}
- </span>
- )}
- </div>
- )}
- {showDetails && (
+ )}
+ </div>
+ {(!headline || showDetails) && (
<Markdown
className="text-sm overflow-auto"
components={{
diff --git a/frontend/src/components/features/chat/messages.tsx b/frontend/src/components/features/chat/messages.tsx
index 03321d14c9..c1fcb51410 100644
--- a/frontend/src/components/features/chat/messages.tsx
+++ b/frontend/src/components/features/chat/messages.tsx
@@ -1,4 +1,5 @@
import React from "react";
+import type { Message } from "#/message";
import { ChatMessage } from "#/components/features/chat/chat-message";
import { ConfirmationButtons } from "#/components/shared/buttons/confirmation-buttons";
import { ImageCarousel } from "../images/image-carousel";
diff --git a/frontend/src/message.d.ts b/frontend/src/message.d.ts
index 65bd7e0cb1..9af06a7384 100644
--- a/frontend/src/message.d.ts
+++ b/frontend/src/message.d.ts
@@ -1,4 +1,4 @@
-type Message = {
+export type Message = {
sender: "user" | "assistant";
content: string;
timestamp: string;
diff --git a/frontend/src/state/chat-slice.ts b/frontend/src/state/chat-slice.ts
index 5bfffb62d4..7975be6cc6 100644
--- a/frontend/src/state/chat-slice.ts
+++ b/frontend/src/state/chat-slice.ts
@@ -1,4 +1,5 @@
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
+import type { Message } from "#/message";
import { ActionSecurityRisk } from "#/state/security-analyzer-slice";
import {
@@ -154,6 +155,11 @@ export const chatSlice = createSlice({
causeMessage.success = !ipythonObs.content
.toLowerCase()
.includes("error:");
+ } else if (observationID === "read" || observationID === "edit") {
+ // For read/edit operations, we consider it successful if there's content and no error
+ causeMessage.success =
+ observation.payload.content.length > 0 &&
+ !observation.payload.content.toLowerCase().includes("error:");
}
if (observationID === "run" || observationID === "run_ipython") {