| 1 | import fs from "fs"; |
| 2 | |
| 3 | import ignore from "ignore"; |
| 4 | |
| 5 | import { IDE } from ".."; |
| 6 | import { getGlobalContinueIgnorePath } from "../util/paths"; |
| 7 | |
| 8 | export const DEFAULT_IGNORE_FILETYPES = [ |
| 9 | "*.DS_Store", |
| 10 | "*-lock.json", |
| 11 | "*.lock", |
| 12 | "*.log", |
| 13 | "*.ttf", |
| 14 | "*.png", |
| 15 | "*.jpg", |
| 16 | "*.jpeg", |
| 17 | "*.gif", |
| 18 | "*.mp4", |
| 19 | "*.svg", |
| 20 | "*.ico", |
| 21 | "*.pdf", |
| 22 | "*.zip", |
| 23 | "*.gz", |
| 24 | "*.tar", |
| 25 | "*.dmg", |
| 26 | "*.tgz", |
| 27 | "*.rar", |
| 28 | "*.7z", |
| 29 | "*.exe", |
| 30 | "*.dll", |
| 31 | "*.obj", |
| 32 | "*.o", |
| 33 | "*.o.d", |
| 34 | "*.a", |
| 35 | "*.lib", |
| 36 | "*.so", |
| 37 | "*.dylib", |
| 38 | "*.ncb", |
| 39 | "*.sdf", |
| 40 | "*.woff", |
| 41 | "*.woff2", |
| 42 | "*.eot", |
| 43 | "*.cur", |
| 44 | "*.avi", |
| 45 | "*.mpg", |
| 46 | "*.mpeg", |
| 47 | "*.mov", |
| 48 | "*.mp3", |
| 49 | "*.mp4", |
| 50 | "*.mkv", |
| 51 | "*.mkv", |
| 52 | "*.webm", |
| 53 | "*.jar", |
| 54 | "*.onnx", |
| 55 | "*.parquet", |
| 56 | "*.pqt", |
| 57 | "*.wav", |
| 58 | "*.webp", |
| 59 | "*.db", |
| 60 | "*.sqlite", |
| 61 | "*.wasm", |
| 62 | "*.plist", |
| 63 | "*.profraw", |
| 64 | "*.gcda", |
| 65 | "*.gcno", |
| 66 | "go.sum", |
| 67 | "*.env", |
| 68 | "*.gitignore", |
| 69 | "*.gitkeep", |
| 70 | "*.continueignore", |
| 71 | "config.json", |
| 72 | "config.yaml", |
| 73 | "*.csv", |
| 74 | "*.uasset", |
| 75 | "*.pdb", |
| 76 | "*.bin", |
| 77 | "*.pag", |
| 78 | "*.swp", |
| 79 | "*.jsonl", |
| 80 | // "*.prompt", // can be incredibly confusing for the LLM to have another set of instructions injected into the prompt |
| 81 | ]; |
| 82 | |
| 83 | export const defaultIgnoreFile = ignore().add(DEFAULT_IGNORE_FILETYPES); |
| 84 | export const DEFAULT_IGNORE_DIRS = [ |
| 85 | ".git/", |
| 86 | ".svn/", |
| 87 | ".vscode/", |
| 88 | ".idea/", |
| 89 | ".vs/", |
| 90 | "venv/", |
| 91 | ".venv/", |
| 92 | "env/", |
| 93 | ".env/", |
| 94 | "node_modules/", |
| 95 | "dist/", |
| 96 | "build/", |
| 97 | "Build/", |
| 98 | "target/", |
| 99 | "out/", |
| 100 | "bin/", |
| 101 | ".pytest_cache/", |
| 102 | ".vscode-test/", |
| 103 | ".continue/", |
| 104 | "__pycache__/", |
| 105 | "site-packages/", |
| 106 | ".gradle/", |
| 107 | ".mvn/", |
| 108 | ".cache/", |
| 109 | "gems/", |
| 110 | "vendor/", |
| 111 | ]; |
| 112 | |
| 113 | export const defaultIgnoreDir = ignore().add(DEFAULT_IGNORE_DIRS); |
| 114 | |
| 115 | export const DEFAULT_IGNORE = |
| 116 | DEFAULT_IGNORE_FILETYPES.join("\n") + "\n" + DEFAULT_IGNORE_DIRS.join("\n"); |
| 117 | |
| 118 | export const defaultIgnoreFileAndDir = ignore() |
| 119 | .add(defaultIgnoreFile) |
| 120 | .add(defaultIgnoreDir); |
| 121 | |
| 122 | export function gitIgArrayFromFile(file: string) { |
| 123 | return file |
| 124 | .split(/\r?\n/) // Split on new line |
| 125 | .map((l) => l.trim()) // Remove whitespace |
| 126 | .filter((l) => !/^#|^$/.test(l)); // Remove empty lines |
| 127 | } |
| 128 | |
| 129 | export const getGlobalContinueIgArray = () => { |
| 130 | const contents = fs.readFileSync(getGlobalContinueIgnorePath(), "utf8"); |
| 131 | return gitIgArrayFromFile(contents); |
| 132 | }; |
| 133 | |
| 134 | export const getWorkspaceContinueIgArray = async (ide: IDE) => { |
| 135 | const dirs = await ide.getWorkspaceDirs(); |
| 136 | return await dirs.reduce( |
| 137 | async (accPromise, dir) => { |
| 138 | const acc = await accPromise; |
| 139 | try { |
| 140 | const contents = await ide.readFile(`${dir}/.continueignore`); |
| 141 | return [...acc, ...gitIgArrayFromFile(contents)]; |
| 142 | } catch (err) { |
| 143 | console.error(err); |
| 144 | return acc; |
| 145 | } |
| 146 | }, |
| 147 | Promise.resolve([] as string[]), |
| 148 | ); |
| 149 | }; |