Skip to content

Commit d990100

Browse files
authored
Merge pull request #1 from schovi/feature/tui-smart-truncation
feat: add adaptive TUI frame detection with multiple strategies
2 parents e7a1620 + c72c8ba commit d990100

File tree

23 files changed

+4537
-40
lines changed

23 files changed

+4537
-40
lines changed

.claude/skills/shelli/SKILL.md

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Use shelli instead of regular Bash when you need:
3535
Do NOT use shelli for:
3636
- One-off commands that don't need state (`ls`, `cat file.txt`, `git status`)
3737
- Commands that complete immediately and don't require follow-up
38-
- TUI applications (vim, htop, k9s) - they don't produce line-based output
38+
- TUI applications (vim, htop, k9s) without `--tui` flag and `--follow` mode (see TUI Applications section in Limitations)
3939

4040
## Commands Reference
4141

@@ -51,6 +51,7 @@ Flags:
5151
- `--cwd /path`: Set working directory
5252
- `--cols N`: Terminal columns (default: 80)
5353
- `--rows N`: Terminal rows (default: 24)
54+
- `--tui`: Enable TUI mode (auto-truncate buffer on frame boundaries)
5455
- `--json`: Output session info as JSON
5556

5657
Examples:
@@ -63,6 +64,7 @@ shelli create server --cmd "ssh user@host" # SSH session
6364
shelli create redis --cmd "redis-cli" # Redis CLI
6465
shelli create dev --env "DEBUG=1" --cwd /app # with env and working dir
6566
shelli create wide --cols 200 --rows 50 # large terminal
67+
shelli create vim --cmd "vim" --tui # TUI mode for editors
6668
```
6769

6870
### exec - Send command and wait for result (primary command for AI)
@@ -147,6 +149,11 @@ shelli read <name> [flags]
147149
- `--follow` / `-f`: Continuous output like `tail -f`
148150
- `--follow-ms N`: Poll interval in ms (default: 100)
149151

152+
**Snapshot mode** (TUI only):
153+
- `--snapshot`: Force full redraw via resize, wait for settle, read clean frame
154+
- Requires `--tui` on create. Incompatible with `--follow`, `--all`, `--wait`.
155+
- Compatible with `--settle` (overrides default 300ms), `--strip-ansi`, `--json`, `--head`, `--tail`, `--timeout`.
156+
150157
**Blocking modes**:
151158
- `--wait "pattern"`: Wait for regex pattern match
152159
- `--settle N`: Wait for N ms of silence
@@ -164,6 +171,8 @@ shelli read myshell --follow # stream continuously (Ctrl+C to stop)
164171
shelli read pyrepl --wait ">>>" # wait for Python prompt
165172
shelli read myshell --settle 300 # wait for 300ms silence
166173
shelli read myshell --strip-ansi # clean output
174+
shelli read tui-app --snapshot --strip-ansi # clean TUI frame
175+
shelli read tui-app --snapshot --tail 10 # last 10 lines of TUI
167176
```
168177

169178
### list - List all sessions
@@ -537,14 +546,30 @@ shelli create session --cmd "command"
537546

538547
### TUI Applications - Now Supported
539548

540-
shelli supports TUI applications using `--follow` mode for continuous streaming:
549+
shelli supports TUI applications using `--follow` mode for continuous streaming, `--tui` mode for reduced storage, and `--snapshot` for clean frame capture:
541550

542551
```bash
543-
shelli create mon --cmd "btop"
552+
shelli create mon --cmd "btop" --tui
544553
shelli read mon --follow # streams output, renders TUI
545-
shelli resize mon --cols 150 --rows 50 # resize works too
554+
shelli read mon --snapshot --strip-ansi # force redraw, get clean frame
555+
shelli resize mon --cols 150 --rows 50 # resize works too
546556
```
547557

558+
**TUI Mode (`--tui` flag):**
559+
560+
When enabled, shelli uses multiple detection strategies to identify frame boundaries:
561+
562+
| Strategy | Trigger | Coverage |
563+
|----------|---------|----------|
564+
| Screen clear | ESC[2J, ESC[?1049h, ESC c | vim, less, nano |
565+
| Sync mode | ESC[?2026h (begin) | Claude Code, modern terminals |
566+
| Cursor home | ESC[1;1H (with reset) | k9s, btm, htop |
567+
| Size cap | Buffer > 100KB after frame | Fallback after frame detection |
568+
569+
This reduces storage from ~50MB to ~2KB for typical TUI sessions.
570+
571+
Use `--tui` for apps that frequently redraw the screen (vim, htop, btop, k9s). Do not use for apps where you need to preserve scrollback history.
572+
548573
**What works well:**
549574
- System monitors: `btop`, `htop`, `k9s`
550575
- Dashboards and status displays

0 commit comments

Comments
 (0)