feat: Implement lesson generation feature and update status display
- Added functionality to generate lessons based on code reviews, including prompts and instructions for the reviewer. - Updated the `.gitignore` to exclude lesson documentation files. - Removed the `/lesson` command from the help menu and command parsing. - Enhanced the status bar to display a message when a lesson is being generated. - Introduced a new `lesson_running` state to track lesson generation progress. - Updated various components to handle the new lesson generation workflow, including subagent events and token usage tracking.
This commit is contained in:
@@ -383,6 +383,7 @@ pub fn run_subagent(ctx: &SubagentContext, tx: &mpsc::Sender<SubagentEvent>) ->
|
||||
let tx_clone = tx.clone();
|
||||
let mut current_thinking = String::new();
|
||||
let mut current_token = String::new();
|
||||
let mut step_usage: Option<(u64, u64)> = None;
|
||||
|
||||
// Use streaming API so the abort flag is checked per SSE event,
|
||||
// making the subagent responsive to cancellation even during an
|
||||
@@ -408,13 +409,20 @@ pub fn run_subagent(ctx: &SubagentContext, tx: &mpsc::Sender<SubagentEvent>) ->
|
||||
let prog = format_subagent_progress("replying", ¤t_token);
|
||||
let _ = tx_clone.blocking_send(SubagentEvent::Progress(prog));
|
||||
}
|
||||
crate::app::runtime::stream::StreamEvent::Usage { prompt_tokens, completion_tokens, .. } => {
|
||||
// Capture usage so the drain thread can route it
|
||||
// to the parent's `UsageStats::review_tokens`.
|
||||
// Last writer wins — providers send exactly one
|
||||
// Usage event per streaming call.
|
||||
step_usage = Some((*prompt_tokens, *completion_tokens));
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
true
|
||||
},
|
||||
);
|
||||
|
||||
let (response, _usage) = match stream_result {
|
||||
let (response, returned_usage) = match stream_result {
|
||||
Ok(result) => result,
|
||||
Err(e) => {
|
||||
let is_abort = ctx.abort_flag.as_ref().is_some_and(|f| f.load(std::sync::atomic::Ordering::SeqCst))
|
||||
@@ -437,6 +445,17 @@ pub fn run_subagent(ctx: &SubagentContext, tx: &mpsc::Sender<SubagentEvent>) ->
|
||||
}
|
||||
};
|
||||
|
||||
// Emit the token usage from this streaming call so the parent's
|
||||
// drain thread can accumulate it and update the Usage panel.
|
||||
// Without this, the Usage panel always shows zeros because the
|
||||
// subagent never tells the parent about the tokens consumed.
|
||||
if let Some((tokens_in, tokens_out)) = returned_usage {
|
||||
let _ = tx.blocking_send(SubagentEvent::Usage {
|
||||
tokens_in,
|
||||
tokens_out,
|
||||
});
|
||||
}
|
||||
|
||||
let has_tool_calls = response.tool_calls.is_some()
|
||||
&& response.tool_calls.as_ref().is_some_and(|tc| !tc.is_empty());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user