Module osc_extractor

Module osc_extractor 

Source
Expand description

Stateful byte-stream OSC sequence extractor.

Parses OSC 0 and OSC 2 sequences from PTY output and normalises Claude Code window-title payloads into bare conversation-topic strings. Used by the agent-pane PTY read loop to surface the session topic as term:activity block metadata without leaking raw escape bytes into the FileStore.

Design notes:

  • State machine buffers across PTY read() calls so sequences split at chunk boundaries are assembled correctly.
  • Buffer is capped at MAX_PAYLOAD_BYTES; overflow discards the partial sequence and resets state (no unbounded memory growth).
  • Non-UTF-8 bytes are replaced with U+FFFD via from_utf8_lossy.
  • Terminal panes use xterm.js to handle OSC natively; this extractor is applied ONLY to agent-pane PTY streams.

Structsยง

OscEvent
A complete, normalised OSC title event.
OscExtractor
Stateful OSC extractor โ€” create one instance per PTY stream and call feed() for each chunk.

Enumsยง

State ๐Ÿ”’

Constantsยง

MAX_PAYLOAD_BYTES ๐Ÿ”’

Functionsยง

normalise_title ๐Ÿ”’
Strip Claude Code title prefixes; discard bare startup/idle titles.