UNPKG

naisys

Version:

NAISYS - Autonomous AI agent runner with built-in context management and cost tracking

35 lines 1.52 kB
import * as readline from "readline"; /** * Singleton readline interface shared across all agent instances. * This prevents conflicts when multiple agents are running but only one is active on the console. * * Lazily initialized to avoid setting stdin to raw mode at import time, * which would prevent Ctrl+C from working during startup (e.g. hub connection). */ let instance = null; export function getSharedReadline() { if (!process.stdin.readable) { return null; } if (!instance) { const isTTY = Boolean(process.stdin.isTTY); instance = readline.createInterface({ input: process.stdin, output: process.stdout, // With this set to true, after an abort the second input will not be processed, see: // https://gist.github.com/swax/964a2488494048c8e03d05493d9370f8 // With this set to false, the stdout.write event above will not be triggered // Use terminal: false when stdin is piped (e.g. E2E tests) to avoid TTY-only features terminal: isTTY, }); instance.pause(); // In terminal mode, readline intercepts Ctrl+C and emits 'SIGINT' on the // rl instance instead of letting the OS deliver it to the process. Re-emit // as a process-level event so handlers in naisys.ts can respond. instance.on("SIGINT", () => { process.emit("SIGINT", "SIGINT"); }); } return instance; } //# sourceMappingURL=sharedReadline.js.map