Fix Timeline tooltips for followup messages and consolidated color retrieval code. (#4164)

* fix: timeline message description

* refactor: merge the timeline's color method to eliminate code duplication.

* add changeset
This commit is contained in:
Charles Xu authored and GitHub committed 2025-06-19 15:38:56 -07:00
1 parent 7cb3bd9f85
commit e46980e40f
4 files changed
+101 -190

No files matched your search

+5
View File
@@ -0,0 +1,5 @@
---
"claude-dev": patch
---
Updated Timeline tooltips for `followup` messages and consolidated color retrieval code.
@@ -4,16 +4,7 @@ import { ClineMessage } from "@shared/ExtensionMessage"
import { combineApiRequests } from "@shared/combineApiRequests"
import { combineCommandSequences } from "@shared/combineCommandSequences"
import TaskTimelineTooltip from "./TaskTimelineTooltip"
import {
COLOR_WHITE,
COLOR_GRAY,
COLOR_DARK_GRAY,
COLOR_BEIGE,
COLOR_BLUE,
COLOR_RED,
COLOR_PURPLE,
COLOR_GREEN,
} from "../colors"
import { getColor } from "./util"
// Timeline dimensions and spacing
const TIMELINE_HEIGHT = "18px"
@@ -26,88 +17,6 @@ interface TaskTimelineProps {
onBlockClick?: (messageIndex: number) => void
}
const getBlockColor = (message: ClineMessage): string => {
if (message.type === "say") {
switch (message.say) {
case "task":
return COLOR_WHITE // White for system prompt
case "user_feedback":
return COLOR_WHITE // White for user feedback
case "text":
return COLOR_GRAY // Gray for assistant responses
case "tool":
if (message.text) {
try {
const toolData = JSON.parse(message.text)
if (
toolData.tool === "readFile" ||
toolData.tool === "listFilesTopLevel" ||
toolData.tool === "listFilesRecursive" ||
toolData.tool === "listCodeDefinitionNames" ||
toolData.tool === "searchFiles"
) {
return COLOR_BEIGE // Beige for file read operations
} else if (toolData.tool === "editedExistingFile" || toolData.tool === "newFileCreated") {
return COLOR_BLUE // Blue for file edit/create operations
} else if (toolData.tool === "webFetch") {
return COLOR_PURPLE // Purple for web fetch operations
}
} catch (e) {
// JSON parse error here
}
}
return COLOR_BEIGE // Default beige for tool use
case "command":
case "command_output":
return COLOR_PURPLE // Red for terminal commands
case "browser_action":
case "browser_action_result":
return COLOR_PURPLE // Purple for browser actions
case "completion_result":
return COLOR_GREEN // Green for task success
default:
return COLOR_DARK_GRAY // Dark gray for unknown
}
} else if (message.type === "ask") {
switch (message.ask) {
case "followup":
return COLOR_GRAY // Gray for user messages
case "plan_mode_respond":
return COLOR_GRAY // Gray for planning responses
case "tool":
// Match the color of the tool approval with the tool type
if (message.text) {
try {
const toolData = JSON.parse(message.text)
if (
toolData.tool === "readFile" ||
toolData.tool === "listFilesTopLevel" ||
toolData.tool === "listFilesRecursive" ||
toolData.tool === "listCodeDefinitionNames" ||
toolData.tool === "searchFiles"
) {
return COLOR_BEIGE // Beige for file read operations
} else if (toolData.tool === "editedExistingFile" || toolData.tool === "newFileCreated") {
return COLOR_BLUE // Blue for file edit/create operations
} else if (toolData.tool === "webFetch") {
return COLOR_PURPLE // Purple for web fetch operations
}
} catch (e) {
// JSON parse error here
}
}
return COLOR_BEIGE // Default beige for tool approvals
case "command":
return COLOR_PURPLE // Red for command approvals (same as terminal commands)
case "browser_action_launch":
return COLOR_PURPLE // Purple for browser launch approvals (same as browser actions)
default:
return COLOR_DARK_GRAY // Dark gray for unknown
}
}
return COLOR_WHITE // Default color
}
const TaskTimeline: React.FC<TaskTimelineProps> = ({ messages, onBlockClick }) => {
const containerRef = useRef<HTMLDivElement>(null)
const scrollableRef = useRef<HTMLDivElement>(null)
@@ -181,7 +90,7 @@ const TaskTimeline: React.FC<TaskTimelineProps> = ({ messages, onBlockClick }) =
style={{
width: BLOCK_WIDTH,
height: "100%",
backgroundColor: getBlockColor(message),
backgroundColor: getColor(message),
flexShrink: 0,
cursor: "pointer",
marginRight: BLOCK_GAP,
@@ -1,18 +1,7 @@
import React from "react"
import { ClineMessage } from "@shared/ExtensionMessage"
import {
COLOR_WHITE,
COLOR_GRAY,
COLOR_DARK_GRAY,
COLOR_BEIGE,
COLOR_BLUE,
COLOR_RED,
COLOR_PURPLE,
COLOR_GREEN,
} from "../colors"
import { Tooltip } from "@heroui/react"
// Color mapping for different message types
import { getColor } from "./util"
interface TaskTimelineTooltipProps {
message: ClineMessage
@@ -73,7 +62,7 @@ const TaskTimelineTooltip = ({ message, children }: TaskTimelineTooltipProps) =>
} else if (message.type === "ask") {
switch (message.ask) {
case "followup":
return "User Message"
return "Assistant Message"
case "plan_mode_respond":
return "Planning Response"
case "tool":
@@ -162,89 +151,6 @@ const TaskTimelineTooltip = ({ message, children }: TaskTimelineTooltipProps) =>
return ""
}
// Get color for the indicator based on message type
const getMessageColor = (message: ClineMessage): string => {
if (message.type === "say") {
switch (message.say) {
case "task":
return COLOR_WHITE // White for system prompt
case "user_feedback":
return COLOR_WHITE // White for user feedback
case "text":
return COLOR_GRAY // Gray for assistant responses
case "tool":
if (message.text) {
try {
const toolData = JSON.parse(message.text)
if (
toolData.tool === "readFile" ||
toolData.tool === "listFilesTopLevel" ||
toolData.tool === "listFilesRecursive" ||
toolData.tool === "listCodeDefinitionNames" ||
toolData.tool === "searchFiles"
) {
return COLOR_BEIGE // Beige for file read operations
} else if (toolData.tool === "editedExistingFile" || toolData.tool === "newFileCreated") {
return COLOR_BLUE // Blue for file edit/create operations
} else if (toolData.tool === "webFetch") {
return COLOR_PURPLE // Beige for web fetch operations
}
} catch (e) {
// JSON parse error here
}
}
return COLOR_BEIGE // Default beige for tool use
case "command":
case "command_output":
return COLOR_PURPLE // Red for terminal commands
case "browser_action":
case "browser_action_result":
return COLOR_PURPLE // Purple for browser actions
case "completion_result":
return COLOR_GREEN // Green for task success
default:
return COLOR_DARK_GRAY // Dark gray for unknown
}
} else if (message.type === "ask") {
switch (message.ask) {
case "followup":
return COLOR_GRAY // Gray for user messages
case "plan_mode_respond":
return COLOR_GRAY // Gray for planning responses
case "tool":
// Match the color of the tool approval with the tool type
if (message.text) {
try {
const toolData = JSON.parse(message.text)
if (
toolData.tool === "readFile" ||
toolData.tool === "listFilesTopLevel" ||
toolData.tool === "listFilesRecursive" ||
toolData.tool === "listCodeDefinitionNames" ||
toolData.tool === "searchFiles"
) {
return COLOR_BEIGE // Beige for file read operations
} else if (toolData.tool === "editedExistingFile" || toolData.tool === "newFileCreated") {
return COLOR_BLUE // Blue for file edit/create operations
} else if (toolData.tool === "webFetch") {
return COLOR_PURPLE // Purple for web fetch operations
}
} catch (e) {
// JSON parse error here
}
}
return COLOR_BEIGE // Default beige for tool approvals
case "command":
return COLOR_PURPLE // Red for command approvals (same as terminal commands)
case "browser_action_launch":
return COLOR_PURPLE // Purple for browser launch approvals (same as browser actions)
default:
return COLOR_DARK_GRAY // Dark gray for unknown
}
}
return COLOR_DARK_GRAY // Default dark gray
}
return (
<Tooltip
content={
@@ -258,7 +164,7 @@ const TaskTimelineTooltip = ({ message, children }: TaskTimelineTooltipProps) =>
minWidth: "10px", // Ensure fixed width
minHeight: "10px", // Ensure fixed height
borderRadius: "50%",
backgroundColor: getMessageColor(message),
backgroundColor: getColor(message),
marginRight: "8px",
display: "inline-block",
flexShrink: 0, // Prevent shrinking when space is limited
@@ -0,0 +1,91 @@
import { ClineMessage } from "@shared/ExtensionMessage"
import { COLOR_WHITE, COLOR_GRAY, COLOR_DARK_GRAY, COLOR_BEIGE, COLOR_BLUE, COLOR_PURPLE, COLOR_GREEN } from "../colors"
/**
*
* Get the color for a block or the indicator based on the message type
*
* @param message ClineMessage - The message to determine the color for
* @returns string - The color code for the block or indicator
*/
export const getColor = (message: ClineMessage): string => {
if (message.type === "say") {
switch (message.say) {
case "task":
return COLOR_WHITE // White for system prompt
case "user_feedback":
return COLOR_WHITE // White for user feedback
case "text":
return COLOR_GRAY // Gray for assistant responses
case "tool":
if (message.text) {
try {
const toolData = JSON.parse(message.text)
if (
toolData.tool === "readFile" ||
toolData.tool === "listFilesTopLevel" ||
toolData.tool === "listFilesRecursive" ||
toolData.tool === "listCodeDefinitionNames" ||
toolData.tool === "searchFiles"
) {
return COLOR_BEIGE // Beige for file read operations
} else if (toolData.tool === "editedExistingFile" || toolData.tool === "newFileCreated") {
return COLOR_BLUE // Blue for file edit/create operations
} else if (toolData.tool === "webFetch") {
return COLOR_PURPLE // Purple for web fetch operations
}
} catch (e) {
// JSON parse error here
}
}
return COLOR_BEIGE // Default beige for tool use
case "command":
case "command_output":
return COLOR_PURPLE // Red for terminal commands
case "browser_action":
case "browser_action_result":
return COLOR_PURPLE // Purple for browser actions
case "completion_result":
return COLOR_GREEN // Green for task success
default:
return COLOR_DARK_GRAY // Dark gray for unknown
}
} else if (message.type === "ask") {
switch (message.ask) {
case "followup":
return COLOR_GRAY // Gray for user messages
case "plan_mode_respond":
return COLOR_GRAY // Gray for planning responses
case "tool":
// Match the color of the tool approval with the tool type
if (message.text) {
try {
const toolData = JSON.parse(message.text)
if (
toolData.tool === "readFile" ||
toolData.tool === "listFilesTopLevel" ||
toolData.tool === "listFilesRecursive" ||
toolData.tool === "listCodeDefinitionNames" ||
toolData.tool === "searchFiles"
) {
return COLOR_BEIGE // Beige for file read operations
} else if (toolData.tool === "editedExistingFile" || toolData.tool === "newFileCreated") {
return COLOR_BLUE // Blue for file edit/create operations
} else if (toolData.tool === "webFetch") {
return COLOR_PURPLE // Purple for web fetch operations
}
} catch (e) {
// JSON parse error here
}
}
return COLOR_BEIGE // Default beige for tool approvals
case "command":
return COLOR_PURPLE // Red for command approvals (same as terminal commands)
case "browser_action_launch":
return COLOR_PURPLE // Purple for browser launch approvals (same as browser actions)
default:
return COLOR_DARK_GRAY // Dark gray for unknown
}
}
return COLOR_WHITE // Default color
}