Skip to content

Commit

Permalink
Fix indexer styles. Tweak code writer prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
RussellCanfield committed Oct 18, 2024
1 parent e7a5361 commit 96abf94
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 46 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "wing-man",
"displayName": "Wingman-AI",
"description": "Wingman - AI powered assistant to help you write your best code, we won't leave you hanging.",
"version": "0.7.24",
"version": "0.7.25",
"publisher": "WingMan",
"license": "MIT",
"workspaces": [
Expand Down Expand Up @@ -216,6 +216,6 @@
"node-fetch": "3.3.2",
"rimraf": "^6.0.1",
"tar": "7.4.3",
"typescript": "^5.6.2"
"typescript": "^5.6.3"
}
}
1 change: 0 additions & 1 deletion shared/src/types/Message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export interface FileMetadata {
analysis?: string;
changes?: string[];
review?: string;
hasChanged?: boolean;
}

export interface CodeContextDetails {
Expand Down
66 changes: 41 additions & 25 deletions src/composer/tools/code-writer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { NoFilesChangedError } from "../errors";
import { ChatOllama } from "@langchain/ollama";
import { AIMessage } from "@langchain/core/messages";
import { FILE_SEPARATOR } from "./common";
import { FileMetadata } from "@shared/types/Message";

export type CodeWriterSchema = z.infer<typeof codeWriterSchema>;

Expand Down Expand Up @@ -39,19 +38,13 @@ export const codeWriterSchema = z.object({
.array(z.string())
.describe("A list of changes made to the file")
.optional(),
hasChanged: z
.boolean()
.describe(
"Whether or not the file has been changed. If false, the file will be skipped"
)
.optional(),
})
.describe("The file in scope that you have modified or created"),
});

const ollamaWriterPrompt = `Analyze this text and output JSON.
Analyze and implement project enhancements for a single file based on the user's objective.
You are an expert software engineer tasked with providing a comprehensive solution that includes both manual steps and code changes.
Implement project enhancements for a single file based on the user's objective.
Focus solely on the file in scope, while considering the context of other files for integration purposes.
Output Structure:
Expand All @@ -70,15 +63,14 @@ Key Instructions:
9. Ensure output adheres to the provided JSON schema.
Step Writing Guidelines:
1. Focus on user-centric, actionable steps not covered in code modifications - these would be manual steps the user still needs to take.
1. Focus on user-centric, actionable steps not covered in code modifications - these would be manual steps the user still needs to take such as installing dependencies.
2. Explicitly mention file names when relevant.
3. Categorize terminal commands in the "command" field.
4. Ensure clarity, conciseness, and no overlap with file changes, for instance if you imported a file in a code change the user does not need to take manual action.
5. Omit steps for testing or code verification unless explicitly required.
6. Do not include new files created in the steps, these are created for the user automatically.
7. Omit steps for verifying code, or ensuring code related steps.
8. If there are no manual steps, simply return an empty array.
9. Do not return steps such as: "No manual steps are required for this change."
7. If there are no manual steps, simply return an empty array.
8. Do not return steps such as: "No manual steps are required for this change."
Code Writing Guidelines:
1. Use GitHub-flavored markdown for ALL code output.
Expand Down Expand Up @@ -121,6 +113,8 @@ File Handling:
------
{{newsteps}}
{{modified}}
{{otherfiles}}
Expand All @@ -143,18 +137,16 @@ You must ALWAYS Output in JSON format using the following template:
"command": "string (optional)"
}
],
"files": [
{
"file": "string",
"markdown": "string",
"changes": ["string"]
}
]
"file": {
"file": "string",
"markdown": "string",
"changes": ["string"]
}
}`;

const baseWriterPrompt = `Analyze this text and output JSON.
Analyze and implement project enhancements for a single file based on the user's objective.
You are an expert software engineer tasked with providing a comprehensive solution that includes both manual steps and code changes.
Implement project enhancements for a single file based on the user's objective.
Focus solely on the file in scope, while considering the context of other files for integration purposes.
Output Structure:
Expand Down Expand Up @@ -222,6 +214,8 @@ File Handling:
------
{{newsteps}}
{{modified}}
{{otherfiles}}
Expand All @@ -237,7 +231,21 @@ File in scope:
Implement required changes for the file in scope to meet the objective.
Use GitHub-flavored markdown for code output and follow the provided JSON schema.
Ensure the "files" property is an array of objects, not a string.
PRODUCE VALID JSON TO AVOID PENALTIES.`;
You must ALWAYS Output in JSON format using the following template:
{
"steps": [
{
"description": "string",
"command": "string (optional)"
}
],
"file": {
"file": "string",
"markdown": "string",
"changes": ["string"]
}
}`;

const buildPrompt = (basePrompt: string, rulePack?: string) => {
const rulePromptAddition = !rulePack
Expand Down Expand Up @@ -317,6 +325,17 @@ ${state.review?.comments?.join("\n")}
objective,
steps: planningSteps,
review: reviewComments,
newsteps:
steps.length === 0
? ""
: `Context: Previously Created Manual Steps
The following list contains manual steps already created based on previously modified or created files.
Use this information as context for subsequent step process. Do not suggest these again.
${steps.map((s) => `${s.description}\n${s.command}`).join("\n\n")}
------`,
modified:
files.length === 0
? ""
Expand Down Expand Up @@ -375,9 +394,7 @@ ${f.code}`
}

if (files.length === 0) {
throw new NoFilesChangedError(
'No files have been changed. Please ensure you have set "hasChanged" to true for relevant files.'
);
throw new NoFilesChangedError("No files have been changed.");
}

return {
Expand All @@ -388,7 +405,6 @@ ${f.code}`
file: f.file,
code: f.markdown,
changes: f.changes,
hasChanged: f.hasChanged,
};
}),
},
Expand Down
4 changes: 1 addition & 3 deletions src/composer/tools/planner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,7 @@ export class CodePlanner {

const docs = await this.filterRelevantDocs(finalDocs, plan);
if (docs.length === 0) {
throw new NoFilesChangedError(
'No files have been changed. Please ensure you have set "hasChanged" to true for relevant files.'
);
throw new NoFilesChangedError("No files have been changed.");
}

return {
Expand Down
6 changes: 3 additions & 3 deletions views-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
},
"devDependencies": {
"@types/react-syntax-highlighter": "15.5.13",
"@rsbuild/core": "1.0.5",
"@rsbuild/plugin-react": "1.0.2",
"@rsbuild/core": "1.0.15",
"@rsbuild/plugin-react": "1.0.5",
"@types/react": "^18.3.5",
"@types/react-dom": "^18.3.0",
"@types/vscode": "1.93.0",
"@types/vscode-webview": "1.57.5",
"tailwindcss": "3.4.11"
"tailwindcss": "3.4.14"
}
}
2 changes: 1 addition & 1 deletion views-ui/src/Chat/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const App = () => {
}, [view]);

return (
<main className="h-full flex flex-col flex-auto">
<main className="h-full flex flex-col overflow-hidden text-base">
<Toolbar />
{activeComponent}
</main>
Expand Down
23 changes: 13 additions & 10 deletions views-ui/src/Chat/features/Indexer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,8 @@ export default function Indexer() {
};

return (
<div className="flex flex-col h-full">
<div className="space-y-4 mt-4">
{/* Other sections remain unchanged */}
<div className="flex flex-col h-full gap-8 overflow-hidden">
<div className="space-y-4 flex-shrink-0">
<p className="text-lg font-bold">
Status:{" "}
{index.exists
Expand Down Expand Up @@ -144,13 +143,17 @@ export default function Indexer() {
)}
</div>
{index.exists && !index.processing && (
<div className="mt-4 overflow-y-auto flex-grow">
<p className="text-lg font-bold">Indexed Files:</p>
<ul className="space-y-1">
{index.files.map((f, index) => (
<li key={index}>{f}</li>
))}
</ul>
<div className="flex-1 overflow-hidden flex flex-col">
<p className="text-lg font-bold flex-shrink-0">
Indexed Files:
</p>
<div className="flex-1 overflow-y-auto">
<ul>
{index.files.map((f, index) => (
<li key={index}>{f}</li>
))}
</ul>
</div>
</div>
)}
</div>
Expand Down
2 changes: 1 addition & 1 deletion views-ui/src/Diff/DiffView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export default function DiffView() {
oldValue={diff.original}
newValue={diff.diff}
styles={newStyles}
compareMethod={DiffMethod.WORDS_WITH_SPACE}
compareMethod={DiffMethod.WORDS}
splitView={false}
useDarkTheme={isDarkTheme}
showDiffOnly={false}
Expand Down

0 comments on commit 96abf94

Please sign in to comment.