Handle rename & deletes in proposal

This commit is contained in:
Will Chen
2025-04-21 16:19:40 -07:00
parent b07defc9b8
commit 7041525c20
3 changed files with 59 additions and 18 deletions

View File

@@ -10,6 +10,8 @@ import {
Check,
Loader2,
Package,
FileX,
SendToBack,
} from "lucide-react";
import type React from "react";
import { useCallback, useEffect, useRef, useState } from "react";
@@ -32,6 +34,7 @@ import {
Proposal,
SuggestedAction,
ProposalResult,
FileChange,
} from "@/lib/schemas";
import type { Message } from "@/ipc/ipc_types";
import { isPreviewOpenAtom } from "@/atoms/viewAtoms";
@@ -461,10 +464,7 @@ function ChatInputActions({
<ul className="space-y-1">
{proposal.filesChanged.map((file, index) => (
<li key={index} className="flex items-center space-x-2">
<FileText
size={16}
className="text-muted-foreground flex-shrink-0"
/>
{getIconForFileChange(file)}
<span title={file.path} className="truncate cursor-default">
{file.name}
</span>
@@ -481,3 +481,20 @@ function ChatInputActions({
</div>
);
}
function getIconForFileChange(file: FileChange) {
switch (file.type) {
case "write":
return (
<FileText size={16} className="text-muted-foreground flex-shrink-0" />
);
case "rename":
return (
<SendToBack size={16} className="text-muted-foreground flex-shrink-0" />
);
case "delete":
return (
<FileX size={16} className="text-muted-foreground flex-shrink-0" />
);
}
}

View File

@@ -1,5 +1,9 @@
import { ipcMain, type IpcMainInvokeEvent } from "electron";
import type { CodeProposal, ProposalResult } from "@/lib/schemas";
import type {
CodeProposal,
FileChange,
ProposalResult,
} from "../../lib/schemas";
import { db } from "../../db";
import { messages } from "../../db/schema";
import { desc, eq, and, Update } from "drizzle-orm";
@@ -8,6 +12,8 @@ import path from "node:path"; // Import path for basename
import {
getDyadAddDependencyTags,
getDyadChatSummaryTag,
getDyadDeleteTags,
getDyadRenameTags,
getDyadWriteTags,
processFullResponseActions,
} from "../processors/response_processor";
@@ -65,34 +71,51 @@ const getProposalHandler = async (
);
const messageContent = latestAssistantMessage.content;
// Parse tags directly from message content
const proposalTitle = getDyadChatSummaryTag(messageContent);
const proposalFiles = getDyadWriteTags(messageContent); // Gets { path: string, content: string }[]
const proposalWriteFiles = getDyadWriteTags(messageContent);
const proposalRenameFiles = getDyadRenameTags(messageContent);
const proposalDeleteFiles = getDyadDeleteTags(messageContent);
const packagesAdded = getDyadAddDependencyTags(messageContent);
const filesChanged = [
...proposalWriteFiles.map((tag) => ({
name: path.basename(tag.path),
path: tag.path,
summary: tag.description ?? "(no change summary found)", // Generic summary
type: "write" as const,
})),
...proposalRenameFiles.map((tag) => ({
name: path.basename(tag.to),
path: tag.to,
summary: `Rename from ${tag.from} to ${tag.to}`,
type: "rename" as const,
})),
...proposalDeleteFiles.map((tag) => ({
name: path.basename(tag),
path: tag,
summary: `Delete file`,
type: "delete" as const,
})),
];
// Check if we have enough information to create a proposal
if (
proposalTitle ||
proposalFiles.length > 0 ||
packagesAdded.length > 0
) {
if (filesChanged.length > 0 || packagesAdded.length > 0) {
const proposal: CodeProposal = {
type: "code-proposal",
// Use parsed title or a default title if summary tag is missing but write tags exist
title: proposalTitle ?? "Proposed File Changes",
securityRisks: [], // Keep empty
filesChanged: proposalFiles.map((tag) => ({
name: path.basename(tag.path),
path: tag.path,
summary: tag.description ?? "(no change summary found)", // Generic summary
})),
filesChanged,
packagesAdded,
};
logger.log(
"Generated code proposal. title=",
proposal.title,
"files=",
proposal.filesChanged.length
proposal.filesChanged.length,
"packages=",
proposal.packagesAdded.length
);
return { proposal, chatId, messageId }; // Return proposal and messageId
} else {

View File

@@ -111,6 +111,7 @@ export interface FileChange {
name: string;
path: string;
summary: string;
type: "write" | "rename" | "delete";
}
export interface CodeProposal {