refactor(site/src/pages/AgentsPage): move git commit prompt into GitPanel (#29159)

> 🤖 This PR was modified by Coder Agents on behalf of Jake Howell.

GitPanel already had the composer ref for diff comments, but Commit
still bubbled an `onCommit` callback up to `AgentChatPage` to insert the
canned prompt. The panel now inserts that prompt itself, so the page no
longer owns git-commit wording or the extra prop plumbing.
This commit is contained in:
Jake Howell authored and GitHub committed 2026-09-28 10:10:56 +00:00
1 parent d853893e8a
commit 407ed0d546
6 files changed
+110 -22

No files matched your search

@@ -405,17 +405,6 @@ const AgentChatPage: React.FC = () => {
username: currentUser.username,
});
const handleCommit = (repoRoot: string) => {
const commitPrompt = `Commit and push the working changes in ${repoRoot}. If there are unstaged files, commit them too.`;
const current = inputValueRef.current;
if (current.includes(commitPrompt)) {
return;
}
const prefix = current.trim() ? "\n\n" : "";
chatInputRef.current?.insertText(prefix + commitPrompt);
chatInputRef.current?.focus();
};
// Validate explicit and historical choices against organization options.
// Prefer the usable organization default before another organization model.
const effectiveSelectedModel = (() => {
@@ -783,7 +772,6 @@ const AgentChatPage: React.FC = () => {
debugLoggingEnabled={debugLoggingEnabled}
gitWatcher={gitWatcher}
sshCommand={sshCommand}
handleCommit={handleCommit}
handleInterrupt={handleInterrupt}
handleDeleteQueuedMessage={handleDeleteQueuedMessage}
handlePromoteQueuedMessage={handlePromoteQueuedMessage}
@@ -186,7 +186,6 @@ const StoryAgentChatPageView: React.FC<StoryProps> = ({
debugLoggingEnabled: false,
gitWatcher: buildGitWatcher(),
sshCommand: undefined as string | undefined,
handleCommit: fn(),
handleInterrupt: fn(),
handleDeleteQueuedMessage: fn(),
handlePromoteQueuedMessage: fn(),
@@ -154,7 +154,6 @@ type AgentChatPageViewProps = {
// Workspace action handlers.
sshCommand: string | undefined;
handleCommit: (repoRoot: string) => void;
// Chat action handlers.
handleInterrupt: () => void;
@@ -304,7 +303,6 @@ export const AgentChatPageView: React.FC<AgentChatPageViewProps> = ({
debugLoggingEnabled,
gitWatcher,
sshCommand,
handleCommit,
handleInterrupt,
handleDeleteQueuedMessage,
handlePromoteQueuedMessage,
@@ -684,7 +682,6 @@ export const AgentChatPageView: React.FC<AgentChatPageViewProps> = ({
!gitWatcher.hasReceivedChanges
}
onRefresh={handleRefresh}
onCommit={handleCommit}
isExpanded={visualExpanded}
remoteDiffStats={chat.diff_status}
chatInputRef={editing.chatInputRef}
@@ -101,7 +101,6 @@ const meta: Meta<typeof GitPanel> = {
component: GitPanel,
args: {
onRefresh: fn().mockReturnValue(true),
onCommit: fn(),
repositories: new Map(),
},
decorators: [
@@ -0,0 +1,95 @@
import { render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { describe, expect, it, vi } from "vitest";
import type { WorkspaceAgentRepoChanges } from "#/api/typesGenerated";
import type { ChatMessageInputRef } from "../AgentChatInput";
import { GitPanel } from "./GitPanel";
vi.mock("../DiffViewer/DiffViewer", () => ({
loadDiffStyle: () => "unified",
saveDiffStyle: () => {},
}));
vi.mock("../DiffViewer/LocalDiffPanel", () => ({
LocalDiffPanel: () => null,
}));
vi.mock("../DiffViewer/RemoteDiffPanel", () => ({
RemoteDiffPanel: () => null,
}));
const repoRoot = "/workspace/special-repo";
const commitPrompt = `Commit and push the working changes in ${repoRoot}. If there are unstaged files, commit them too.`;
const repo: WorkspaceAgentRepoChanges = {
repo_root: repoRoot,
branch: "feat/example",
unified_diff: `diff --git a/src/main.ts b/src/main.ts
index abc1234..def5678 100644
--- a/src/main.ts
+++ b/src/main.ts
@@ -1 +1,2 @@
existing
+added
`,
};
function mockComposer(value = ""): ChatMessageInputRef {
let current = value;
return {
getValue: () => current,
insertText: vi.fn((text: string) => {
current += text;
}),
setValue: vi.fn(),
clear: vi.fn(),
focus: vi.fn(),
addFileReference: vi.fn(),
getContentParts: vi.fn(() => []),
};
}
function renderGitPanel(input: ChatMessageInputRef) {
render(
<GitPanel
repositories={new Map([[repoRoot, repo]])}
onRefresh={() => true}
chatInputRef={{ current: input }}
/>,
);
}
describe("GitPanel", () => {
it("inserts a commit prompt for the active repo when Commit is clicked", async () => {
const user = userEvent.setup();
const input = mockComposer();
renderGitPanel(input);
await user.click(screen.getByRole("button", { name: "Commit" }));
expect(input.insertText).toHaveBeenCalledWith(commitPrompt);
expect(input.focus).toHaveBeenCalled();
});
it("does not insert the prompt twice for the same repo", async () => {
const user = userEvent.setup();
const input = mockComposer();
renderGitPanel(input);
const commit = screen.getByRole("button", { name: "Commit" });
await user.click(commit);
await user.click(commit);
expect(input.insertText).toHaveBeenCalledTimes(1);
});
it("separates the prompt from existing composer text", async () => {
const user = userEvent.setup();
const input = mockComposer("please review");
renderGitPanel(input);
await user.click(screen.getByRole("button", { name: "Commit" }));
expect(input.insertText).toHaveBeenCalledWith(`\n\n${commitPrompt}`);
});
});
@@ -65,15 +65,13 @@ type GitPanelProps = {
repositories: ReadonlyMap<string, WorkspaceAgentRepoChanges>;
/** Callback to send a refresh to the git watcher. Returns false when disconnected. */
onRefresh: () => boolean;
/** Called when the user clicks the Commit button for a working repo. */
onCommit: (repoRoot: string) => void;
/** Whether the panel is in expanded/fullscreen mode. */
isExpanded?: boolean;
/** Whether the watcher is loading its initial repository state. */
isGitStatusLoading?: boolean;
/** Diff status for the remote/branch view (includes PR metadata). */
remoteDiffStats?: ChatDiffStatus;
/** Ref to the chat input, forwarded to RemoteDiffPanel. */
/** Chat composer, used to insert commit prompts and file comments. */
chatInputRef?: React.RefObject<ChatMessageInputRef | null>;
/**
* Repo roots that have been dirty at some point during this session.
@@ -111,7 +109,6 @@ export const GitPanel: React.FC<GitPanelProps> = ({
prTab,
repositories,
onRefresh,
onCommit,
isExpanded,
isGitStatusLoading = false,
remoteDiffStats,
@@ -322,6 +319,19 @@ export const GitPanel: React.FC<GitPanelProps> = ({
}
};
const handleCommit = (repoRoot: string) => {
const input = chatInputRef?.current;
if (!input) {
return;
}
const prompt = `Commit and push the working changes in ${repoRoot}. If there are unstaged files, commit them too.`;
const current = input.getValue();
if (!current.includes(prompt)) {
input.insertText(current.trim() ? `\n\n${prompt}` : prompt);
}
input.focus();
};
return (
<div className="flex h-full flex-col">
{/* Toolbar */}
@@ -440,7 +450,7 @@ export const GitPanel: React.FC<GitPanelProps> = ({
deletions: 0,
}
}
onCommit={onCommit}
onCommit={handleCommit}
isExpanded={isExpanded}
diffStyle={diffStyle}
chatInputRef={chatInputRef}