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 ¶
- func CapturePane(sessionName string, lines int) (string, error)
- func CapturePaneClean(sessionName string, lines int) (string, error)
- func IsSessionAlive(sessionName string) bool
- func ListSessions() ([]string, error)
- func ProcessKeyWords(input string) string
- func SendKeys(sessionName, input string, delayMs ...int) error
- func StripANSI(input string) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CapturePane ¶
CapturePane captures the last N lines from a tmux session
func CapturePaneClean ¶
CapturePaneClean captures and strips ANSI codes from tmux output
func IsSessionAlive ¶
IsSessionAlive checks if a tmux session exists and is running
func ListSessions ¶
ListSessions returns a list of all tmux session names
func ProcessKeyWords ¶
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.
Types ¶
This section is empty.