context-forge
Version:
AI orchestration platform with autonomous teams, enhancement planning, migration tools, 25+ slash commands, checkpoints & hooks. Multi-IDE: Claude, Cursor, Windsurf, Cline, Copilot
164 lines (159 loc) • 5.41 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.FileLogger = void 0;
const fs_extra_1 = __importDefault(require("fs-extra"));
const path_1 = __importDefault(require("path"));
const chalk_1 = __importDefault(require("chalk"));
class FileLogger {
constructor(rootPath) {
this.operations = [];
this.rootPath = rootPath;
this.logFilePath = path_1.default.join(rootPath, 'context-forge.log');
}
logOperation(operation) {
const relativePath = path_1.default.relative(this.rootPath, operation.filePath);
const fullOperation = {
...operation,
relativePath,
timestamp: new Date(),
};
this.operations.push(fullOperation);
// Log to console with actual file path
const symbol = this.getSymbol(operation.type);
const color = this.getColor(operation.type);
const message = `${symbol} ${color(relativePath)}`;
console.log(message);
if (operation.error) {
console.log(chalk_1.default.red(` Error: ${operation.error}`));
}
}
getSymbol(type) {
switch (type) {
case 'created':
return '✔';
case 'updated':
return '↻';
case 'skipped':
return '⊝';
case 'failed':
return '✗';
default:
return '•';
}
}
getColor(type) {
switch (type) {
case 'created':
return chalk_1.default.green;
case 'updated':
return chalk_1.default.blue;
case 'skipped':
return chalk_1.default.yellow;
case 'failed':
return chalk_1.default.red;
default:
return chalk_1.default.gray;
}
}
async writeLogFile() {
const logContent = this.generateLogContent();
await fs_extra_1.default.writeFile(this.logFilePath, logContent, 'utf-8');
}
generateLogContent() {
const timestamp = new Date().toISOString();
const summary = this.generateSummary();
let content = `# Context Forge Generation Log
Generated: ${timestamp}
## Summary
${summary}
## File Operations
`;
for (const operation of this.operations) {
content += `
### ${operation.type.toUpperCase()}: ${operation.relativePath}
- **Full Path**: ${operation.filePath}
- **Description**: ${operation.description}
- **Timestamp**: ${operation.timestamp.toISOString()}`;
if (operation.error) {
content += `
- **Error**: ${operation.error}`;
}
}
content += `
## Directory Structure Created
${this.generateDirectoryStructure()}
## Next Steps
1. Review the generated files above
2. Customize the configuration files as needed
3. Add project-specific documentation
4. Test the IDE integration
5. Begin development with enhanced AI assistance
---
Generated by Context Forge v${this.getVersion()}
`;
return content;
}
generateSummary() {
const counts = this.operations.reduce((acc, op) => {
acc[op.type] = (acc[op.type] || 0) + 1;
return acc;
}, {});
const total = this.operations.length;
const success = (counts.created || 0) + (counts.updated || 0);
const failed = counts.failed || 0;
const skipped = counts.skipped || 0;
return `- **Total Operations**: ${total}
- **Successfully Created/Updated**: ${success}
- **Failed**: ${failed}
- **Skipped**: ${skipped}
- **Success Rate**: ${total > 0 ? Math.round((success / total) * 100) : 0}%`;
}
generateDirectoryStructure() {
const dirs = new Set();
for (const operation of this.operations) {
if (operation.type === 'created' || operation.type === 'updated') {
const dir = path_1.default.dirname(operation.relativePath);
if (dir !== '.') {
dirs.add(dir);
}
}
}
const sortedDirs = Array.from(dirs).sort();
if (sortedDirs.length === 0) {
return '- No subdirectories created';
}
return sortedDirs.map((dir) => `- ${dir}/`).join('\n');
}
getVersion() {
try {
// Try to read package.json version
const packagePath = path_1.default.join(__dirname, '../../package.json');
const packageJson = JSON.parse(fs_extra_1.default.readFileSync(packagePath, 'utf-8'));
return packageJson.version || 'unknown';
}
catch {
return 'unknown';
}
}
getOperations() {
return [...this.operations];
}
getSummaryStats() {
const counts = this.operations.reduce((acc, op) => {
acc[op.type] = (acc[op.type] || 0) + 1;
return acc;
}, {});
return {
total: this.operations.length,
created: counts.created || 0,
updated: counts.updated || 0,
skipped: counts.skipped || 0,
failed: counts.failed || 0,
};
}
}
exports.FileLogger = FileLogger;
//# sourceMappingURL=fileLogger.js.map