watchdog

package
v0.1.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 28, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package watchdog provides utilities for tmux session monitoring and output parsing.

This file handles keyword-based key sequence conversion for AI CLI tools. It converts entire input messages matching specific keywords to actual key sequences.

Package watchdog provides tmux session monitoring and output parsing capabilities.

The watchdog package handles two main concerns:

1. Low-level tmux operations: CapturePane, SendKeys, StripANSI, IsSessionAlive 2. Content parsing and filtering: ExtractContentAfterPrompt, IsThinking, RemoveUIStatusLines

Tmux Operations

This package wraps tmux commands for session management:

  • CapturePane: Capture output from a tmux session
  • SendKeys: Send keystrokes to a tmux session
  • IsSessionAlive: Check if a session exists
  • ListSessions: List all active sessions

Content Parsing

The parser provides utilities for extracting relevant content from tmux output:

  • ExtractContentAfterPrompt: Filters tmux output to show only the latest AI response
  • IsThinking: Detects if the AI is still processing (shows "thinking" indicators)
  • RemoveUIStatusLines: Removes UI artifacts like "ESC to interrupt"
  • StripANSI: Removes ANSI escape codes for clean text

Example Usage

// Capture and parse tmux output
output, err := watchdog.CapturePane("my-session", 100)
if err != nil {
    log.Fatal(err)
}
clean := watchdog.StripANSI(output)
filtered := watchdog.ExtractContentAfterPrompt(clean, "my prompt")

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CapturePane

func CapturePane(sessionName string, lines int) (string, error)

CapturePane captures the last N lines from a tmux session

func CapturePaneClean

func CapturePaneClean(sessionName string, lines int) (string, error)

CapturePaneClean captures and strips ANSI codes from tmux output

func IsSessionAlive

func IsSessionAlive(sessionName string) bool

IsSessionAlive checks if a tmux session exists and is running

func ListSessions

func ListSessions() ([]string, error)

ListSessions returns a list of all tmux session names

func ProcessKeyWords

func ProcessKeyWords(input string) string

ProcessKeyWords converts entire input matching key words to tmux key names.

Only processes when the ENTIRE input matches (case-insensitive, trimmed). This is designed for AI CLI tools where users frequently send special keys like Tab, Esc, and Shift+Tab.

Supported keywords:

  • "tab" → Tab key (C-i)
  • "esc" → Escape key (C-[)
  • "stab" → Shift+Tab
  • "s-tab" → Shift+Tab (alias)
  • "enter" → Enter key (C-m)
  • "ctrlc" → Ctrl+C interrupt (C-c)
  • "ctrl-c" → Ctrl+C interrupt (C-c) (alias)
  • "ctrlt" → Ctrl+T (C-t)
  • "ctrl-t" → Ctrl+T (C-t) (alias)

Examples:

ProcessKeyWords("tab")      → "C-i"
ProcessKeyWords("TAB")      → "C-i"
ProcessKeyWords("  tab  ")  → "C-i"
ProcessKeyWords("esc")      → "C-["
ProcessKeyWords("stab")     → "S-Tab"
ProcessKeyWords("s-tab")    → "S-Tab"
ProcessKeyWords("ctrlc")    → "C-c"
ProcessKeyWords("CTRL-C")   → "C-c"
ProcessKeyWords("help tab") → "help tab" (no match, return as-is)

Returns the original input if no keyword match is found.

Note: This returns tmux key names (like "C-[", "C-i") instead of raw escape sequences because SendKeys uses the "-l" (literal) flag, which sends input as literal text rather than interpreting key names.

func SendKeys

func SendKeys(sessionName, input string, delayMs ...int) error

SendKeys sends keystrokes to a tmux session Parameters:

  • sessionName: tmux session name
  • input: text to send
  • delayMs: delay in milliseconds before sending Enter key (default 0)

func StripANSI

func StripANSI(input string) string

StripANSI removes ANSI escape codes from a string

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL