vibe-coder-mcp
Version:
Production-ready MCP server with complete agent integration, multi-transport support, and comprehensive development automation tools for AI-assisted workflows.
94 lines (93 loc) • 2.93 kB
JavaScript
import chalk from 'chalk';
export class MultilineInput {
buffer = [];
isMultiline = false;
startDelimiter = '```';
endDelimiter = '```';
isStarting(line) {
return line.trim() === this.startDelimiter ||
line.trim() === '{' ||
line.trim() === '[' ||
line.endsWith(' \\');
}
isEnding(line) {
if (this.buffer.length > 0) {
const firstLine = this.buffer[0].trim();
if (firstLine === this.startDelimiter) {
return line.trim() === this.endDelimiter;
}
if (firstLine === '{') {
return line.trim() === '}';
}
if (firstLine === '[') {
return line.trim() === ']';
}
if (firstLine.endsWith(' \\')) {
return !line.endsWith(' \\');
}
}
return false;
}
startMultiline() {
this.isMultiline = true;
this.buffer = [];
console.log(chalk.gray('Entering multi-line mode. End with ``` on a new line (or matching bracket/brace).'));
}
addLine(line) {
if (!this.isMultiline && this.isStarting(line)) {
this.startMultiline();
this.buffer.push(line);
return false;
}
if (this.isMultiline) {
if (this.isEnding(line)) {
if (line.trim() !== this.endDelimiter) {
this.buffer.push(line);
}
this.isMultiline = false;
return true;
}
this.buffer.push(line);
return false;
}
return true;
}
getContent() {
if (this.buffer.length === 0) {
return '';
}
const firstLine = this.buffer[0].trim();
if (firstLine === this.startDelimiter || firstLine.startsWith(this.startDelimiter)) {
const content = this.buffer.slice(1);
if (firstLine.length > 3) {
const language = firstLine.substring(3).trim();
return `[Code: ${language}]\n${content.join('\n')}`;
}
return content.join('\n');
}
if (firstLine === '{' || firstLine === '[') {
return this.buffer.join('\n');
}
if (this.buffer[0].endsWith(' \\')) {
return this.buffer.map(line => line.endsWith(' \\') ? line.slice(0, -2) : line).join(' ');
}
return this.buffer.join('\n');
}
isActive() {
return this.isMultiline;
}
reset() {
this.buffer = [];
this.isMultiline = false;
}
getPrompt() {
if (!this.isMultiline) {
return chalk.green('vibe> ');
}
const lineNum = this.buffer.length + 1;
return chalk.gray(` ${lineNum.toString().padStart(2)}| `);
}
getCurrentBuffer() {
return [...this.buffer];
}
}