-
Notifications
You must be signed in to change notification settings - Fork 2.3k
fix: reset context progress bar on /clear command (#5651) #5713
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -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(); | ||||||
|
|
||||||
|
Comment on lines
+18
to
+20
|
||||||
| // Reset the session context usage | |
| session.reset_context_usage(); |
Copilot
AI
Nov 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The module crate::ui does not exist in the goose-cli crate. Calling ui::reset_progress_bar() will result in a compilation error.
Copilot
AI
Nov 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The handle_command function is defined but never integrated into the CLI's command handling flow. There's no evidence this function is called from the session input handling code, so the /clear command won't actually be processed.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
| } | ||
|
Comment on lines
+52
to
+99
|
||
|
|
||
|
|
||
| pub fn format_task_execution_notification( | ||
| data: &Value, | ||
| ) -> Option<(String, Option<String>, Option<String>)> { | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,30 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import React, { useState, useImperativeHandle, forwardRef } from 'react'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export interface ProgressBarHandle { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| resetProgressBar: () => void; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const ProgressBar = forwardRef<ProgressBarHandle>((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 ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <div> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <div style={{ marginBottom: '8px' }}> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Context Usage: {progress}% ({tokensUsed} tokens) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <progress value={progress} max={100} style={{ width: '100%' }} /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+7
to
+28
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const ProgressBar = forwardRef<ProgressBarHandle>((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 ( | |
| <div> | |
| <div style={{ marginBottom: '8px' }}> | |
| Context Usage: {progress}% ({tokensUsed} tokens) | |
| </div> | |
| <progress value={progress} max={100} style={{ width: '100%' }} /> | |
| </div> | |
| ); | |
| }); | |
| export interface ProgressBarProps { | |
| progress: number; // percentage 0-100 | |
| tokensUsed: number; | |
| onReset?: () => void; | |
| } | |
| const ProgressBar = forwardRef<ProgressBarHandle, ProgressBarProps>( | |
| ({ progress, tokensUsed, onReset }, ref) => { | |
| // Expose resetProgressBar method to parent components via ref | |
| useImperativeHandle(ref, () => ({ | |
| resetProgressBar() { | |
| if (onReset) { | |
| onReset(); | |
| } | |
| }, | |
| })); | |
| // Display progress text and progress bar | |
| return ( | |
| <div> | |
| <div style={{ marginBottom: '8px' }}> | |
| Context Usage: {progress}% ({tokensUsed} tokens) | |
| </div> | |
| <progress value={progress} max={100} style={{ width: '100%' }} /> | |
| </div> | |
| ); | |
| } | |
| ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Conflicting imports: line 5 imports
Sessionfromgoose::session, and line 11 importsSessionfromcrate::session. These are two different types and will cause a compilation error. Additionally, line 13 duplicates theanyhow::Resultimport already present on line 2.