feat: add git failed operations as failed chat messages (#371)

This commit is contained in:
Carlos Florêncio
2026-03-05 20:26:55 +00:00
committed by GitHub
parent 53dbd22dbf
commit 7fb2f0bcfa
8 changed files with 673 additions and 5 deletions
@@ -22,6 +22,7 @@ import { ClarificationRequestMessage } from "@/components/task/chat/messages/cla
import { ToolSubagentMessage } from "@/components/task/chat/messages/tool-subagent-message";
import { AgentPlanMessage } from "@/components/task/chat/messages/agent-plan-message";
import { AgentErrorRecoveryMessage } from "@/components/task/chat/messages/agent-error-recovery-message";
import { GitOperationErrorMessage } from "@/components/task/chat/messages/git-operation-error-message";
type AdapterContext = {
isTaskDescription: boolean;
@@ -172,6 +173,12 @@ const adapters: MessageAdapter[] = [
);
},
},
{
matches: (comment) =>
comment.type === "error" &&
!!(comment.metadata as Record<string, unknown> | undefined)?.git_operation_error,
render: (comment) => <GitOperationErrorMessage comment={comment} />,
},
{
matches: (comment) =>
(comment.type === "status" || comment.type === "error") &&
@@ -0,0 +1,80 @@
"use client";
import { useState, useCallback, memo } from "react";
import { IconGitCommit, IconSparkles } from "@tabler/icons-react";
import { Button } from "@kandev/ui/button";
import { getWebSocketClient } from "@/lib/ws/connection";
import type { Message } from "@/lib/types/http";
import type { GitOperationErrorMetadata } from "@/components/task/chat/types";
export const GitOperationErrorMessage = memo(function GitOperationErrorMessage({
comment,
}: {
comment: Message;
}) {
const [fixSent, setFixSent] = useState(false);
const metadata = comment.metadata as GitOperationErrorMetadata | undefined;
const handleFix = useCallback(async () => {
const client = getWebSocketClient();
if (!client || !metadata) return;
setFixSent(true);
const prompt = [
`The git ${metadata.operation} command failed with the following error:`,
"",
"```",
metadata.error_output,
"```",
"",
"Please fix the issues reported above.",
].join("\n");
try {
await client.request("message.add", {
task_id: metadata.task_id,
session_id: metadata.session_id,
content: prompt,
});
} catch {
setFixSent(false);
}
}, [metadata]);
const operation = metadata?.operation || "operation";
const title = comment.content || `Git ${operation} failed`;
return (
<div className="w-full" data-testid="git-operation-error-message">
<div className="flex items-start gap-3 w-full rounded px-2 py-1 -mx-2">
<div className="flex-shrink-0 mt-0.5">
<IconGitCommit className="h-4 w-4 text-red-500" />
</div>
<div className="flex-1 min-w-0 pt-0.5">
<div className="text-xs font-medium text-red-600 dark:text-red-400">{title}</div>
{metadata?.error_output && (
<pre className="mt-1.5 text-[11px] font-mono text-muted-foreground bg-muted/50 rounded p-2 overflow-auto max-h-[300px] whitespace-pre-wrap break-words">
{metadata.error_output}
</pre>
)}
<div className="mt-2">
<Button
variant="outline"
size="sm"
className="h-7 text-xs cursor-pointer gap-1.5"
disabled={fixSent}
onClick={handleFix}
data-testid="git-fix-button"
>
<IconSparkles className="h-3 w-3" />
{fixSent ? "Fix requested" : "Fix"}
</Button>
</div>
</div>
</div>
</div>
);
});
+8
View File
@@ -113,6 +113,14 @@ export type RecoveryMetadata = StatusMetadata & {
has_resume_token: boolean;
};
export type GitOperationErrorMetadata = StatusMetadata & {
git_operation_error: true;
operation: string;
error_output: string;
session_id: string;
task_id: string;
};
export type TodoMetadata = { text: string; done?: boolean } | string;
export type ContentBlock = {