context-squeezer-cli 1.0.1 → 1.0.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/ignorer.js +1 -7
- package/dist/packager.js +2 -15
- package/package.json +1 -1
package/dist/ignorer.js
CHANGED
|
@@ -10,7 +10,6 @@ const DEFAULT_IGNORES = [
|
|
|
10
10
|
'build',
|
|
11
11
|
'.DS_Store'
|
|
12
12
|
];
|
|
13
|
-
// Kuralları çalışma zamanında hafızada tutacak önbellek mekanizması
|
|
14
13
|
let cachedCustomRules = null;
|
|
15
14
|
/**
|
|
16
15
|
* Projenin kök dizinindeki .aiignore dosyasını sadece bir kez okuyarak belleğe alır.
|
|
@@ -43,25 +42,20 @@ function loadCustomIgnoreRules(projectRoot) {
|
|
|
43
42
|
* @param projectRoot Projenin ana çalışma dizini
|
|
44
43
|
*/
|
|
45
44
|
export function shouldIgnore(filePath, projectRoot) {
|
|
46
|
-
// Windows'taki \ işaretlerini / işaretine çevirerek yolları normalize ediyoruz
|
|
47
45
|
const relativePath = path.relative(projectRoot, filePath).replace(/\\/g, '/');
|
|
48
46
|
const parts = relativePath.split('/');
|
|
49
|
-
// 1. Çıktı ve test dosyalarının kendi kendini taramasını engeller
|
|
50
47
|
const file = path.basename(filePath);
|
|
51
48
|
if (file.endsWith('.txt') && (file === 'ai_context.txt' || file === 'kodlarim.txt' || file === 'test_output.txt')) {
|
|
52
49
|
return true;
|
|
53
50
|
}
|
|
54
|
-
// 2. Varsayılan global engelleme listesi kontrolü
|
|
55
51
|
if (parts.some(part => DEFAULT_IGNORES.includes(part))) {
|
|
56
52
|
return true;
|
|
57
53
|
}
|
|
58
|
-
// 3. Kullanıcı tanımlı .aiignore kurallarının kontrolü
|
|
59
54
|
const customRules = loadCustomIgnoreRules(projectRoot);
|
|
60
55
|
for (const rule of customRules) {
|
|
61
|
-
// .aiignore içindeki olası Windows yollarını da normalize et
|
|
62
56
|
const normalizedRule = rule.replace(/\\/g, '/');
|
|
63
57
|
if (normalizedRule.startsWith('*.')) {
|
|
64
|
-
const ext = normalizedRule.slice(1);
|
|
58
|
+
const ext = normalizedRule.slice(1);
|
|
65
59
|
if (filePath.endsWith(ext))
|
|
66
60
|
return true;
|
|
67
61
|
}
|
package/dist/packager.js
CHANGED
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
import * as fs from 'fs';
|
|
2
2
|
import * as path from 'path';
|
|
3
3
|
import { shouldIgnore } from './ignorer.js';
|
|
4
|
-
// Güvenli işleme için maksimum dosya boyutu sınırı (Örn: 500 KB)
|
|
5
4
|
const MAX_FILE_SIZE_BYTES = 500 * 1024;
|
|
6
|
-
/**
|
|
7
|
-
* Bir dosyanın ikili (binary) olup olmadığını ilk byte bloklarını tarayarak kontrol eder.
|
|
8
|
-
* @param filePath Denetlenecek dosyanın tam yolu
|
|
9
|
-
*/
|
|
10
5
|
function isBinaryFile(filePath) {
|
|
11
6
|
const buffer = Buffer.alloc(512);
|
|
12
7
|
let fd = null;
|
|
@@ -14,7 +9,6 @@ function isBinaryFile(filePath) {
|
|
|
14
9
|
fd = fs.openSync(filePath, 'r');
|
|
15
10
|
const bytesRead = fs.readSync(fd, buffer, 0, 512, 0);
|
|
16
11
|
for (let i = 0; i < bytesRead; i++) {
|
|
17
|
-
// Null karakteri (\0) kontrolü ikili dosyaları tespit etmek için en güvenli yöntemdir
|
|
18
12
|
if (buffer[i] === 0) {
|
|
19
13
|
return true;
|
|
20
14
|
}
|
|
@@ -22,7 +16,7 @@ function isBinaryFile(filePath) {
|
|
|
22
16
|
return false;
|
|
23
17
|
}
|
|
24
18
|
catch (err) {
|
|
25
|
-
return true;
|
|
19
|
+
return true;
|
|
26
20
|
}
|
|
27
21
|
finally {
|
|
28
22
|
if (fd !== null) {
|
|
@@ -30,9 +24,6 @@ function isBinaryFile(filePath) {
|
|
|
30
24
|
}
|
|
31
25
|
}
|
|
32
26
|
}
|
|
33
|
-
/**
|
|
34
|
-
* Kod içindeki hassas şifre, token ve API anahtarlarını sansürler
|
|
35
|
-
*/
|
|
36
27
|
function maskSensitiveData(content) {
|
|
37
28
|
const sensitivePatterns = [
|
|
38
29
|
/(secret[-_]?key|api[-_]?key|password|passwd|auth[-_]?token|client[-_]?secret)\s*[:=]\s*['"`][^'"`]{4,200}['"`]/gi,
|
|
@@ -65,8 +56,6 @@ export function packProject(dirPath) {
|
|
|
65
56
|
for (const file of files) {
|
|
66
57
|
const fullPath = path.join(currentDir, file);
|
|
67
58
|
const stat = fs.statSync(fullPath);
|
|
68
|
-
// Modüler kontrol: Dosya veya klasörün engellenip engellenmeyeceğini kontrol eder
|
|
69
|
-
// (Çıktı .txt dosyaları da artık tamamen ignorer.ts içinde yakalanıyor)
|
|
70
59
|
if (shouldIgnore(fullPath, dirPath)) {
|
|
71
60
|
continue;
|
|
72
61
|
}
|
|
@@ -75,12 +64,10 @@ export function packProject(dirPath) {
|
|
|
75
64
|
}
|
|
76
65
|
else if (stat.isFile()) {
|
|
77
66
|
const relativePath = path.relative(dirPath, fullPath);
|
|
78
|
-
// PERFORMANS & GÜVENLİK: Belirlenen boyuttan büyük dosyaları atlar
|
|
79
67
|
if (stat.size > MAX_FILE_SIZE_BYTES) {
|
|
80
68
|
console.warn(`⚠️ Skipped large file (over 500KB): ${relativePath}`);
|
|
81
69
|
continue;
|
|
82
70
|
}
|
|
83
|
-
// GÜVENLİK: İkili (Resim, PDF, Derlenmiş Dosya vb.) içerikleri filtreler
|
|
84
71
|
if (isBinaryFile(fullPath)) {
|
|
85
72
|
continue;
|
|
86
73
|
}
|
|
@@ -95,7 +82,7 @@ export function packProject(dirPath) {
|
|
|
95
82
|
combinedContent += `\n--- END OF FILE: ${relativePath} ---\n`;
|
|
96
83
|
}
|
|
97
84
|
catch (e) {
|
|
98
|
-
//
|
|
85
|
+
// Hata durumunda es geç
|
|
99
86
|
}
|
|
100
87
|
}
|
|
101
88
|
}
|