feat(context): Introduce smart context system: analyzer, lazy loader, cache and README/docs improvements
This commit is contained in:
@@ -243,4 +243,68 @@ export class ContextTrimmer {
|
||||
...config
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Trim a file based on its importance tier
|
||||
* @param filePath The path to the file
|
||||
* @param content The file's contents
|
||||
* @param level The trimming level to apply ('none', 'light', 'aggressive')
|
||||
* @returns The trimmed file contents
|
||||
*/
|
||||
public trimFileWithLevel(
|
||||
filePath: string,
|
||||
content: string,
|
||||
level: 'none' | 'light' | 'aggressive'
|
||||
): string {
|
||||
// No trimming for essential files
|
||||
if (level === 'none') {
|
||||
return content;
|
||||
}
|
||||
|
||||
// Create a temporary config based on level
|
||||
const originalConfig = { ...this.config };
|
||||
|
||||
try {
|
||||
if (level === 'light') {
|
||||
// Light trimming: preserve signatures, remove only complex implementations
|
||||
this.config = {
|
||||
...this.config,
|
||||
removeImplementations: false,
|
||||
preserveInterfaces: true,
|
||||
preserveTypeDefs: true,
|
||||
preserveJSDoc: true,
|
||||
maxFunctionLines: 10,
|
||||
removeComments: false,
|
||||
removeBlankLines: true
|
||||
};
|
||||
} else if (level === 'aggressive') {
|
||||
// Aggressive trimming: remove all implementations, keep only signatures
|
||||
this.config = {
|
||||
...this.config,
|
||||
removeImplementations: true,
|
||||
preserveInterfaces: true,
|
||||
preserveTypeDefs: true,
|
||||
preserveJSDoc: true,
|
||||
maxFunctionLines: 3,
|
||||
removeComments: true,
|
||||
removeBlankLines: true
|
||||
};
|
||||
}
|
||||
|
||||
// Process based on file type
|
||||
let result = content;
|
||||
if (filePath.endsWith('.ts') || filePath.endsWith('.tsx')) {
|
||||
result = this.trimTypeScriptFile(content);
|
||||
} else if (filePath.endsWith('.md')) {
|
||||
result = this.trimMarkdownFile(content);
|
||||
} else if (filePath.endsWith('.json')) {
|
||||
result = this.trimJsonFile(content);
|
||||
}
|
||||
|
||||
return result;
|
||||
} finally {
|
||||
// Restore original config
|
||||
this.config = originalConfig;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user