@optiqcode/cli 2.1.3 → 2.1.5

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.
Files changed (2) hide show
  1. package/dist/index.js +23 -15
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -273,17 +273,24 @@ async function indexOnce(targetPath, config) {
273
273
  spinner.text = `Reading ${files.length} files...`;
274
274
  // Read files in parallel (100 at a time)
275
275
  const PARALLEL_READS = 100;
276
+ const MAX_FILE_SIZE = 100_000; // 100KB max per file
276
277
  const filesArray = [];
277
278
  for (let i = 0; i < files.length; i += PARALLEL_READS) {
278
279
  const chunk = files.slice(i, i + PARALLEL_READS);
279
280
  const results = await Promise.allSettled(chunk.map(async (file) => {
280
281
  const content = await fs.readFile(file, 'utf-8');
281
282
  const relativePath = path.relative(targetPath, file).replace(/\\/g, '/');
283
+ // Skip files that are too large
284
+ if (content.length > MAX_FILE_SIZE) {
285
+ if (DEBUG)
286
+ console.log(chalk.yellow(`[DEBUG] Skipping large file: ${relativePath} (${Math.round(content.length / 1024)}KB)`));
287
+ return null;
288
+ }
282
289
  return { path: relativePath, content };
283
290
  }));
284
- // Filter successful reads
291
+ // Filter successful reads (and non-null)
285
292
  for (const result of results) {
286
- if (result.status === 'fulfilled') {
293
+ if (result.status === 'fulfilled' && result.value) {
287
294
  filesArray.push(result.value);
288
295
  }
289
296
  }
@@ -292,7 +299,7 @@ async function indexOnce(targetPath, config) {
292
299
  // Generate repository ID from path
293
300
  const repoId = generateRepoId(targetPath);
294
301
  // Upload in small batches to avoid gateway timeouts
295
- const BATCH_SIZE = 10;
302
+ const BATCH_SIZE = 5;
296
303
  let totalChunks = 0;
297
304
  if (DEBUG) {
298
305
  console.log(chalk.gray(`\n[DEBUG] Sending to: ${ENGINE_URL}/api/v1/index`));
@@ -321,7 +328,7 @@ async function indexOnce(targetPath, config) {
321
328
  headers: {
322
329
  'Content-Type': 'application/json',
323
330
  },
324
- timeout: 120000, // 2 minute timeout per batch
331
+ timeout: 120000,
325
332
  });
326
333
  if (!response.data.success) {
327
334
  spinner.fail(chalk.red('Indexing failed'));
@@ -329,20 +336,18 @@ async function indexOnce(targetPath, config) {
329
336
  return;
330
337
  }
331
338
  totalChunks += response.data.result?.chunks_created || 0;
332
- break; // Success, exit retry loop
339
+ break;
333
340
  }
334
341
  catch (err) {
335
342
  lastError = err;
336
343
  retries--;
337
- if (DEBUG) {
338
- console.log(chalk.red(`\n[DEBUG] Error: ${err.code || err.message}`));
339
- if (err.response) {
340
- console.log(chalk.red(`[DEBUG] Status: ${err.response.status}`));
341
- }
342
- }
344
+ // Always log which files failed
345
+ console.log(chalk.red(`\n Batch ${batchNum} failed: ${err.code || err.message}`));
346
+ console.log(chalk.yellow(` Files in batch: ${batch.map(f => f.path).join(', ')}`));
347
+ console.log(chalk.gray(` Sizes: ${batch.map(f => `${f.path}(${Math.round(f.content.length / 1024)}KB)`).join(', ')}`));
343
348
  if (retries > 0) {
344
- spinner.text = `Retrying batch ${batchNum}... (${retries} attempts left)`;
345
- await new Promise(r => setTimeout(r, 2000)); // Wait 2s before retry
349
+ console.log(chalk.gray(` Retrying... (${retries} left)`));
350
+ await new Promise(r => setTimeout(r, 2000));
346
351
  }
347
352
  }
348
353
  }
@@ -376,23 +381,26 @@ async function watchDirectory(targetPath, config) {
376
381
  spinner.text = `Reading ${files.length} files...`;
377
382
  // Read files in parallel (100 at a time)
378
383
  const PARALLEL_READS = 100;
384
+ const MAX_FILE_SIZE = 100_000; // 100KB max per file
379
385
  const filesArray = [];
380
386
  for (let i = 0; i < files.length; i += PARALLEL_READS) {
381
387
  const chunk = files.slice(i, i + PARALLEL_READS);
382
388
  const results = await Promise.allSettled(chunk.map(async (file) => {
383
389
  const content = await fs.readFile(file, 'utf-8');
384
390
  const relativePath = path.relative(targetPath, file).replace(/\\/g, '/');
391
+ if (content.length > MAX_FILE_SIZE)
392
+ return null;
385
393
  return { path: relativePath, content };
386
394
  }));
387
395
  for (const result of results) {
388
- if (result.status === 'fulfilled') {
396
+ if (result.status === 'fulfilled' && result.value) {
389
397
  filesArray.push(result.value);
390
398
  }
391
399
  }
392
400
  spinner.text = `Reading... ${Math.min(i + PARALLEL_READS, files.length)}/${files.length}`;
393
401
  }
394
402
  // Upload in small batches to avoid gateway timeouts
395
- const BATCH_SIZE = 20;
403
+ const BATCH_SIZE = 5;
396
404
  for (let i = 0; i < filesArray.length; i += BATCH_SIZE) {
397
405
  const batch = filesArray.slice(i, i + BATCH_SIZE);
398
406
  const batchNum = Math.floor(i / BATCH_SIZE) + 1;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optiqcode/cli",
3
- "version": "2.1.3",
3
+ "version": "2.1.5",
4
4
  "description": "CLI tool for Optiq - automatic code indexing and context engine",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",