warn/errorのTUIへの通知ルート

This commit is contained in:
2026-04-15 12:58:31 +09:00
parent 0c29de1b10
commit faa8eb5793
15 changed files with 735 additions and 38 deletions
+29 -1
View File
@@ -1,4 +1,4 @@
use protocol::{Event, Greeting, Method};
use protocol::{Event, Greeting, Method, NotificationLevel, NotificationSource};
pub struct App {
pub pod_name: String,
@@ -35,6 +35,10 @@ pub enum MessageKind {
Tool,
Error,
TurnStats,
/// Pod → user notification, Warn level.
NoticeWarn,
/// Pod → user notification, Error level.
NoticeError,
}
impl App {
@@ -166,6 +170,21 @@ impl App {
self.current_tool = None;
}
Event::ToolCallArgsDelta { .. } => {}
Event::Notification(notification) => {
let kind = match notification.level {
NotificationLevel::Warn => MessageKind::NoticeWarn,
NotificationLevel::Error => MessageKind::NoticeError,
};
let prefix = match notification.level {
NotificationLevel::Warn => "[notice]",
NotificationLevel::Error => "[notice error]",
};
let source = notification_source_label(notification.source);
self.output_queue.push(OutputItem::Padded(
kind,
format!("{prefix} {source}: {}", notification.message),
));
}
Event::History { items, greeting } => {
self.restore_history(&items);
if self.turn_index == 0 {
@@ -298,6 +317,15 @@ impl App {
}
}
fn notification_source_label(source: NotificationSource) -> &'static str {
match source {
NotificationSource::Pod => "pod",
NotificationSource::Worker => "worker",
NotificationSource::Compactor => "compactor",
NotificationSource::AgentsMd => "AGENTS.md",
}
}
pub fn fmt_tokens(n: u64) -> String {
if n >= 1_000_000 {
format!("{:.1}M", n as f64 / 1_000_000.0)
+8
View File
@@ -232,6 +232,14 @@ pub fn kind_style(kind: &MessageKind) -> Style {
MessageKind::Tool => Style::default().fg(Color::Cyan),
MessageKind::Error => Style::default().fg(Color::Red),
MessageKind::TurnStats => Style::default().fg(Color::DarkGray),
MessageKind::NoticeWarn => Style::default()
.fg(Color::Black)
.bg(Color::Yellow)
.add_modifier(Modifier::BOLD),
MessageKind::NoticeError => Style::default()
.fg(Color::White)
.bg(Color::Red)
.add_modifier(Modifier::BOLD),
}
}