Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ type CommentableDiffViewerProps = {
/** Parsed file diffs to render. */
parsedFiles: readonly FileDiffMetadata[];
/** Whether the panel is in expanded mode. */
isExpanded?: boolean;
isExpanded: boolean;
/** Loading state. */
isLoading?: boolean;
/** Error state. */
Expand All @@ -182,7 +182,7 @@ type CommentableDiffViewerProps = {
/** Which diff rendering style to use. */
diffStyle: DiffStyle;
/** Ref to the chat message input for inserting comments. */
chatInputRef?: React.RefObject<ChatMessageInputRef | null>;
chatInputRef: React.RefObject<ChatMessageInputRef | null>;
/** Scroll to a specific file. */
scrollToFile?: string | null;
/** Called after scrollToFile has been processed. */
Expand Down Expand Up @@ -297,16 +297,16 @@ export const CommentableDiffViewer: React.FC<CommentableDiffViewerProps> = ({
);
// Single imperative call: chip inserted atomically
// in one Lexical update. No rAF hack needed.
chatInputRef?.current?.addFileReference({
chatInputRef.current?.addFileReference({
fileName: box.fileName,
startLine,
endLine,
content,
});
if (text.trim()) {
chatInputRef?.current?.insertText(text);
chatInputRef.current?.insertText(text);
}
chatInputRef?.current?.focus();
chatInputRef.current?.focus();
updateCommentBox(null);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,12 @@ const meta: Meta<typeof DiffViewer> = {
args: {
parsedFiles,
diffStyle: "unified" satisfies DiffStyle,
isExpanded: false,
onLineNumberClick: fn(),
onLineSelected: fn(),
onLineSelectionChange: fn(),
getLineAnnotations: () => [],
getSelectedLines: () => null,
onScrollToFileComplete: fn(),
},
decorators: [
Expand Down
27 changes: 13 additions & 14 deletions site/src/pages/AgentsPage/components/DiffViewer/DiffViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,24 @@ import { useActiveFileTracking } from "./useActiveFileTracking";

type DiffViewerProps = {
parsedFiles: readonly FileDiffMetadata[];
isExpanded?: boolean;
isExpanded: boolean;
isLoading?: boolean;
error?: unknown;
emptyMessage?: string;
diffStyle: DiffStyle;
onLineNumberClick?: (
onLineNumberClick: (
fileName: string,
props: { lineNumber: number; annotationSide: "additions" | "deletions" },
) => void;
/** Fires when a line selection is committed (e.g. on pointer up). */
onLineSelected?: (fileName: string, range: SelectedLineRange | null) => void;
onLineSelected: (fileName: string, range: SelectedLineRange | null) => void;
/** Fires continuously as the selection range changes during a drag. */
onLineSelectionChange?: (
onLineSelectionChange: (
fileName: string,
range: SelectedLineRange | null,
) => void;
getLineAnnotations?: (fileName: string) => DiffLineAnnotation<string>[];
getSelectedLines?: (fileName: string) => SelectedLineRange | null;
getLineAnnotations: (fileName: string) => DiffLineAnnotation<string>[];
getSelectedLines: (fileName: string) => SelectedLineRange | null;
renderAnnotation?: (
annotation: DiffLineAnnotation<string>,
) => React.ReactNode;
Expand Down Expand Up @@ -156,9 +156,9 @@ export function compareTreePaths(a: string, b: string): number {
// count at 1 but must still re-render, so fold each annotation's side and line
// into the version. Exported for unit tests.
export function annotationsVersion(
annotations: readonly DiffLineAnnotation<string>[] | undefined,
annotations: readonly DiffLineAnnotation<string>[],
): number {
if (!annotations || annotations.length === 0) {
if (annotations.length === 0) {
return 0;
}
return annotations.reduce(
Expand Down Expand Up @@ -453,22 +453,22 @@ export const DiffViewer: React.FC<DiffViewerProps> = ({
enableGutterUtility: true,
onLineNumberClick: (props, item) => {
if (item.type === "diff" && props.type === "diff-line") {
onLineNumberClick?.(item.item.id, props);
onLineNumberClick(item.item.id, props);
}
},
onLineSelected: (range, item) => {
if (item.type === "diff") {
onLineSelected?.(item.item.id, range);
onLineSelected(item.item.id, range);
}
},
onLineSelectionChange: (range, item) => {
if (item.type === "diff") {
onLineSelectionChange?.(item.item.id, range);
onLineSelectionChange(item.item.id, range);
}
},
onGutterUtilityClick: (range, item) => {
if (item.type === "diff") {
onLineSelected?.(item.item.id, range);
onLineSelected(item.item.id, range);
}
},
};
Expand All @@ -480,7 +480,7 @@ export const DiffViewer: React.FC<DiffViewerProps> = ({
);

const items: CodeViewItem<string>[] = sortedFiles.map((fileDiff) => {
const annotations = getLineAnnotations?.(fileDiff.name);
const annotations = getLineAnnotations(fileDiff.name);
return {
id: fileDiff.name,
type: "diff",
Expand All @@ -491,7 +491,6 @@ export const DiffViewer: React.FC<DiffViewerProps> = ({
});

const selectedLines = (() => {
if (!getSelectedLines) return undefined;
for (const fileDiff of sortedFiles) {
const range = getSelectedLines(fileDiff.name);
if (range) return { id: fileDiff.name, range };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { parseDiffString } from "../DiffViewer/parseDiff";

type LocalDiffPanelProps = {
repo: WorkspaceAgentRepoChanges;
isExpanded?: boolean;
isExpanded: boolean;
diffStyle: DiffStyle;
chatInputRef?: React.RefObject<ChatMessageInputRef | null>;
chatInputRef: React.RefObject<ChatMessageInputRef | null>;
};

export const LocalDiffPanel: React.FC<LocalDiffPanelProps> = ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ const BranchCopyButton: React.FC<{ branch: string }> = ({ branch }) => {

type RemoteDiffPanelProps = {
chatId: string;
isExpanded?: boolean;
chatInputRef?: React.RefObject<ChatMessageInputRef | null>;
isExpanded: boolean;
chatInputRef: React.RefObject<ChatMessageInputRef | null>;
diffStyle: DiffStyle;
diffStatus?: TypesGen.ChatDiffStatus;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const annotation = (

describe("annotationsVersion", () => {
it("is 0 when there are no annotations", () => {
expect(annotationsVersion(undefined)).toBe(0);
expect(annotationsVersion([])).toBe(0);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ const meta: Meta<typeof GitPanel> = {
args: {
onRefresh: fn().mockReturnValue(true),
repositories: new Map(),
everDirty: new Set(),
isGitStatusLoading: false,
isExpanded: false,
chatInputRef: { current: null },
},
decorators: [
(Story) => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ function renderGitPanel(input: ChatMessageInputRef) {
<GitPanel
repositories={new Map([[repoRoot, repo]])}
onRefresh={() => true}
isExpanded={false}
isGitStatusLoading={false}
everDirty={new Set()}
chatInputRef={{ current: input }}
/>,
);
Expand Down
28 changes: 13 additions & 15 deletions site/src/pages/AgentsPage/components/GitPanel/GitPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,20 @@ type GitPanelProps = {
/** Callback to send a refresh to the git watcher. Returns false when disconnected. */
onRefresh: () => boolean;
/** Whether the panel is in expanded/fullscreen mode. */
isExpanded?: boolean;
isExpanded: boolean;
/** Whether the watcher is loading its initial repository state. */
isGitStatusLoading?: boolean;
isGitStatusLoading: boolean;
/** Diff status for the remote/branch view (includes PR metadata). */
remoteDiffStats?: ChatDiffStatus;
/** Chat composer, used to insert commit prompts and file comments. */
chatInputRef?: React.RefObject<ChatMessageInputRef | null>;
chatInputRef: React.RefObject<ChatMessageInputRef | null>;
/**
* Repo roots that have been dirty at some point during this session.
* Used to keep a repo's entry visible after its diff goes empty, so
* the view switcher does not visibly flip when the agent edits a
* file and then reverts it.
*/
everDirty?: ReadonlySet<string>;
everDirty: ReadonlySet<string>;
};

function repoLabel(repoRoot: string): string {
Expand Down Expand Up @@ -110,7 +110,7 @@ export const GitPanel: React.FC<GitPanelProps> = ({
repositories,
onRefresh,
isExpanded,
isGitStatusLoading = false,
isGitStatusLoading,
remoteDiffStats,
chatInputRef,
everDirty,
Expand Down Expand Up @@ -154,11 +154,9 @@ export const GitPanel: React.FC<GitPanelProps> = ({
// the watcher) so a clean-revert does not hide the entry.
const localRepos = (() => {
const roots = new Set<string>(repoStats.keys());
if (everDirty) {
for (const root of everDirty) {
if (repositories.has(root)) {
roots.add(root);
}
for (const root of everDirty) {
if (repositories.has(root)) {
roots.add(root);
}
}
return Array.from(roots).sort((a, b) => a.localeCompare(b));
Expand Down Expand Up @@ -320,7 +318,7 @@ export const GitPanel: React.FC<GitPanelProps> = ({
};

const handleCommit = (repoRoot: string) => {
const input = chatInputRef?.current;
const input = chatInputRef.current;
if (!input) {
return;
}
Expand Down Expand Up @@ -589,8 +587,8 @@ const RemoteContent: React.FC<{
prTab?: { prNumber: number; chatId: string };
hasGitContext: boolean;
isGitStatusLoading: boolean;
isExpanded?: boolean;
chatInputRef?: React.RefObject<ChatMessageInputRef | null>;
isExpanded: boolean;
chatInputRef: React.RefObject<ChatMessageInputRef | null>;
diffStyle: DiffStyle;
diffStatus?: ChatDiffStatus;
}> = ({
Expand Down Expand Up @@ -650,9 +648,9 @@ const LocalRepoContent: React.FC<{
repo: WorkspaceAgentRepoChanges | undefined;
diffStats: DiffStats;
onCommit: (repoRoot: string) => void;
isExpanded?: boolean;
isExpanded: boolean;
diffStyle: DiffStyle;
chatInputRef?: React.RefObject<ChatMessageInputRef | null>;
chatInputRef: React.RefObject<ChatMessageInputRef | null>;
}> = ({
repoRoot,
repo,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {

type DebugPanelProps = {
chatId: string;
isVisible?: boolean;
isVisible: boolean;
download?: DownloadDebugFile;
};

Expand Down Expand Up @@ -100,7 +100,7 @@ const fetchDebugRunDetailsForExport = async (

export const DebugPanel: React.FC<DebugPanelProps> = ({
chatId,
isVisible = false,
isVisible,
download = saveAs,
}) => {
const runsQuery = useQuery({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export const CopyableCodeBlock: React.FC<CopyableCodeBlockProps> = ({

type PillToggleProps = {
label: string;
count?: number;
count: number;
isActive: boolean;
onToggle: () => void;
icon?: React.ReactNode;
Expand All @@ -107,7 +107,7 @@ export const PillToggle: React.FC<PillToggleProps> = ({
>
{icon}
{label}
{count !== undefined && count > 0 ? ` (${count})` : null}
{count > 0 ? ` (${count})` : null}
</button>
);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { cn } from "cn";
import { saveAs } from "file-saver";
import { ChevronDownIcon, DownloadIcon } from "lucide-react";
import { useId, useState } from "react";
import { useQuery } from "react-query";
Expand Down Expand Up @@ -38,7 +37,7 @@ type DebugRunCardProps = {
run: ChatDebugRunSummary;
chatId: string;
isVisible: boolean;
download?: DownloadDebugFile;
download: DownloadDebugFile;
};

// Max characters shown in the run header label before truncation.
Expand All @@ -64,7 +63,7 @@ export const DebugRunCard: React.FC<DebugRunCardProps> = ({
run,
chatId,
isVisible,
download = saveAs,
download,
}) => {
const [isExpanded, setIsExpanded] = useState(false);
const [isExporting, setIsExporting] = useState(false);
Expand Down Expand Up @@ -281,7 +280,7 @@ export const DebugRunCard: React.FC<DebugRunCardProps> = ({
</section>
) : null}
{steps.map((step) => (
<DebugStepCard key={step.id} step={step} defaultOpen={false} />
<DebugStepCard key={step.id} step={step} />
))}
{steps.length === 0 ? (
<p className="text-sm text-content-secondary">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ type DebugRunListProps = {
runs: ChatDebugRunSummary[];
chatId: string;
isVisible: boolean;
download?: DownloadDebugFile;
download: DownloadDebugFile;
};

export const DebugRunList: React.FC<DebugRunListProps> = ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,11 @@ import {

type DebugStepCardProps = {
step: ChatDebugStep;
defaultOpen?: boolean;
};

type SectionKey = "tools" | "options" | "usage" | "policy";

export const DebugStepCard: React.FC<DebugStepCardProps> = ({
step,
defaultOpen = false,
}) => {
export const DebugStepCard: React.FC<DebugStepCardProps> = ({ step }) => {
// Single active metadata pill: only one section open at a time.
const [activeSection, setActiveSection] = useState<SectionKey | null>(null);

Expand Down Expand Up @@ -114,7 +110,7 @@ export const DebugStepCard: React.FC<DebugStepCardProps> = ({
const errorText = getErrorMessage(rawError, safeJsonStringify(rawError));

return (
<Collapsible defaultOpen={defaultOpen}>
<Collapsible>
<div className="overflow-hidden rounded-lg border border-solid border-border-default/40 bg-surface-secondary/10">
<CollapsibleTrigger asChild>
<button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ type ToolEventCardProps = {
toolCallId?: string;
payloadLabel?: string;
payload?: string;
copyLabel?: string;
copyLabel: string;
};

export const ToolEventCard: React.FC<ToolEventCardProps> = ({
Expand All @@ -74,7 +74,7 @@ export const ToolEventCard: React.FC<ToolEventCardProps> = ({
</span>
) : null}
</div>
{payloadLabel && payload && copyLabel ? (
{payloadLabel && payload ? (
<ToolPayloadDisclosure
label={payloadLabel}
code={payload}
Expand Down
Loading
Loading