Skip to content

Commit 7953f7d

Browse files
authored
Fix: recover /save, /usage, and /compact behavior after slash command refactor (#281)
* fix /usage * fix al
1 parent 8b5a7f3 commit 7953f7d

File tree

5 files changed

+62
-10
lines changed

5 files changed

+62
-10
lines changed

crates/chat-cli/src/cli/chat/cli/compact.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ How it works
3131
pub struct CompactArgs {
3232
/// The prompt to use when generating the summary
3333
prompt: Option<String>,
34+
#[arg(long)]
3435
show_summary: bool,
3536
}
3637

crates/chat-cli/src/cli/chat/cli/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub enum ContextSubcommand {
3939
Show {
4040
/// Print out each matched file's content, hook configurations, and last
4141
/// session.conversation summary
42-
#[arg(short, long)]
42+
#[arg(long)]
4343
expand: bool,
4444
},
4545
/// Add context rules (filenames or glob patterns)

crates/chat-cli/src/cli/chat/cli/persist.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ use crate::platform::Context;
1818
#[derive(Debug, PartialEq, Subcommand)]
1919
pub enum PersistSubcommand {
2020
/// Save the current conversation
21-
Save { path: String, force: bool },
21+
Save {
22+
path: String,
23+
#[arg(short, long)]
24+
force: bool,
25+
},
2226
/// Load a previous conversation
2327
Load { path: String },
2428
}

crates/chat-cli/src/cli/chat/cli/prompts.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,21 @@ impl PromptsArgs {
8888
optimal_case
8989
}
9090
};
91+
// Add usage guidance at the top
92+
queue!(
93+
session.output,
94+
style::Print("\n"),
95+
style::SetAttribute(Attribute::Bold),
96+
style::Print("Usage: "),
97+
style::SetAttribute(Attribute::Reset),
98+
style::Print("You can use a prompt by typing "),
99+
style::SetAttribute(Attribute::Bold),
100+
style::SetForegroundColor(Color::Green),
101+
style::Print("'@<prompt name> [...args]'"),
102+
style::SetForegroundColor(Color::Reset),
103+
style::SetAttribute(Attribute::Reset),
104+
style::Print("\n\n"),
105+
)?;
91106
queue!(
92107
session.output,
93108
style::Print("\n"),

crates/chat-cli/src/cli/chat/cli/usage.rs

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,16 @@ use crossterm::{
1010
};
1111

1212
use crate::cli::chat::consts::CONTEXT_WINDOW_SIZE;
13-
use crate::cli::chat::token_counter::TokenCount;
13+
use crate::cli::chat::token_counter::{
14+
CharCount,
15+
TokenCount,
16+
};
1417
use crate::cli::chat::{
1518
ChatError,
1619
ChatSession,
1720
ChatState,
1821
};
1922
use crate::platform::Context;
20-
2123
#[deny(missing_docs)]
2224
#[derive(Debug, PartialEq, Args)]
2325
pub struct UsageArgs;
@@ -43,13 +45,19 @@ impl UsageArgs {
4345
}
4446

4547
let data = state.calculate_conversation_size();
46-
48+
let tool_specs_json: String = state
49+
.tools
50+
.values()
51+
.filter_map(|s| serde_json::to_string(s).ok())
52+
.collect::<Vec<String>>()
53+
.join("");
4754
let context_token_count: TokenCount = data.context_messages.into();
4855
let assistant_token_count: TokenCount = data.assistant_messages.into();
4956
let user_token_count: TokenCount = data.user_messages.into();
57+
let tools_char_count: CharCount = tool_specs_json.len().into(); // usize → CharCount
58+
let tools_token_count: TokenCount = tools_char_count.into(); // CharCount → TokenCount
5059
let total_token_used: TokenCount =
51-
(data.context_messages + data.user_messages + data.assistant_messages).into();
52-
60+
(data.context_messages + data.user_messages + data.assistant_messages + tools_char_count).into();
5361
let window_width = session.terminal_width();
5462
// set a max width for the progress bar for better aesthetic
5563
let progress_bar_width = std::cmp::min(window_width, 80);
@@ -58,13 +66,18 @@ impl UsageArgs {
5866
((context_token_count.value() as f64 / CONTEXT_WINDOW_SIZE as f64) * progress_bar_width as f64) as usize;
5967
let assistant_width =
6068
((assistant_token_count.value() as f64 / CONTEXT_WINDOW_SIZE as f64) * progress_bar_width as f64) as usize;
69+
let tools_width =
70+
((tools_token_count.value() as f64 / CONTEXT_WINDOW_SIZE as f64) * progress_bar_width as f64) as usize;
6171
let user_width =
6272
((user_token_count.value() as f64 / CONTEXT_WINDOW_SIZE as f64) * progress_bar_width as f64) as usize;
6373

64-
let left_over_width =
65-
progress_bar_width - std::cmp::min(context_width + assistant_width + user_width, progress_bar_width);
74+
let left_over_width = progress_bar_width
75+
- std::cmp::min(
76+
context_width + assistant_width + user_width + tools_width,
77+
progress_bar_width,
78+
);
6679

67-
let is_overflow = (context_width + assistant_width + user_width) > progress_bar_width;
80+
let is_overflow = (context_width + assistant_width + user_width + tools_width) > progress_bar_width;
6881

6982
if is_overflow {
7083
queue!(
@@ -91,6 +104,7 @@ impl UsageArgs {
91104
total_token_used,
92105
CONTEXT_WINDOW_SIZE / 1000
93106
)),
107+
// Context files
94108
style::SetForegroundColor(Color::DarkCyan),
95109
// add a nice visual to mimic "tiny" progress, so the overral progress bar doesn't look too
96110
// empty
@@ -100,13 +114,23 @@ impl UsageArgs {
100114
0
101115
})),
102116
style::Print("█".repeat(context_width)),
117+
// Tools
118+
style::SetForegroundColor(Color::DarkRed),
119+
style::Print("|".repeat(if tools_width == 0 && *tools_token_count > 0 {
120+
1
121+
} else {
122+
0
123+
})),
124+
style::Print("█".repeat(tools_width)),
125+
// Assistant responses
103126
style::SetForegroundColor(Color::Blue),
104127
style::Print("|".repeat(if assistant_width == 0 && *assistant_token_count > 0 {
105128
1
106129
} else {
107130
0
108131
})),
109132
style::Print("█".repeat(assistant_width)),
133+
// User prompts
110134
style::SetForegroundColor(Color::Magenta),
111135
style::Print("|".repeat(if user_width == 0 && *user_token_count > 0 { 1 } else { 0 })),
112136
style::Print("█".repeat(user_width)),
@@ -133,6 +157,14 @@ impl UsageArgs {
133157
context_token_count,
134158
(context_token_count.value() as f32 / CONTEXT_WINDOW_SIZE as f32) * 100.0
135159
)),
160+
style::SetForegroundColor(Color::DarkRed),
161+
style::Print("█ Tools: "),
162+
style::SetForegroundColor(Color::Reset),
163+
style::Print(format!(
164+
" ~{} tokens ({:.2}%)\n",
165+
tools_token_count,
166+
(tools_token_count.value() as f32 / CONTEXT_WINDOW_SIZE as f32) * 100.0
167+
)),
136168
style::SetForegroundColor(Color::Blue),
137169
style::Print("█ Q responses: "),
138170
style::SetForegroundColor(Color::Reset),

0 commit comments

Comments
 (0)