Skip to content

v0.1.5 — Terminal automation events

Latest

Choose a tag to compare

@holiber holiber released this 26 Feb 15:32
· 2 commits to main since this release
36aeaa8

What's New

Terminal automation events (#27)

This release adds structured events and helpers for terminal automation workflows — making it possible to reliably detect command success/failure, react to output, and execute send-and-wait patterns without fragile regex parsing.

Server

  • ptyExit event: The server now sends a { type: "ptyExit", exitCode, signal } WebSocket message before closing the connection when the PTY process exits. Previously, clients only received a close code (1000 vs 1011) with no structured exit information.

  • commandEnd event via shell integration: New opt-in shellIntegration: true option on createJabtermServer(). When enabled, the server injects PROMPT_COMMAND (bash) or precmd (zsh) hooks that emit OSC 633 escape sequences after each command. The server intercepts these sequences, strips them from the terminal output (so xterm never sees them), and sends { type: "commandEnd", exitCode } structured messages to the client.

const server = createJabtermServer({
  port: 3223,
  shellIntegration: true, // opt-in, default: false
});

React Component (<JabTerm>)

  • onData callback: New prop onData?: (data: string) => void fires for each chunk of terminal output, enabling reactive patterns (e.g., detecting when a dev server prints its URL).

  • onExit callback: New prop onExit?: (exitCode: number, signal: number | null) => void fires when the PTY process exits.

  • onCommandEnd callback: New prop onCommandEnd?: (exitCode: number) => void fires after each command completes (requires shellIntegration: true on the server).

  • getLastExitCode(): New imperative handle method returning the most recent command exit code, or null if none observed.

  • waitForCommandEnd(timeoutMs?): New imperative handle method returning a Promise<number> that resolves with the next command's exit code.

  • writeAndWait(input, options?): New imperative handle method that sends input and resolves when one of three conditions is met:

    • Quiet mode (default): resolves after quietMs milliseconds of no new output (default: 300ms)
    • Marker mode: resolves when a waitFor substring appears in the output
    • Command mode: resolves on the next commandEnd event (requires shell integration)

    Returns { output: string, exitCode?: number }.

Full Changelog

v0.1.4...v0.1.5