npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@love-moon/tui-driver

v0.2.11

Published

TUI Driver for interactive CLI tools like Claude Code and Codex

Downloads

1,243

Readme

TUI Driver

A headless TUI driver for interacting with interactive CLI tools like Claude Code and Codex.

Requirements

  • Node.js >= 18.0.0 (recommended: Node.js 20.x LTS)
  • node-pty requires native compilation (Python and build tools)

Note: node-pty may have compatibility issues with Node.js 23+. Use Node.js 20.x LTS for best compatibility.

Features

  • PTY Session Management: Spawn and manage pseudo-terminal sessions
  • Headless Terminal Emulation: Parse ANSI sequences and maintain screen buffer using @xterm/headless
  • Expect Engine: Wait for screen conditions with stability checks and idle detection
  • State Machine: Track interaction states (BOOT, READY, TYPING, STREAMING, etc.)
  • Output Extraction: Extract model responses using diff-based algorithms
  • Profile System: Configurable profiles for different TUI tools

Installation

pnpm install
pnpm build

Usage

Basic Usage

import { createDriver } from "@love-moon/tui-driver";

const driver = createDriver("claude-code", { debug: true });

await driver.boot();
const result = await driver.ask("What is 2 + 2?");

if (result.success) {
  console.log("Answer:", result.answer);
}

driver.kill();

Advanced Usage

import { TuiDriver, claudeCodeProfile } from "@love-moon/tui-driver";

const driver = new TuiDriver({
  profile: claudeCodeProfile,
  debug: true,
  onSnapshot: (snapshot, state) => {
    console.log(`[${state}] Hash: ${snapshot.hash}`);
  },
});

await driver.boot();

// Multiple questions in sequence
const q1 = await driver.ask("Hello!");
const q2 = await driver.ask("What can you do?");

driver.kill();

Custom Profile

import { TuiDriver, createProfile } from "@love-moon/tui-driver";

const myProfile = createProfile({
  name: "claude-code",
  command: "my-cli",
  args: ["--interactive"],
  anchors: {
    ready: [/>\s*$/m, /prompt:/i],
    busy: [/thinking/i],
  },
  keys: {
    submit: ["ENTER"],
    cancel: ["CTRL_C"],
  },
  extraction: {
    mode: "diff-scrollback",
    stripPatterns: [/^>\s*/gm],
    bottomUiLines: 2,
  },
});

const driver = new TuiDriver({ profile: myProfile });

Architecture

src/
  pty/
    PtySession.ts       # node-pty wrapper
  term/
    HeadlessScreen.ts   # @xterm/headless wrapper
    ScreenSnapshot.ts   # Screen state snapshot
  expect/
    ExpectEngine.ts     # Wait/expect engine
    Matchers.ts         # Pattern matchers
  driver/
    TuiProfile.ts       # Profile type definitions
    TuiDriver.ts        # Main driver class
    StateMachine.ts     # State management
    profiles/
      claudeCode.profile.ts
      codex.profile.ts
  extract/
    OutputExtractor.ts  # Response extraction
    Diff.ts             # Text diff utilities

API Reference

TuiDriver

  • boot(): Initialize and wait for TUI to be ready
  • ask(prompt): Send a prompt and wait for response
  • ensureReady(): Ensure TUI is in ready state
  • snapshot(): Get current screen snapshot
  • sendKeys(keys): Send key sequences
  • kill(): Terminate the PTY session

ExpectEngine

  • until(options): Wait for condition with stability
  • untilIdle(options): Wait for screen to stop changing
  • waitForChange(timeout): Wait for any screen change

ScreenSnapshot

  • viewportText: Current visible screen content
  • scrollbackText: Full scrollback buffer
  • cursor: Current cursor position
  • hash: Screen content hash for change detection