openmagic 0.33.1 → 0.33.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -189,13 +189,14 @@ function writeFileSafe(filePath, content, roots) {
189
189
  return { ok: false, error: `Failed to write file: ${e.message}` };
190
190
  }
191
191
  }
192
+ var MAX_LIST_ENTRIES = 2e3;
192
193
  function listFiles(rootPath, roots, maxDepth = 4) {
193
194
  if (!isPathSafe(rootPath, roots)) {
194
195
  return [];
195
196
  }
196
197
  const entries = [];
197
198
  function walk(dir, depth) {
198
- if (depth > maxDepth) return;
199
+ if (depth > maxDepth || entries.length >= MAX_LIST_ENTRIES) return;
199
200
  let items;
200
201
  try {
201
202
  items = readdirSync(dir);
@@ -203,6 +204,7 @@ function listFiles(rootPath, roots, maxDepth = 4) {
203
204
  return;
204
205
  }
205
206
  for (const item of items) {
207
+ if (entries.length >= MAX_LIST_ENTRIES) return;
206
208
  if (IGNORED_DIRS.has(item)) continue;
207
209
  if (item.startsWith(".") && item !== ".env.example") continue;
208
210
  const fullPath = join2(dir, item);
@@ -251,12 +253,15 @@ var GREP_EXTENSIONS = /* @__PURE__ */ new Set([
251
253
  ".py",
252
254
  ".rb"
253
255
  ]);
256
+ var MAX_GREP_FILE_SIZE = 256 * 1024;
257
+ var MAX_GREP_FILES_SCANNED = 500;
254
258
  function grepFiles(pattern, searchRoot, roots, maxResults = 30) {
255
259
  if (!isPathSafe(searchRoot, roots)) return [];
256
260
  const results = [];
257
261
  const lowerPattern = pattern.toLowerCase();
262
+ let filesScanned = 0;
258
263
  function walk(dir, depth) {
259
- if (depth > 5 || results.length >= maxResults) return;
264
+ if (depth > 6 || results.length >= maxResults || filesScanned >= MAX_GREP_FILES_SCANNED) return;
260
265
  let items;
261
266
  try {
262
267
  items = readdirSync(dir);
@@ -264,7 +269,7 @@ function grepFiles(pattern, searchRoot, roots, maxResults = 30) {
264
269
  return;
265
270
  }
266
271
  for (const item of items) {
267
- if (results.length >= maxResults) return;
272
+ if (results.length >= maxResults || filesScanned >= MAX_GREP_FILES_SCANNED) return;
268
273
  if (IGNORED_DIRS.has(item) || item.startsWith(".") && item !== ".env.example") continue;
269
274
  const fullPath = join2(dir, item);
270
275
  let stat;
@@ -279,6 +284,8 @@ function grepFiles(pattern, searchRoot, roots, maxResults = 30) {
279
284
  } else if (stat.isFile()) {
280
285
  const ext = extname(item).toLowerCase();
281
286
  if (!GREP_EXTENSIONS.has(ext)) continue;
287
+ if (stat.size > MAX_GREP_FILE_SIZE) continue;
288
+ filesScanned++;
282
289
  try {
283
290
  const content = readFileSync2(fullPath, "utf-8");
284
291
  const lines = content.split("\n");