Skip to content

Commit 8e0e1e3

Browse files
committed
Implemented Chat saver & chat loader
1 parent 44cf246 commit 8e0e1e3

6 files changed

Lines changed: 519 additions & 34 deletions

File tree

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ A lightweight CLI-based IDE with integrated AI assistance through Ollama. Featur
1515
- **Code Editor**: Syntax-aware text editing with line numbers and file type detection
1616
- **AI Integration**: Context-aware AI assistance powered by Ollama or Gemini
1717
- **Agentic Code Fixing**: AI autonomously reads, analyzes, and fixes code directly in the editor
18+
- **Chat History Management**: Save and reload complete AI conversations with Ctrl+A and Ctrl+L
1819
- **File Management**: Create, open, save, and delete files
1920
- **Command Execution**: Run scripts and programs with Ctrl+R (auto-detects file type)
2021
- **Go Development**: Full support for running Go programs and tests
@@ -273,6 +274,10 @@ You can edit this file to customize your settings. The application will load it
273274
| `Ctrl+S` | Save current file |
274275
| `Ctrl+R` | Execute current script |
275276
| `Ctrl+Enter` | Send message to AI |
277+
| `Ctrl+Y` | List code blocks from AI response (Execute/Insert/Return) |
278+
| `Ctrl+A` | Save full chat history to .ti/ folder |
279+
| `Ctrl+L` | Load saved chat from .ti/ folder |
280+
| `Ctrl+T` | Clear chat / New chat |
276281
| `Ctrl+H` | Show help dialog with all shortcuts |
277282
| `Ctrl+C` or `Ctrl+Q` | Quit application |
278283

docs/CHAT_LOADER_IMPLEMENTATION.md

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
# Chat Loader Implementation Summary
2+
3+
## Overview
4+
Implemented Ctrl+L functionality to load previously saved chat histories back into the AI pane, complementing the existing Ctrl+A save feature.
5+
6+
## Implementation Details
7+
8+
### 1. App Structure Changes (`internal/ui/app.go`)
9+
10+
Added new fields to the App struct:
11+
- `showChatLoader bool` - Flag to show/hide the chat loader dialog
12+
- `chatList []string` - List of available chat files for the picker
13+
14+
### 2. Ctrl+L Handler
15+
16+
The handler performs the following steps:
17+
1. Checks if `.ti/` directory exists
18+
2. Scans for all `chat-*.md` files
19+
3. Sorts them newest first (reverse alphabetical order)
20+
4. Opens the chat loader dialog with the list
21+
5. Shows status message with count of found chats
22+
23+
### 3. Chat Loader Dialog
24+
25+
Similar to the backup picker, the chat loader provides:
26+
- Scrollable list of saved chats (up to 15 visible at once)
27+
- Navigation with `↑↓` or `k/j` keys
28+
- Selection with `Enter` key
29+
- Cancel with `Esc` key
30+
- Centered modal dialog with rounded border
31+
32+
### 4. Chat History Parser (`loadChatHistory` method)
33+
34+
The parser:
35+
1. Clears existing chat history
36+
2. Parses the markdown file line by line
37+
3. Identifies role lines (starting with "user " or "assistant ")
38+
4. Extracts timestamps in HH:MM:SS format
39+
5. Accumulates message content until next role line
40+
6. Creates ChatMessage objects with proper timestamps
41+
7. Adds messages to the AI pane's message list
42+
8. Extracts code blocks from loaded messages
43+
9. Scrolls to bottom of chat
44+
45+
### 5. File Format Support
46+
47+
The parser handles the format created by Ctrl+A:
48+
```
49+
role timestamp
50+
content line 1
51+
content line 2
52+
53+
role timestamp
54+
content
55+
```
56+
57+
### 6. UI Updates
58+
59+
Updated the AI pane title bar to show:
60+
```
61+
AI Responses (02) [Gemini] | Ctrl+Y: Code | Ctrl+A: Save | Ctrl+L: Load | ↑↓: Scroll | Ctrl+T: New
62+
```
63+
64+
### 7. Help System Updates
65+
66+
Updated help text in:
67+
- `internal/ui/help.go` - Main help dialog
68+
- `internal/ui/app.go` - Inline help text
69+
- `README.md` - Keyboard shortcuts table
70+
71+
## User Workflow
72+
73+
### Saving a Chat
74+
1. User has conversation with AI
75+
2. Presses `Ctrl+A`
76+
3. Chat saved to `.ti/chat-YYYY-MM-DD-HH-MM-SS-query.md`
77+
4. File opens in editor
78+
79+
### Loading a Chat
80+
1. User presses `Ctrl+L` (works anytime, especially after `Ctrl+T` clear)
81+
2. Dialog shows list of saved chats
82+
3. User navigates with arrow keys
83+
4. User presses `Enter` to load
84+
5. Chat history loads into AI pane
85+
6. Focus switches to AI pane
86+
7. User can continue the conversation
87+
88+
## Benefits
89+
90+
- **Conversation Continuity**: Resume previous discussions seamlessly
91+
- **Knowledge Base**: Build a searchable archive of AI interactions
92+
- **Learning Tool**: Review past solutions and explanations
93+
- **Workflow Efficiency**: Quick access to previous work
94+
- **No Data Loss**: All conversations can be preserved and recalled
95+
96+
## Technical Considerations
97+
98+
### Timestamp Handling
99+
- Saved timestamps are in HH:MM:SS format only
100+
- On load, timestamps are reconstructed using today's date
101+
- This is acceptable since the date is in the filename
102+
103+
### Error Handling
104+
- Gracefully handles missing `.ti/` directory
105+
- Reports errors if files can't be read
106+
- Validates file format during parsing
107+
- Falls back to current time if timestamp parsing fails
108+
109+
### Performance
110+
- Efficient file scanning with `os.ReadDir`
111+
- Minimal memory footprint (only loads selected chat)
112+
- Fast parsing with string operations
113+
114+
## Future Enhancements
115+
116+
Potential improvements:
117+
- Search/filter chats by content
118+
- Delete chats from the loader dialog
119+
- Export chats to other formats
120+
- Merge multiple chats
121+
- Chat statistics and analytics
122+
- Tag/categorize chats

docs/CHAT_SAVE_FEATURE.md

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# Chat Save Feature
2+
3+
## Overview
4+
The Ctrl+A shortcut saves the entire AI chat history to a markdown file in the `.ti/` folder. The Ctrl+L shortcut allows you to reload previously saved chats back into the AI pane.
5+
6+
## Save Chat (Ctrl+A)
7+
8+
### Usage
9+
10+
1. Have a conversation with the AI assistant
11+
2. Press `Ctrl+A` at any time during or after the conversation
12+
3. The entire chat history will be automatically saved to `.ti/chat-YYYY-MM-DD-HH-MM-SS-query.md`
13+
4. The saved file will automatically open in the editor
14+
15+
### File Format
16+
17+
The saved chat file follows this format:
18+
19+
```markdown
20+
user 13:32:48
21+
using Go language create a program to display cpu, memory, root volume used and capacity
22+
23+
assistant 13:32:59
24+
To create a system monitor in Go, the most reliable and cross-platform way is to use the `gopsutil` library. It is the Go equivalent of Python's `psutil`.
25+
26+
user 13:35:12
27+
Can you add network statistics too?
28+
29+
assistant 13:35:20
30+
Sure! I'll add network statistics to the program...
31+
```
32+
33+
### Filename Convention
34+
35+
The filename is generated automatically using:
36+
- Current date: `YYYY-MM-DD`
37+
- First user message timestamp: `HH-MM-SS`
38+
- First few words of the user's initial query (sanitized for filename compatibility)
39+
40+
Example: `chat-2026-02-26-13-32-48-using-Go-language-create-a-program.md`
41+
42+
## Load Chat (Ctrl+L)
43+
44+
### Usage
45+
46+
1. Press `Ctrl+L` to open the chat loader dialog
47+
2. A list of all saved chats from the `.ti/` folder will be displayed (newest first)
48+
3. Use `` and `` arrow keys (or `k` and `j`) to navigate through the list
49+
4. Press `Enter` to load the selected chat into the AI pane
50+
5. Press `Esc` to cancel and close the dialog
51+
52+
### Features
53+
54+
- Loads complete conversation history with timestamps
55+
- Preserves message roles (user/assistant)
56+
- Extracts code blocks from loaded messages
57+
- Automatically scrolls to the bottom of the loaded chat
58+
- Switches focus to the AI pane after loading
59+
60+
### When to Use
61+
62+
- After clearing chat with `Ctrl+T` to start fresh
63+
- When opening TI with an empty chat
64+
- To review or continue previous conversations
65+
- To reference past solutions or discussions
66+
67+
## Directory Structure
68+
69+
All chat files are saved in the `.ti/` directory at the workspace root:
70+
```
71+
<workspace-root>/
72+
.ti/
73+
chat-2026-02-26-13-32-48-query1.md
74+
chat-2026-02-26-14-15-30-query2.md
75+
20260219-160311_test.py (existing backup files)
76+
```
77+
78+
## Benefits
79+
80+
- Complete conversation history preserved
81+
- Timestamped for easy reference
82+
- Searchable markdown format
83+
- Automatic organization in `.ti/` folder
84+
- No manual filename prompts
85+
- Easy to reload and continue conversations
86+
- Instantly viewable in the editor

internal/ui/aichat.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1473,15 +1473,8 @@ func (a *AIChatPane) View() string {
14731473
string(rune('0'+len(a.messages)%10)) + ")"
14741474
}
14751475

1476-
// Add provider indicator
1477-
if a.provider == "gemini" {
1478-
title += " [Gemini]"
1479-
} else {
1480-
title += " [Ollama]"
1481-
}
1482-
14831476
// Add instructions to title
1484-
title += " | Ctrl+Y: Code | ↑↓: Scroll | Ctrl+T: New Chat"
1477+
title += " | Ctrl+Y: Code | Ctrl+A: Save | Ctrl+L: Load | ↑↓: Scroll | Ctrl+T: New"
14851478

14861479
titleStyle := lipgloss.NewStyle().
14871480
Bold(true).

0 commit comments

Comments
 (0)