UNPKG

vibe-coder-mcp

Version:

Production-ready MCP server with complete agent integration, multi-transport support, and comprehensive development automation tools for AI-assisted workflows.

88 lines (87 loc) 2.72 kB
import fs from 'fs-extra'; import path from 'path'; import os from 'os'; export class CommandHistory { history = []; currentIndex = -1; maxSize; historyFile; tempCommand = ''; constructor(maxSize = 100, historyFile) { this.maxSize = maxSize; this.historyFile = historyFile || path.join(os.homedir(), '.vibe', 'history.txt'); this.loadHistory(); } async loadHistory() { try { if (await fs.pathExists(this.historyFile)) { const content = await fs.readFile(this.historyFile, 'utf-8'); this.history = content.split('\n').filter(line => line.trim()); if (this.history.length > this.maxSize) { this.history = this.history.slice(-this.maxSize); } this.currentIndex = this.history.length; } } catch { } } async saveHistory() { try { await fs.ensureDir(path.dirname(this.historyFile)); await fs.writeFile(this.historyFile, this.history.join('\n')); } catch { } } add(command) { if (command && command.trim()) { if (this.history.length === 0 || this.history[this.history.length - 1] !== command) { this.history.push(command); if (this.history.length > this.maxSize) { this.history.shift(); } } this.currentIndex = this.history.length; this.tempCommand = ''; this.saveHistory().catch(() => { }); } } getPrevious(currentInput) { if (this.currentIndex === this.history.length && currentInput) { this.tempCommand = currentInput; } if (this.currentIndex > 0) { this.currentIndex--; return this.history[this.currentIndex]; } return undefined; } getNext() { if (this.currentIndex < this.history.length - 1) { this.currentIndex++; return this.history[this.currentIndex]; } else if (this.currentIndex === this.history.length - 1) { this.currentIndex = this.history.length; return this.tempCommand; } return ''; } resetPosition() { this.currentIndex = this.history.length; this.tempCommand = ''; } getAll() { return [...this.history]; } clear() { this.history = []; this.currentIndex = -1; this.tempCommand = ''; this.saveHistory().catch(() => { }); } search(query) { return this.history.filter(cmd => cmd.includes(query)); } }