Unverified 提交 42cbb59b authored 作者: Will Chen's avatar Will Chen 提交者: GitHub

Remove shadcn from exclude list for smartcontext (#769)

上级 6c82cef5
...@@ -63,12 +63,12 @@ ...@@ -63,12 +63,12 @@
}, },
{ {
"path": "src/components/ui/button.tsx", "path": "src/components/ui/button.tsx",
"content": "// File contents excluded from context", "content": "// button.tsx\n",
"force": false "force": false
}, },
{ {
"path": "src/components/ui/helper.ts", "path": "src/components/ui/helper.ts",
"content": "// File contents excluded from context", "content": "// helper.ts\n",
"force": false "force": false
}, },
{ {
......
...@@ -43,7 +43,7 @@ ...@@ -43,7 +43,7 @@
}, },
{ {
"path": "src/components/ui/helper.ts", "path": "src/components/ui/helper.ts",
"content": "// File contents excluded from context", "content": "// helper.ts\n",
"force": false "force": false
}, },
{ {
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
"files": [ "files": [
{ {
"path": "src/components/ui/helper.ts", "path": "src/components/ui/helper.ts",
"content": "// File contents excluded from context", "content": "// helper.ts\n",
"force": false "force": false
}, },
{ {
......
...@@ -79,12 +79,12 @@ ...@@ -79,12 +79,12 @@
}, },
{ {
"path": "src/components/ui/button.tsx", "path": "src/components/ui/button.tsx",
"content": "// File contents excluded from context", "content": "// button.tsx\n",
"force": false "force": false
}, },
{ {
"path": "src/components/ui/helper.ts", "path": "src/components/ui/helper.ts",
"content": "// File contents excluded from context", "content": "// helper.ts\n",
"force": false "force": false
}, },
{ {
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -57,16 +57,20 @@ const EXCLUDED_FILES = ["pnpm-lock.yaml", "package-lock.json"]; ...@@ -57,16 +57,20 @@ const EXCLUDED_FILES = ["pnpm-lock.yaml", "package-lock.json"];
// Files to always include, regardless of extension // Files to always include, regardless of extension
const ALWAYS_INCLUDE_FILES = ["package.json", "vercel.json", ".gitignore"]; const ALWAYS_INCLUDE_FILES = ["package.json", "vercel.json", ".gitignore"];
// File patterns to always omit (contents will be replaced with a placeholder)
// We don't want to send environment variables to the LLM because they
// are sensitive and users should be configuring them via the UI.
const ALWAYS_OMITTED_FILES = [".env", ".env.local"];
// File patterns to omit (contents will be replaced with a placeholder) // File patterns to omit (contents will be replaced with a placeholder)
// //
// Why are we not using path.join here? // Why are we not using path.join here?
// Because we have already normalized the path to use /. // Because we have already normalized the path to use /.
const OMITTED_FILES = [ const OMITTED_FILES = [
...ALWAYS_OMITTED_FILES,
"src/components/ui", "src/components/ui",
"eslint.config", "eslint.config",
"tsconfig.json", "tsconfig.json",
".env",
]; ];
// Maximum file size to include (in bytes) - 1MB // Maximum file size to include (in bytes) - 1MB
...@@ -306,11 +310,6 @@ async function collectFiles(dir: string, baseDir: string): Promise<string[]> { ...@@ -306,11 +310,6 @@ async function collectFiles(dir: string, baseDir: string): Promise<string[]> {
return files; return files;
} }
// Skip large configuration files or generated code (just include the path)
function isOmittedFile(relativePath: string): boolean {
return OMITTED_FILES.some((pattern) => relativePath.includes(pattern));
}
const OMITTED_FILE_CONTENT = "// File contents excluded from context"; const OMITTED_FILE_CONTENT = "// File contents excluded from context";
/** /**
...@@ -327,7 +326,34 @@ function shouldReadFileContents({ ...@@ -327,7 +326,34 @@ function shouldReadFileContents({
const fileName = path.basename(filePath); const fileName = path.basename(filePath);
// OMITTED_FILES takes precedence - never read if omitted // OMITTED_FILES takes precedence - never read if omitted
if (isOmittedFile(normalizedRelativePath)) { if (
OMITTED_FILES.some((pattern) => normalizedRelativePath.includes(pattern))
) {
return false;
}
// Check if file should be included based on extension or filename
return (
ALLOWED_EXTENSIONS.includes(ext) || ALWAYS_INCLUDE_FILES.includes(fileName)
);
}
function shouldReadFileContentsForSmartContext({
filePath,
normalizedRelativePath,
}: {
filePath: string;
normalizedRelativePath: string;
}): boolean {
const ext = path.extname(filePath).toLowerCase();
const fileName = path.basename(filePath);
// ALWAYS__OMITTED_FILES takes precedence - never read if omitted
if (
ALWAYS_OMITTED_FILES.some((pattern) =>
normalizedRelativePath.includes(pattern),
)
) {
return false; return false;
} }
...@@ -521,7 +547,12 @@ export async function extractCodebase({ ...@@ -521,7 +547,12 @@ export async function extractCodebase({
// Determine file content based on whether we should read it // Determine file content based on whether we should read it
let fileContent: string; let fileContent: string;
if (!shouldReadFileContents({ filePath: file, normalizedRelativePath })) { if (
!shouldReadFileContentsForSmartContext({
filePath: file,
normalizedRelativePath,
})
) {
fileContent = OMITTED_FILE_CONTENT; fileContent = OMITTED_FILE_CONTENT;
} else { } else {
const readContent = await readFileWithCache(file, virtualFileSystem); const readContent = await readFileWithCache(file, virtualFileSystem);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论