TerminalOutputBuffer (cerebellum/terminal-buffer.ts)

ai-maestro · lib/cerebellum/terminal-buffer.ts · typescript · MIT
ai

Ring buffer for accumulating terminal output for LLM summarization in AI agents.

// Source: https://github.com/23blocks-OS/ai-maestro | License: MIT | Copyright 2025 Juan Peláez / 23blocks
// Provided via justclaw.it.com; keep this notice with the code.
/**
 * Terminal Output Buffer - Ring buffer for accumulating PTY output
 *
 * Used by the voice subsystem to collect recent terminal output
 * for LLM summarization when the agent goes idle.
 */

export type BufferListener = (data: string) => void

export class TerminalOutputBuffer {
  private buffer = ''
  private maxSize: number
  private listeners = new Set<BufferListener>()

  constructor(maxSize = 8192) {
    this.maxSize = maxSize
  }

  write(data: string): void {
    this.buffer += data
    if (this.buffer.length > this.maxSize) {
      this.buffer = this.buffer.slice(-this.maxSize)
    }
    for (const listener

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key