Show warning if there's uncommitted changes (#92)
This commit is contained in:
@@ -486,6 +486,7 @@ This conversation includes one or more image attachments. When the user uploads
|
||||
event.sender.send("chat:response:end", {
|
||||
chatId: req.chatId,
|
||||
updatedFiles: status.updatedFiles ?? false,
|
||||
uncommittedFiles: status.uncommittedFiles,
|
||||
} satisfies ChatResponseEnd);
|
||||
} else {
|
||||
event.sender.send("chat:response:end", {
|
||||
|
||||
@@ -331,7 +331,11 @@ const getProposalHandler = async (
|
||||
const approveProposalHandler = async (
|
||||
_event: IpcMainInvokeEvent,
|
||||
{ chatId, messageId }: { chatId: number; messageId: number }
|
||||
): Promise<{ success: boolean; error?: string }> => {
|
||||
): Promise<{
|
||||
success: boolean;
|
||||
error?: string;
|
||||
uncommittedFiles?: string[];
|
||||
}> => {
|
||||
logger.log(
|
||||
`IPC: approve-proposal called for chatId: ${chatId}, messageId: ${messageId}`
|
||||
);
|
||||
@@ -380,7 +384,7 @@ const approveProposalHandler = async (
|
||||
};
|
||||
}
|
||||
|
||||
return { success: true };
|
||||
return { success: true, uncommittedFiles: processResult.uncommittedFiles };
|
||||
} catch (error) {
|
||||
logger.error(`Error approving proposal for messageId ${messageId}:`, error);
|
||||
return {
|
||||
|
||||
@@ -111,10 +111,10 @@ export class IpcClient {
|
||||
});
|
||||
|
||||
this.ipcRenderer.on("chat:response:end", (payload) => {
|
||||
const { chatId, updatedFiles } = payload as unknown as ChatResponseEnd;
|
||||
const { chatId } = payload as unknown as ChatResponseEnd;
|
||||
const callbacks = this.chatStreams.get(chatId);
|
||||
if (callbacks) {
|
||||
callbacks.onEnd({ chatId, updatedFiles });
|
||||
callbacks.onEnd(payload as unknown as ChatResponseEnd);
|
||||
console.debug("chat:response:end");
|
||||
this.chatStreams.delete(chatId);
|
||||
} else {
|
||||
@@ -734,13 +734,21 @@ export class IpcClient {
|
||||
}: {
|
||||
chatId: number;
|
||||
messageId: number;
|
||||
}): Promise<{ success: boolean; error?: string }> {
|
||||
}): Promise<{
|
||||
success: boolean;
|
||||
error?: string;
|
||||
uncommittedFiles?: string[];
|
||||
}> {
|
||||
try {
|
||||
const result = await this.ipcRenderer.invoke("approve-proposal", {
|
||||
chatId,
|
||||
messageId,
|
||||
});
|
||||
return result as { success: boolean; error?: string };
|
||||
return result as {
|
||||
success: boolean;
|
||||
error?: string;
|
||||
uncommittedFiles?: string[];
|
||||
};
|
||||
} catch (error) {
|
||||
showError(error);
|
||||
return { success: false, error: (error as Error).message };
|
||||
|
||||
@@ -24,6 +24,7 @@ export interface ChatStreamParams {
|
||||
export interface ChatResponseEnd {
|
||||
chatId: number;
|
||||
updatedFiles: boolean;
|
||||
uncommittedFiles?: string[];
|
||||
}
|
||||
|
||||
export interface CreateAppParams {
|
||||
|
||||
@@ -175,7 +175,11 @@ export async function processFullResponseActions(
|
||||
chatSummary,
|
||||
messageId,
|
||||
}: { chatSummary: string | undefined; messageId: number }
|
||||
): Promise<{ updatedFiles?: boolean; error?: string }> {
|
||||
): Promise<{
|
||||
updatedFiles?: boolean;
|
||||
error?: string;
|
||||
uncommittedFiles?: string[];
|
||||
}> {
|
||||
logger.log("processFullResponseActions for chatId", chatId);
|
||||
// Get the app associated with the chat
|
||||
const chatWithApp = await db.query.chats.findFirst({
|
||||
@@ -453,6 +457,13 @@ export async function processFullResponseActions(
|
||||
})
|
||||
.where(eq(messages.id, messageId));
|
||||
}
|
||||
|
||||
// Check for any uncommitted changes after the commit
|
||||
const statusMatrix = await git.statusMatrix({ fs, dir: appPath });
|
||||
const uncommittedFiles = statusMatrix
|
||||
.filter((row) => row[1] !== 1 || row[2] !== 1 || row[3] !== 1)
|
||||
.map((row) => row[0]); // Get just the file paths
|
||||
|
||||
logger.log("mark as approved: hasChanges", hasChanges);
|
||||
// Update the message to approved
|
||||
await db
|
||||
@@ -461,7 +472,12 @@ export async function processFullResponseActions(
|
||||
approvalState: "approved",
|
||||
})
|
||||
.where(eq(messages.id, messageId));
|
||||
return { updatedFiles: hasChanges };
|
||||
|
||||
return {
|
||||
updatedFiles: hasChanges,
|
||||
uncommittedFiles:
|
||||
uncommittedFiles.length > 0 ? uncommittedFiles : undefined,
|
||||
};
|
||||
} catch (error: unknown) {
|
||||
logger.error("Error processing files:", error);
|
||||
return { error: (error as any).toString() };
|
||||
|
||||
Reference in New Issue
Block a user