ai-cmg 0.1.4 → 0.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.
- package/dist/index.js +57 -4
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -23,7 +23,7 @@ const LOCK_FILES = new Set([
|
|
|
23
23
|
const GENERATED_PREFIXES = ['dist/', 'build/', '.next/', 'coverage/', 'node_modules/'];
|
|
24
24
|
const MAX_BLOCK_LINES = 400;
|
|
25
25
|
const MAX_BLOCK_CHARS = 20000;
|
|
26
|
-
const MAX_INPUT_CHARS =
|
|
26
|
+
const MAX_INPUT_CHARS = 60000;
|
|
27
27
|
function getPackageVersion() {
|
|
28
28
|
try {
|
|
29
29
|
const currentFile = fileURLToPath(import.meta.url);
|
|
@@ -378,10 +378,63 @@ function limitDiffSize(diff) {
|
|
|
378
378
|
if (diff.length <= MAX_INPUT_CHARS) {
|
|
379
379
|
return { diff, truncated: false };
|
|
380
380
|
}
|
|
381
|
-
|
|
381
|
+
// Split by file blocks to preserve context - keep file boundaries intact
|
|
382
|
+
const blocks = diff.split(/^diff --git /m);
|
|
383
|
+
const keptBlocks = [];
|
|
384
|
+
const truncatedFiles = [];
|
|
385
|
+
let currentLength = 0;
|
|
386
|
+
let isFirstBlock = true;
|
|
387
|
+
// Preserve existing summary header if present
|
|
388
|
+
const headerMatch = diff.match(/^(# Omitted file contents \(summarized\)\n.+?\n\n)/s);
|
|
389
|
+
if (headerMatch) {
|
|
390
|
+
const header = headerMatch[1];
|
|
391
|
+
keptBlocks.push(header.trim());
|
|
392
|
+
currentLength = header.length;
|
|
393
|
+
isFirstBlock = false;
|
|
394
|
+
}
|
|
395
|
+
for (const block of blocks) {
|
|
396
|
+
if (!block.trim())
|
|
397
|
+
continue;
|
|
398
|
+
const headerLine = block.split('\n')[0] ?? '';
|
|
399
|
+
const match = headerLine.match(/^a\/(.+?) b\/(.+?)$/);
|
|
400
|
+
const fullBlock = isFirstBlock ? block : `diff --git ${block}`;
|
|
401
|
+
const blockLength = fullBlock.length;
|
|
402
|
+
isFirstBlock = false;
|
|
403
|
+
if (match) {
|
|
404
|
+
const aPath = match[1];
|
|
405
|
+
const bPath = match[2];
|
|
406
|
+
const filePath = bPath === '/dev/null' ? aPath : bPath;
|
|
407
|
+
// Check if this block is already summarized (from summarizeDiff)
|
|
408
|
+
const isAlreadySummarized = fullBlock.includes('# content omitted');
|
|
409
|
+
// Check if adding this block would exceed limit
|
|
410
|
+
if (!isAlreadySummarized && currentLength + blockLength > MAX_INPUT_CHARS) {
|
|
411
|
+
// Truncate: replace full diff with summary
|
|
412
|
+
truncatedFiles.push({ path: filePath });
|
|
413
|
+
const summaryBlock = `diff --git a/${aPath} b/${bPath}\n# content truncated due to size limit\n`;
|
|
414
|
+
keptBlocks.push(summaryBlock);
|
|
415
|
+
currentLength += summaryBlock.length;
|
|
416
|
+
}
|
|
417
|
+
else {
|
|
418
|
+
// Include full block (either fits, or already summarized)
|
|
419
|
+
keptBlocks.push(fullBlock);
|
|
420
|
+
currentLength += blockLength;
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
else {
|
|
424
|
+
// Non-file block (should be rare), include if space allows
|
|
425
|
+
if (currentLength + blockLength <= MAX_INPUT_CHARS) {
|
|
426
|
+
keptBlocks.push(fullBlock);
|
|
427
|
+
currentLength += blockLength;
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
// Add summary of truncated files if any
|
|
432
|
+
const truncatedSummary = truncatedFiles.length > 0
|
|
433
|
+
? `\n\n# Additional files truncated due to size limit (${truncatedFiles.length} file${truncatedFiles.length > 1 ? 's' : ''})\n${truncatedFiles.map(f => `- ${f.path}`).join('\n')}`
|
|
434
|
+
: '';
|
|
382
435
|
return {
|
|
383
|
-
diff: `${
|
|
384
|
-
truncated:
|
|
436
|
+
diff: `${keptBlocks.join('\n')}${truncatedSummary}`.trim(),
|
|
437
|
+
truncated: truncatedFiles.length > 0
|
|
385
438
|
};
|
|
386
439
|
}
|
|
387
440
|
async function main() {
|