Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
493 changes: 493 additions & 0 deletions current-errors.txt

Large diffs are not rendered by default.

76 changes: 76 additions & 0 deletions error-breakdown.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
107 Argument
67 The
59 Type
43 Expected
36 All
34 Property
23 'CacheEngine'
12 '_tokenCounter'
10 Module
5 'tokenCounter'
5 'compact'
4 Operator
4 'createHash'
4 Cannot
3 'projectRoot'
3 'path'
3 Block-scoped
3 '_metrics'
2 'metrics'
2 Could
2 '_stat'
2 '_reductionPercentage'
2 '_readdir'
2 '_pipelineAsync'
2 '_mkdir'
2 '_dnsResolve'
2 '"fs"'
2 '"../../core/token-counter"'
1 'zlib'
1 'writeFileSync'
1 'unparseCsv'
1 'ts'
1 'TokenCounter'
1 'tarStream'
1 'tar'
1 'SymbolInfo'
1 'stats'
1 'si'
1 'relationships'
1 'parseYAML'
1 'parsePatch'
1 'nlp'
1 'net'
1 'mkdirSync'
1 'MetricsCollector'
1 'includeMetadata'
1 'hash'
1 'grammarCache'
1 'getDefaultTTL'
1 'fs'
1 'existsSync'
1 'diffWords'
1 'diffLines'
1 'diffChars'
1 'DeltaState'
1 'crypto'
1 'createTwoFilesPatch'
1 'ComplexityMetrics'
1 'CacheEngineClass'
1 '_unlink'
1 '_symbolsResult'
1 '_stdout'
1 '_size'
1 '_rmdir'
1 '_rename'
1 '_projectRoot'
1 '_markAsIgnored'
1 '_fileDir'
1 '_execAsync'
1 '_dnsReverse'
1 '_dnsResolve6'
1 '_dnsResolve4'
1 '_dnsLookup'
1 '_coAccessPatterns'
1 '_cachedResult'
1 '_access'
198 changes: 52 additions & 146 deletions fix-cache-set-syntax.cjs
Original file line number Diff line number Diff line change
@@ -1,171 +1,77 @@
#!/usr/bin/env node
/**
* Fix malformed cache.set() calls created by previous regex script
*
* The previous fix-migrated-tools.cjs created syntax errors like:
* cache.set(key, value, BAD SYNTAX)
*
* This needs to be:
* cache.set(key, value, originalSize, compressedSize)
*
* Strategy:
* 1. Find all cache.set() calls with malformed syntax
* 2. Extract actual values for originalSize and compressedSize
* 3. Reconstruct proper call
*/

const fs = require('fs');
const path = require('path');
const { execSync } = require('child_process');

// Find all TypeScript files in src/tools
function findToolFiles(dir, files = []) {
const entries = fs.readdirSync(dir, { withFileTypes: true });

for (const entry of entries) {
const fullPath = path.join(dir, entry.name);
if (entry.isDirectory()) {
findToolFiles(fullPath, files);
} else if (entry.isFile() && entry.name.endsWith('.ts')) {
files.push(fullPath);
}
}
console.log('Getting list of syntax errors from build...');

return files;
}

/**
* Fix cache.set() syntax errors
*
* Patterns to fix:
* 1. cache.set calls with malformed parameter comments
* 2. cache.set calls with wrong parameters
*/
function fixCacheSetSyntax(content, filePath) {
let fixed = content;
let changesMade = false;

// Pattern 1: Remove malformed syntax with duration label and fix parameters
// Example: cache.set with bad comment syntax
const pattern1 = /this\.cache\.set\(\s*([^,]+),\s*([^,]+),\s*(?:duration:\s*)?([^\/,]+)\s*\/\*\s*originalSize\s*\*\/\s*,\s*([^)]+)\s*\/\*\s*compressedSize\s*\*\/\s*\)/g;

fixed = fixed.replace(pattern1, (match, key, value, param3, param4) => {
changesMade = true;

// Extract actual variable names from param3 and param4
const originalSize = param3.trim();
const compressedSize = param4.trim();

console.log(` Fixing: ${match.substring(0, 80)}...`);
console.log(` Key: ${key.trim()}`);
console.log(` Value: ${value.trim()}`);
console.log(` OriginalSize: ${originalSize}`);
console.log(` CompressedSize: ${compressedSize}`);

return `this.cache.set(${key}, ${value}, ${originalSize}, ${compressedSize})`;
let buildOutput;
try {
buildOutput = execSync('npm run build 2>&1', {
cwd: __dirname,
encoding: 'utf-8',
maxBuffer: 10 * 1024 * 1024
});
} catch (error) {
buildOutput = error.stdout || error.output.join('');
}

// Pattern 2: Fix any remaining malformed cache.set() with comments in wrong places
// Example: cache.set with label syntax
const pattern2 = /this\.cache\.set\(\s*([^,]+),\s*([^,]+),\s*([^:;,]+):\s*([^)]+)\s*\)/g;

fixed = fixed.replace(pattern2, (match, key, value, label, rest) => {
changesMade = true;
console.log(` Fixing labeled parameter: ${match.substring(0, 80)}...`);

// This pattern indicates broken syntax - we need context to fix it properly
// For now, mark it for manual review
return `this.cache.set(${key}, ${value}, 0, 0) /* FIXME: Manual review needed */`;
});
const lines = buildOutput.split('\n');
const errorFiles = new Set();

// Pattern 3: Fix cache.set() calls with only 2 parameters (missing originalSize and compressedSize)
const pattern3 = /this\.cache\.set\(\s*([^,]+),\s*([^,)]+)\s*\);/g;

// Only fix if the match doesn't have 4 parameters already
fixed = fixed.replace(pattern3, (match, key, value) => {
// Check if this is actually a 2-parameter call or if it's just a formatting issue
const fullMatch = match.trim();
if (!fullMatch.includes('/*') && fullMatch.split(',').length === 2) {
changesMade = true;
console.log(` Adding missing parameters to: ${match.substring(0, 60)}...`);
return `this.cache.set(${key}, ${value}, 0, 0) /* FIXME: Add originalSize and compressedSize */`;
}
return match;
});
lines.forEach(line => {
const cleanLine = line.replace(/\r/g, '');
const syntaxMatch = cleanLine.match(/^(.+\.ts)\(\d+,\d+\): error TS1(005|109|134|128):/);
if (syntaxMatch) {
errorFiles.add(syntaxMatch[1]);
}
});

return { fixed, changesMade };
}
console.log(`Found ${errorFiles.size} files with syntax errors`);

/**
* Analyze file to understand cache.set() context
*/
function analyzeFileContext(content, filePath) {
const lines = content.split('\n');
const cacheSetLines = [];

lines.forEach((line, index) => {
if (line.includes('cache.set')) {
cacheSetLines.push({
line: index + 1,
content: line.trim(),
context: lines.slice(Math.max(0, index - 3), Math.min(lines.length, index + 3))
});
}
});
let filesModified = 0;

return cacheSetLines;
}
for (const relativeFilePath of errorFiles) {
const filePath = path.join(__dirname, relativeFilePath);

// Main processing
function processFile(filePath) {
const relativePath = path.relative(process.cwd(), filePath);
if (!fs.existsSync(filePath)) {
console.log(`Skipping ${relativeFilePath} - file not found`);
continue;
}

let content = fs.readFileSync(filePath, 'utf-8');
const original = content;
const originalContent = content;

// Analyze context first
const cacheSetCalls = analyzeFileContext(content, filePath);
// Fix: JSON.stringify(data), "utf-8"), -> JSON.stringify(data),
content = content.replace(/JSON\.stringify\(([^)]+)\),\s*"utf-8"\),/g, 'JSON.stringify($1),');

if (cacheSetCalls.length > 0) {
console.log(`\n${relativePath} - ${cacheSetCalls.length} cache.set() calls found`);
// Fix: variable), "utf-8"), -> variable,
content = content.replace(/([a-zA-Z_$][a-zA-Z0-9_$]*)\),\s*"utf-8"\),/g, '$1,');

// Apply fixes
const { fixed, changesMade } = fixCacheSetSyntax(content, filePath);
// Fix: JSON.stringify(data)), -> JSON.stringify(data),
content = content.replace(/JSON\.stringify\(([^)]+)\)\),/g, 'JSON.stringify($1),');

// Only write if changes were made
if (changesMade && fixed !== original) {
fs.writeFileSync(filePath, fixed, 'utf-8');
console.log(` ✓ Fixed and saved`);
return true;
} else if (cacheSetCalls.length > 0) {
console.log(` - No auto-fix applied (may need manual review)`);
}
}

return false;
}
// Fix: variable)), -> variable,
content = content.replace(/([a-zA-Z_$][a-zA-Z0-9_$]*)\)\),/g, '$1,');

// Run
const toolsDir = path.join(__dirname, 'src', 'tools');
// Fix: JSON.stringify(data), 'utf-8'); -> JSON.stringify(data);
content = content.replace(/JSON\.stringify\(([^)]+)\),\s*['"]utf-8['"]?\);/g, 'JSON.stringify($1);');

if (!fs.existsSync(toolsDir)) {
console.error(`Error: ${toolsDir} not found`);
process.exit(1);
}
// Fix: variable), 'utf-8'); -> variable;
content = content.replace(/([a-zA-Z_$][a-zA-Z0-9_$]*)\),\s*['"]utf-8['"]?\);/g, '$1);');

const files = findToolFiles(toolsDir);
// Fix: JSON.stringify(data)); -> JSON.stringify(data);
content = content.replace(/JSON\.stringify\(([^)]+)\)\);/g, 'JSON.stringify($1);');

console.log(`Analyzing ${files.length} tool files for cache.set() syntax errors...\n`);
// Fix: variable)); -> variable;
content = content.replace(/\b([a-zA-Z_$][a-zA-Z0-9_$]*)\)\);/g, '$1);');

let fixedCount = 0;
for (const file of files) {
try {
if (processFile(file)) {
fixedCount++;
}
} catch (error) {
console.error(` ✗ Error processing ${file}: ${error.message}`);
if (content !== originalContent) {
fs.writeFileSync(filePath, content, 'utf-8');
filesModified++;
console.log(`✓ ${relativeFilePath}: Fixed syntax errors`);
}
}

console.log(`\n✓ Fixed cache.set() syntax in ${fixedCount} files out of ${files.length}`);
console.log(`\nNext: Run 'npm run build' to verify TypeScript compilation`);
console.log(`\n✅ Summary:`);
console.log(` Files modified: ${filesModified}`);
console.log(`\nRun 'npm run build' to verify all syntax errors are fixed.`);
Loading