@hakkisagdic/context-manager
Version:
Universal LLM context manager supporting 14+ languages with method-level filtering, token optimization, and GitIngest format support
51 lines (42 loc) • 1.67 kB
JavaScript
/**
* Method Filter Parser
* Parses .methodinclude and .methodignore files for method-level filtering
*/
const fs = require('fs');
class MethodFilterParser {
constructor(methodIncludePath, methodIgnorePath) {
this.includePatterns = [];
this.ignorePatterns = [];
this.hasIncludeFile = false;
if (methodIncludePath && fs.existsSync(methodIncludePath)) {
this.includePatterns = this.parseMethodFile(methodIncludePath);
this.hasIncludeFile = true;
console.log(`🔧 Method include rules loaded: ${this.includePatterns.length} patterns`);
}
if (methodIgnorePath && fs.existsSync(methodIgnorePath)) {
this.ignorePatterns = this.parseMethodFile(methodIgnorePath);
console.log(`🚫 Method ignore rules loaded: ${this.ignorePatterns.length} patterns`);
}
}
parseMethodFile(filePath) {
return fs.readFileSync(filePath, 'utf8')
.split('\n')
.map(line => line.trim())
.filter(line => line && !line.startsWith('#'))
.map(pattern => ({
pattern: pattern,
regex: new RegExp(pattern.replace(/\*/g, '.*'), 'i')
}));
}
shouldIncludeMethod(methodName, fileName) {
if (this.hasIncludeFile) {
return this.includePatterns.some(p =>
p.regex.test(methodName) || p.regex.test(`${fileName}.${methodName}`)
);
}
return !this.ignorePatterns.some(p =>
p.regex.test(methodName) || p.regex.test(`${fileName}.${methodName}`)
);
}
}
module.exports = MethodFilterParser;