Skip to content

🙌 OpenHands: AI-Driven Development

fix : planner PLAN.md rendering and search labels (#13418)

Neha Prasad38099934b692
diff --git a/frontend/__tests__/components/v1/chat/hooks/use-plan-preview-events.test.ts b/frontend/__tests__/components/v1/chat/hooks/use-plan-preview-events.test.ts
index ee5f61556e..438140fdb5 100644
--- a/frontend/__tests__/components/v1/chat/hooks/use-plan-preview-events.test.ts
+++ b/frontend/__tests__/components/v1/chat/hooks/use-plan-preview-events.test.ts
@@ -28,6 +28,7 @@ const createUserMessageEvent = (id: string): MessageEvent => ({
const createPlanningObservationEvent = (
id: string,
actionId: string = "action-1",
+ path: string = "/workspace/PLAN.md",
): ObservationEvent<PlanningFileEditorObservation> => ({
id,
timestamp: new Date().toISOString(),
@@ -40,7 +41,7 @@ const createPlanningObservationEvent = (
content: [{ type: "text", text: "Plan content" }],
is_error: false,
command: "create",
- path: "/workspace/PLAN.md",
+ path,
prev_exist: false,
old_content: null,
new_content: "Plan content",
@@ -172,6 +173,31 @@ describe("usePlanPreviewEvents", () => {
expect(result.current.size).toBe(1);
expect(result.current.has("plan-obs-1")).toBe(true);
});
+
+ it("should exclude PlanningFileEditorObservation for non-Plan.md paths", () => {
+ const events: OpenHandsEvent[] = [
+ createUserMessageEvent("user-1"),
+ createPlanningObservationEvent("plan-obs-1", "action-1", "settings.py"),
+ createPlanningObservationEvent("plan-obs-2", "action-2", "use-add-mcp.ts"),
+ ];
+
+ const { result } = renderHook(() => usePlanPreviewEvents(events));
+
+ expect(result.current.size).toBe(0);
+ });
+
+ it("should include only Plan.md observations when mixed with other file edits", () => {
+ const events: OpenHandsEvent[] = [
+ createUserMessageEvent("user-1"),
+ createPlanningObservationEvent("plan-obs-1", "action-1", "settings.py"),
+ createPlanningObservationEvent("plan-obs-2", "action-2", "/workspace/PLAN.md"),
+ ];
+
+ const { result } = renderHook(() => usePlanPreviewEvents(events));
+
+ expect(result.current.size).toBe(1);
+ expect(result.current.has("plan-obs-2")).toBe(true);
+ });
});
describe("shouldShowPlanPreview", () => {
diff --git a/frontend/src/components/v1/chat/event-content-helpers/get-action-content.ts b/frontend/src/components/v1/chat/event-content-helpers/get-action-content.ts
index 1489493652..62e907de27 100644
--- a/frontend/src/components/v1/chat/event-content-helpers/get-action-content.ts
+++ b/frontend/src/components/v1/chat/event-content-helpers/get-action-content.ts
@@ -21,6 +21,8 @@ import {
BrowserListTabsAction,
BrowserSwitchTabAction,
BrowserCloseTabAction,
+ GlobAction,
+ GrepAction,
} from "#/types/v1/core/base/action";
const getRiskText = (risk: SecurityRisk) => {
@@ -39,6 +41,28 @@ const getRiskText = (risk: SecurityRisk) => {
const getNoContentActionContent = (): string => "";
+// Grep/Glob search actions
+const getSearchActionContent = (
+ event: ActionEvent<GlobAction | GrepAction>,
+): string => {
+ const { action } = event;
+ const parts: string[] = [];
+ if (action.pattern) {
+ parts.push(`**Pattern:** \`${action.pattern}\``);
+ }
+ if (action.path) {
+ parts.push(`**Path:** \`${action.path}\``);
+ }
+ if ("include" in action && action.include) {
+ parts.push(`**Include:** \`${action.include}\``);
+ }
+ const { summary } = event as { summary?: string };
+ if (summary) {
+ parts.push(`**Summary:** ${summary}`);
+ }
+ return parts.length > 0 ? parts.join("\n") : getNoContentActionContent();
+};
+
// File Editor Actions
const getFileEditorActionContent = (
action: FileEditorAction | StrReplaceEditorAction,
@@ -228,6 +252,12 @@ export const getActionContent = (event: ActionEvent): string => {
case "BrowserCloseTabAction":
return getBrowserActionContent(action);
+ case "GrepAction":
+ case "GlobAction":
+ return getSearchActionContent(
+ event as ActionEvent<GlobAction | GrepAction>,
+ );
+
default:
return getDefaultEventContent(event);
}
diff --git a/frontend/src/components/v1/chat/event-content-helpers/get-event-content.tsx b/frontend/src/components/v1/chat/event-content-helpers/get-event-content.tsx
index 88f546d5b1..55e9e939db 100644
--- a/frontend/src/components/v1/chat/event-content-helpers/get-event-content.tsx
+++ b/frontend/src/components/v1/chat/event-content-helpers/get-event-content.tsx
@@ -84,6 +84,24 @@ const getActionEventTitle = (event: OpenHandsEvent): React.ReactNode => {
case "TaskTrackerAction":
actionKey = "ACTION_MESSAGE$TASK_TRACKING";
break;
+ case "GrepAction":
+ actionKey = "ACTION_MESSAGE$GREP";
+ actionValues = {
+ pattern:
+ "pattern" in event.action && event.action.pattern
+ ? trimText(String(event.action.pattern), 50)
+ : "",
+ };
+ break;
+ case "GlobAction":
+ actionKey = "ACTION_MESSAGE$GLOB";
+ actionValues = {
+ pattern:
+ "pattern" in event.action && event.action.pattern
+ ? trimText(String(event.action.pattern), 50)
+ : "",
+ };
+ break;
case "BrowserNavigateAction":
case "BrowserClickAction":
case "BrowserTypeAction":
diff --git a/frontend/src/components/v1/chat/hooks/use-plan-preview-events.ts b/frontend/src/components/v1/chat/hooks/use-plan-preview-events.ts
index b36c97786b..60cee582cd 100644
--- a/frontend/src/components/v1/chat/hooks/use-plan-preview-events.ts
+++ b/frontend/src/components/v1/chat/hooks/use-plan-preview-events.ts
@@ -38,19 +38,24 @@ function groupEventsByPhase(events: OpenHandsEvent[]): OpenHandsEvent[][] {
return phases;
}
+const isPlanFilePath = (path: string | null): boolean =>
+ path?.toUpperCase().endsWith("PLAN.MD") ?? false;
+
/**
- * Finds the last PlanningFileEditorObservation in a phase.
+ * Finds the last PlanningFileEditorObservation for Plan.md in a phase.
*
* @param phase - Array of events in a phase
- * @returns The event ID of the last PlanningFileEditorObservation, or null
+ * @returns The event ID of the last Plan.md observation, or null
*/
function findLastPlanningObservationInPhase(
phase: OpenHandsEvent[],
): string | null {
- // Iterate backwards to find the last one
for (let i = phase.length - 1; i >= 0; i -= 1) {
const event = phase[i];
- if (isPlanningFileEditorObservationEvent(event)) {
+ if (
+ isPlanningFileEditorObservationEvent(event) &&
+ isPlanFilePath(event.observation.path)
+ ) {
return event.id;
}
}
diff --git a/frontend/src/contexts/conversation-websocket-context.tsx b/frontend/src/contexts/conversation-websocket-context.tsx
index 33c7169a77..3e56c3d289 100644
--- a/frontend/src/contexts/conversation-websocket-context.tsx
+++ b/frontend/src/contexts/conversation-websocket-context.tsx
@@ -126,13 +126,15 @@ export function ConversationWebSocketProvider({
const receivedEventCountRefMain = useRef(0);
const receivedEventCountRefPlanning = useRef(0);
- // Track the latest PlanningFileEditorObservation event during history replay
- // We'll only call the API once after history loading completes
+ // Track the latest PlanningFileEditorObservation for Plan.md during history replay
const latestPlanningFileEventRef = useRef<{
path: string;
conversationId: string;
} | null>(null);
+ const isPlanFilePath = (path: string | null): boolean =>
+ path?.toUpperCase().endsWith("PLAN.MD") ?? false;
+
// Helper function to update metrics from stats event
const updateMetricsFromStats = useCallback(
(event: ConversationStateUpdateEventStats) => {
@@ -612,37 +614,39 @@ export function ConversationWebSocketProvider({
appendOutput(textContent);
}
- // Handle PlanningFileEditorObservation events - read and update plan content
+ // Handle PlanningFileEditorObservation - only update plan for Plan.md
if (isPlanningFileEditorObservationEvent(event)) {
- const planningAgentConversation = subConversations?.[0];
- const planningConversationId = planningAgentConversation?.id;
-
- if (planningConversationId && event.observation.path) {
- // During history replay, track the latest event but don't call API
- // After history loading completes, we'll call the API once with the latest event
- if (isLoadingHistoryPlanning) {
- latestPlanningFileEventRef.current = {
- path: event.observation.path,
- conversationId: planningConversationId,
- };
- } else {
- // History loading is complete - this is a new real-time event
- // Call the API immediately for real-time updates
- readConversationFile(
- {
+ const { path } = event.observation;
+ if (isPlanFilePath(path)) {
+ const planningAgentConversation = subConversations?.[0];
+ const planningConversationId = planningAgentConversation?.id;
+
+ if (planningConversationId && path) {
+ if (isLoadingHistoryPlanning) {
+ latestPlanningFileEventRef.current = {
+ path,
conversationId: planningConversationId,
- filePath: event.observation.path,
- },
- {
- onSuccess: (fileContent) => {
- setPlanContent(fileContent);
+ };
+ } else {
+ readConversationFile(
+ {
+ conversationId: planningConversationId,
+ filePath: path,
},
- onError: (error) => {
- // eslint-disable-next-line no-console
- console.warn("Failed to read conversation file:", error);
+ {
+ onSuccess: (fileContent) => {
+ setPlanContent(fileContent);
+ },
+ onError: (error) => {
+ // eslint-disable-next-line no-console
+ console.warn(
+ "Failed to read conversation file:",
+ error,
+ );
+ },
},
- },
- );
+ );
+ }
}
}
}
diff --git a/frontend/src/i18n/declaration.ts b/frontend/src/i18n/declaration.ts
index 25bb3a7c37..51f1bd288c 100644
--- a/frontend/src/i18n/declaration.ts
+++ b/frontend/src/i18n/declaration.ts
@@ -533,6 +533,8 @@ export enum I18nKey {
ACTION_MESSAGE$SYSTEM = "ACTION_MESSAGE$SYSTEM",
ACTION_MESSAGE$CONDENSATION = "ACTION_MESSAGE$CONDENSATION",
ACTION_MESSAGE$TASK_TRACKING = "ACTION_MESSAGE$TASK_TRACKING",
+ ACTION_MESSAGE$GREP = "ACTION_MESSAGE$GREP",
+ ACTION_MESSAGE$GLOB = "ACTION_MESSAGE$GLOB",
OBSERVATION_MESSAGE$RUN = "OBSERVATION_MESSAGE$RUN",
OBSERVATION_MESSAGE$RUN_IPYTHON = "OBSERVATION_MESSAGE$RUN_IPYTHON",
OBSERVATION_MESSAGE$READ = "OBSERVATION_MESSAGE$READ",
diff --git a/frontend/src/i18n/translation.json b/frontend/src/i18n/translation.json
index 466e9b01cc..7455ad2436 100644
--- a/frontend/src/i18n/translation.json
+++ b/frontend/src/i18n/translation.json
@@ -8527,6 +8527,38 @@
"tr": "Görevleri yönetiyor",
"uk": "Керування завданнями"
},
+ "ACTION_MESSAGE$GREP": {
+ "en": "Search in files: <cmd>{{pattern}}</cmd>",
+ "ja": "ファイル内検索: <cmd>{{pattern}}</cmd>",
+ "zh-CN": "在文件中搜索: <cmd>{{pattern}}</cmd>",
+ "zh-TW": "在檔案中搜尋: <cmd>{{pattern}}</cmd>",
+ "ko-KR": "파일 내 검색: <cmd>{{pattern}}</cmd>",
+ "no": "Søk i filer: <cmd>{{pattern}}</cmd>",
+ "it": "Cerca nei file: <cmd>{{pattern}}</cmd>",
+ "pt": "Pesquisar em arquivos: <cmd>{{pattern}}</cmd>",
+ "es": "Buscar en archivos: <cmd>{{pattern}}</cmd>",
+ "ar": "البحث داخل الملفات: <cmd>{{pattern}}</cmd>",
+ "fr": "Rechercher dans les fichiers: <cmd>{{pattern}}</cmd>",
+ "tr": "Dosyalarda ara: <cmd>{{pattern}}</cmd>",
+ "de": "In Dateien suchen: <cmd>{{pattern}}</cmd>",
+ "uk": "Пошук у файлах: <cmd>{{pattern}}</cmd>"
+ },
+ "ACTION_MESSAGE$GLOB": {
+ "en": "Search files: <cmd>{{pattern}}</cmd>",
+ "ja": "ファイル検索: <cmd>{{pattern}}</cmd>",
+ "zh-CN": "搜索文件: <cmd>{{pattern}}</cmd>",
+ "zh-TW": "搜尋檔案: <cmd>{{pattern}}</cmd>",
+ "ko-KR": "파일 검색: <cmd>{{pattern}}</cmd>",
+ "no": "Søk filer: <cmd>{{pattern}}</cmd>",
+ "it": "Cerca file: <cmd>{{pattern}}</cmd>",
+ "pt": "Pesquisar arquivos: <cmd>{{pattern}}</cmd>",
+ "es": "Buscar archivos: <cmd>{{pattern}}</cmd>",
+ "ar": "البحث في الملفات: <cmd>{{pattern}}</cmd>",
+ "fr": "Rechercher des fichiers: <cmd>{{pattern}}</cmd>",
+ "tr": "Dosya ara: <cmd>{{pattern}}</cmd>",
+ "de": "Dateien suchen: <cmd>{{pattern}}</cmd>",
+ "uk": "Пошук файлів: <cmd>{{pattern}}</cmd>"
+ },
"OBSERVATION_MESSAGE$RUN": {
"en": "Ran <cmd>{{command}}</cmd>",
"zh-CN": "运行 <cmd>{{command}}</cmd>",
@@ -8672,36 +8704,36 @@
"uk": "Думка"
},
"OBSERVATION_MESSAGE$GLOB": {
- "en": "Glob: <cmd>{{pattern}}</cmd>",
- "ja": "Glob: <cmd>{{pattern}}</cmd>",
- "zh-CN": "Glob: <cmd>{{pattern}}</cmd>",
- "zh-TW": "Glob: <cmd>{{pattern}}</cmd>",
- "ko-KR": "Glob: <cmd>{{pattern}}</cmd>",
- "no": "Glob: <cmd>{{pattern}}</cmd>",
- "it": "Glob: <cmd>{{pattern}}</cmd>",
- "pt": "Glob: <cmd>{{pattern}}</cmd>",
- "es": "Glob: <cmd>{{pattern}}</cmd>",
- "ar": "Glob: <cmd>{{pattern}}</cmd>",
- "fr": "Glob: <cmd>{{pattern}}</cmd>",
- "tr": "Glob: <cmd>{{pattern}}</cmd>",
- "de": "Glob: <cmd>{{pattern}}</cmd>",
- "uk": "Glob: <cmd>{{pattern}}</cmd>"
+ "en": "Search files: <cmd>{{pattern}}</cmd>",
+ "ja": "ファイル検索: <cmd>{{pattern}}</cmd>",
+ "zh-CN": "搜索文件: <cmd>{{pattern}}</cmd>",
+ "zh-TW": "搜尋檔案: <cmd>{{pattern}}</cmd>",
+ "ko-KR": "파일 검색: <cmd>{{pattern}}</cmd>",
+ "no": "Søk filer: <cmd>{{pattern}}</cmd>",
+ "it": "Cerca file: <cmd>{{pattern}}</cmd>",
+ "pt": "Pesquisar arquivos: <cmd>{{pattern}}</cmd>",
+ "es": "Buscar archivos: <cmd>{{pattern}}</cmd>",
+ "ar": "البحث في الملفات: <cmd>{{pattern}}</cmd>",
+ "fr": "Rechercher des fichiers: <cmd>{{pattern}}</cmd>",
+ "tr": "Dosya ara: <cmd>{{pattern}}</cmd>",
+ "de": "Dateien suchen: <cmd>{{pattern}}</cmd>",
+ "uk": "Пошук файлів: <cmd>{{pattern}}</cmd>"
},
"OBSERVATION_MESSAGE$GREP": {
- "en": "Grep: <cmd>{{pattern}}</cmd>",
- "ja": "Grep: <cmd>{{pattern}}</cmd>",
- "zh-CN": "Grep: <cmd>{{pattern}}</cmd>",
- "zh-TW": "Grep: <cmd>{{pattern}}</cmd>",
- "ko-KR": "Grep: <cmd>{{pattern}}</cmd>",
- "no": "Grep: <cmd>{{pattern}}</cmd>",
- "it": "Grep: <cmd>{{pattern}}</cmd>",
- "pt": "Grep: <cmd>{{pattern}}</cmd>",
- "es": "Grep: <cmd>{{pattern}}</cmd>",
- "ar": "Grep: <cmd>{{pattern}}</cmd>",
- "fr": "Grep: <cmd>{{pattern}}</cmd>",
- "tr": "Grep: <cmd>{{pattern}}</cmd>",
- "de": "Grep: <cmd>{{pattern}}</cmd>",
- "uk": "Grep: <cmd>{{pattern}}</cmd>"
+ "en": "Search in files: <cmd>{{pattern}}</cmd>",
+ "ja": "ファイル内検索: <cmd>{{pattern}}</cmd>",
+ "zh-CN": "在文件中搜索: <cmd>{{pattern}}</cmd>",
+ "zh-TW": "在檔案中搜尋: <cmd>{{pattern}}</cmd>",
+ "ko-KR": "파일 내 검색: <cmd>{{pattern}}</cmd>",
+ "no": "Søk i filer: <cmd>{{pattern}}</cmd>",
+ "it": "Cerca nei file: <cmd>{{pattern}}</cmd>",
+ "pt": "Pesquisar em arquivos: <cmd>{{pattern}}</cmd>",
+ "es": "Buscar en archivos: <cmd>{{pattern}}</cmd>",
+ "ar": "البحث داخل الملفات: <cmd>{{pattern}}</cmd>",
+ "fr": "Rechercher dans les fichiers: <cmd>{{pattern}}</cmd>",
+ "tr": "Dosyalarda ara: <cmd>{{pattern}}</cmd>",
+ "de": "In Dateien suchen: <cmd>{{pattern}}</cmd>",
+ "uk": "Пошук у файлах: <cmd>{{pattern}}</cmd>"
},
"OBSERVATION_MESSAGE$TASK_TRACKING_PLAN": {
"en": "Agent updated the plan",
diff --git a/frontend/src/types/v1/core/base/action.ts b/frontend/src/types/v1/core/base/action.ts
index 2fcef92087..d2e0b9af88 100644
--- a/frontend/src/types/v1/core/base/action.ts
+++ b/frontend/src/types/v1/core/base/action.ts
@@ -244,6 +244,32 @@ export interface PlanningFileEditorAction extends ActionBase<"PlanningFileEditor
view_range: [number, number] | null;
}
+export interface GlobAction extends ActionBase<"GlobAction"> {
+ /**
+ * The glob pattern to match files against.
+ */
+ pattern: string;
+ /**
+ * The directory to search in.
+ */
+ path: string | null;
+}
+
+export interface GrepAction extends ActionBase<"GrepAction"> {
+ /**
+ * The regex pattern to search for in file contents.
+ */
+ pattern: string;
+ /**
+ * The file or directory to search in.
+ */
+ path: string | null;
+ /**
+ * Glob pattern to filter files.
+ */
+ include: string | null;
+}
+
export type Action =
| MCPToolAction
| FinishAction
@@ -263,4 +289,6 @@ export type Action =
| BrowserGoBackAction
| BrowserListTabsAction
| BrowserSwitchTabAction
- | BrowserCloseTabAction;
+ | BrowserCloseTabAction
+ | GlobAction
+ | GrepAction;
diff --git a/frontend/src/types/v1/core/base/base.ts b/frontend/src/types/v1/core/base/base.ts
index 531168d17b..1ab4492174 100644
--- a/frontend/src/types/v1/core/base/base.ts
+++ b/frontend/src/types/v1/core/base/base.ts
@@ -23,7 +23,11 @@ type ActionOnlyType =
type ObservationOnlyType = "Browser";
-type ActionEventType = `${ActionOnlyType}Action` | `${EventType}Action`;
+type ActionEventType =
+ | `${ActionOnlyType}Action`
+ | `${EventType}Action`
+ | "GlobAction"
+ | "GrepAction";
type ObservationEventType =
| `${ObservationOnlyType}Observation`
| `${EventType}Observation`