optivise
Version:
Optivise - The Ultimate Optimizely Development Assistant with AI-powered features, zero-config setup, and comprehensive development support
35 lines • 1.53 kB
JavaScript
import { promises as fs } from 'fs';
import * as path from 'path';
export class PromptAwareSearchService {
logger;
constructor(logger) {
this.logger = logger;
}
async findMentionedArtifacts(root, entities) {
const results = [];
try {
// Search for file name matches in a shallow walk (non-recursive heavy), limited for perf
const items = await fs.readdir(root, { withFileTypes: true });
for (const item of items) {
const full = path.join(root, item.name);
if (item.isDirectory()) {
if (/src|app|extensions|modules|Controllers|Views|FrontEnd/i.test(item.name)) {
results.push({ path: full, type: 'directory', reason: 'likely source directory' });
}
continue;
}
if (entities.files?.some(f => item.name.toLowerCase().includes(path.basename(f).toLowerCase()))) {
results.push({ path: full, type: 'file', reason: 'mentioned in prompt' });
}
if (entities.classes?.some(c => item.name.includes(c))) {
results.push({ path: full, type: 'file', reason: 'class name match' });
}
}
}
catch (error) {
this.logger.debug?.('Prompt-aware search skipped (no workspace or access denied)');
}
return results.slice(0, 50);
}
}
//# sourceMappingURL=prompt-aware-search.js.map