AsciinemaWriter
monitors all terminal output for pruning sequences:
\x1b[3J
- Clear scrollback buffer (most common in modern terminals)\x1bc
- Terminal reset (RIS - Reset to Initial State)\x1b[2J
- Clear screen\x1b[H\x1b[J
- Home cursor + clear (older pattern)\x1b[H\x1b[2J
- Home cursor + clear screen variant\x1b[?1049h
- Enter alternate screen (vim, less, etc)\x1b[?1049l
- Exit alternate screen\x1b[?47h
- Save screen and enter alternate screen (legacy)\x1b[?47l
- Restore screen and exit alternate screen (legacy)AsciinemaWriter
maintains precise byte position tracking:
PtyManager
updates the session info:
StreamWatcher
:
lastClearOffset
from session infoStreamWatcher
also scans for pruning sequences when analyzing existing content:
utils/pruning-detector.ts
)
pty/asciinema-writer.ts
)
pty/pty-manager.ts
)
services/stream-watcher.ts
)
test/unit/pruning-detector.test.ts
)
test/unit/asciinema-writer.test.ts
)
pty-manager.ts
- During data write (imprecise)stream-watcher.ts
- During playback (retroactive)lastIndexOf()
calls on potentially large stringspruning-detector.ts
asciinema-writer.ts
Aspect | Old Logic | New Logic | Improvement |
---|---|---|---|
Detection Timing | Retroactive (on playback) | Real-time (on write) | ✅ No playback delay |
Processing Passes | 2 (write + read) | 1 (write only) | ✅ 50% reduction |
Byte Accuracy | Approximate | Exact | ✅ Precise pruning |
Memory Usage | Re-read entire file | Stream processing | ✅ Lower memory |
CPU Usage | O(n) on each client connect | O(1) lookup | ✅ Much faster |
Code Duplication | 3 implementations | 1 centralized | ✅ Maintainable |