14 Commits

Author SHA1 Message Date
bdda669d4d Bump version to 0.1.8 in PKGBUILD, Cargo.toml, and README
Some checks failed
ci/someci/tag/woodpecker/1 Pipeline was successful
ci/someci/tag/woodpecker/2 Pipeline was successful
ci/someci/tag/woodpecker/3 Pipeline was successful
ci/someci/tag/woodpecker/4 Pipeline was successful
ci/someci/tag/woodpecker/5 Pipeline was successful
ci/someci/tag/woodpecker/6 Pipeline was successful
ci/someci/tag/woodpecker/7 Pipeline failed
2025-10-02 03:00:00 +02:00
108070db4b Update Woodpecker CI: improve cross-compilation setup and refine build steps 2025-10-02 02:58:13 +02:00
08ba04e99f Add command suggestions and enhancements to Command mode
- Introduce `command_suggestions` feature for autocompletion in Command mode.
- Implement `render_command_suggestions` to display filtered suggestions in a popup.
- Enable navigation through suggestions using Up/Down keys and Tab for completion.
- Add dynamic filtering of suggestions based on input buffer.
- Improve input handling, ensuring suggestion state resets appropriately when exiting Command mode.
2025-10-02 02:48:36 +02:00
5c59539120 Bump version to 0.1.7 in PKGBUILD, Cargo.toml, and README
Some checks failed
ci/someci/tag/woodpecker/1 Pipeline was successful
ci/someci/tag/woodpecker/2 Pipeline was successful
ci/someci/tag/woodpecker/3 Pipeline failed
ci/someci/tag/woodpecker/4 Pipeline failed
ci/someci/tag/woodpecker/5 Pipeline failed
ci/someci/tag/woodpecker/6 Pipeline failed
ci/someci/tag/woodpecker/7 Pipeline failed
2025-10-02 02:09:26 +02:00
c725bb1ce6 Add tabbed help UI with enhanced navigation
- Refactor `render_help` to display tabbed UI for help topics.
- Introduce `help_tab_index` to manage selected tab state.
- Allow navigation between help tabs using Tab, h/l, and number keys (1-5).
- Enhance visual design of help sections using styled tabs and categorized content.
- Update input handling to reset tab state upon exit from help mode.
2025-10-02 02:07:23 +02:00
c4a6bb1c0f Merge pull request 'dev' (#23) from dev into main
Some checks failed
ci/someci/tag/woodpecker/1 Pipeline was successful
ci/someci/tag/woodpecker/2 Pipeline was successful
ci/someci/tag/woodpecker/3 Pipeline failed
ci/someci/tag/woodpecker/4 Pipeline failed
ci/someci/tag/woodpecker/5 Pipeline failed
ci/someci/tag/woodpecker/6 Pipeline failed
ci/someci/tag/woodpecker/7 Pipeline failed
Reviewed-on: #23
2025-10-02 01:38:22 +02:00
dcbfe6ef06 Update README: bump version to 0.1.5 in Alpha Status section 2025-10-02 01:37:44 +02:00
e468658d63 Bump version to 0.1.5 in Cargo.toml 2025-10-02 01:37:15 +02:00
2ad801f0c1 Remove release workflow: delete .gitea/workflows/release.yml 2025-10-02 01:36:59 +02:00
1bfc6e5956 Merge pull request 'Add session persistence and browser functionality' (#22) from dev into main
Reviewed-on: #22
2025-10-02 01:35:31 +02:00
6b8774f0aa Add session persistence and browser functionality
Some checks failed
Release / Build aarch64-unknown-linux-gnu (push) Has been cancelled
Release / Build aarch64-unknown-linux-musl (push) Has been cancelled
Release / Build armv7-unknown-linux-gnueabihf (push) Has been cancelled
Release / Build armv7-unknown-linux-musleabihf (push) Has been cancelled
Release / Build x86_64-unknown-linux-gnu (push) Has been cancelled
Release / Build x86_64-unknown-linux-musl (push) Has been cancelled
Release / Build aarch64-apple-darwin (push) Has been cancelled
Release / Build x86_64-apple-darwin (push) Has been cancelled
Release / Build aarch64-pc-windows-msvc (push) Has been cancelled
Release / Build x86_64-pc-windows-msvc (push) Has been cancelled
Release / Create Release (push) Has been cancelled
- Implement `StorageManager` for saving, loading, and managing sessions.
- Introduce platform-specific session directories for persistence.
- Add session browser UI for listing, loading, and deleting saved sessions.
- Enable AI-generated descriptions for session summaries.
- Update configurations to support storage settings and description generation.
- Extend README and tests to document and validate new functionality.
2025-10-02 01:33:49 +02:00
ec6876727f Update PKGBUILD: bump version to 0.1.4, adjust maintainer details, refine build steps, and improve compatibility settings 2025-10-01 23:59:46 +02:00
e3eb4d7a04 Update PKGBUILD: add sha256 checksum for source archive 2025-10-01 20:52:10 +02:00
7234021014 Add Windows support to builds and enhance multi-platform configuration
Some checks failed
ci/someci/tag/woodpecker/1 Pipeline was successful
ci/someci/tag/woodpecker/2 Pipeline was successful
ci/someci/tag/woodpecker/3 Pipeline failed
ci/someci/tag/woodpecker/4 Pipeline failed
ci/someci/tag/woodpecker/5 Pipeline failed
ci/someci/tag/woodpecker/6 Pipeline failed
ci/someci/tag/woodpecker/7 Pipeline failed
- Introduce `.cargo/config.toml` with platform-specific linker and flags.
- Update Woodpecker CI to include Windows target, adjust build and packaging steps.
- Modify `Cargo.toml` to use `reqwest` with `rustls-tls` for TLS support.
2025-10-01 20:46:27 +02:00
16 changed files with 1344 additions and 145 deletions

20
.cargo/config.toml Normal file
View File

@@ -0,0 +1,20 @@
[target.x86_64-unknown-linux-musl]
linker = "x86_64-linux-gnu-gcc"
rustflags = ["-C", "target-feature=+crt-static", "-C", "link-arg=-lgcc"]
[target.aarch64-unknown-linux-gnu]
linker = "aarch64-linux-gnu-gcc"
[target.aarch64-unknown-linux-musl]
linker = "aarch64-linux-gnu-gcc"
rustflags = ["-C", "target-feature=+crt-static", "-C", "link-arg=-lgcc"]
[target.armv7-unknown-linux-gnueabihf]
linker = "arm-linux-gnueabihf-gcc"
[target.armv7-unknown-linux-musleabihf]
linker = "arm-linux-gnueabihf-gcc"
rustflags = ["-C", "target-feature=+crt-static", "-C", "link-arg=-lgcc"]
[target.x86_64-pc-windows-gnu]
linker = "x86_64-w64-mingw32-gcc"

View File

@@ -11,63 +11,109 @@ matrix:
- TARGET: x86_64-unknown-linux-gnu
ARTIFACT: owlen-linux-x86_64-gnu
PLATFORM: linux
EXT: ""
- TARGET: x86_64-unknown-linux-musl
ARTIFACT: owlen-linux-x86_64-musl
PLATFORM: linux
EXT: ""
- TARGET: aarch64-unknown-linux-gnu
ARTIFACT: owlen-linux-aarch64-gnu
PLATFORM: linux
EXT: ""
- TARGET: aarch64-unknown-linux-musl
ARTIFACT: owlen-linux-aarch64-musl
PLATFORM: linux
EXT: ""
- TARGET: armv7-unknown-linux-gnueabihf
ARTIFACT: owlen-linux-armv7-gnu
PLATFORM: linux
EXT: ""
- TARGET: armv7-unknown-linux-musleabihf
ARTIFACT: owlen-linux-armv7-musl
PLATFORM: linux
EXT: ""
# Windows
- TARGET: x86_64-pc-windows-gnu
ARTIFACT: owlen-windows-x86_64
PLATFORM: windows
EXT: ".exe"
steps:
- name: install-deps
image: *rust_image
commands:
- apt-get update
- apt-get install -y musl-tools gcc-aarch64-linux-gnu gcc-arm-linux-gnueabihf
- name: build
image: *rust_image
commands:
# Install cross-compilation tools
- apt-get update
- apt-get install -y musl-tools gcc-aarch64-linux-gnu g++-aarch64-linux-gnu gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf mingw-w64 zip
# Verify cross-compilers are installed
- which aarch64-linux-gnu-gcc || echo "aarch64-linux-gnu-gcc not found!"
- which arm-linux-gnueabihf-gcc || echo "arm-linux-gnueabihf-gcc not found!"
- which x86_64-w64-mingw32-gcc || echo "x86_64-w64-mingw32-gcc not found!"
# Add rust target
- rustup target add ${TARGET}
# Set up cross-compilation environment variables and build
- |
case "${TARGET}" in
aarch64-unknown-linux-gnu)
export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc
export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=/usr/bin/aarch64-linux-gnu-gcc
export CC_aarch64_unknown_linux_gnu=/usr/bin/aarch64-linux-gnu-gcc
export CXX_aarch64_unknown_linux_gnu=/usr/bin/aarch64-linux-gnu-g++
export AR_aarch64_unknown_linux_gnu=/usr/bin/aarch64-linux-gnu-ar
;;
aarch64-unknown-linux-musl)
export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER=aarch64-linux-gnu-gcc
export CC_aarch64_unknown_linux_musl=aarch64-linux-gnu-gcc
export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER=/usr/bin/aarch64-linux-gnu-gcc
export CC_aarch64_unknown_linux_musl=/usr/bin/aarch64-linux-gnu-gcc
export CXX_aarch64_unknown_linux_musl=/usr/bin/aarch64-linux-gnu-g++
export AR_aarch64_unknown_linux_musl=/usr/bin/aarch64-linux-gnu-ar
;;
armv7-unknown-linux-gnueabihf)
export CARGO_TARGET_ARMV7_UNKNOWN_LINUX_GNUEABIHF_LINKER=arm-linux-gnueabihf-gcc
export CARGO_TARGET_ARMV7_UNKNOWN_LINUX_GNUEABIHF_LINKER=/usr/bin/arm-linux-gnueabihf-gcc
export CC_armv7_unknown_linux_gnueabihf=/usr/bin/arm-linux-gnueabihf-gcc
export CXX_armv7_unknown_linux_gnueabihf=/usr/bin/arm-linux-gnueabihf-g++
export AR_armv7_unknown_linux_gnueabihf=/usr/bin/arm-linux-gnueabihf-ar
;;
armv7-unknown-linux-musleabihf)
export CARGO_TARGET_ARMV7_UNKNOWN_LINUX_MUSLEABIHF_LINKER=arm-linux-gnueabihf-gcc
export CC_armv7_unknown_linux_musleabihf=arm-linux-gnueabihf-gcc
export CARGO_TARGET_ARMV7_UNKNOWN_LINUX_MUSLEABIHF_LINKER=/usr/bin/arm-linux-gnueabihf-gcc
export CC_armv7_unknown_linux_musleabihf=/usr/bin/arm-linux-gnueabihf-gcc
export CXX_armv7_unknown_linux_musleabihf=/usr/bin/arm-linux-gnueabihf-g++
export AR_armv7_unknown_linux_musleabihf=/usr/bin/arm-linux-gnueabihf-ar
;;
x86_64-pc-windows-gnu)
export CARGO_TARGET_X86_64_PC_WINDOWS_GNU_LINKER=/usr/bin/x86_64-w64-mingw32-gcc
export CC_x86_64_pc_windows_gnu=/usr/bin/x86_64-w64-mingw32-gcc
export CXX_x86_64_pc_windows_gnu=/usr/bin/x86_64-w64-mingw32-g++
export AR_x86_64_pc_windows_gnu=/usr/bin/x86_64-w64-mingw32-ar
;;
esac
- cargo build --release --all-features --target ${TARGET}
# Build the project
cargo build --release --all-features --target ${TARGET}
- name: package
image: *rust_image
commands:
- mkdir -p dist
- cp target/${TARGET}/release/owlen dist/owlen
- cp target/${TARGET}/release/owlen-code dist/owlen-code
- cd dist
- tar czf ${ARTIFACT}.tar.gz owlen owlen-code
- cd ..
- mv dist/${ARTIFACT}.tar.gz .
- sha256sum ${ARTIFACT}.tar.gz > ${ARTIFACT}.tar.gz.sha256
- |
if [ "${PLATFORM}" = "windows" ]; then
cp target/${TARGET}/release/owlen.exe dist/owlen.exe
cp target/${TARGET}/release/owlen-code.exe dist/owlen-code.exe
cd dist
zip -9 ${ARTIFACT}.zip owlen.exe owlen-code.exe
cd ..
mv dist/${ARTIFACT}.zip .
sha256sum ${ARTIFACT}.zip > ${ARTIFACT}.zip.sha256
else
cp target/${TARGET}/release/owlen dist/owlen
cp target/${TARGET}/release/owlen-code dist/owlen-code
cd dist
tar czf ${ARTIFACT}.tar.gz owlen owlen-code
cd ..
mv dist/${ARTIFACT}.tar.gz .
sha256sum ${ARTIFACT}.tar.gz > ${ARTIFACT}.tar.gz.sha256
fi
- name: release
image: plugins/gitea-release
@@ -78,5 +124,7 @@ steps:
files:
- ${ARTIFACT}.tar.gz
- ${ARTIFACT}.tar.gz.sha256
- ${ARTIFACT}.zip
- ${ARTIFACT}.zip.sha256
title: Release ${CI_COMMIT_TAG}
note: "Release ${CI_COMMIT_TAG}"

View File

@@ -9,7 +9,7 @@ members = [
exclude = []
[workspace.package]
version = "0.1.0"
version = "0.1.8"
edition = "2021"
authors = ["Owlibou"]
license = "AGPL-3.0"
@@ -32,7 +32,7 @@ crossterm = "0.28"
tui-textarea = "0.6"
# HTTP client and JSON handling
reqwest = { version = "0.12", features = ["json", "stream"] }
reqwest = { version = "0.12", default-features = false, features = ["json", "stream", "rustls-tls"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"

View File

@@ -1,45 +1,44 @@
# Maintainer: Owlibou
# Maintainer: vikingowl <christian@nachtigall.dev>
pkgname=owlen
pkgver=0.1.0
pkgver=0.1.8
pkgrel=1
pkgdesc="Terminal User Interface LLM client for Ollama with chat and code assistance features"
arch=('x86_64' 'aarch64')
arch=('x86_64')
url="https://somegit.dev/Owlibou/owlen"
license=('AGPL-3.0-only')
license=('AGPL-3.0-or-later')
depends=('gcc-libs')
makedepends=('cargo' 'git')
source=("${pkgname}-${pkgver}.tar.gz::https://somegit.dev/Owlibou/owlen/archive/v${pkgver}.tar.gz")
sha256sums=('SKIP') # Update this after first release
options=(!lto) # avoid LTO-linked ring symbol drop with lld
source=("$pkgname-$pkgver.tar.gz::$url/archive/v$pkgver.tar.gz")
sha256sums=('cabb1cfdfc247b5d008c6c5f94e13548bcefeba874aae9a9d45aa95ae1c085ec')
prepare() {
cd "$pkgname"
export RUSTUP_TOOLCHAIN=stable
cargo fetch --locked --target "$(rustc -vV | sed -n 's/host: //p')"
cd $pkgname
cargo fetch --target "$(rustc -vV | sed -n 's/host: //p')"
}
build() {
cd "$pkgname"
export RUSTUP_TOOLCHAIN=stable
cd $pkgname
export RUSTFLAGS="${RUSTFLAGS:-} -C link-arg=-Wl,--no-as-needed"
export CARGO_PROFILE_RELEASE_LTO=false
export CARGO_TARGET_DIR=target
cargo build --frozen --release --all-features
}
check() {
cd "$pkgname"
export RUSTUP_TOOLCHAIN=stable
cd $pkgname
export RUSTFLAGS="${RUSTFLAGS:-} -C link-arg=-Wl,--no-as-needed"
cargo test --frozen --all-features
}
package() {
cd "$pkgname"
cd $pkgname
# Install binaries
install -Dm755 "target/release/owlen" "$pkgdir/usr/bin/owlen"
install -Dm755 "target/release/owlen-code" "$pkgdir/usr/bin/owlen-code"
# Install license
install -Dm644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
install -Dm755 target/release/owlen "$pkgdir/usr/bin/owlen"
install -Dm755 target/release/owlen-code "$pkgdir/usr/bin/owlen-code"
# Install documentation
install -Dm644 README.md "$pkgdir/usr/share/doc/$pkgname/README.md"
}

View File

@@ -3,13 +3,13 @@
> Terminal-native assistant for running local language models with a comfortable TUI.
![Status](https://img.shields.io/badge/status-alpha-yellow)
![Version](https://img.shields.io/badge/version-0.1.0-blue)
![Version](https://img.shields.io/badge/version-0.1.8-blue)
![Rust](https://img.shields.io/badge/made_with-Rust-ffc832?logo=rust&logoColor=white)
![License](https://img.shields.io/badge/license-AGPL--3.0-blue)
## Alpha Status
- This project is currently in **alpha** (v0.1.0) and under active development.
- This project is currently in **alpha** (v0.1.8) and under active development.
- Core features are functional but expect occasional bugs and missing polish.
- Breaking changes may occur between releases as we refine the API.
- Feedback, bug reports, and contributions are very welcome!
@@ -42,7 +42,9 @@ The OWLEN interface features a clean, multi-panel layout with vim-inspired navig
- **Visual Selection & Clipboard** - Yank/paste text across panels
- **Flexible Scrolling** - Half-page, full-page, and cursor-based navigation
- **Model Management** - Interactive model and provider selection (press `m`)
- **Session Management** - Start new conversations, clear history
- **Session Persistence** - Save and load conversations to/from disk
- **AI-Generated Descriptions** - Automatic short summaries for saved sessions
- **Session Management** - Start new conversations, clear history, browse saved sessions
- **Thinking Mode Support** - Dedicated panel for extended reasoning content
- **Bracketed Paste** - Safe paste handling for multi-line content
@@ -139,6 +141,15 @@ cargo build --release --bin owlen-code --features code-client
- `:m` / `:model` - Open model selector
- `:n` / `:new` - Start new conversation
- `:h` / `:help` - Show help
- `:save [name]` / `:w [name]` - Save current conversation
- `:load` / `:open` - Browse and load saved sessions
- `:sessions` / `:ls` - List saved sessions
**Session Browser** (accessed via `:load` or `:sessions`):
- `j` / `k` / `↑` / `↓` - Navigate sessions
- `Enter` - Load selected session
- `d` - Delete selected session
- `Esc` - Close browser
### Panel Management
- Three panels: Chat, Thinking, and Input
@@ -164,6 +175,22 @@ base_url = "http://localhost:11434"
timeout = 300
```
### Storage Settings
Sessions are saved to platform-specific directories by default:
- **Linux**: `~/.local/share/owlen/sessions`
- **Windows**: `%APPDATA%\owlen\sessions`
- **macOS**: `~/Library/Application Support/owlen/sessions`
You can customize this in your config:
```toml
[storage]
# conversation_dir = "~/custom/path" # Optional: override default location
max_saved_sessions = 25
generate_descriptions = true # AI-generated summaries for saved sessions
```
Configuration is automatically saved when you change models or providers.
## Repository Layout
@@ -226,9 +253,10 @@ cargo fmt
- [x] Bracketed paste support
### In Progress
- [x] Session persistence (save/load conversations)
- [ ] Theming options and color customization
- [ ] Enhanced configuration UX (in-app settings)
- [ ] Chat history management (save/load/export)
- [ ] Conversation export (Markdown, JSON, plain text)
### Planned
- [ ] Code Client Enhancement

View File

@@ -23,6 +23,8 @@ futures = "0.3.28"
async-trait = "0.1.73"
toml = "0.8.0"
shellexpand = "3.1.0"
dirs = "5.0"
[dev-dependencies]
tokio-test = { workspace = true }
tempfile = { workspace = true }

View File

@@ -238,18 +238,20 @@ impl Default for UiSettings {
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct StorageSettings {
#[serde(default = "StorageSettings::default_conversation_dir")]
pub conversation_dir: String,
pub conversation_dir: Option<String>,
#[serde(default = "StorageSettings::default_auto_save")]
pub auto_save_sessions: bool,
#[serde(default = "StorageSettings::default_max_sessions")]
pub max_saved_sessions: usize,
#[serde(default = "StorageSettings::default_session_timeout")]
pub session_timeout_minutes: u64,
#[serde(default = "StorageSettings::default_generate_descriptions")]
pub generate_descriptions: bool,
}
impl StorageSettings {
fn default_conversation_dir() -> String {
"~/.local/share/owlen/conversations".to_string()
fn default_conversation_dir() -> Option<String> {
None
}
fn default_auto_save() -> bool {
@@ -264,19 +266,35 @@ impl StorageSettings {
120
}
fn default_generate_descriptions() -> bool {
true
}
/// Resolve storage directory path
/// Uses platform-specific data directory if not explicitly configured:
/// - Linux: ~/.local/share/owlen/sessions
/// - Windows: %APPDATA%\owlen\sessions
/// - macOS: ~/Library/Application Support/owlen/sessions
pub fn conversation_path(&self) -> PathBuf {
PathBuf::from(shellexpand::tilde(&self.conversation_dir).as_ref())
if let Some(ref dir) = self.conversation_dir {
PathBuf::from(shellexpand::tilde(dir).as_ref())
} else {
// Use platform-specific data directory
dirs::data_local_dir()
.map(|d| d.join("owlen").join("sessions"))
.unwrap_or_else(|| PathBuf::from("./owlen_sessions"))
}
}
}
impl Default for StorageSettings {
fn default() -> Self {
Self {
conversation_dir: Self::default_conversation_dir(),
conversation_dir: None, // Use platform-specific defaults
auto_save_sessions: Self::default_auto_save(),
max_saved_sessions: Self::default_max_sessions(),
session_timeout_minutes: Self::default_session_timeout(),
generate_descriptions: Self::default_generate_descriptions(),
}
}
}
@@ -340,3 +358,48 @@ pub fn ensure_ollama_config(config: &mut Config) -> &ProviderConfig {
pub fn session_timeout(config: &Config) -> Duration {
Duration::from_secs(config.storage.session_timeout_minutes.max(1) * 60)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_storage_platform_specific_paths() {
let config = Config::default();
let path = config.storage.conversation_path();
// Verify it contains owlen/sessions
assert!(path.to_string_lossy().contains("owlen"));
assert!(path.to_string_lossy().contains("sessions"));
// Platform-specific checks
#[cfg(target_os = "linux")]
{
// Linux should use ~/.local/share/owlen/sessions
assert!(path.to_string_lossy().contains(".local/share"));
}
#[cfg(target_os = "windows")]
{
// Windows should use AppData
assert!(path.to_string_lossy().contains("AppData"));
}
#[cfg(target_os = "macos")]
{
// macOS should use ~/Library/Application Support
assert!(path.to_string_lossy().contains("Library/Application Support"));
}
println!("Config conversation path: {}", path.display());
}
#[test]
fn test_storage_custom_path() {
let mut config = Config::default();
config.storage.conversation_dir = Some("~/custom/path".to_string());
let path = config.storage.conversation_path();
assert!(path.to_string_lossy().contains("custom/path"));
}
}

View File

@@ -1,7 +1,9 @@
use crate::storage::StorageManager;
use crate::types::{Conversation, Message};
use crate::Result;
use serde_json::{Number, Value};
use std::collections::{HashMap, VecDeque};
use std::path::{Path, PathBuf};
use std::time::{Duration, Instant};
use uuid::Uuid;
@@ -47,8 +49,8 @@ impl ConversationManager {
&self.active
}
/// Mutable access to the active conversation (auto refreshing indexes afterwards)
fn active_mut(&mut self) -> &mut Conversation {
/// Public mutable access to the active conversation
pub fn active_mut(&mut self) -> &mut Conversation {
&mut self.active
}
@@ -264,6 +266,33 @@ impl ConversationManager {
fn stream_reset(&mut self) {
self.streaming.clear();
}
/// Save the active conversation to disk
pub fn save_active(&self, storage: &StorageManager, name: Option<String>) -> Result<PathBuf> {
storage.save_conversation(&self.active, name)
}
/// Save the active conversation to disk with a description
pub fn save_active_with_description(
&self,
storage: &StorageManager,
name: Option<String>,
description: Option<String>
) -> Result<PathBuf> {
storage.save_conversation_with_description(&self.active, name, description)
}
/// Load a conversation from disk and make it active
pub fn load_from_disk(&mut self, storage: &StorageManager, path: impl AsRef<Path>) -> Result<()> {
let conversation = storage.load_conversation(path)?;
self.load(conversation);
Ok(())
}
/// List all saved sessions
pub fn list_saved_sessions(storage: &StorageManager) -> Result<Vec<crate::storage::SessionMeta>> {
storage.list_sessions()
}
}
impl StreamingMetadata {

View File

@@ -11,6 +11,7 @@ pub mod model;
pub mod provider;
pub mod router;
pub mod session;
pub mod storage;
pub mod types;
pub mod ui;
pub mod wrap_cursor;
@@ -54,6 +55,9 @@ pub enum Error {
#[error("Serialization error: {0}")]
Serialization(#[from] serde_json::Error),
#[error("Storage error: {0}")]
Storage(String),
#[error("Unknown error: {0}")]
Unknown(String),
}

View File

@@ -87,9 +87,8 @@ impl ProviderRegistry {
for provider in self.providers.values() {
match provider.list_models().await {
Ok(mut models) => all_models.append(&mut models),
Err(e) => {
// Log error but continue with other providers
eprintln!("Failed to get models from {}: {}", provider.name(), e);
Err(_) => {
// Continue with other providers
}
}
}

View File

@@ -218,4 +218,88 @@ impl SessionController {
pub fn clear(&mut self) {
self.conversation.clear();
}
/// Generate a short AI description for the current conversation
pub async fn generate_conversation_description(&self) -> Result<String> {
let conv = self.conversation.active();
// If conversation is empty or very short, return a simple description
if conv.messages.is_empty() {
return Ok("Empty conversation".to_string());
}
if conv.messages.len() == 1 {
let first_msg = &conv.messages[0];
let preview = first_msg.content.chars().take(50).collect::<String>();
return Ok(format!("{}{}", preview, if first_msg.content.len() > 50 { "..." } else { "" }));
}
// Build a summary prompt from the first few and last few messages
let mut summary_messages = Vec::new();
// Add system message to guide the description
summary_messages.push(crate::types::Message::system(
"Summarize this conversation in 1-2 short sentences (max 100 characters). \
Focus on the main topic or question being discussed. Be concise and descriptive.".to_string()
));
// Include first message
if let Some(first) = conv.messages.first() {
summary_messages.push(first.clone());
}
// Include a middle message if conversation is long enough
if conv.messages.len() > 4 {
if let Some(mid) = conv.messages.get(conv.messages.len() / 2) {
summary_messages.push(mid.clone());
}
}
// Include last message
if let Some(last) = conv.messages.last() {
if conv.messages.len() > 1 {
summary_messages.push(last.clone());
}
}
// Create a summarization request
let request = crate::types::ChatRequest {
model: conv.model.clone(),
messages: summary_messages,
parameters: crate::types::ChatParameters {
temperature: Some(0.3), // Lower temperature for more focused summaries
max_tokens: Some(50), // Keep it short
stream: false,
extra: std::collections::HashMap::new(),
},
};
// Get the summary from the provider
match self.provider.chat(request).await {
Ok(response) => {
let description = response.message.content.trim().to_string();
// If description is empty, use fallback
if description.is_empty() {
let first_msg = &conv.messages[0];
let preview = first_msg.content.chars().take(50).collect::<String>();
return Ok(format!("{}{}", preview, if first_msg.content.len() > 50 { "..." } else { "" }));
}
// Truncate if too long
let truncated = if description.len() > 100 {
format!("{}...", description.chars().take(97).collect::<String>())
} else {
description
};
Ok(truncated)
}
Err(_e) => {
// Fallback to simple description if AI generation fails
let first_msg = &conv.messages[0];
let preview = first_msg.content.chars().take(50).collect::<String>();
Ok(format!("{}{}", preview, if first_msg.content.len() > 50 { "..." } else { "" }))
}
}
}
}

View File

@@ -0,0 +1,308 @@
//! Session persistence and storage management
use crate::types::Conversation;
use crate::{Error, Result};
use serde::{Deserialize, Serialize};
use std::fs;
use std::path::{Path, PathBuf};
use std::time::SystemTime;
/// Metadata about a saved session
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SessionMeta {
/// Session file path
pub path: PathBuf,
/// Conversation ID
pub id: uuid::Uuid,
/// Optional session name
pub name: Option<String>,
/// Optional AI-generated description
pub description: Option<String>,
/// Number of messages in the conversation
pub message_count: usize,
/// Model used
pub model: String,
/// When the session was created
pub created_at: SystemTime,
/// When the session was last updated
pub updated_at: SystemTime,
}
/// Storage manager for persisting conversations
pub struct StorageManager {
sessions_dir: PathBuf,
}
impl StorageManager {
/// Create a new storage manager with the default sessions directory
pub fn new() -> Result<Self> {
let sessions_dir = Self::default_sessions_dir()?;
Self::with_directory(sessions_dir)
}
/// Create a storage manager with a custom sessions directory
pub fn with_directory(sessions_dir: PathBuf) -> Result<Self> {
// Ensure the directory exists
if !sessions_dir.exists() {
fs::create_dir_all(&sessions_dir).map_err(|e| {
Error::Storage(format!(
"Failed to create sessions directory: {}",
e
))
})?;
}
Ok(Self { sessions_dir })
}
/// Get the default sessions directory
/// - Linux: ~/.local/share/owlen/sessions
/// - Windows: %APPDATA%\owlen\sessions
/// - macOS: ~/Library/Application Support/owlen/sessions
pub fn default_sessions_dir() -> Result<PathBuf> {
let data_dir = dirs::data_local_dir()
.ok_or_else(|| Error::Storage("Could not determine data directory".to_string()))?;
Ok(data_dir.join("owlen").join("sessions"))
}
/// Save a conversation to disk
pub fn save_conversation(&self, conversation: &Conversation, name: Option<String>) -> Result<PathBuf> {
self.save_conversation_with_description(conversation, name, None)
}
/// Save a conversation to disk with an optional description
pub fn save_conversation_with_description(
&self,
conversation: &Conversation,
name: Option<String>,
description: Option<String>
) -> Result<PathBuf> {
let filename = if let Some(ref session_name) = name {
// Use provided name, sanitized
let sanitized = sanitize_filename(session_name);
format!("{}_{}.json", conversation.id, sanitized)
} else {
// Use conversation ID and timestamp
let timestamp = SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)
.unwrap_or_default()
.as_secs();
format!("{}_{}.json", conversation.id, timestamp)
};
let path = self.sessions_dir.join(filename);
// Create a saveable version with the name and description
let mut save_conv = conversation.clone();
if name.is_some() {
save_conv.name = name;
}
if description.is_some() {
save_conv.description = description;
}
let json = serde_json::to_string_pretty(&save_conv).map_err(|e| {
Error::Storage(format!("Failed to serialize conversation: {}", e))
})?;
fs::write(&path, json).map_err(|e| {
Error::Storage(format!("Failed to write session file: {}", e))
})?;
Ok(path)
}
/// Load a conversation from disk
pub fn load_conversation(&self, path: impl AsRef<Path>) -> Result<Conversation> {
let content = fs::read_to_string(path.as_ref()).map_err(|e| {
Error::Storage(format!("Failed to read session file: {}", e))
})?;
let conversation: Conversation = serde_json::from_str(&content).map_err(|e| {
Error::Storage(format!("Failed to parse session file: {}", e))
})?;
Ok(conversation)
}
/// List all saved sessions with metadata
pub fn list_sessions(&self) -> Result<Vec<SessionMeta>> {
let mut sessions = Vec::new();
let entries = fs::read_dir(&self.sessions_dir).map_err(|e| {
Error::Storage(format!("Failed to read sessions directory: {}", e))
})?;
for entry in entries {
let entry = entry.map_err(|e| {
Error::Storage(format!("Failed to read directory entry: {}", e))
})?;
let path = entry.path();
if path.extension().and_then(|s| s.to_str()) != Some("json") {
continue;
}
// Try to load the conversation to extract metadata
match self.load_conversation(&path) {
Ok(conv) => {
sessions.push(SessionMeta {
path: path.clone(),
id: conv.id,
name: conv.name.clone(),
description: conv.description.clone(),
message_count: conv.messages.len(),
model: conv.model.clone(),
created_at: conv.created_at,
updated_at: conv.updated_at,
});
}
Err(_) => {
// Skip files that can't be parsed
continue;
}
}
}
// Sort by updated_at, most recent first
sessions.sort_by(|a, b| b.updated_at.cmp(&a.updated_at));
Ok(sessions)
}
/// Delete a saved session
pub fn delete_session(&self, path: impl AsRef<Path>) -> Result<()> {
fs::remove_file(path.as_ref()).map_err(|e| {
Error::Storage(format!("Failed to delete session file: {}", e))
})
}
/// Get the sessions directory path
pub fn sessions_dir(&self) -> &Path {
&self.sessions_dir
}
}
impl Default for StorageManager {
fn default() -> Self {
Self::new().expect("Failed to create default storage manager")
}
}
/// Sanitize a filename by removing invalid characters
fn sanitize_filename(name: &str) -> String {
name.chars()
.map(|c| {
if c.is_alphanumeric() || c == '_' || c == '-' {
c
} else if c.is_whitespace() {
'_'
} else {
'-'
}
})
.collect::<String>()
.chars()
.take(50) // Limit length
.collect()
}
#[cfg(test)]
mod tests {
use super::*;
use crate::types::Message;
use tempfile::TempDir;
#[test]
fn test_platform_specific_default_path() {
let path = StorageManager::default_sessions_dir().unwrap();
// Verify it contains owlen/sessions
assert!(path.to_string_lossy().contains("owlen"));
assert!(path.to_string_lossy().contains("sessions"));
// Platform-specific checks
#[cfg(target_os = "linux")]
{
// Linux should use ~/.local/share/owlen/sessions
assert!(path.to_string_lossy().contains(".local/share"));
}
#[cfg(target_os = "windows")]
{
// Windows should use AppData
assert!(path.to_string_lossy().contains("AppData"));
}
#[cfg(target_os = "macos")]
{
// macOS should use ~/Library/Application Support
assert!(path.to_string_lossy().contains("Library/Application Support"));
}
println!("Default sessions directory: {}", path.display());
}
#[test]
fn test_sanitize_filename() {
assert_eq!(sanitize_filename("Hello World"), "Hello_World");
assert_eq!(sanitize_filename("test/path\\file"), "test-path-file");
assert_eq!(sanitize_filename("file:name?"), "file-name-");
}
#[test]
fn test_save_and_load_conversation() {
let temp_dir = TempDir::new().unwrap();
let storage = StorageManager::with_directory(temp_dir.path().to_path_buf()).unwrap();
let mut conv = Conversation::new("test-model".to_string());
conv.messages.push(Message::user("Hello".to_string()));
conv.messages.push(Message::assistant("Hi there!".to_string()));
// Save conversation
let path = storage.save_conversation(&conv, Some("test_session".to_string())).unwrap();
assert!(path.exists());
// Load conversation
let loaded = storage.load_conversation(&path).unwrap();
assert_eq!(loaded.id, conv.id);
assert_eq!(loaded.model, conv.model);
assert_eq!(loaded.messages.len(), 2);
assert_eq!(loaded.name, Some("test_session".to_string()));
}
#[test]
fn test_list_sessions() {
let temp_dir = TempDir::new().unwrap();
let storage = StorageManager::with_directory(temp_dir.path().to_path_buf()).unwrap();
// Create multiple sessions
for i in 0..3 {
let mut conv = Conversation::new("test-model".to_string());
conv.messages.push(Message::user(format!("Message {}", i)));
storage.save_conversation(&conv, Some(format!("session_{}", i))).unwrap();
}
// List sessions
let sessions = storage.list_sessions().unwrap();
assert_eq!(sessions.len(), 3);
// Check that sessions are sorted by updated_at (most recent first)
for i in 0..sessions.len() - 1 {
assert!(sessions[i].updated_at >= sessions[i + 1].updated_at);
}
}
#[test]
fn test_delete_session() {
let temp_dir = TempDir::new().unwrap();
let storage = StorageManager::with_directory(temp_dir.path().to_path_buf()).unwrap();
let conv = Conversation::new("test-model".to_string());
let path = storage.save_conversation(&conv, None).unwrap();
assert!(path.exists());
storage.delete_session(&path).unwrap();
assert!(!path.exists());
}
}

View File

@@ -50,6 +50,9 @@ pub struct Conversation {
pub id: Uuid,
/// Optional name/title for the conversation
pub name: Option<String>,
/// Optional AI-generated description of the conversation
#[serde(default)]
pub description: Option<String>,
/// Messages in chronological order
pub messages: Vec<Message>,
/// Model used for this conversation
@@ -167,6 +170,7 @@ impl Conversation {
Self {
id: Uuid::new_v4(),
name: None,
description: None,
messages: Vec::new(),
model,
created_at: now,

View File

@@ -22,6 +22,7 @@ pub enum InputMode {
Help,
Visual,
Command,
SessionBrowser,
}
impl fmt::Display for InputMode {
@@ -34,6 +35,7 @@ impl fmt::Display for InputMode {
InputMode::Help => "Help",
InputMode::Visual => "Visual",
InputMode::Command => "Command",
InputMode::SessionBrowser => "Sessions",
};
f.write_str(label)
}

View File

@@ -1,6 +1,7 @@
use anyhow::Result;
use owlen_core::{
session::{SessionController, SessionOutcome},
storage::{SessionMeta, StorageManager},
types::{ChatParameters, ChatResponse, Conversation, ModelInfo, Role},
ui::{AppState, AutoScroll, FocusedPanel, InputMode},
};
@@ -50,11 +51,18 @@ pub struct ChatApp {
pending_key: Option<char>, // For multi-key sequences like gg, dd
clipboard: String, // Vim-style clipboard for yank/paste
command_buffer: String, // Buffer for command mode input
command_suggestions: Vec<String>, // Filtered command suggestions based on current input
selected_suggestion: usize, // Index of selected suggestion
visual_start: Option<(usize, usize)>, // Visual mode selection start (row, col) for Input panel
visual_end: Option<(usize, usize)>, // Visual mode selection end (row, col) for scrollable panels
focused_panel: FocusedPanel, // Currently focused panel for scrolling
chat_cursor: (usize, usize), // Cursor position in Chat panel (row, col)
thinking_cursor: (usize, usize), // Cursor position in Thinking panel (row, col)
storage: StorageManager, // Storage manager for session persistence
saved_sessions: Vec<SessionMeta>, // Cached list of saved sessions
selected_session_index: usize, // Index of selected session in browser
save_name_buffer: String, // Buffer for entering save name
help_tab_index: usize, // Currently selected help tab (0-4)
}
impl ChatApp {
@@ -63,6 +71,12 @@ impl ChatApp {
let mut textarea = TextArea::default();
configure_textarea_defaults(&mut textarea);
let storage = StorageManager::new().unwrap_or_else(|e| {
eprintln!("Warning: Failed to initialize storage: {}", e);
StorageManager::with_directory(std::path::PathBuf::from("/tmp/owlen_sessions"))
.expect("Failed to create fallback storage")
});
let app = Self {
controller,
mode: InputMode::Normal,
@@ -88,11 +102,18 @@ impl ChatApp {
pending_key: None,
clipboard: String::new(),
command_buffer: String::new(),
command_suggestions: Vec::new(),
selected_suggestion: 0,
visual_start: None,
visual_end: None,
focused_panel: FocusedPanel::Input,
chat_cursor: (0, 0),
thinking_cursor: (0, 0),
storage,
saved_sessions: Vec::new(),
selected_session_index: 0,
save_name_buffer: String::new(),
help_tab_index: 0,
};
(app, session_rx)
@@ -189,6 +210,76 @@ impl ChatApp {
&self.command_buffer
}
pub fn command_suggestions(&self) -> &[String] {
&self.command_suggestions
}
pub fn selected_suggestion(&self) -> usize {
self.selected_suggestion
}
/// Returns all available commands with their aliases
fn get_all_commands() -> Vec<(&'static str, &'static str)> {
vec![
("quit", "Exit the application"),
("q", "Alias for quit"),
("clear", "Clear the conversation"),
("c", "Alias for clear"),
("w", "Alias for write"),
("save", "Alias for write"),
("load", "Load a saved conversation"),
("open", "Alias for load"),
("o", "Alias for load"),
("sessions", "List saved sessions"),
("ls", "Alias for sessions"),
("help", "Show help documentation"),
("h", "Alias for help"),
("model", "Select a model"),
("m", "Alias for model"),
("new", "Start a new conversation"),
("n", "Alias for new"),
]
}
/// Update command suggestions based on current input
fn update_command_suggestions(&mut self) {
let input = self.command_buffer.trim();
if input.is_empty() {
// Show all commands when input is empty
self.command_suggestions = Self::get_all_commands()
.iter()
.map(|(cmd, _)| cmd.to_string())
.collect();
} else {
// Filter commands that start with the input
self.command_suggestions = Self::get_all_commands()
.iter()
.filter_map(|(cmd, _)| {
if cmd.starts_with(input) {
Some(cmd.to_string())
} else {
None
}
})
.collect();
}
// Reset selection if out of bounds
if self.selected_suggestion >= self.command_suggestions.len() {
self.selected_suggestion = 0;
}
}
/// Complete the current command with the selected suggestion
fn complete_command(&mut self) {
if let Some(suggestion) = self.command_suggestions.get(self.selected_suggestion) {
self.command_buffer = suggestion.clone();
self.update_command_suggestions();
self.status = format!(":{}", self.command_buffer);
}
}
pub fn focused_panel(&self) -> FocusedPanel {
self.focused_panel
}
@@ -209,6 +300,18 @@ impl ChatApp {
self.thinking_cursor
}
pub fn saved_sessions(&self) -> &[SessionMeta] {
&self.saved_sessions
}
pub fn selected_session_index(&self) -> usize {
self.selected_session_index
}
pub fn help_tab_index(&self) -> usize {
self.help_tab_index
}
pub fn cycle_focus_forward(&mut self) {
self.focused_panel = match self.focused_panel {
FocusedPanel::Chat => {
@@ -387,6 +490,8 @@ impl ChatApp {
(KeyCode::Char(':'), KeyModifiers::NONE) => {
self.mode = InputMode::Command;
self.command_buffer.clear();
self.selected_suggestion = 0;
self.update_command_suggestions();
self.status = ":".to_string();
}
// Enter editing mode
@@ -971,12 +1076,36 @@ impl ChatApp {
(KeyCode::Esc, _) => {
self.mode = InputMode::Normal;
self.command_buffer.clear();
self.command_suggestions.clear();
self.reset_status();
}
(KeyCode::Tab, _) => {
// Tab completion
self.complete_command();
}
(KeyCode::Up, _) | (KeyCode::Char('k'), KeyModifiers::CONTROL) => {
// Navigate up in suggestions
if !self.command_suggestions.is_empty() {
self.selected_suggestion = self
.selected_suggestion
.saturating_sub(1);
}
}
(KeyCode::Down, _) | (KeyCode::Char('j'), KeyModifiers::CONTROL) => {
// Navigate down in suggestions
if !self.command_suggestions.is_empty() {
self.selected_suggestion = (self.selected_suggestion + 1)
.min(self.command_suggestions.len().saturating_sub(1));
}
}
(KeyCode::Enter, _) => {
// Execute command
let cmd = self.command_buffer.trim();
match cmd {
let parts: Vec<&str> = cmd.split_whitespace().collect();
let command = parts.first().copied().unwrap_or("");
let args = &parts[1..];
match command {
"q" | "quit" => {
return Ok(AppState::Quit);
}
@@ -984,19 +1113,79 @@ impl ChatApp {
self.controller.clear();
self.status = "Conversation cleared".to_string();
}
"w" | "write" => {
// Could implement saving conversation here
self.status = "Conversation saved".to_string();
"w" | "write" | "save" => {
// Save current conversation with AI-generated description
let name = if !args.is_empty() {
Some(args.join(" "))
} else {
None
};
// Generate description if enabled in config
let description = if self.controller.config().storage.generate_descriptions {
self.status = "Generating description...".to_string();
match self.controller.generate_conversation_description().await {
Ok(desc) => Some(desc),
Err(_) => None,
}
} else {
None
};
// Save the conversation with description
match self.controller.conversation_mut().save_active_with_description(&self.storage, name.clone(), description) {
Ok(path) => {
self.status = format!("Session saved: {}", path.display());
self.error = None;
}
Err(e) => {
self.error = Some(format!("Failed to save session: {}", e));
}
}
}
"load" | "open" | "o" => {
// Load saved sessions and enter browser mode
match self.storage.list_sessions() {
Ok(sessions) => {
self.saved_sessions = sessions;
self.selected_session_index = 0;
self.mode = InputMode::SessionBrowser;
self.command_buffer.clear();
self.command_suggestions.clear();
return Ok(AppState::Running);
}
Err(e) => {
self.error = Some(format!("Failed to list sessions: {}", e));
}
}
}
"sessions" | "ls" => {
// List saved sessions
match self.storage.list_sessions() {
Ok(sessions) => {
self.saved_sessions = sessions;
self.selected_session_index = 0;
self.mode = InputMode::SessionBrowser;
self.command_buffer.clear();
self.command_suggestions.clear();
return Ok(AppState::Running);
}
Err(e) => {
self.error = Some(format!("Failed to list sessions: {}", e));
}
}
}
"h" | "help" => {
self.mode = InputMode::Help;
self.command_buffer.clear();
self.command_suggestions.clear();
return Ok(AppState::Running);
}
"m" | "model" => {
self.refresh_models().await?;
self.mode = InputMode::ProviderSelection;
self.command_buffer.clear();
self.command_suggestions.clear();
return Ok(AppState::Running);
}
"n" | "new" => {
@@ -1008,15 +1197,18 @@ impl ChatApp {
}
}
self.command_buffer.clear();
self.command_suggestions.clear();
self.mode = InputMode::Normal;
}
(KeyCode::Char(c), KeyModifiers::NONE)
| (KeyCode::Char(c), KeyModifiers::SHIFT) => {
self.command_buffer.push(c);
self.update_command_suggestions();
self.status = format!(":{}", self.command_buffer);
}
(KeyCode::Backspace, _) => {
self.command_buffer.pop();
self.update_command_suggestions();
self.status = format!(":{}", self.command_buffer);
}
_ => {}
@@ -1092,8 +1284,76 @@ impl ChatApp {
_ => {}
},
InputMode::Help => match key.code {
KeyCode::Esc | KeyCode::Enter => {
KeyCode::Esc | KeyCode::Enter | KeyCode::Char('q') => {
self.mode = InputMode::Normal;
self.help_tab_index = 0; // Reset to first tab
}
KeyCode::Tab | KeyCode::Right | KeyCode::Char('l') => {
// Next tab
if self.help_tab_index < 4 {
self.help_tab_index += 1;
}
}
KeyCode::BackTab | KeyCode::Left | KeyCode::Char('h') => {
// Previous tab
if self.help_tab_index > 0 {
self.help_tab_index -= 1;
}
}
KeyCode::Char('1') => self.help_tab_index = 0,
KeyCode::Char('2') => self.help_tab_index = 1,
KeyCode::Char('3') => self.help_tab_index = 2,
KeyCode::Char('4') => self.help_tab_index = 3,
KeyCode::Char('5') => self.help_tab_index = 4,
_ => {}
},
InputMode::SessionBrowser => match key.code {
KeyCode::Esc => {
self.mode = InputMode::Normal;
}
KeyCode::Enter => {
// Load selected session
if let Some(session) = self.saved_sessions.get(self.selected_session_index) {
match self.controller.conversation_mut().load_from_disk(&self.storage, &session.path) {
Ok(_) => {
self.status = format!("Loaded session: {}", session.name.as_deref().unwrap_or("Unnamed"));
self.error = None;
// Update thinking panel
self.update_thinking_from_last_message();
}
Err(e) => {
self.error = Some(format!("Failed to load session: {}", e));
}
}
}
self.mode = InputMode::Normal;
}
KeyCode::Up | KeyCode::Char('k') => {
if self.selected_session_index > 0 {
self.selected_session_index -= 1;
}
}
KeyCode::Down | KeyCode::Char('j') => {
if self.selected_session_index + 1 < self.saved_sessions.len() {
self.selected_session_index += 1;
}
}
KeyCode::Char('d') => {
// Delete selected session
if let Some(session) = self.saved_sessions.get(self.selected_session_index) {
match self.storage.delete_session(&session.path) {
Ok(_) => {
self.saved_sessions.remove(self.selected_session_index);
if self.selected_session_index >= self.saved_sessions.len() && !self.saved_sessions.is_empty() {
self.selected_session_index = self.saved_sessions.len() - 1;
}
self.status = "Session deleted".to_string();
}
Err(e) => {
self.error = Some(format!("Failed to delete session: {}", e));
}
}
}
}
_ => {}
},
@@ -1342,7 +1602,7 @@ impl ChatApp {
stream,
}) => {
// Step 3: Model loaded, now generating response
self.status = "Generating response...".to_string();
self.status = format!("Model loaded. Generating response... (streaming)");
self.spawn_stream(response_id, stream);
match self.controller.mark_stream_placeholder(response_id, "") {

View File

@@ -80,7 +80,9 @@ pub fn render_chat(frame: &mut Frame<'_>, app: &mut ChatApp) {
match app.mode() {
InputMode::ProviderSelection => render_provider_selector(frame, app),
InputMode::ModelSelection => render_model_selector(frame, app),
InputMode::Help => render_help(frame),
InputMode::Help => render_help(frame, app),
InputMode::SessionBrowser => render_session_browser(frame, app),
InputMode::Command => render_command_suggestions(frame, app),
_ => {}
}
}
@@ -943,14 +945,13 @@ fn render_status(frame: &mut Frame<'_>, area: Rect, app: &ChatApp) {
InputMode::Help => (" HELP", Color::LightMagenta),
InputMode::Visual => (" VISUAL", Color::Magenta),
InputMode::Command => (" COMMAND", Color::Yellow),
InputMode::SessionBrowser => (" SESSIONS", Color::Yellow),
};
let status_message = if app.streaming_count() > 0 {
format!("Streaming... ({})", app.streaming_count())
} else if let Some(error) = app.error_message() {
let status_message = if let Some(error) = app.error_message() {
format!("Error: {}", error)
} else {
"Ready".to_string()
app.status_message().to_string()
};
let help_text = "i:Input :m:Model :n:New :c:Clear :h:Help q:Quit";
@@ -1083,23 +1084,48 @@ fn render_model_selector(frame: &mut Frame<'_>, app: &ChatApp) {
frame.render_stateful_widget(list, area, &mut state);
}
fn render_help(frame: &mut Frame<'_>) {
let area = centered_rect(70, 60, frame.area());
fn render_help(frame: &mut Frame<'_>, app: &ChatApp) {
let area = centered_rect(75, 70, frame.area());
frame.render_widget(Clear, area);
let help_text = vec![
Line::from("MODES:"),
Line::from(" Normal → default mode for navigation"),
Line::from(" Insert → editing input text"),
Line::from(" Visual → selecting text"),
Line::from(" Command → executing commands (: prefix)"),
let tab_index = app.help_tab_index();
let tabs = vec!["Navigation", "Editing", "Visual", "Commands", "Sessions"];
// Build tab line
let mut tab_spans = Vec::new();
for (i, tab_name) in tabs.iter().enumerate() {
if i == tab_index {
tab_spans.push(Span::styled(
format!(" {} ", tab_name),
Style::default()
.fg(Color::Black)
.bg(Color::LightMagenta)
.add_modifier(Modifier::BOLD),
));
} else {
tab_spans.push(Span::styled(
format!(" {} ", tab_name),
Style::default().fg(Color::Gray),
));
}
if i < tabs.len() - 1 {
tab_spans.push(Span::raw(""));
}
}
let help_text = match tab_index {
0 => vec![ // Navigation
Line::from(""),
Line::from("PANEL NAVIGATION:"),
Line::from(vec![
Span::styled("PANEL NAVIGATION", Style::default().add_modifier(Modifier::BOLD).fg(Color::Yellow))
]),
Line::from(" Tab → cycle panels forward"),
Line::from(" Shift+Tab → cycle panels backward"),
Line::from(" (Panels: Chat, Thinking, Input)"),
Line::from(""),
Line::from("CURSOR MOVEMENT (Normal mode, Chat/Thinking panels):"),
Line::from(vec![
Span::styled("CURSOR MOVEMENT", Style::default().add_modifier(Modifier::BOLD).fg(Color::Yellow))
]),
Line::from(" h/← l/→ → move left/right by character"),
Line::from(" j/↓ k/↑ → move down/up by line"),
Line::from(" w → forward to next word start"),
@@ -1110,67 +1136,390 @@ fn render_help(frame: &mut Frame<'_>) {
Line::from(" $ / End → end of line"),
Line::from(" gg → jump to top"),
Line::from(" G → jump to bottom"),
Line::from(""),
Line::from(vec![
Span::styled("SCROLLING", Style::default().add_modifier(Modifier::BOLD).fg(Color::Yellow))
]),
Line::from(" Ctrl+d/u → scroll half page down/up"),
Line::from(" Ctrl+f/b → scroll full page down/up"),
Line::from(" PageUp/Down → scroll full page"),
],
1 => vec![ // Editing
Line::from(""),
Line::from("EDITING (Normal mode):"),
Line::from(vec![
Span::styled("ENTERING INSERT MODE", Style::default().add_modifier(Modifier::BOLD).fg(Color::Yellow))
]),
Line::from(" i / Enter → enter insert mode at cursor"),
Line::from(" a → append after cursor"),
Line::from(" A → append at end of line"),
Line::from(" I → insert at start of line"),
Line::from(" o → insert line below and enter insert mode"),
Line::from(" O → insert line above and enter insert mode"),
Line::from(" dd → clear input buffer"),
Line::from(" p → paste from clipboard to input"),
Line::from(" Esc → return to normal mode"),
Line::from(""),
Line::from("INSERT MODE:"),
Line::from(vec![
Span::styled("INSERT MODE KEYS", Style::default().add_modifier(Modifier::BOLD).fg(Color::Yellow))
]),
Line::from(" Enter → send message"),
Line::from(" Ctrl+J → insert newline"),
Line::from(" Ctrl+J → insert newline (multiline message)"),
Line::from(" Ctrl+↑/↓ → navigate input history"),
Line::from(" Ctrl+A start of line"),
Line::from(" Ctrl+E end of line"),
Line::from(" Ctrl+A → jump to start of line"),
Line::from(" Ctrl+E → jump to end of line"),
Line::from(" Ctrl+W → word forward"),
Line::from(" Ctrl+B → word backward"),
Line::from(" Esc → return to normal mode"),
Line::from(""),
Line::from("VISUAL MODE (all panels):"),
Line::from(vec![
Span::styled("NORMAL MODE OPERATIONS", Style::default().add_modifier(Modifier::BOLD).fg(Color::Yellow))
]),
Line::from(" dd → clear input buffer"),
Line::from(" p → paste from clipboard to input"),
],
2 => vec![ // Visual
Line::from(""),
Line::from(vec![
Span::styled("VISUAL MODE", Style::default().add_modifier(Modifier::BOLD).fg(Color::Yellow))
]),
Line::from(" v → enter visual mode at cursor"),
Line::from(""),
Line::from(vec![
Span::styled("SELECTION MOVEMENT", Style::default().add_modifier(Modifier::BOLD).fg(Color::Yellow))
]),
Line::from(" h/j/k/l → extend selection left/down/up/right"),
Line::from(" w / e / b → extend by word (start/end/back)"),
Line::from(" 0 / ^ / $ → extend to line start/first char/end"),
Line::from(" yyank (copy) selection"),
Line::from(" d → yank selection (delete in Input)"),
Line::from(" w → extend to next word start"),
Line::from(" e → extend to word end"),
Line::from(" b extend backward to previous word"),
Line::from(" 0 → extend to line start"),
Line::from(" ^ → extend to first non-blank"),
Line::from(" $ → extend to line end"),
Line::from(""),
Line::from(vec![
Span::styled("VISUAL MODE OPERATIONS", Style::default().add_modifier(Modifier::BOLD).fg(Color::Yellow))
]),
Line::from(" y → yank (copy) selection to clipboard"),
Line::from(" d → cut selection (Input panel only)"),
Line::from(" v / Esc → exit visual mode"),
Line::from(""),
Line::from("COMMANDS (press : then type):"),
Line::from(vec![
Span::styled("NOTES", Style::default().add_modifier(Modifier::BOLD).fg(Color::Cyan))
]),
Line::from(" • Visual mode works across all panels (Chat, Thinking, Input)"),
Line::from(" • Yanked text is available for paste with 'p' in normal mode"),
],
3 => vec![ // Commands
Line::from(""),
Line::from(vec![
Span::styled("COMMAND MODE", Style::default().add_modifier(Modifier::BOLD).fg(Color::Yellow))
]),
Line::from(" Press ':' to enter command mode, then type one of:"),
Line::from(""),
Line::from(vec![
Span::styled("HELP & NAVIGATION", Style::default().add_modifier(Modifier::BOLD).fg(Color::Cyan))
]),
Line::from(" :h, :help → show this help"),
Line::from(" :m, :model → select model"),
Line::from(" :n, :new → start new conversation"),
Line::from(" :c, :clear → clear current conversation"),
Line::from(" :q, :quit → quit application"),
Line::from(""),
Line::from("QUICK KEYS:"),
Line::from(" q → quit (from normal mode)"),
Line::from(" Ctrl+C → quit"),
Line::from(vec![
Span::styled("MODEL MANAGEMENT", Style::default().add_modifier(Modifier::BOLD).fg(Color::Cyan))
]),
Line::from(" :m, :model → open model selector"),
Line::from(""),
Line::from("Press Esc or Enter to close this help."),
Line::from(vec![
Span::styled("CONVERSATION MANAGEMENT", Style::default().add_modifier(Modifier::BOLD).fg(Color::Cyan))
]),
Line::from(" :n, :new → start new conversation"),
Line::from(" :c, :clear → clear current conversation"),
Line::from(""),
Line::from(vec![
Span::styled("SESSION MANAGEMENT", Style::default().add_modifier(Modifier::BOLD).fg(Color::Cyan))
]),
Line::from(" :save [name] → save current session (with optional name)"),
Line::from(" :w [name] → alias for :save"),
Line::from(" :load, :o, :open → browse and load saved sessions"),
Line::from(" :sessions, :ls → browse saved sessions"),
Line::from(""),
Line::from(vec![
Span::styled("QUICK SHORTCUTS", Style::default().add_modifier(Modifier::BOLD).fg(Color::Cyan))
]),
Line::from(" q (normal mode) → quit without :"),
Line::from(" Ctrl+C → quit immediately"),
],
4 => vec![ // Sessions
Line::from(""),
Line::from(vec![
Span::styled("SESSION MANAGEMENT", Style::default().add_modifier(Modifier::BOLD).fg(Color::Yellow))
]),
Line::from(""),
Line::from(vec![
Span::styled("SAVING SESSIONS", Style::default().add_modifier(Modifier::BOLD).fg(Color::Cyan))
]),
Line::from(" :save → save with auto-generated name"),
Line::from(" :save my-session → save with custom name"),
Line::from(" • AI generates description automatically (configurable)"),
Line::from(" • Sessions stored in platform-specific directories"),
Line::from(""),
Line::from(vec![
Span::styled("LOADING SESSIONS", Style::default().add_modifier(Modifier::BOLD).fg(Color::Cyan))
]),
Line::from(" :load, :o, :open → browse and select session"),
Line::from(" :sessions, :ls → browse saved sessions"),
Line::from(""),
Line::from(vec![
Span::styled("SESSION BROWSER KEYS", Style::default().add_modifier(Modifier::BOLD).fg(Color::Cyan))
]),
Line::from(" j/k or ↑/↓ → navigate sessions"),
Line::from(" Enter → load selected session"),
Line::from(" d → delete selected session"),
Line::from(" Esc → close browser"),
Line::from(""),
Line::from(vec![
Span::styled("STORAGE LOCATIONS", Style::default().add_modifier(Modifier::BOLD).fg(Color::Cyan))
]),
Line::from(" Linux → ~/.local/share/owlen/sessions"),
Line::from(" Windows → %APPDATA%\\owlen\\sessions"),
Line::from(" macOS → ~/Library/Application Support/owlen/sessions"),
Line::from(""),
Line::from(vec![
Span::styled("CONTEXT PRESERVATION", Style::default().add_modifier(Modifier::BOLD).fg(Color::Green))
]),
Line::from(" • Full conversation history is preserved when saving"),
Line::from(" • All context is restored when loading a session"),
Line::from(" • Continue conversations seamlessly across restarts"),
],
_ => vec![],
};
// Create layout for tabs and content
let layout = Layout::default()
.direction(Direction::Vertical)
.constraints([
Constraint::Length(3), // Tab bar
Constraint::Min(0), // Content
Constraint::Length(2), // Navigation hint
])
.split(area);
// Render tabs
let tabs_block = Block::default()
.borders(Borders::TOP | Borders::LEFT | Borders::RIGHT)
.border_style(Style::default().fg(Color::Rgb(95, 20, 135)));
let tabs_para = Paragraph::new(Line::from(tab_spans)).block(tabs_block);
frame.render_widget(tabs_para, layout[0]);
// Render content
let content_block = Block::default()
.borders(Borders::LEFT | Borders::RIGHT)
.border_style(Style::default().fg(Color::Rgb(95, 20, 135)));
let content_para = Paragraph::new(help_text).block(content_block);
frame.render_widget(content_para, layout[1]);
// Render navigation hint
let nav_hint = Line::from(vec![
Span::raw(" "),
Span::styled("Tab/h/l", Style::default().fg(Color::LightMagenta).add_modifier(Modifier::BOLD)),
Span::raw(":Switch "),
Span::styled("1-5", Style::default().fg(Color::LightMagenta).add_modifier(Modifier::BOLD)),
Span::raw(":Jump "),
Span::styled("Esc/q", Style::default().fg(Color::LightMagenta).add_modifier(Modifier::BOLD)),
Span::raw(":Close "),
]);
let nav_block = Block::default()
.borders(Borders::ALL)
.border_style(Style::default().fg(Color::Rgb(95, 20, 135)));
let nav_para = Paragraph::new(nav_hint)
.block(nav_block)
.alignment(Alignment::Center);
frame.render_widget(nav_para, layout[2]);
}
fn render_session_browser(frame: &mut Frame<'_>, app: &ChatApp) {
let area = centered_rect(70, 70, frame.area());
frame.render_widget(Clear, area);
let sessions = app.saved_sessions();
if sessions.is_empty() {
let text = vec![
Line::from(""),
Line::from("No saved sessions found."),
Line::from(""),
Line::from("Save your current session with :save [name]"),
Line::from(""),
Line::from("Press Esc to close."),
];
let paragraph = Paragraph::new(help_text).block(
let paragraph = Paragraph::new(text)
.block(
Block::default()
.title(Span::styled(
"Help",
" Saved Sessions ",
Style::default().fg(Color::Yellow).add_modifier(Modifier::BOLD),
))
.borders(Borders::ALL)
.border_style(Style::default().fg(Color::Yellow)),
)
.alignment(Alignment::Center);
frame.render_widget(paragraph, area);
return;
}
let items: Vec<ListItem> = sessions
.iter()
.enumerate()
.map(|(idx, session)| {
let name = session
.name
.as_deref()
.unwrap_or("Unnamed session");
let created = session.created_at
.duration_since(std::time::UNIX_EPOCH)
.unwrap_or_default()
.as_secs();
let now = std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.unwrap_or_default()
.as_secs();
let age_hours = (now - created) / 3600;
let age_str = if age_hours < 1 {
"< 1h ago".to_string()
} else if age_hours < 24 {
format!("{}h ago", age_hours)
} else {
format!("{}d ago", age_hours / 24)
};
let info = format!(
"{} messages · {} · {}",
session.message_count,
session.model,
age_str
);
let is_selected = idx == app.selected_session_index();
let style = if is_selected {
Style::default()
.fg(Color::LightMagenta)
.fg(Color::Black)
.bg(Color::Yellow)
.add_modifier(Modifier::BOLD)
} else {
Style::default().fg(Color::White)
};
let info_style = if is_selected {
Style::default().fg(Color::Black).bg(Color::Yellow)
} else {
Style::default().fg(Color::Gray)
};
let desc_style = if is_selected {
Style::default().fg(Color::Black).bg(Color::Yellow).add_modifier(Modifier::ITALIC)
} else {
Style::default().fg(Color::DarkGray).add_modifier(Modifier::ITALIC)
};
let mut lines = vec![
Line::from(Span::styled(name, style)),
];
// Add description if available and not empty
if let Some(description) = &session.description {
if !description.is_empty() {
lines.push(Line::from(Span::styled(format!(" \"{}\"", description), desc_style)));
}
}
// Add metadata line
lines.push(Line::from(Span::styled(format!(" {}", info), info_style)));
ListItem::new(lines)
})
.collect();
let list = List::new(items).block(
Block::default()
.title(Span::styled(
format!(" Saved Sessions ({}) ", sessions.len()),
Style::default().fg(Color::Yellow).add_modifier(Modifier::BOLD),
))
.borders(Borders::ALL)
.border_style(Style::default().fg(Color::Yellow)),
);
let footer = Paragraph::new(vec![
Line::from(""),
Line::from("↑/↓ or j/k: Navigate · Enter: Load · d: Delete · Esc: Cancel"),
])
.alignment(Alignment::Center)
.style(Style::default().fg(Color::Gray));
let layout = Layout::default()
.direction(Direction::Vertical)
.constraints([
Constraint::Min(5),
Constraint::Length(3),
])
.split(area);
frame.render_widget(list, layout[0]);
frame.render_widget(footer, layout[1]);
}
fn render_command_suggestions(frame: &mut Frame<'_>, app: &ChatApp) {
let suggestions = app.command_suggestions();
// Only show suggestions if there are any
if suggestions.is_empty() {
return;
}
// Create a small popup near the status bar (bottom of screen)
let frame_height = frame.area().height;
let suggestion_count = suggestions.len().min(8); // Show max 8 suggestions
let popup_height = (suggestion_count as u16) + 2; // +2 for borders
// Position the popup above the status bar
let popup_area = Rect {
x: 1,
y: frame_height.saturating_sub(popup_height + 3), // 3 for status bar height
width: 40.min(frame.area().width - 2),
height: popup_height,
};
frame.render_widget(Clear, popup_area);
let items: Vec<ListItem> = suggestions
.iter()
.enumerate()
.map(|(idx, cmd)| {
let is_selected = idx == app.selected_suggestion();
let style = if is_selected {
Style::default()
.fg(Color::Black)
.bg(Color::Yellow)
.add_modifier(Modifier::BOLD)
} else {
Style::default().fg(Color::White)
};
ListItem::new(Span::styled(cmd.to_string(), style))
})
.collect();
let list = List::new(items)
.block(
Block::default()
.title(Span::styled(
" Commands (Tab to complete) ",
Style::default()
.fg(Color::Yellow)
.add_modifier(Modifier::BOLD),
))
.borders(Borders::ALL)
.border_style(Style::default().fg(Color::Rgb(95, 20, 135))),
.border_style(Style::default().fg(Color::Yellow)),
);
frame.render_widget(paragraph, area);
frame.render_widget(list, popup_area);
}
fn centered_rect(percent_x: u16, percent_y: u16, area: Rect) -> Rect {