diff --git a/crates/goose-cli/src/commands/session.rs b/crates/goose-cli/src/commands/session.rs index a145f01ffd33..3e3c0d930ad1 100644 --- a/crates/goose-cli/src/commands/session.rs +++ b/crates/goose-cli/src/commands/session.rs @@ -8,9 +8,32 @@ use regex::Regex; use std::fs; use std::io::Write; use std::path::PathBuf; - +use crate::session::Session; +use crate::ui; +use anyhow::Result; const TRUNCATED_DESC_LENGTH: usize = 60; +pub fn handle_command(command: &str, session: &mut Session) -> Result<()> { + if command.trim() == "/clear" { + // Reset the session context usage + session.reset_context_usage(); + + // Reset the UI progress bar to zero + ui::reset_progress_bar(); + + println!("Context cleared."); + return Ok(()); + } + + // Existing command handling code here... + + println!("Command not recognized: {}", command); + Ok(()) +} + + + + pub async fn remove_sessions(sessions: Vec) -> Result<()> { println!("The following sessions will be removed:"); for session in &sessions { diff --git a/crates/goose-cli/src/session/task_execution_display/mod.rs b/crates/goose-cli/src/session/task_execution_display/mod.rs index 434c777271a2..a7c931a71a00 100644 --- a/crates/goose-cli/src/session/task_execution_display/mod.rs +++ b/crates/goose-cli/src/session/task_execution_display/mod.rs @@ -49,6 +49,56 @@ fn process_output_for_display(output: &str) -> String { safe_truncate(&clean_output, OUTPUT_PREVIEW_LENGTH) } +pub struct Session { + pub id: String, + pub name: String, + pub token_usage: usize, + pub max_token_limit: usize, + pub other_usage_metrics: usize, + pub messages_count: usize, + pub context_data_size: usize, + // Add other relevant session fields here +} + +impl Session { + pub fn new(id: String, name: String, max_token_limit: usize) -> Self { + Self { + id, + name, + token_usage: 0, + max_token_limit, + other_usage_metrics: 0, + messages_count: 0, + context_data_size: 0, + // Initialize other fields as needed + } + } + + pub fn add_tokens(&mut self, count: usize) { + self.token_usage += count; + // Possibly add checks against max_token_limit + } + + pub fn add_message(&mut self) { + self.messages_count += 1; + } + + pub fn reset_context_usage(&mut self) { + self.token_usage = 0; + self.other_usage_metrics = 0; + self.messages_count = 0; + self.context_data_size = 0; + // Reset other context/session related state if applicable + } + + pub fn is_token_limit_reached(&self) -> bool { + self.token_usage >= self.max_token_limit + } + + // Add more existing methods relevant to session management +} + + pub fn format_task_execution_notification( data: &Value, ) -> Option<(String, Option, Option)> { diff --git a/ui/desktop/src/components/context_management/ProgressBar.tsx b/ui/desktop/src/components/context_management/ProgressBar.tsx new file mode 100644 index 000000000000..c92ade2110f6 --- /dev/null +++ b/ui/desktop/src/components/context_management/ProgressBar.tsx @@ -0,0 +1,30 @@ +import React, { useState, useImperativeHandle, forwardRef } from 'react'; + +export interface ProgressBarHandle { + resetProgressBar: () => void; +} + +const ProgressBar = forwardRef((props, ref) => { + const [progress, setProgress] = useState(0); // percentage 0-100 + const [tokensUsed, setTokensUsed] = useState(0); + + // Expose resetProgressBar method to parent components via ref + useImperativeHandle(ref, () => ({ + resetProgressBar() { + setProgress(0); + setTokensUsed(0); + }, + })); + + // Simulate progress text display and progress bar + return ( +
+
+ Context Usage: {progress}% ({tokensUsed} tokens) +
+ +
+ ); +}); + +export default ProgressBar;