Skip to content
CortexPrism Bot edited this page Jun 21, 2026 · 4 revisions

TUI

CortexPrism ships with a custom Deno-native TUI framework (v0.48.0) providing flicker-free terminal rendering, rich components, and full keyboard interaction.

Architecture (src/tui/)

File Purpose
buffer.ts Double-buffered VirtualScreen with cell-level diff-and-flush
screen.ts Screen management, terminal size detection (getTermCols()/getTermRows())
style.ts Style system with ANSI color, bold, italic, underline support
component.ts Class-based Component tree with lifecycle hooks (onMount, onUpdate, onDestroy, onResize, onKeyPress)
layout.ts Layout engine — HSplit, VSplit, ScrollView, Box with flex/percentage sizing
renderer.ts Renderer with SIGWINCH resize handling
input-engine.ts Raw InputEngine with ANSI escape decoding and emacs-style keybindings (Ctrl+A/E/K/W/U, Alt+F/B/D, Ctrl+R history search)
themes/dark.ts Dark theme
themes/light.ts Light theme
themes/contrast.ts High-contrast theme
hyperlink.ts OSC-8 hyperlink rendering
progress.ts Braille/ASCII spinners and progress bars
completions.ts Completion provider for slash commands, file paths, agent names

Components (src/tui/components/)

Component Description
Header Title bar with session info
StatusBar Footer with model, tokens, cost, session ID
TextInput Multi-line input with cursor movement, history, selection
CompletionMenu Floating dropdown for slash commands/file paths/agent names
MarkdownBlock Headers, bold, italic, inline code rendering
CodeBlock Syntax highlighting for TS/JS/Python/Go/Rust/Bash/SQL
DiffBlock Unified diff with +/- coloring
ToolCard Tool call status with spinner/checkmark/cross and duration
ChatView Scrollable message list with streaming support

Layouts

Chat Mode (cortex agent chat)

┌─────────────────────────────────────────────────┐
│ Header (title)                                  │
├─────────────────────────────────────────────────┤
│ ChatView (scrollable messages)                  │
│                                                 │
│                                                 │
│                                                 │
├─────────────────────────────────────────────────┤
│ TextInput (> prompt)                            │
├─────────────────────────────────────────────────┤
│ StatusBar (model | tokens | cost | session)     │
└─────────────────────────────────────────────────┘

TUI Mode (cortex agent tui)

┌─────────────────────────────────────────────────┐
│ Header (title)                                  │
├───────────────────────┬─────────────────────────┤
│ ChatView (70%)        │ ToolPanel (30%)         │
│                       │ • ToolCard (sub_agent)  │
│                       │ • ToolCard (file_read)  │
│                       │ • ToolCard (file_write) │
├───────────────────────┴─────────────────────────┤
│ TextInput (> prompt)                            │
├─────────────────────────────────────────────────┤
│ StatusBar (model | tokens | cost | session)     │
└─────────────────────────────────────────────────┘

Slash Commands

12 slash commands available in interactive chat sessions:

Command Description
/model <name> Switch model mid-session
/compact Trigger context compaction (runs automatically)
/status Show session info (turns, tokens, cost)
/clear Clear chat history
/save [file] Save transcript to file
/load <file> Load transcript from file
/export Export session as markdown
/theme <name> Switch theme (dark/light/contrast)
/diff Show last file change
/review Review pending approvals
/plan Planning mode (runs automatically)
/help List all commands
/! <cmd> Bash command passthrough
/soul Show soul context

Agent Exec Mode

Non-interactive one-shot mode for CI and scripting:

cortex agent exec "summarize this repo" --json
cortex agent exec "fix eslint config" --max-turns 5
cortex agent exec "write a script" -o output.sh

--json flag outputs { success, output, cost, durationMs, turns, tokensIn, tokensOut } for machine consumption.

CLI

cortex agent chat              # Interactive streaming chat (TUI)
cortex agent tui               # Full-featured TUI with tool panel
cortex agent exec <prompt>     # One-shot non-interactive execution

See Also

Clone this wiki locally