hikma-engine
Version:
Code Knowledge Graph Indexer - A sophisticated TypeScript-based indexer that transforms Git repositories into multi-dimensional knowledge stores for AI agents
67 lines (66 loc) • 2.54 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.IndexingStrategy = void 0;
const git_analyzer_1 = require("../../modules/git-analyzer");
const error_handling_1 = require("../../utils/error-handling");
class IndexingStrategy {
constructor(projectRoot, config, logger) {
this.gitAnalyzer = new git_analyzer_1.GitAnalyzer(projectRoot, config);
this.logger = logger;
}
async determine(forceFullIndex) {
try {
const currentCommitHash = await this.gitAnalyzer.getCurrentCommitHash();
if (forceFullIndex) {
this.logger.info('Force full index requested');
return {
isIncremental: false,
lastCommitHash: null,
currentCommitHash,
changedFiles: [],
};
}
const lastCommitHash = await this.gitAnalyzer.getLastIndexedCommit();
if (!lastCommitHash || !currentCommitHash) {
this.logger.info('No previous index found, using full indexing');
return {
isIncremental: false,
lastCommitHash: null,
currentCommitHash,
changedFiles: [],
};
}
if (lastCommitHash === currentCommitHash) {
this.logger.info('No new commits since last indexing');
return {
isIncremental: true,
lastCommitHash,
currentCommitHash,
changedFiles: [],
};
}
const changedFiles = await this.gitAnalyzer.getChangedFiles(lastCommitHash, currentCommitHash);
return {
isIncremental: true,
lastCommitHash,
currentCommitHash,
changedFiles,
};
}
catch (error) {
this.logger.warn('Failed to determine incremental strategy, falling back to full index', { error: (0, error_handling_1.getErrorMessage)(error) });
return {
isIncremental: false,
lastCommitHash: null,
currentCommitHash: null,
changedFiles: [],
};
}
}
async update(currentCommitHash) {
if (currentCommitHash) {
await this.gitAnalyzer.setLastIndexedCommit(currentCommitHash);
}
}
}
exports.IndexingStrategy = IndexingStrategy;
;