WIP: rename MFE -> Edit

This commit is contained in:
Test 2024-11-20 14:51:38 -08:00
parent 554a1ac4b1
commit 0ac11c5398
16 changed files with 93 additions and 164 deletions

View file

@ -2,7 +2,6 @@ import GenerateTerminalCommand from "./cmd";
import CommitMessageCommand from "./commit";
import DraftIssueCommand from "./draftIssue";
import HttpSlashCommand from "./http";
import MultiFileEditSlashCommand from "./multifileEdit";
import OnboardSlashCommand from "./onboard";
import ReviewMessageCommand from "./review";
import ShareSlashCommand from "./share";
@ -15,5 +14,4 @@ export default [
CommitMessageCommand,
ReviewMessageCommand,
OnboardSlashCommand,
MultiFileEditSlashCommand,
];

View file

@ -1,107 +0,0 @@
import { SlashCommand } from "../..";
import { stripImages } from "../../llm/images";
const MultiFileEditSlashCommand: SlashCommand = {
name: "multifile-edit",
description: "Edit multiple files in the codebase at once",
run: async function* ({ llm, contextItems, selectedCode, input, ide }) {
// TODO: This is causing GUI builds to fail, so we're disabling it for now
// const selectedCodeStr = (
// await Promise.all(
// selectedCode.map(async (item) => {
// // Split the range string from the filename, e.g. `filename.ts (1-2) -> [filename.ts, (1-2)]`
// const [filepath, rangeStr] = item.filepath.split(" ");
// const { getFullyQualifiedPath } = await import(
// "../../../extensions/vscode/src/util/util"
// );
// const fullPath = getFullyQualifiedPath(ide as any, filepath); // any = VsCodeIde here, but importing it breaks tests
// if (!fullPath) {
// return "";
// }
// const codeStr = await ide.readRangeInFile(fullPath, item.range);
// // Include the filepath so the model can map it correctly with codeblock outputs
// return `\`\`\`${fullPath} ${rangeStr}\n${codeStr}\`\`\``;
// }),
// )
// ).join("\n");
const fileContextItemsStr = contextItems
.filter((item) => item.uri?.type === "file")
.map((item) => item.content)
.join("\n");
const filesToEditStr = fileContextItemsStr + "\n"; // + selectedCodeStr;
const additionalContextStr = contextItems
.filter((item) => item.uri?.type !== "file")
.map((item) => `${item.description}: ${item.content}`)
.join("\n");
const content = createPrompt(filesToEditStr, additionalContextStr, input);
for await (const chunk of llm.streamChat([{ role: "user", content }], new AbortController().signal)) {
yield stripImages(chunk.content);
}
},
};
function createPrompt(
filesToEditStr: string,
additionalContextStr: string,
input: string,
): string {
return `
You are an AI assistant designed to help software engineers make multi-file edits in their codebase. Your task is to generate the necessary code changes for multiple files based on the engineer's request. Follow these guidelines:
1. Start with a brief introduction of the task you're about to perform. Do not start with any other preamble, such as "Certainly!"
2. When providing instructions, if a user needs to interact with a CLI, walk them through each step
2. Perform file edits in a logical, sequential ordering
3. For each file edit, provide a brief explanation of the changes
4. If the user submits a code block that contains a filename in the language specifier, always include the filename in any code block you generate based on that file. The filename should be on the same line as the language specifier in your code block.
a. When creating new files, also inlcude the filname in the language specifier of the code block.
6. After providing all file changes, include a brief, sequential overview of the most important 3-5 edits
Remember to be concise and focus on the code changes and their impact.
Here's an example of how your response should be structured:
<example>
I'll make the following changes to implement feature X:
1. First, I'll modify file1.js to add a new function:
\`\`\`javascript /path/to/file1.js
// Entire content of file1.js or changes to be made
\`\`\`
2. Next, let's create a new test file:
\`\`\`javascript /path/to/file1.test.js
# Entire content of file2.py or changes to be made
\`\`\`
Summary:
- [Sequential overview of the most important 3-5 edits]
</example>
Now, let's make the changes based on the engineer's request:
<input>
${input}
</input>
Here are the files to base your edits on:
<files>
${filesToEditStr}
</files>
And here is any additional context the engineer has provided:
<context>
${additionalContextStr}
</context>
Please provide the multi-file edit details based on the engineer's request.
`;
}
export default MultiFileEditSlashCommand;

View file

@ -1,12 +1,12 @@
{
"name": "continue",
"version": "0.9.231",
"version": "0.9.232",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "continue",
"version": "0.9.231",
"version": "0.9.232",
"license": "Apache-2.0",
"dependencies": {
"@electron/rebuild": "^3.2.10",

View file

@ -15,7 +15,7 @@ import {
} from "../redux/slices/editModeState";
import { setShowDialog } from "../redux/slices/uiStateSlice";
import {
setIsInMultifileEdit,
setIsInEditMode,
updateApplyState,
updateCurCheckpoint,
} from "../redux/slices/stateSlice";
@ -195,7 +195,7 @@ const Layout = () => {
"focusEdit",
async (payload) => {
// TODO: Move into edit state
dispatch(setIsInMultifileEdit(true));
dispatch(setIsInEditMode(true));
dispatch(focusEdit(payload));
navigate("/edit");

View file

@ -12,7 +12,7 @@ export interface MultifileEditActionsProps {
item: ChatHistoryItem;
}
export default function MultifileEditActions({
export default function EditActions({
index,
item,
}: MultifileEditActionsProps) {

View file

@ -6,7 +6,7 @@ import { useSelector } from "react-redux";
import { RootState } from "../../redux/store";
import { ChatHistoryItem } from "core";
import FeedbackButtons from "./FeedbackButtons";
import MultifileEditActions from "./MultifileEditActions";
import EditActions from "./EditActions";
export interface ResponseActionsProps {
isTruncated: boolean;
@ -23,15 +23,15 @@ export default function ResponseActions({
isTruncated,
onDelete,
}: ResponseActionsProps) {
const isInMultifileEdit = useSelector(
(store: RootState) => store.state.isMultifileEdit,
const isInEditMode = useSelector(
(store: RootState) => store.editModeState.isInEditMode,
);
// Only render delete button if there is more than one message
const shouldRenderDelete = index !== 1;
if (isInMultifileEdit) {
return <MultifileEditActions index={index} item={item} />;
if (isInEditMode) {
return <EditActions index={index} item={item} />;
}
return (

View file

@ -31,13 +31,13 @@ export default function StepContainer(props: StepContainerProps) {
const curCheckpointIndex = useSelector(
(store: RootState) => store.state.curCheckpointIndex,
);
const isMultifileEdit = useSelector(
(store: RootState) => store.state.isMultifileEdit,
const isInEditMode = useSelector(
(store: RootState) => store.editModeState.isInEditMode,
);
const uiConfig = useUIConfig();
const shouldHideActions = active && props.isLast;
const isStepAheadOfCurCheckpoint =
isMultifileEdit && Math.floor(props.index / 2) > curCheckpointIndex;
isInEditMode && Math.floor(props.index / 2) > curCheckpointIndex;
useEffect(() => {
if (!active) {

View file

@ -65,6 +65,7 @@ import {
} from "./handleMetaKeyIssues";
import { ComboBoxItem } from "./types";
import useIsOSREnabled from "../../hooks/useIsOSREnabled";
import { setShouldAddFileForEditing } from "../../redux/slices/uiStateSlice";
const InputBoxDiv = styled.div<{ border?: string }>`
resize: none;
@ -170,6 +171,7 @@ function TipTapEditor(props: TipTapEditorProps) {
const historyLength = useSelector(
(store: RootState) => store.state.history.length,
);
const useActiveFile = useSelector(selectUseActiveFile);
const { saveSession, loadSession } = useHistory(dispatch);
@ -183,11 +185,13 @@ function TipTapEditor(props: TipTapEditorProps) {
const isOSREnabled = useIsOSREnabled();
const isMultifileEdit = useSelector(
(state: RootState) => state.state.isMultifileEdit,
const isInEditMode = useSelector(
(state: RootState) => state.editModeState.isInEditMode,
);
console.log("isMultifileEdit", isMultifileEdit);
const shouldAddFileForEditing = useSelector(
(state: RootState) => state.uiState.shouldAddFileForEditing,
);
const enterSubmenu = async (editor: Editor, providerId: string) => {
const contents = editor.getText();
@ -473,7 +477,7 @@ function TipTapEditor(props: TipTapEditorProps) {
},
})
: undefined,
isMultifileEdit
isInEditMode
? Mention.configure({
HTMLAttributes: {
class: "mention",
@ -808,6 +812,13 @@ function TipTapEditor(props: TipTapEditorProps) {
const [activeKey, setActiveKey] = useState<string | null>(null);
useEffect(() => {
if (shouldAddFileForEditing && props.isMainInput) {
insertCharacterWithWhitespace("#");
dispatch(setShouldAddFileForEditing(false));
}
}, [shouldAddFileForEditing]);
const insertCharacterWithWhitespace = useCallback(
(char: string) => {
const text = editor.getText();

View file

@ -68,11 +68,11 @@ export default function StepContainerPreToolbar(
const ideMessenger = useContext(IdeMessengerContext);
const streamIdRef = useRef<string>(uuidv4());
const wasGeneratingRef = useRef(props.isGeneratingCodeBlock);
const isMultifileEdit = useSelector(
(state: RootState) => state.state.isMultifileEdit,
const isInEditMode = useSelector(
(state: RootState) => state.editModeState.isInEditMode,
);
const active = useSelector((state: RootState) => state.state.active);
const [isExpanded, setIsExpanded] = useState(isMultifileEdit ? false : true);
const [isExpanded, setIsExpanded] = useState(isInEditMode ? false : true);
const [codeBlockContent, setCodeBlockContent] = useState("");
const isChatActive = useSelector((state: RootState) => state.state.active);
@ -135,7 +135,7 @@ export default function StepContainerPreToolbar(
useEffect(() => {
const hasCompletedGenerating =
wasGeneratingRef.current && !isGeneratingCodeBlock;
const shouldAutoApply = hasCompletedGenerating && isMultifileEdit;
const shouldAutoApply = hasCompletedGenerating && isInEditMode;
if (shouldAutoApply) {
onClickApply();

View file

@ -166,7 +166,7 @@ const StyledMarkdownPreview = memo(function StyledMarkdownPreview(
// So in this case we just put them in refs
const symbolsRef = useRef<SymbolWithRange[]>([]);
const contextItemsRef = useRef<ContextItemWithId[]>([]);
useEffect(() => {
contextItemsRef.current = contextItems || [];
}, [contextItems]);

View file

@ -8,6 +8,7 @@ import CodeToEditListItem from "./CodeToEditListItem";
import { RangeInFileWithContents } from "core/commands/util";
import { vscEditorBackground } from "../../components";
import { ToolTip } from "../../components/gui/Tooltip";
import { setShouldAddFileForEditing } from "../../redux/slices/uiStateSlice";
export default function WorkingSet() {
const dispatch = useDispatch();
@ -20,7 +21,9 @@ export default function WorkingSet() {
dispatch(removeEntryFromCodeToEdit(rif));
}
function onClickAddFileToCodeToEdit() {}
function onClickAddFileToCodeToEdit() {
dispatch(setShouldAddFileForEditing(true));
}
function onClickFilename(rif: RangeInFileWithContents) {
const { filepath, range } = editModeState.codeToEdit.find(
@ -44,7 +47,7 @@ export default function WorkingSet() {
className="mx-1 flex flex-col rounded-t-lg px-1 pb-1"
style={{ backgroundColor: vscEditorBackground }}
>
<div className="flex items-center justify-between gap-1.5 border-0 border-b border-solid border-zinc-600 px-1 py-1.5 text-xs text-zinc-400">
<div className="flex items-center justify-between gap-1.5 border-0 border-b border-solid border-neutral-500 px-1 py-1.5 text-xs text-neutral-500">
<span>Code to edit</span>
<span
@ -58,7 +61,7 @@ export default function WorkingSet() {
<div className="scrollbar-hide max-h-[25vh] overflow-y-auto">
{hasCodeToEdit ? (
<ul className="my-1.5 list-outside list-none space-y-1 pl-0">
<ul className="my-1.5 list-outside list-none space-y-1.5 pl-0">
{codeToEditItems}
</ul>
) : (

View file

@ -3,12 +3,12 @@ import FileIcon from "../../components/FileIcon";
import {
ChevronDownIcon,
ChevronRightIcon,
ChevronUpIcon,
XMarkIcon,
} from "@heroicons/react/24/outline";
import { useState } from "react";
import StyledMarkdownPreview from "../../components/markdown/StyledMarkdownPreview";
import { getMarkdownLanguageTagForFile } from "core/util";
import styled from "styled-components";
export interface CodeToEditListItemProps {
rif: RangeInFileWithContents;
@ -16,6 +16,19 @@ export interface CodeToEditListItemProps {
onClickFilename: (rif: RangeInFileWithContents) => void;
}
// Easiest method to overwrite the top level styling of the markdown preview
const NoPaddingWrapper = styled.div`
> * {
margin: 0 !important;
padding: 0 !important;
}
pre {
margin: 0 !important;
padding: 0 !important;
}
`;
export default function CodeToEditListItem({
rif,
onDelete,
@ -36,12 +49,13 @@ export default function CodeToEditListItem({
return (
<li
className={`flex cursor-pointer flex-col rounded p-1 transition-colors hover:bg-white/10 ${showCodeSnippet && "bg-white/10"}`}
className="flex cursor-pointer flex-col rounded border border-solid border-neutral-500 shadow-sm transition-transform"
onClick={() => setShowCodeSnippet((showCodeSnippet) => !showCodeSnippet)}
>
{" "}
<div className="flex justify-between">
<div className="flex gap-0.5">
<div
className={`flex justify-between px-2 py-1 ${showCodeSnippet ? "border-x-0 border-b border-t-0 border-solid border-neutral-500" : ""}`}
>
<div className="flex items-center gap-0.5">
{showCodeSnippet ? (
<ChevronDownIcon
onClick={(e) => {
@ -61,7 +75,7 @@ export default function CodeToEditListItem({
)}
<FileIcon filename={rif.filepath} height={"18px"} width={"18px"} />
<span
className="hover:underline"
className="text-xs hover:underline"
onClick={(e) => {
e.stopPropagation();
onClickFilename(rif);
@ -81,8 +95,10 @@ export default function CodeToEditListItem({
</div>
</div>
{showCodeSnippet && (
<div className="max-h-[15vh] overflow-y-auto">
<StyledMarkdownPreview source={source} />
<div className="max-h-[15vh] overflow-y-auto px-1 py-2">
<NoPaddingWrapper>
<StyledMarkdownPreview source={source} />
</NoPaddingWrapper>
</div>
)}
</li>

View file

@ -58,7 +58,11 @@ export default function Edit() {
(store: RootState) => store.state.config.contextProviders,
);
const state = useSelector((state: RootState) => state.state);
const history = useSelector((state: RootState) => state.state.history);
const applyStates = useSelector(
(state: RootState) => state.state.applyStates,
);
const applyState = useSelector(
(store: RootState) =>
@ -83,11 +87,7 @@ export default function Edit() {
}
}, [applyState, editModeState.editStatus]);
const applyStates = useSelector(
(state: RootState) => state.state.applyStates,
);
const active = useSelector((state: RootState) => state.state.active);
// const active = useSelector((state: RootState) => state.state.active);
const pendingApplyStates = applyStates.filter(
(state) => state.status === "done",
@ -98,8 +98,8 @@ export default function Edit() {
editModeState.editStatus === "accepting";
const toolbarOptions = {
hideAddContext: true,
hideImageUpload: true,
hideAddContext: false,
hideImageUpload: false,
hideUseCodebase: true,
hideSelectModel: false,
enterText: isStreaming ? "Retry" : "Edit",
@ -124,6 +124,7 @@ export default function Edit() {
},
ideMessenger,
[],
dispatch,
);
const prompt = [
@ -166,11 +167,11 @@ export default function Edit() {
const isLastUserInput = useCallback(
(index: number): boolean => {
return !state.history
return !history
.slice(index + 1)
.some((entry) => entry.message.role === "user");
},
[state.history],
[history],
);
return (
@ -181,7 +182,7 @@ export default function Edit() {
<TipTapEditor
isMainInput
toolbarOptions={toolbarOptions}
placeholder="Describe how to modify code - use '#' to add files to 'Code to edit'"
placeholder="Describe how to modify the code - use '#' to add files to 'Code to edit'"
availableContextProviders={filteredContextProviders}
historyKey="edit"
availableSlashCommands={[]}
@ -189,9 +190,9 @@ export default function Edit() {
/>
</div>
{!isSingleFileEdit && state.history.length > 1 && (
{!isSingleFileEdit && history.length > 1 && (
<div>
{state.history.slice(1).map((item, index: number) => (
{history.slice(1).map((item, index: number) => (
<div>
{item.message.role === "user" ? (
<ContinueInputBox
@ -211,7 +212,7 @@ export default function Edit() {
) : (
<StepContainer
index={index}
isLast={index === state.history.length - 1}
isLast={index === history.length - 1}
item={item}
/>
)}

View file

@ -8,12 +8,14 @@ interface EditModeState {
previousInputs: MessageContent[];
fileAfterEdit?: string;
codeToEdit: RangeInFileWithContents[];
isInEditMode: boolean;
}
const initialState: EditModeState = {
editStatus: "not-started",
previousInputs: [],
codeToEdit: [],
isInEditMode: false,
};
export const editModeStateSlice = createSlice({
@ -98,6 +100,9 @@ export const editModeStateSlice = createSlice({
state.editStatus = "done";
state.previousInputs = [];
},
setIsInEditMode: (state, { payload }: PayloadAction<boolean>) => {
state.isInEditMode = payload;
},
},
});
@ -110,5 +115,6 @@ export const {
removeEntryFromCodeToEdit,
focusEdit,
clearCodeToEdit,
setIsInEditMode,
} = editModeStateSlice.actions;
export default editModeStateSlice.reducer;

View file

@ -46,7 +46,6 @@ type State = {
statuses: Record<string, IndexingStatus>;
};
streamAborter: AbortController;
isMultifileEdit: boolean;
};
const initialState: State = {
@ -78,7 +77,6 @@ const initialState: State = {
defaultModelTitle: "GPT-4",
selectedProfileId: "local",
checkpoints: [],
isMultifileEdit: false,
curCheckpointIndex: 0,
nextCodeBlockToApplyIndex: 0,
applyStates: [],
@ -308,7 +306,6 @@ export const stateSlice = createSlice({
state.active = false;
state.context.isGathering = false;
state.isMultifileEdit = false;
state.symbols = {};
if (payload) {
state.history = payload.history as any;
@ -374,10 +371,6 @@ export const stateSlice = createSlice({
selectedProfileId: payload,
};
},
setIsInMultifileEdit: (state, { payload }: PayloadAction<boolean>) => {
state.isMultifileEdit = payload;
},
setCurCheckpointIndex: (state, { payload }: PayloadAction<number>) => {
state.curCheckpointIndex = payload;
},
@ -472,7 +465,6 @@ export const {
setSelectedProfileId,
deleteMessage,
setIsGatheringContext,
setIsInMultifileEdit,
updateCurCheckpoint,
setCurCheckpointIndex,
resetNextCodeBlockToApplyIndex,

View file

@ -9,6 +9,7 @@ type UiState = {
dialogMessage: string | JSX.Element | undefined;
dialogEntryOn: boolean;
onboardingCard: OnboardingCardState;
shouldAddFileForEditing: boolean;
};
export const uiStateSlice = createSlice({
@ -18,6 +19,7 @@ export const uiStateSlice = createSlice({
dialogMessage: "",
dialogEntryOn: false,
onboardingCard: defaultOnboardingCardState,
shouldAddFileForEditing: false,
} as UiState,
reducers: {
setOnboardingCard: (
@ -41,6 +43,12 @@ export const uiStateSlice = createSlice({
setShowDialog: (state, action: PayloadAction<UiState["showDialog"]>) => {
state.showDialog = action.payload;
},
setShouldAddFileForEditing: (
state,
action: PayloadAction<UiState["shouldAddFileForEditing"]>,
) => {
state.shouldAddFileForEditing = action.payload;
},
},
});
@ -49,6 +57,7 @@ export const {
setDialogMessage,
setDialogEntryOn,
setShowDialog,
setShouldAddFileForEditing,
} = uiStateSlice.actions;
export default uiStateSlice.reducer;