Transform the Magic Shell TUI from a single-command interface into a chat-like conversation interface with visible history, similar to the website mockup.
The TUI uses @opentui/core with these main components:
BoxRenderable- Layout containersTextRenderable- Text displayInputRenderable- User input fieldSelectRenderable- Dropdown/selection menus
Current layout:
┌─────────────────────────────────────────┐
│ magic-shell - natural language... │
├─────────────────────────────────────────┤
│ cwd: /path/to/dir [zen] Model │
├─────────────────────────────────────────┤
│ > [input field] │
├─────────────────────────────────────────┤
│ Command: <last command> │
│ [Safety warning if applicable] │
├─────────────────────────────────────────┤
│ ┌─ Output ─────────────────────────────┐│
│ │ ││
│ │ [Single output area] ││
│ │ ││
│ └──────────────────────────────────────┘│
├─────────────────────────────────────────┤
│ Ctrl+X P palette | Ctrl+X M model | ... │
└─────────────────────────────────────────┘
┌─────────────────────────────────────────────────────┐
│ magic-shell [Kimi K2.6 Free] │
├─────────────────────────────────────────────────────┤
│ Provider: opencode-zen Model: Kimi K2.6 Free ● Safe│
├─────────────────────────────────────────────────────┤
│ │
│ ┌─ Chat History (scrollable) ─────────────────────┐ │
│ │ │ │
│ │ > find all large files │ │
│ │ ┌───────────────────────────────────────────┐ │ │
│ │ │ Command: find . -type f -size +100M │ │ │
│ │ │ ● Low risk │ │ │
│ │ │ [Enter] Run [c] Copy [e] Edit │ │ │
│ │ └───────────────────────────────────────────┘ │ │
│ │ │ │
│ │ > kill process on port 8080 │ │
│ │ ┌───────────────────────────────────────────┐ │ │
│ │ │ Command: kill $(lsof -t -i:8080) │ │ │
│ │ │ ● Medium risk - kills processes │ │ │
│ │ │ [Enter] Run [c] Copy [e] Edit │ │ │
│ │ └───────────────────────────────────────────┘ │ │
│ │ │ │
│ └─────────────────────────────────────────────────┘ │
│ │
├─────────────────────────────────────────────────────┤
│ ~> [input field with cursor] │
├─────────────────────────────────────────────────────┤
│ Ctrl+X M Model Ctrl+X T Theme Ctrl+X D Dry-run │
└─────────────────────────────────────────────────────┘
- Scrollable area showing conversation history
- Each exchange = user query + AI response
- Response cards with:
- Translated command
- Safety badge with severity color
- Action buttons (Run/Copy/Edit)
- Auto-scroll to bottom on new messages
interface ChatMessage {
id: string
type: 'user' | 'assistant' | 'system' | 'result'
content: string
timestamp: number
// For assistant messages:
command?: string
safety?: SafetyAnalysis
executed?: boolean
output?: string
}User Message:
> [user's natural language query]
Assistant Response Card:
┌──────────────────────────────────────┐
│ Command: [translated command] │
│ ● [severity] risk - [reason] │
│ [Enter] Run [c] Copy [e] Edit │
└──────────────────────────────────────┘
Execution Result:
┌──────────────────────────────────────┐
│ ✓ Executed successfully │
│ [output if any] │
└──────────────────────────────────────┘
- Provider name
- Model name (clickable/shortcut)
- Safe Mode indicator (green dot)
- Dry-run indicator when active
- Prompt:
~>or custom - Full-width input
- Cursor visible
- Key shortcuts
- Contextual based on state
- Create
ChatMessageinterface - Create
ChatHistorymanager class - Migrate from single
outputTextto message array
- Create new layout structure in
createMainUI() - Create
ChatHistoryRenderablecomponent (scrollable box with messages) - Create
MessageCardhelper for rendering response cards - Update header/status bar layout
- Implement scroll in chat history
- Add keyboard navigation (up/down to select messages)
- Add action shortcuts on selected message
- Match website design (colors, spacing)
- Add message animations (fade in)
- Improve safety badge styling
- Re-run previous commands from history
- Edit and re-submit queries
- Copy command to clipboard
- Clear history option
| File | Changes |
|---|---|
src/cli.ts |
Major refactor - new layout, chat history |
src/lib/types.ts |
Add ChatMessage interface |
src/lib/config.ts |
Update history format if needed |
Medium-High
The main challenges:
- Scrolling in
@opentui/core- need to verify scrollable container support - Dynamic message list rendering
- Keyboard navigation between messages
- Maintaining backwards compatibility with existing features
- Should we persist chat history across sessions?
- Max messages to display before auto-cleanup?
- Should executed commands show their output inline?
- Mobile/small terminal handling?
- Chat history visible with multiple exchanges
- Each response in a styled card
- Safety badges with correct colors
- Scrollable history area
- Input at bottom with visible cursor
- All existing shortcuts still work
- Keyboard navigation between messages
- Run/Copy/Edit actions on messages