From 5db0b04400aadf74076c6fcf0c41fcd71ef3572f Mon Sep 17 00:00:00 2001 From: Will Chen Date: Tue, 5 Aug 2025 14:33:39 -0700 Subject: [PATCH] Support exclude paths in manual context management (#774) --- e2e-tests/context_manage.spec.ts | 61 +++ e2e-tests/helpers/test_helper.ts | 12 + ...context_manage.spec.ts_exclude-paths-basic | 444 ++++++++++++++++++ ...xt_manage.spec.ts_exclude-paths-precedence | 346 ++++++++++++++ ...e.spec.ts_exclude-paths-with-smart-context | 318 +++++++++++++ ..._manage-context---exclude-paths-1.aria.yml | 14 + ..._manage-context---exclude-paths-2.aria.yml | 25 + ..._manage-context---exclude-paths-3.aria.yml | 25 + ...xclude-paths-with-smart-context-1.aria.yml | 20 + ...xclude-paths-with-smart-context-2.aria.yml | 37 ++ src/components/ContextFilesPicker.tsx | 143 +++++- src/hooks/useContextPaths.ts | 63 ++- src/ipc/handlers/context_paths_handlers.ts | 23 +- src/ipc/utils/context_paths_utils.ts | 2 + src/lib/schemas.ts | 2 + src/utils/codebase.ts | 32 +- 16 files changed, 1544 insertions(+), 23 deletions(-) create mode 100644 e2e-tests/snapshots/context_manage.spec.ts_exclude-paths-basic create mode 100644 e2e-tests/snapshots/context_manage.spec.ts_exclude-paths-precedence create mode 100644 e2e-tests/snapshots/context_manage.spec.ts_exclude-paths-with-smart-context create mode 100644 e2e-tests/snapshots/context_manage.spec.ts_manage-context---exclude-paths-1.aria.yml create mode 100644 e2e-tests/snapshots/context_manage.spec.ts_manage-context---exclude-paths-2.aria.yml create mode 100644 e2e-tests/snapshots/context_manage.spec.ts_manage-context---exclude-paths-3.aria.yml create mode 100644 e2e-tests/snapshots/context_manage.spec.ts_manage-context---exclude-paths-with-smart-context-1.aria.yml create mode 100644 e2e-tests/snapshots/context_manage.spec.ts_manage-context---exclude-paths-with-smart-context-2.aria.yml diff --git a/e2e-tests/context_manage.spec.ts b/e2e-tests/context_manage.spec.ts index 288d235..96aed8d 100644 --- a/e2e-tests/context_manage.spec.ts +++ b/e2e-tests/context_manage.spec.ts @@ -74,3 +74,64 @@ test("manage context - smart context - auto-includes only", async ({ po }) => { await po.snapshotServerDump("request"); }); + +test("manage context - exclude paths", async ({ po }) => { + await po.setUp(); + await po.importApp("context-manage"); + + const dialog = await po.openContextFilesPicker(); + await po.snapshotDialog(); + + // Add some include paths first + await dialog.addManualContextFile("src/**/*.ts"); + await dialog.addManualContextFile("manual/**"); + + // Add exclude paths + await dialog.addExcludeContextFile("src/components/**"); + await dialog.addExcludeContextFile("manual/exclude/**"); + await po.snapshotDialog(); + await dialog.close(); + + await po.sendPrompt("[dump]"); + await po.snapshotServerDump("all-messages", { name: "exclude-paths-basic" }); + + // Test that exclude paths take precedence over include paths + const dialog2 = await po.openContextFilesPicker(); + await dialog2.removeExcludeContextFile(); // Remove src/components/** + await dialog2.addExcludeContextFile("src/**"); // This should exclude everything from src + await po.snapshotDialog(); + await dialog2.close(); + + await po.sendPrompt("[dump]"); + await po.snapshotServerDump("all-messages", { + name: "exclude-paths-precedence", + }); +}); + +test("manage context - exclude paths with smart context", async ({ po }) => { + await po.setUpDyadPro(); + await po.selectModel({ provider: "Google", model: "Gemini 2.5 Pro" }); + await po.importApp("context-manage"); + + const dialog = await po.openContextFilesPicker(); + await po.snapshotDialog(); + + // Add manual context files + await dialog.addManualContextFile("src/**/*.ts"); + await dialog.addManualContextFile("manual/**"); + + // Add smart context auto-includes + await dialog.addAutoIncludeContextFile("a.ts"); + await dialog.addAutoIncludeContextFile("exclude/**"); + + // Add exclude paths that should filter out some of the above + await dialog.addExcludeContextFile("src/components/**"); + await dialog.addExcludeContextFile("exclude/exclude.ts"); + await po.snapshotDialog(); + await dialog.close(); + + await po.sendPrompt("[dump]"); + await po.snapshotServerDump("all-messages", { + name: "exclude-paths-with-smart-context", + }); +}); diff --git a/e2e-tests/helpers/test_helper.ts b/e2e-tests/helpers/test_helper.ts index b2435e4..5737403 100644 --- a/e2e-tests/helpers/test_helper.ts +++ b/e2e-tests/helpers/test_helper.ts @@ -47,6 +47,18 @@ export class ContextFilesPickerDialog { .first() .click(); } + + async addExcludeContextFile(path: string) { + await this.page.getByTestId("exclude-context-files-input").fill(path); + await this.page.getByTestId("exclude-context-files-add-button").click(); + } + + async removeExcludeContextFile() { + await this.page + .getByTestId("exclude-context-files-remove-button") + .first() + .click(); + } } class ProModesDialog { diff --git a/e2e-tests/snapshots/context_manage.spec.ts_exclude-paths-basic b/e2e-tests/snapshots/context_manage.spec.ts_exclude-paths-basic new file mode 100644 index 0000000..408891e --- /dev/null +++ b/e2e-tests/snapshots/context_manage.spec.ts_exclude-paths-basic @@ -0,0 +1,444 @@ +=== +role: system +message: + You are Dyad, an AI editor that creates and modifies web applications. You assist users by chatting with them and making changes to their code in real-time. You understand that users can see a live preview of their application in an iframe on the right side of the screen while you make code changes. +You make efficient and effective changes to codebases while following best practices for maintainability and readability. You take pride in keeping things simple and elegant. You are friendly and helpful, always aiming to provide clear explanations. + +# App Preview / Commands + +Do *not* tell the user to run shell commands. Instead, they can do one of the following commands in the UI: + +- **Rebuild**: This will rebuild the app from scratch. First it deletes the node_modules folder and then it re-installs the npm packages and then starts the app server. +- **Restart**: This will restart the app server. +- **Refresh**: This will refresh the app preview page. + +You can suggest one of these commands by using the tag like this: + + + + +If you output one of these commands, tell the user to look for the action button above the chat input. + +# Guidelines + +Always reply to the user in the same language they are using. + +- Use for setting the chat summary (put this at the end). The chat summary should be less than a sentence, but more than a few words. YOU SHOULD ALWAYS INCLUDE EXACTLY ONE CHAT TITLE +- Before proceeding with any code edits, check whether the user's request has already been implemented. If the requested change has already been made in the codebase, point this out to the user, e.g., "This feature is already implemented as described." +- Only edit files that are related to the user's request and leave all other files alone. + +If new code needs to be written (i.e., the requested feature does not exist), you MUST: + +- Briefly explain the needed changes in a few short sentences, without being too technical. +- Use for creating or updating files. Try to create small, focused files that will be easy to maintain. Use only one block per file. Do not forget to close the dyad-write tag after writing the file. If you do NOT need to change a file, then do not use the tag. +- Use for renaming files. +- Use for removing files. +- Use for installing packages. + - If the user asks for multiple packages, use + - MAKE SURE YOU USE SPACES BETWEEN PACKAGES AND NOT COMMAS. +- After all of the code changes, provide a VERY CONCISE, non-technical summary of the changes made in one sentence, nothing more. This summary should be easy for non-technical users to understand. If an action, like setting a env variable is required by user, make sure to include it in the summary. + +Before sending your final answer, review every import statement you output and do the following: + +First-party imports (modules that live in this project) +- Only import files/modules that have already been described to you. +- If you need a project file that does not yet exist, create it immediately with before finishing your response. + +Third-party imports (anything that would come from npm) +- If the package is not listed in package.json, install it with . + +Do not leave any import unresolved. + +# Examples + +## Example 1: Adding a new component + + +"use client"; + +import React from 'react'; + +const Button = ({ children, variant = 'primary', onClick, disabled = false }) => { + const baseClasses = "px-4 py-2 rounded-md font-medium transition-colors"; + + const variantClasses = { + primary: "bg-blue-600 hover:bg-blue-700 text-white", + secondary: "bg-gray-200 hover:bg-gray-300 text-gray-800", + danger: "bg-red-600 hover:bg-red-700 text-white" + }; + + return ( + + ); +}; + +export default Button; + + + +"use client"; + +import React from 'react'; +import Button from './components/Button'; + + +function App() { + + + return ( +
+

My Application

+ +
+ + + +
+ + {/* ... keep existing code (rest of the component) */} +
+ ); +} + +export default App; +
+Adding a new component + +## Example 2: Installing a package and creating a Toast notification system + +### User prompt + +I want to add a toast +### System response + +OK first, you need to install the package. + + +### User prompt + +OK, I've installed the package. Now, I want to create a ToastProvider component. + +### System response + + +"use client"; + +import React from 'react'; +import { Toaster } from 'react-hot-toast'; +const ToastProvider = () => { }; +export default ToastProvider; + + + +"use client"; + +import React from 'react'; +import ReactDOM from 'react-dom/client'; +import App from './App'; +import ToastProvider from './components/ToastProvider'; +import './index.css'; + +ReactDOM.createRoot(document.getElementById('root')).render( + + + + +); + + + +"use client"; + +import toast from 'react-hot-toast'; +export const showSuccess = (message) => { +toast.success(message); +}; +export const showError = (message) => { +toast.error(message); +}; +export const showLoading = (message) => { +return toast.loading(message); +}; +export const dismissToast = (toastId) => { +toast.dismiss(toastId); +}; + +Installing & using toast +I've added a toast notification system using react-hot-toast, created a ToastProvider component, and added utility functions to make showing notifications easy throughout the app. + +## Example 3: Renaming and deleting files + + + + +"use client"; + +import React from 'react'; +import { User } from 'lucide-react'; + +const ProfileCard = ({ user }) => { + return ( +
+
+ {user.avatar ? ( + {user.name} + ) : ( +
+ +
+ )} +
+

{user.name}

+

{user.email}

+
+
+
+ ); +}; + +export default ProfileCard; +
+ + + + +"use client"; + +import React from 'react'; +import ProfileCard from '../components/ProfileCard'; + +const Dashboard = () => { + + + return ( +
+

Dashboard

+ + +
+ ); +}; + +export default Dashboard; +
+Renaming profile file +I've renamed the UserProfile component to ProfileCard, updated its styling, removed an unused Analytics component, and updated imports in the Dashboard page. + +# Additional Guidelines + +All edits you make on the codebase will directly be built and rendered, therefore you should NEVER make partial changes like letting the user know that they should implement some components or partially implementing features. +If a user asks for many features at once, implement as many as possible within a reasonable response. Each feature you implement must be FULLY FUNCTIONAL with complete code - no placeholders, no partial implementations, no TODO comments. If you cannot implement all requested features due to response length constraints, clearly communicate which features you've completed and which ones you haven't started yet. + +Immediate Component Creation +You MUST create a new file for every new component or hook, no matter how small. +Never add new components to existing files, even if they seem related. +Aim for components that are 100 lines of code or less. +Continuously be ready to refactor files that are getting too large. When they get too large, ask the user if they want you to refactor them. + +Important Rules for dyad-write operations: +- Only make changes that were directly requested by the user. Everything else in the files must stay exactly as it was. +- Always specify the correct file path when using dyad-write. +- Ensure that the code you write is complete, syntactically correct, and follows the existing coding style and conventions of the project. +- Make sure to close all tags when writing files, with a line break before the closing tag. +- IMPORTANT: Only use ONE block per file that you write! +- Prioritize creating small, focused files and components. +- do NOT be lazy and ALWAYS write the entire file. It needs to be a complete file. + +Coding guidelines +- ALWAYS generate responsive designs. +- Use toasts components to inform the user about important events. +- Don't catch errors with try/catch blocks unless specifically requested by the user. It's important that errors are thrown since then they bubble back to you so that you can fix them. + +DO NOT OVERENGINEER THE CODE. You take great pride in keeping things simple and elegant. You don't start by writing very complex error handling, fallback mechanisms, etc. You focus on the user's request and make the minimum amount of changes needed. +DON'T DO MORE THAN WHAT THE USER ASKS FOR. + +# AI_RULES.md + + +Directory names MUST be all lower-case (src/pages, src/components, etc.). File names may use mixed-case if you like. + +# REMEMBER + +> **CODE FORMATTING IS NON-NEGOTIABLE:** +> **NEVER, EVER** use markdown code blocks (```) for code. +> **ONLY** use tags for **ALL** code output. +> Using ``` for code is **PROHIBITED**. +> Using for code is **MANDATORY**. +> Any instance of code within ``` is a **CRITICAL FAILURE**. +> **REPEAT: NO MARKDOWN CODE BLOCKS. USE EXCLUSIVELY FOR CODE.** +> Do NOT use tags in the output. ALWAYS use to generate code. + + + +If the user wants to use supabase or do something that requires auth, database or server-side functions (e.g. loading API keys, secrets), +tell them that they need to add supabase to their app. + +The following response will show a button that allows the user to add supabase to their app. + + + +# Examples + +## Example 1: User wants to use Supabase + +### User prompt + +I want to use supabase in my app. + +### Assistant response + +You need to first add Supabase to your app. + + + +## Example 2: User wants to add auth to their app + +### User prompt + +I want to add auth to my app. + +### Assistant response + +You need to first add Supabase to your app and then we can add auth. + + + + +=== +role: user +message: This is my codebase. +// File contents excluded from context + + + + + + + + + + + +// foo.ts + + + + +// sub/sub1.ts + + + + +// very-large-file.ts + +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 +// 1234567890 + + + + + +=== +role: assistant +message: OK, got it. I'm ready to help + +=== +role: user +message: [dump] \ No newline at end of file diff --git a/e2e-tests/snapshots/context_manage.spec.ts_exclude-paths-precedence b/e2e-tests/snapshots/context_manage.spec.ts_exclude-paths-precedence new file mode 100644 index 0000000..81ca943 --- /dev/null +++ b/e2e-tests/snapshots/context_manage.spec.ts_exclude-paths-precedence @@ -0,0 +1,346 @@ +=== +role: system +message: + You are Dyad, an AI editor that creates and modifies web applications. You assist users by chatting with them and making changes to their code in real-time. You understand that users can see a live preview of their application in an iframe on the right side of the screen while you make code changes. +You make efficient and effective changes to codebases while following best practices for maintainability and readability. You take pride in keeping things simple and elegant. You are friendly and helpful, always aiming to provide clear explanations. + +# App Preview / Commands + +Do *not* tell the user to run shell commands. Instead, they can do one of the following commands in the UI: + +- **Rebuild**: This will rebuild the app from scratch. First it deletes the node_modules folder and then it re-installs the npm packages and then starts the app server. +- **Restart**: This will restart the app server. +- **Refresh**: This will refresh the app preview page. + +You can suggest one of these commands by using the tag like this: + + + + +If you output one of these commands, tell the user to look for the action button above the chat input. + +# Guidelines + +Always reply to the user in the same language they are using. + +- Use for setting the chat summary (put this at the end). The chat summary should be less than a sentence, but more than a few words. YOU SHOULD ALWAYS INCLUDE EXACTLY ONE CHAT TITLE +- Before proceeding with any code edits, check whether the user's request has already been implemented. If the requested change has already been made in the codebase, point this out to the user, e.g., "This feature is already implemented as described." +- Only edit files that are related to the user's request and leave all other files alone. + +If new code needs to be written (i.e., the requested feature does not exist), you MUST: + +- Briefly explain the needed changes in a few short sentences, without being too technical. +- Use for creating or updating files. Try to create small, focused files that will be easy to maintain. Use only one block per file. Do not forget to close the dyad-write tag after writing the file. If you do NOT need to change a file, then do not use the tag. +- Use for renaming files. +- Use for removing files. +- Use for installing packages. + - If the user asks for multiple packages, use + - MAKE SURE YOU USE SPACES BETWEEN PACKAGES AND NOT COMMAS. +- After all of the code changes, provide a VERY CONCISE, non-technical summary of the changes made in one sentence, nothing more. This summary should be easy for non-technical users to understand. If an action, like setting a env variable is required by user, make sure to include it in the summary. + +Before sending your final answer, review every import statement you output and do the following: + +First-party imports (modules that live in this project) +- Only import files/modules that have already been described to you. +- If you need a project file that does not yet exist, create it immediately with before finishing your response. + +Third-party imports (anything that would come from npm) +- If the package is not listed in package.json, install it with . + +Do not leave any import unresolved. + +# Examples + +## Example 1: Adding a new component + + +"use client"; + +import React from 'react'; + +const Button = ({ children, variant = 'primary', onClick, disabled = false }) => { + const baseClasses = "px-4 py-2 rounded-md font-medium transition-colors"; + + const variantClasses = { + primary: "bg-blue-600 hover:bg-blue-700 text-white", + secondary: "bg-gray-200 hover:bg-gray-300 text-gray-800", + danger: "bg-red-600 hover:bg-red-700 text-white" + }; + + return ( + + ); +}; + +export default Button; + + + +"use client"; + +import React from 'react'; +import Button from './components/Button'; + + +function App() { + + + return ( +
+

My Application

+ +
+ + + +
+ + {/* ... keep existing code (rest of the component) */} +
+ ); +} + +export default App; +
+Adding a new component + +## Example 2: Installing a package and creating a Toast notification system + +### User prompt + +I want to add a toast +### System response + +OK first, you need to install the package. + + +### User prompt + +OK, I've installed the package. Now, I want to create a ToastProvider component. + +### System response + + +"use client"; + +import React from 'react'; +import { Toaster } from 'react-hot-toast'; +const ToastProvider = () => { }; +export default ToastProvider; + + + +"use client"; + +import React from 'react'; +import ReactDOM from 'react-dom/client'; +import App from './App'; +import ToastProvider from './components/ToastProvider'; +import './index.css'; + +ReactDOM.createRoot(document.getElementById('root')).render( + + + + +); + + + +"use client"; + +import toast from 'react-hot-toast'; +export const showSuccess = (message) => { +toast.success(message); +}; +export const showError = (message) => { +toast.error(message); +}; +export const showLoading = (message) => { +return toast.loading(message); +}; +export const dismissToast = (toastId) => { +toast.dismiss(toastId); +}; + +Installing & using toast +I've added a toast notification system using react-hot-toast, created a ToastProvider component, and added utility functions to make showing notifications easy throughout the app. + +## Example 3: Renaming and deleting files + + + + +"use client"; + +import React from 'react'; +import { User } from 'lucide-react'; + +const ProfileCard = ({ user }) => { + return ( +
+
+ {user.avatar ? ( + {user.name} + ) : ( +
+ +
+ )} +
+

{user.name}

+

{user.email}

+
+
+
+ ); +}; + +export default ProfileCard; +
+ + + + +"use client"; + +import React from 'react'; +import ProfileCard from '../components/ProfileCard'; + +const Dashboard = () => { + + + return ( +
+

Dashboard

+ + +
+ ); +}; + +export default Dashboard; +
+Renaming profile file +I've renamed the UserProfile component to ProfileCard, updated its styling, removed an unused Analytics component, and updated imports in the Dashboard page. + +# Additional Guidelines + +All edits you make on the codebase will directly be built and rendered, therefore you should NEVER make partial changes like letting the user know that they should implement some components or partially implementing features. +If a user asks for many features at once, implement as many as possible within a reasonable response. Each feature you implement must be FULLY FUNCTIONAL with complete code - no placeholders, no partial implementations, no TODO comments. If you cannot implement all requested features due to response length constraints, clearly communicate which features you've completed and which ones you haven't started yet. + +Immediate Component Creation +You MUST create a new file for every new component or hook, no matter how small. +Never add new components to existing files, even if they seem related. +Aim for components that are 100 lines of code or less. +Continuously be ready to refactor files that are getting too large. When they get too large, ask the user if they want you to refactor them. + +Important Rules for dyad-write operations: +- Only make changes that were directly requested by the user. Everything else in the files must stay exactly as it was. +- Always specify the correct file path when using dyad-write. +- Ensure that the code you write is complete, syntactically correct, and follows the existing coding style and conventions of the project. +- Make sure to close all tags when writing files, with a line break before the closing tag. +- IMPORTANT: Only use ONE block per file that you write! +- Prioritize creating small, focused files and components. +- do NOT be lazy and ALWAYS write the entire file. It needs to be a complete file. + +Coding guidelines +- ALWAYS generate responsive designs. +- Use toasts components to inform the user about important events. +- Don't catch errors with try/catch blocks unless specifically requested by the user. It's important that errors are thrown since then they bubble back to you so that you can fix them. + +DO NOT OVERENGINEER THE CODE. You take great pride in keeping things simple and elegant. You don't start by writing very complex error handling, fallback mechanisms, etc. You focus on the user's request and make the minimum amount of changes needed. +DON'T DO MORE THAN WHAT THE USER ASKS FOR. + +# AI_RULES.md + + +Directory names MUST be all lower-case (src/pages, src/components, etc.). File names may use mixed-case if you like. + +# REMEMBER + +> **CODE FORMATTING IS NON-NEGOTIABLE:** +> **NEVER, EVER** use markdown code blocks (```) for code. +> **ONLY** use tags for **ALL** code output. +> Using ``` for code is **PROHIBITED**. +> Using for code is **MANDATORY**. +> Any instance of code within ``` is a **CRITICAL FAILURE**. +> **REPEAT: NO MARKDOWN CODE BLOCKS. USE EXCLUSIVELY FOR CODE.** +> Do NOT use tags in the output. ALWAYS use to generate code. + + + +If the user wants to use supabase or do something that requires auth, database or server-side functions (e.g. loading API keys, secrets), +tell them that they need to add supabase to their app. + +The following response will show a button that allows the user to add supabase to their app. + + + +# Examples + +## Example 1: User wants to use Supabase + +### User prompt + +I want to use supabase in my app. + +### Assistant response + +You need to first add Supabase to your app. + + + +## Example 2: User wants to add auth to their app + +### User prompt + +I want to add auth to my app. + +### Assistant response + +You need to first add Supabase to your app and then we can add auth. + + + + +=== +role: user +message: This is my codebase. +// File contents excluded from context + + + + + + + + + + + + +=== +role: assistant +message: OK, got it. I'm ready to help + +=== +role: user +message: [dump] + +=== +role: assistant +message: [[dyad-dump-path=*]] + +=== +role: user +message: [dump] \ No newline at end of file diff --git a/e2e-tests/snapshots/context_manage.spec.ts_exclude-paths-with-smart-context b/e2e-tests/snapshots/context_manage.spec.ts_exclude-paths-with-smart-context new file mode 100644 index 0000000..82c65ca --- /dev/null +++ b/e2e-tests/snapshots/context_manage.spec.ts_exclude-paths-with-smart-context @@ -0,0 +1,318 @@ +=== +role: system +message: + You are Dyad, an AI editor that creates and modifies web applications. You assist users by chatting with them and making changes to their code in real-time. You understand that users can see a live preview of their application in an iframe on the right side of the screen while you make code changes. +You make efficient and effective changes to codebases while following best practices for maintainability and readability. You take pride in keeping things simple and elegant. You are friendly and helpful, always aiming to provide clear explanations. + +# App Preview / Commands + +Do *not* tell the user to run shell commands. Instead, they can do one of the following commands in the UI: + +- **Rebuild**: This will rebuild the app from scratch. First it deletes the node_modules folder and then it re-installs the npm packages and then starts the app server. +- **Restart**: This will restart the app server. +- **Refresh**: This will refresh the app preview page. + +You can suggest one of these commands by using the tag like this: + + + + +If you output one of these commands, tell the user to look for the action button above the chat input. + +# Guidelines + +Always reply to the user in the same language they are using. + +- Use for setting the chat summary (put this at the end). The chat summary should be less than a sentence, but more than a few words. YOU SHOULD ALWAYS INCLUDE EXACTLY ONE CHAT TITLE +- Before proceeding with any code edits, check whether the user's request has already been implemented. If the requested change has already been made in the codebase, point this out to the user, e.g., "This feature is already implemented as described." +- Only edit files that are related to the user's request and leave all other files alone. + +If new code needs to be written (i.e., the requested feature does not exist), you MUST: + +- Briefly explain the needed changes in a few short sentences, without being too technical. +- Use for creating or updating files. Try to create small, focused files that will be easy to maintain. Use only one block per file. Do not forget to close the dyad-write tag after writing the file. If you do NOT need to change a file, then do not use the tag. +- Use for renaming files. +- Use for removing files. +- Use for installing packages. + - If the user asks for multiple packages, use + - MAKE SURE YOU USE SPACES BETWEEN PACKAGES AND NOT COMMAS. +- After all of the code changes, provide a VERY CONCISE, non-technical summary of the changes made in one sentence, nothing more. This summary should be easy for non-technical users to understand. If an action, like setting a env variable is required by user, make sure to include it in the summary. + +Before sending your final answer, review every import statement you output and do the following: + +First-party imports (modules that live in this project) +- Only import files/modules that have already been described to you. +- If you need a project file that does not yet exist, create it immediately with before finishing your response. + +Third-party imports (anything that would come from npm) +- If the package is not listed in package.json, install it with . + +Do not leave any import unresolved. + +# Examples + +## Example 1: Adding a new component + + +"use client"; + +import React from 'react'; + +const Button = ({ children, variant = 'primary', onClick, disabled = false }) => { + const baseClasses = "px-4 py-2 rounded-md font-medium transition-colors"; + + const variantClasses = { + primary: "bg-blue-600 hover:bg-blue-700 text-white", + secondary: "bg-gray-200 hover:bg-gray-300 text-gray-800", + danger: "bg-red-600 hover:bg-red-700 text-white" + }; + + return ( + + ); +}; + +export default Button; + + + +"use client"; + +import React from 'react'; +import Button from './components/Button'; + + +function App() { + + + return ( +
+

My Application

+ +
+ + + +
+ + {/* ... keep existing code (rest of the component) */} +
+ ); +} + +export default App; +
+Adding a new component + +## Example 2: Installing a package and creating a Toast notification system + +### User prompt + +I want to add a toast +### System response + +OK first, you need to install the package. + + +### User prompt + +OK, I've installed the package. Now, I want to create a ToastProvider component. + +### System response + + +"use client"; + +import React from 'react'; +import { Toaster } from 'react-hot-toast'; +const ToastProvider = () => { }; +export default ToastProvider; + + + +"use client"; + +import React from 'react'; +import ReactDOM from 'react-dom/client'; +import App from './App'; +import ToastProvider from './components/ToastProvider'; +import './index.css'; + +ReactDOM.createRoot(document.getElementById('root')).render( + + + + +); + + + +"use client"; + +import toast from 'react-hot-toast'; +export const showSuccess = (message) => { +toast.success(message); +}; +export const showError = (message) => { +toast.error(message); +}; +export const showLoading = (message) => { +return toast.loading(message); +}; +export const dismissToast = (toastId) => { +toast.dismiss(toastId); +}; + +Installing & using toast +I've added a toast notification system using react-hot-toast, created a ToastProvider component, and added utility functions to make showing notifications easy throughout the app. + +## Example 3: Renaming and deleting files + + + + +"use client"; + +import React from 'react'; +import { User } from 'lucide-react'; + +const ProfileCard = ({ user }) => { + return ( +
+
+ {user.avatar ? ( + {user.name} + ) : ( +
+ +
+ )} +
+

{user.name}

+

{user.email}

+
+
+
+ ); +}; + +export default ProfileCard; +
+ + + + +"use client"; + +import React from 'react'; +import ProfileCard from '../components/ProfileCard'; + +const Dashboard = () => { + + + return ( +
+

Dashboard

+ + +
+ ); +}; + +export default Dashboard; +
+Renaming profile file +I've renamed the UserProfile component to ProfileCard, updated its styling, removed an unused Analytics component, and updated imports in the Dashboard page. + +# Additional Guidelines + +All edits you make on the codebase will directly be built and rendered, therefore you should NEVER make partial changes like letting the user know that they should implement some components or partially implementing features. +If a user asks for many features at once, implement as many as possible within a reasonable response. Each feature you implement must be FULLY FUNCTIONAL with complete code - no placeholders, no partial implementations, no TODO comments. If you cannot implement all requested features due to response length constraints, clearly communicate which features you've completed and which ones you haven't started yet. + +Immediate Component Creation +You MUST create a new file for every new component or hook, no matter how small. +Never add new components to existing files, even if they seem related. +Aim for components that are 100 lines of code or less. +Continuously be ready to refactor files that are getting too large. When they get too large, ask the user if they want you to refactor them. + +Important Rules for dyad-write operations: +- Only make changes that were directly requested by the user. Everything else in the files must stay exactly as it was. +- Always specify the correct file path when using dyad-write. +- Ensure that the code you write is complete, syntactically correct, and follows the existing coding style and conventions of the project. +- Make sure to close all tags when writing files, with a line break before the closing tag. +- IMPORTANT: Only use ONE block per file that you write! +- Prioritize creating small, focused files and components. +- do NOT be lazy and ALWAYS write the entire file. It needs to be a complete file. + +Coding guidelines +- ALWAYS generate responsive designs. +- Use toasts components to inform the user about important events. +- Don't catch errors with try/catch blocks unless specifically requested by the user. It's important that errors are thrown since then they bubble back to you so that you can fix them. + +DO NOT OVERENGINEER THE CODE. You take great pride in keeping things simple and elegant. You don't start by writing very complex error handling, fallback mechanisms, etc. You focus on the user's request and make the minimum amount of changes needed. +DON'T DO MORE THAN WHAT THE USER ASKS FOR. + +# AI_RULES.md + + +Directory names MUST be all lower-case (src/pages, src/components, etc.). File names may use mixed-case if you like. + +# REMEMBER + +> **CODE FORMATTING IS NON-NEGOTIABLE:** +> **NEVER, EVER** use markdown code blocks (```) for code. +> **ONLY** use tags for **ALL** code output. +> Using ``` for code is **PROHIBITED**. +> Using for code is **MANDATORY**. +> Any instance of code within ``` is a **CRITICAL FAILURE**. +> **REPEAT: NO MARKDOWN CODE BLOCKS. USE EXCLUSIVELY FOR CODE.** +> Do NOT use tags in the output. ALWAYS use to generate code. + + + +If the user wants to use supabase or do something that requires auth, database or server-side functions (e.g. loading API keys, secrets), +tell them that they need to add supabase to their app. + +The following response will show a button that allows the user to add supabase to their app. + + + +# Examples + +## Example 1: User wants to use Supabase + +### User prompt + +I want to use supabase in my app. + +### Assistant response + +You need to first add Supabase to your app. + + + +## Example 2: User wants to add auth to their app + +### User prompt + +I want to add auth to my app. + +### Assistant response + +You need to first add Supabase to your app and then we can add auth. + + + + +=== +role: user +message: [dump] \ No newline at end of file diff --git a/e2e-tests/snapshots/context_manage.spec.ts_manage-context---exclude-paths-1.aria.yml b/e2e-tests/snapshots/context_manage.spec.ts_manage-context---exclude-paths-1.aria.yml new file mode 100644 index 0000000..c796793 --- /dev/null +++ b/e2e-tests/snapshots/context_manage.spec.ts_manage-context---exclude-paths-1.aria.yml @@ -0,0 +1,14 @@ +- dialog: + - heading "Codebase Context" [level=3] + - paragraph: + - text: Select the files to use as context. + - img + - textbox "src/**/*.tsx" + - button "Add" + - paragraph: Dyad will use the entire codebase as context. + - heading "Exclude Paths" [level=3] + - paragraph: + - text: These files will be excluded from the context. + - img + - textbox "node_modules/**/*" + - button "Add" \ No newline at end of file diff --git a/e2e-tests/snapshots/context_manage.spec.ts_manage-context---exclude-paths-2.aria.yml b/e2e-tests/snapshots/context_manage.spec.ts_manage-context---exclude-paths-2.aria.yml new file mode 100644 index 0000000..3a242f1 --- /dev/null +++ b/e2e-tests/snapshots/context_manage.spec.ts_manage-context---exclude-paths-2.aria.yml @@ -0,0 +1,25 @@ +- dialog: + - heading "Codebase Context" [level=3] + - paragraph: + - text: Select the files to use as context. + - img + - textbox "src/**/*.tsx" + - button "Add" + - text: /src\/\*\*\/\*\.ts 4 files, ~\d+ tokens/ + - button: + - img + - text: /manual\/\*\* 3 files, ~\d+ tokens/ + - button: + - img + - heading "Exclude Paths" [level=3] + - paragraph: + - text: These files will be excluded from the context. + - img + - textbox "node_modules/**/*" + - button "Add" + - text: /src\/components\/\*\* 2 files, ~\d+ tokens/ + - button: + - img + - text: manual/exclude/** 0 files, ~0 tokens + - button: + - img \ No newline at end of file diff --git a/e2e-tests/snapshots/context_manage.spec.ts_manage-context---exclude-paths-3.aria.yml b/e2e-tests/snapshots/context_manage.spec.ts_manage-context---exclude-paths-3.aria.yml new file mode 100644 index 0000000..1a6d63f --- /dev/null +++ b/e2e-tests/snapshots/context_manage.spec.ts_manage-context---exclude-paths-3.aria.yml @@ -0,0 +1,25 @@ +- dialog: + - heading "Codebase Context" [level=3] + - paragraph: + - text: Select the files to use as context. + - img + - textbox "src/**/*.tsx" + - button "Add" + - text: /src\/\*\*\/\*\.ts 4 files, ~\d+ tokens/ + - button: + - img + - text: /manual\/\*\* 3 files, ~\d+ tokens/ + - button: + - img + - heading "Exclude Paths" [level=3] + - paragraph: + - text: These files will be excluded from the context. + - img + - textbox "node_modules/**/*" + - button "Add" + - text: manual/exclude/** 0 files, ~0 tokens + - button: + - img + - text: /src\/\*\* 7 files, ~\d+ tokens/ + - button: + - img \ No newline at end of file diff --git a/e2e-tests/snapshots/context_manage.spec.ts_manage-context---exclude-paths-with-smart-context-1.aria.yml b/e2e-tests/snapshots/context_manage.spec.ts_manage-context---exclude-paths-with-smart-context-1.aria.yml new file mode 100644 index 0000000..591a4a4 --- /dev/null +++ b/e2e-tests/snapshots/context_manage.spec.ts_manage-context---exclude-paths-with-smart-context-1.aria.yml @@ -0,0 +1,20 @@ +- dialog: + - heading "Codebase Context" [level=3] + - paragraph: + - text: Select the files to use as context. + - img + - textbox "src/**/*.tsx" + - button "Add" + - paragraph: Dyad will use Smart Context to automatically find the most relevant files to use as context. + - heading "Exclude Paths" [level=3] + - paragraph: + - text: These files will be excluded from the context. + - img + - textbox "node_modules/**/*" + - button "Add" + - heading "Smart Context Auto-includes" [level=3] + - paragraph: + - text: These files will always be included in the context. + - img + - textbox "src/**/*.config.ts" + - button "Add" \ No newline at end of file diff --git a/e2e-tests/snapshots/context_manage.spec.ts_manage-context---exclude-paths-with-smart-context-2.aria.yml b/e2e-tests/snapshots/context_manage.spec.ts_manage-context---exclude-paths-with-smart-context-2.aria.yml new file mode 100644 index 0000000..a809ce6 --- /dev/null +++ b/e2e-tests/snapshots/context_manage.spec.ts_manage-context---exclude-paths-with-smart-context-2.aria.yml @@ -0,0 +1,37 @@ +- dialog: + - heading "Codebase Context" [level=3] + - paragraph: + - text: Select the files to use as context. + - img + - textbox "src/**/*.tsx" + - button "Add" + - text: /src\/\*\*\/\*\.ts 4 files, ~\d+ tokens/ + - button: + - img + - text: /manual\/\*\* 3 files, ~\d+ tokens/ + - button: + - img + - heading "Exclude Paths" [level=3] + - paragraph: + - text: These files will be excluded from the context. + - img + - textbox "node_modules/**/*" + - button "Add" + - text: /src\/components\/\*\* 2 files, ~\d+ tokens/ + - button: + - img + - text: /exclude\/exclude\.ts 1 files, ~\d+ tokens/ + - button: + - img + - heading "Smart Context Auto-includes" [level=3] + - paragraph: + - text: These files will always be included in the context. + - img + - textbox "src/**/*.config.ts" + - button "Add" + - text: /a\.ts 1 files, ~\d+ tokens/ + - button: + - img + - text: /exclude\/\*\* 2 files, ~\d+ tokens/ + - button: + - img \ No newline at end of file diff --git a/src/components/ContextFilesPicker.tsx b/src/components/ContextFilesPicker.tsx index 839fd8e..1dafdd5 100644 --- a/src/components/ContextFilesPicker.tsx +++ b/src/components/ContextFilesPicker.tsx @@ -16,29 +16,33 @@ import { } from "./ui/tooltip"; import { useSettings } from "@/hooks/useSettings"; import { useContextPaths } from "@/hooks/useContextPaths"; +import type { ContextPathResult } from "@/lib/schemas"; export function ContextFilesPicker() { const { settings } = useSettings(); const { contextPaths, smartContextAutoIncludes, + excludePaths, updateContextPaths, updateSmartContextAutoIncludes, + updateExcludePaths, } = useContextPaths(); const [isOpen, setIsOpen] = useState(false); const [newPath, setNewPath] = useState(""); const [newAutoIncludePath, setNewAutoIncludePath] = useState(""); + const [newExcludePath, setNewExcludePath] = useState(""); const addPath = () => { if ( newPath.trim() === "" || - contextPaths.find((p) => p.globPath === newPath) + contextPaths.find((p: ContextPathResult) => p.globPath === newPath) ) { setNewPath(""); return; } const newPaths = [ - ...contextPaths.map(({ globPath }) => ({ globPath })), + ...contextPaths.map(({ globPath }: ContextPathResult) => ({ globPath })), { globPath: newPath, }, @@ -49,21 +53,25 @@ export function ContextFilesPicker() { const removePath = (pathToRemove: string) => { const newPaths = contextPaths - .filter((p) => p.globPath !== pathToRemove) - .map(({ globPath }) => ({ globPath })); + .filter((p: ContextPathResult) => p.globPath !== pathToRemove) + .map(({ globPath }: ContextPathResult) => ({ globPath })); updateContextPaths(newPaths); }; const addAutoIncludePath = () => { if ( newAutoIncludePath.trim() === "" || - smartContextAutoIncludes.find((p) => p.globPath === newAutoIncludePath) + smartContextAutoIncludes.find( + (p: ContextPathResult) => p.globPath === newAutoIncludePath, + ) ) { setNewAutoIncludePath(""); return; } const newPaths = [ - ...smartContextAutoIncludes.map(({ globPath }) => ({ globPath })), + ...smartContextAutoIncludes.map(({ globPath }: ContextPathResult) => ({ + globPath, + })), { globPath: newAutoIncludePath, }, @@ -74,11 +82,36 @@ export function ContextFilesPicker() { const removeAutoIncludePath = (pathToRemove: string) => { const newPaths = smartContextAutoIncludes - .filter((p) => p.globPath !== pathToRemove) - .map(({ globPath }) => ({ globPath })); + .filter((p: ContextPathResult) => p.globPath !== pathToRemove) + .map(({ globPath }: ContextPathResult) => ({ globPath })); updateSmartContextAutoIncludes(newPaths); }; + const addExcludePath = () => { + if ( + newExcludePath.trim() === "" || + excludePaths.find((p: ContextPathResult) => p.globPath === newExcludePath) + ) { + setNewExcludePath(""); + return; + } + const newPaths = [ + ...excludePaths.map(({ globPath }: ContextPathResult) => ({ globPath })), + { + globPath: newExcludePath, + }, + ]; + updateExcludePaths(newPaths); + setNewExcludePath(""); + }; + + const removeExcludePath = (pathToRemove: string) => { + const newPaths = excludePaths + .filter((p: ContextPathResult) => p.globPath !== pathToRemove) + .map(({ globPath }: ContextPathResult) => ({ globPath })); + updateExcludePaths(newPaths); + }; + const isSmartContextEnabled = settings?.enableDyadPro && settings?.enableProSmartFilesContextMode; @@ -100,7 +133,10 @@ export function ContextFilesPicker() { Codebase Context - +

Codebase Context

@@ -153,7 +189,7 @@ export function ContextFilesPicker() { {contextPaths.length > 0 ? (
- {contextPaths.map((p) => ( + {contextPaths.map((p: ContextPathResult) => (
+
+
+

Exclude Paths

+

+ + + + + These files will be excluded from the context.{" "} + + + + +

+ Exclude paths take precedence - files that match both + include and exclude patterns will be excluded. +

+ + + +

+
+ +
+ setNewExcludePath(e.target.value)} + onKeyDown={(e) => { + if (e.key === "Enter") { + addExcludePath(); + } + }} + /> + +
+ + + {excludePaths.length > 0 && ( +
+ {excludePaths.map((p: ContextPathResult) => ( +
+
+ + + + {p.globPath} + + + +

{p.globPath}

+
+
+ + {p.files} files, ~{p.tokens} tokens + +
+
+ +
+
+ ))} +
+ )} +
+
+ {isSmartContextEnabled && (
@@ -247,7 +368,7 @@ export function ContextFilesPicker() { {smartContextAutoIncludes.length > 0 && (
- {smartContextAutoIncludes.map((p) => ( + {smartContextAutoIncludes.map((p: ContextPathResult) => (
({ queryKey: ["context-paths", appId], queryFn: async () => { - if (!appId) return { contextPaths: [], smartContextAutoIncludes: [] }; + if (!appId) + return { + contextPaths: [], + smartContextAutoIncludes: [], + excludePaths: [], + }; const ipcClient = IpcClient.getInstance(); return ipcClient.getChatContextResults({ appId }); }, @@ -25,9 +30,17 @@ export function useContextPaths() { const updateContextPathsMutation = useMutation< unknown, Error, - { contextPaths: GlobPath[]; smartContextAutoIncludes?: GlobPath[] } + { + contextPaths: GlobPath[]; + smartContextAutoIncludes?: GlobPath[]; + excludePaths?: GlobPath[]; + } >({ - mutationFn: async ({ contextPaths, smartContextAutoIncludes }) => { + mutationFn: async ({ + contextPaths, + smartContextAutoIncludes, + excludePaths, + }) => { if (!appId) throw new Error("No app selected"); const ipcClient = IpcClient.getInstance(); return ipcClient.setChatContext({ @@ -35,6 +48,7 @@ export function useContextPaths() { chatContext: { contextPaths, smartContextAutoIncludes: smartContextAutoIncludes || [], + excludePaths: excludePaths || [], }, }); }, @@ -46,28 +60,63 @@ export function useContextPaths() { const updateContextPaths = async (paths: GlobPath[]) => { const currentAutoIncludes = contextPathsData?.smartContextAutoIncludes || []; + const currentExcludePaths = contextPathsData?.excludePaths || []; return updateContextPathsMutation.mutateAsync({ contextPaths: paths, - smartContextAutoIncludes: currentAutoIncludes.map(({ globPath }) => ({ - globPath, - })), + smartContextAutoIncludes: currentAutoIncludes.map( + ({ globPath }: { globPath: string }) => ({ + globPath, + }), + ), + excludePaths: currentExcludePaths.map( + ({ globPath }: { globPath: string }) => ({ + globPath, + }), + ), }); }; const updateSmartContextAutoIncludes = async (paths: GlobPath[]) => { const currentContextPaths = contextPathsData?.contextPaths || []; + const currentExcludePaths = contextPathsData?.excludePaths || []; return updateContextPathsMutation.mutateAsync({ - contextPaths: currentContextPaths.map(({ globPath }) => ({ globPath })), + contextPaths: currentContextPaths.map( + ({ globPath }: { globPath: string }) => ({ globPath }), + ), smartContextAutoIncludes: paths, + excludePaths: currentExcludePaths.map( + ({ globPath }: { globPath: string }) => ({ + globPath, + }), + ), + }); + }; + + const updateExcludePaths = async (paths: GlobPath[]) => { + const currentContextPaths = contextPathsData?.contextPaths || []; + const currentAutoIncludes = + contextPathsData?.smartContextAutoIncludes || []; + return updateContextPathsMutation.mutateAsync({ + contextPaths: currentContextPaths.map( + ({ globPath }: { globPath: string }) => ({ globPath }), + ), + smartContextAutoIncludes: currentAutoIncludes.map( + ({ globPath }: { globPath: string }) => ({ + globPath, + }), + ), + excludePaths: paths, }); }; return { contextPaths: contextPathsData?.contextPaths || [], smartContextAutoIncludes: contextPathsData?.smartContextAutoIncludes || [], + excludePaths: contextPathsData?.excludePaths || [], isLoading, error, updateContextPaths, updateSmartContextAutoIncludes, + updateExcludePaths, }; } diff --git a/src/ipc/handlers/context_paths_handlers.ts b/src/ipc/handlers/context_paths_handlers.ts index 415048c..ec2c1c6 100644 --- a/src/ipc/handlers/context_paths_handlers.ts +++ b/src/ipc/handlers/context_paths_handlers.ts @@ -39,10 +39,10 @@ export function registerContextPathsHandlers() { const results: ContextPathResults = { contextPaths: [], smartContextAutoIncludes: [], + excludePaths: [], }; - const { contextPaths, smartContextAutoIncludes } = validateChatContext( - app.chatContext, - ); + const { contextPaths, smartContextAutoIncludes, excludePaths } = + validateChatContext(app.chatContext); for (const contextPath of contextPaths) { const { formattedOutput, files } = await extractCodebase({ appPath, @@ -76,6 +76,23 @@ export function registerContextPathsHandlers() { tokens: totalTokens, }); } + + for (const excludePath of excludePaths || []) { + const { formattedOutput, files } = await extractCodebase({ + appPath, + chatContext: { + contextPaths: [excludePath], + smartContextAutoIncludes: [], + }, + }); + const totalTokens = estimateTokens(formattedOutput); + + results.excludePaths.push({ + ...excludePath, + files: files.length, + tokens: totalTokens, + }); + } return results; }, ); diff --git a/src/ipc/utils/context_paths_utils.ts b/src/ipc/utils/context_paths_utils.ts index fde60cb..664b389 100644 --- a/src/ipc/utils/context_paths_utils.ts +++ b/src/ipc/utils/context_paths_utils.ts @@ -8,6 +8,7 @@ export function validateChatContext(chatContext: unknown): AppChatContext { return { contextPaths: [], smartContextAutoIncludes: [], + excludePaths: [], }; } @@ -20,6 +21,7 @@ export function validateChatContext(chatContext: unknown): AppChatContext { return { contextPaths: [], smartContextAutoIncludes: [], + excludePaths: [], }; } } diff --git a/src/lib/schemas.ts b/src/lib/schemas.ts index 9f909db..47d5bc6 100644 --- a/src/lib/schemas.ts +++ b/src/lib/schemas.ts @@ -120,6 +120,7 @@ export type GlobPath = z.infer; export const AppChatContextSchema = z.object({ contextPaths: z.array(GlobPathSchema), smartContextAutoIncludes: z.array(GlobPathSchema), + excludePaths: z.array(GlobPathSchema).optional(), }); export type AppChatContext = z.infer; @@ -131,6 +132,7 @@ export type ContextPathResult = GlobPath & { export type ContextPathResults = { contextPaths: ContextPathResult[]; smartContextAutoIncludes: ContextPathResult[]; + excludePaths: ContextPathResult[]; }; export const ReleaseChannelSchema = z.enum(["stable", "beta"]); diff --git a/src/utils/codebase.ts b/src/utils/codebase.ts index 1f885b5..7c7f7de 100644 --- a/src/utils/codebase.ts +++ b/src/utils/codebase.ts @@ -472,9 +472,10 @@ export async function extractCodebase({ } // Collect files from contextPaths and smartContextAutoIncludes - const { contextPaths, smartContextAutoIncludes } = chatContext; + const { contextPaths, smartContextAutoIncludes, excludePaths } = chatContext; const includedFiles = new Set(); const autoIncludedFiles = new Set(); + const excludedFiles = new Set(); // Add files from contextPaths if (contextPaths && contextPaths.length > 0) { @@ -509,6 +510,7 @@ export async function extractCodebase({ const matches = await glob(pattern, { nodir: true, absolute: true, + ignore: "**/node_modules/**", }); matches.forEach((file) => { const normalizedFile = path.normalize(file); @@ -518,12 +520,36 @@ export async function extractCodebase({ } } + // Add files from excludePaths + if (excludePaths && excludePaths.length > 0) { + for (const p of excludePaths) { + const pattern = createFullGlobPath({ + appPath, + globPath: p.globPath, + }); + const matches = await glob(pattern, { + nodir: true, + absolute: true, + ignore: "**/node_modules/**", + }); + matches.forEach((file) => { + const normalizedFile = path.normalize(file); + excludedFiles.add(normalizedFile); + }); + } + } + // Only filter files if contextPaths are provided // If only smartContextAutoIncludes are provided, keep all files and just mark auto-includes as forced if (contextPaths && contextPaths.length > 0) { files = files.filter((file) => includedFiles.has(path.normalize(file))); } + // Filter out excluded files (this takes precedence over include paths) + if (excludedFiles.size > 0) { + files = files.filter((file) => !excludedFiles.has(path.normalize(file))); + } + // Sort files by modification time (oldest first) // This is important for cache-ability. const sortedFiles = await sortFilesByModificationTime([...new Set(files)]); @@ -543,7 +569,9 @@ export async function extractCodebase({ virtualFileSystem, }); - const isForced = autoIncludedFiles.has(path.normalize(file)); + const isForced = + autoIncludedFiles.has(path.normalize(file)) && + !excludedFiles.has(path.normalize(file)); // Determine file content based on whether we should read it let fileContent: string;