Skip to content

Commit cde686a

Browse files
committed
implement save/restore session manager
1 parent 6815506 commit cde686a

9 files changed

Lines changed: 587 additions & 3 deletions

File tree

Cargo.lock

Lines changed: 97 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ syntect = "5.2"
2727
# Utilities
2828
futures = "0.3"
2929
pathdiff = "0.2"
30+
chrono = "0.4"
3031

3132
# Logging (optional but helpful)
3233
tracing = "0.1"

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ A blazingly fast, interactive AI coding assistant powered by Claude, implemented
99
## Features
1010

1111
- **Interactive REPL** - Multi-turn conversations with Claude
12+
- **Session History** - Automatic session saving and resume previous conversations
1213
- **File Operations** - Read, write, list, and create files/directories (sandboxed to current directory)
1314
- **Ultra-Fast Editing** - Optional Morph Apply integration (10,500+ tokens/sec, 96-98% accuracy)
1415
- **Code Search** - Fast regex-based code search using `ripgrep` (optional)
@@ -67,19 +68,27 @@ sofos --prompt "Create a hello world Rust program"
6768
- `clear` - Clear conversation history
6869
- `exit` or `quit` - Exit
6970
- `Ctrl+D` - Exit
71+
- `resume` - Resume previous session
7072

7173
### Options
7274

7375
```
7476
--api-key <KEY> Anthropic API key (overrides ANTHROPIC_API_KEY)
7577
--morph-api-key <KEY> Morph API key (overrides MORPH_API_KEY)
7678
-p, --prompt <TEXT> One-shot mode
79+
-r, --resume Resume a previous conversation session
7780
--model <MODEL> Claude model (default: claude-sonnet-4-5)
7881
--morph-model <MODEL> Morph model (default: morph-v3-fast)
7982
--max-tokens <N> Max response tokens (default: 8192)
8083
-v, --verbose Verbose logging
8184
```
8285

86+
## Session History
87+
88+
All conversations are automatically saved to `.sofos/sessions/` in your project directory.
89+
Resume previous sessions with `sofos --resume` or type `resume` in the REPL.
90+
Sessions show a preview of the first message, last updated time, and message count.
91+
8392
## Available Tools
8493

8594
Claude can automatically use these tools:

src/cli.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ pub struct Cli {
1818
#[arg(short, long)]
1919
pub prompt: Option<String>,
2020

21+
/// Resume a previous conversation session
22+
#[arg(short, long)]
23+
pub resume: bool,
24+
2125
#[arg(long, default_value = "claude-sonnet-4-5")]
2226
pub model: String,
2327

src/conversation.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::api::Message;
22

3-
const MAX_MESSAGES: usize = 50;
3+
const MAX_MESSAGES: usize = 500;
44

55
/// Manages conversation history for the REPL
66
pub struct ConversationHistory {
@@ -103,6 +103,10 @@ Your goal is to help users with coding tasks efficiently and accurately."#,
103103
self.messages.clear();
104104
}
105105

106+
pub fn restore_messages(&mut self, messages: Vec<Message>) {
107+
self.messages = messages;
108+
}
109+
106110
pub fn _len(&self) -> usize {
107111
self.messages.len()
108112
}

0 commit comments

Comments
 (0)