- Avvisi di sicurezza, buffering e catalogo plugin senza link a help.openai.com e chatgpt.com; snapshot aggiornati. - Rimossi il riesporto e la funzione per i link sottolineati rimasti senza utilizzi (nessun avviso nella build release). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
382 lines
12 KiB
Rust
382 lines
12 KiB
Rust
//! Informational, warning, update, and policy notice history cells.
|
||
|
||
use super::*;
|
||
use crate::style::accent_color;
|
||
use crate::terminal_hyperlinks::LineWrapPolicy;
|
||
use crate::terminal_hyperlinks::remap_source_wrapped_line;
|
||
use crate::wrapping::adaptive_wrap_line_to_width;
|
||
|
||
#[cfg_attr(not(test), allow(dead_code))]
|
||
const RECAP_HEADING: &str = "Conversation recap";
|
||
|
||
/// One-line startup notice for a newer aKode release (`akode update` installs it).
|
||
#[derive(Debug)]
|
||
pub(crate) struct UpdateAvailableHistoryCell {
|
||
latest_version: String,
|
||
}
|
||
|
||
impl UpdateAvailableHistoryCell {
|
||
pub(crate) fn new(latest_version: String) -> Self {
|
||
Self { latest_version }
|
||
}
|
||
}
|
||
|
||
impl HistoryCell for UpdateAvailableHistoryCell {
|
||
fn display_lines(&self, width: u16) -> Vec<Line<'static>> {
|
||
let line = Line::from(vec![
|
||
"È disponibile aKode ".fg(accent_color()),
|
||
self.latest_version.clone().bold().fg(accent_color()),
|
||
" — esegui ".into(),
|
||
"\"akode update\"".bold(),
|
||
]);
|
||
vec![
|
||
crate::line_truncation::truncate_line_with_ellipsis_if_overflow(
|
||
line,
|
||
usize::from(width),
|
||
),
|
||
]
|
||
}
|
||
|
||
fn raw_lines(&self) -> Vec<Line<'static>> {
|
||
vec![Line::from(format!(
|
||
"È disponibile aKode {} — esegui \"akode update\"",
|
||
self.latest_version
|
||
))]
|
||
}
|
||
|
||
fn display_hyperlink_lines(&self, width: u16) -> Vec<HyperlinkLine> {
|
||
crate::terminal_hyperlinks::annotate_web_urls(self.display_lines(width))
|
||
}
|
||
|
||
fn transcript_hyperlink_lines(&self, width: u16) -> Vec<HyperlinkLine> {
|
||
self.display_hyperlink_lines(width)
|
||
}
|
||
}
|
||
pub(crate) fn new_warning_event(message: String) -> WarningHistoryCell {
|
||
let style = crate::style::status_style(crate::style::StatusTone::Attention);
|
||
WarningHistoryCell {
|
||
server_version_notice: false,
|
||
visible_in_transcript: false,
|
||
key: message.clone(),
|
||
diagnostic: message.clone(),
|
||
details: PrefixedWrappedHistoryCell::new(
|
||
message.set_style(style),
|
||
"⚠ ".set_style(style),
|
||
" ",
|
||
),
|
||
}
|
||
}
|
||
|
||
pub(crate) fn new_visible_warning_event(message: String) -> WarningHistoryCell {
|
||
WarningHistoryCell {
|
||
visible_in_transcript: true,
|
||
..new_warning_event(message)
|
||
}
|
||
}
|
||
|
||
pub(crate) fn new_server_version_warning(
|
||
notice: crate::status::remote_connection::ServerVersionNotice,
|
||
) -> WarningHistoryCell {
|
||
let key = notice.message.clone();
|
||
let style = crate::style::status_style(crate::style::StatusTone::Attention);
|
||
let mut lines = vec![Line::from(notice.message.set_style(style))];
|
||
if notice.offer_update {
|
||
lines.push(Line::from(
|
||
"Use /daemon to manage the local background server.".fg(accent_color()),
|
||
));
|
||
lines.push(Line::from(
|
||
"Updating may interrupt active or queued work.".set_style(style),
|
||
));
|
||
}
|
||
WarningHistoryCell {
|
||
server_version_notice: true,
|
||
visible_in_transcript: false,
|
||
key,
|
||
diagnostic: lines
|
||
.iter()
|
||
.map(ToString::to_string)
|
||
.collect::<Vec<_>>()
|
||
.join("\n"),
|
||
details: PrefixedWrappedHistoryCell::new(Text::from(lines), "⚠ ".set_style(style), " "),
|
||
}
|
||
}
|
||
|
||
#[derive(Debug)]
|
||
pub(crate) struct SafetyAccessBlockCell {
|
||
title: &'static str,
|
||
pub(crate) explanation: Option<String>,
|
||
body: &'static str,
|
||
}
|
||
|
||
pub(crate) fn new_safety_access_block_event() -> SafetyAccessBlockCell {
|
||
SafetyAccessBlockCell {
|
||
title: "This content can't be shown",
|
||
explanation: Some("We take extra caution with requests involving biological research and applications that could pose safety risks.".into()),
|
||
body: "Some biological research requests are limited.",
|
||
}
|
||
}
|
||
|
||
pub(crate) fn new_cyber_policy_error_event() -> SafetyAccessBlockCell {
|
||
SafetyAccessBlockCell {
|
||
title: "This content can’t be shown",
|
||
explanation: Some("We take extra care with some cybersecurity requests.".into()),
|
||
body: "Some cybersecurity requests are limited.",
|
||
}
|
||
}
|
||
|
||
impl SafetyAccessBlockCell {
|
||
fn message(&self) -> String {
|
||
match &self.explanation {
|
||
Some(explanation) => format!("{explanation} {}", self.body),
|
||
None => self.body.to_owned(),
|
||
}
|
||
}
|
||
}
|
||
|
||
impl HistoryCell for SafetyAccessBlockCell {
|
||
fn display_lines(&self, width: u16) -> Vec<Line<'static>> {
|
||
visible_lines(self.display_hyperlink_lines(width))
|
||
}
|
||
|
||
fn display_hyperlink_lines(&self, width: u16) -> Vec<HyperlinkLine> {
|
||
let mut lines = vec![HyperlinkLine::new(
|
||
vec!["ⓘ ".fg(accent_color()), self.title.bold()].into(),
|
||
)];
|
||
let body = Line::from(vec![" ".into(), self.message().dim()]);
|
||
let wrap_width = width.saturating_sub(2).max(1) as usize;
|
||
let wrapped = adaptive_wrap_line(
|
||
&body,
|
||
RtOptions::new(wrap_width).subsequent_indent(" ".into()),
|
||
);
|
||
let mut wrapped_body = Vec::new();
|
||
push_owned_lines(&wrapped, &mut wrapped_body);
|
||
lines.extend(plain_hyperlink_lines(wrapped_body));
|
||
lines
|
||
}
|
||
|
||
fn raw_lines(&self) -> Vec<Line<'static>> {
|
||
vec![Line::from(self.title), Line::from(self.message())]
|
||
}
|
||
|
||
fn transcript_hyperlink_lines(&self, width: u16) -> Vec<HyperlinkLine> {
|
||
self.display_hyperlink_lines(width)
|
||
}
|
||
}
|
||
|
||
#[derive(Debug, Eq, PartialEq)]
|
||
pub(crate) struct DeprecationNoticeCell {
|
||
summary: String,
|
||
details: Option<String>,
|
||
}
|
||
|
||
pub(crate) fn new_deprecation_notice(
|
||
summary: String,
|
||
details: Option<String>,
|
||
) -> DeprecationNoticeCell {
|
||
DeprecationNoticeCell { summary, details }
|
||
}
|
||
|
||
impl HistoryCell for DeprecationNoticeCell {
|
||
fn warning_entries(&self) -> Vec<WarningEntry> {
|
||
vec![WarningEntry {
|
||
id: WarningId::Message(self.summary.clone()),
|
||
source: "Deprecation".into(),
|
||
details: self
|
||
.raw_lines()
|
||
.iter()
|
||
.map(ToString::to_string)
|
||
.collect::<Vec<_>>()
|
||
.join("\n"),
|
||
}]
|
||
}
|
||
|
||
fn live_raw_lines(&self) -> Vec<Line<'static>> {
|
||
Vec::new()
|
||
}
|
||
|
||
fn display_lines(&self, _width: u16) -> Vec<Line<'static>> {
|
||
Vec::new()
|
||
}
|
||
|
||
fn warning_keys(&self) -> Vec<WarningKey<'_>> {
|
||
vec![WarningKey::Message(&self.summary)]
|
||
}
|
||
|
||
fn transcript_lines(&self, width: u16) -> Vec<Line<'static>> {
|
||
let mut lines: Vec<Line<'static>> = Vec::new();
|
||
lines.push(vec!["⚠ ".red().bold(), self.summary.clone().red()].into());
|
||
|
||
let wrap_width = width.saturating_sub(4).max(1) as usize;
|
||
|
||
if let Some(details) = &self.details {
|
||
let detail_line = Line::from(details.clone().dim());
|
||
let wrapped = adaptive_wrap_line(&detail_line, RtOptions::new(wrap_width));
|
||
push_owned_lines(&wrapped, &mut lines);
|
||
}
|
||
|
||
lines
|
||
}
|
||
|
||
fn raw_lines(&self) -> Vec<Line<'static>> {
|
||
let mut lines = vec![Line::from(self.summary.clone())];
|
||
if let Some(details) = &self.details {
|
||
lines.extend(raw_lines_from_source(details));
|
||
}
|
||
lines
|
||
}
|
||
}
|
||
pub(crate) fn new_info_event(message: String, hint: Option<String>) -> PlainHistoryCell {
|
||
let mut line = vec!["• ".dim(), message.into()];
|
||
if let Some(hint) = hint {
|
||
line.push(" ".into());
|
||
line.push(hint.dark_gray());
|
||
}
|
||
let lines: Vec<Line<'static>> = vec![line.into()];
|
||
PlainHistoryCell { lines }
|
||
}
|
||
|
||
pub(crate) fn new_error_event(message: String) -> PlainHistoryCell {
|
||
// Use a hair space (U+200A) to create a subtle, near-invisible separation
|
||
// before the text. VS16 is intentionally omitted to keep spacing tighter
|
||
// in terminals like Ghostty.
|
||
let lines: Vec<Line<'static>> = vec![vec![format!("■ {message}").red()].into()];
|
||
PlainHistoryCell { lines }
|
||
}
|
||
|
||
#[derive(Debug)]
|
||
pub(crate) struct ThreadRecapLoadingCell {
|
||
start_time: Instant,
|
||
animations_enabled: bool,
|
||
}
|
||
|
||
impl ThreadRecapLoadingCell {
|
||
pub(crate) fn new(animations_enabled: bool) -> Self {
|
||
Self {
|
||
start_time: Instant::now(),
|
||
animations_enabled,
|
||
}
|
||
}
|
||
}
|
||
|
||
impl HistoryCell for ThreadRecapLoadingCell {
|
||
fn display_lines(&self, _width: u16) -> Vec<Line<'static>> {
|
||
vec![
|
||
vec![
|
||
activity_indicator(
|
||
Some(self.start_time),
|
||
MotionMode::from_animations_enabled(self.animations_enabled),
|
||
ReducedMotionIndicator::StaticBullet,
|
||
)
|
||
.unwrap_or_else(|| "•".dim()),
|
||
" ".into(),
|
||
"Generating conversation recap".bold(),
|
||
"…".dim(),
|
||
]
|
||
.into(),
|
||
]
|
||
}
|
||
|
||
fn raw_lines(&self) -> Vec<Line<'static>> {
|
||
vec![Line::from("Generating conversation recap...")]
|
||
}
|
||
|
||
fn transcript_animation_tick(&self) -> Option<u64> {
|
||
if !self.animations_enabled {
|
||
return None;
|
||
}
|
||
|
||
Some((self.start_time.elapsed().as_millis() / 50) as u64)
|
||
}
|
||
}
|
||
|
||
#[cfg_attr(not(test), allow(dead_code))]
|
||
#[derive(Debug)]
|
||
pub(crate) struct ThreadRecapHistoryCell {
|
||
recap: String,
|
||
next_action: Option<String>,
|
||
}
|
||
|
||
#[cfg_attr(not(test), allow(dead_code))]
|
||
impl ThreadRecapHistoryCell {
|
||
pub(crate) fn new(recap: String) -> Self {
|
||
Self {
|
||
recap,
|
||
next_action: None,
|
||
}
|
||
}
|
||
|
||
pub(crate) fn with_next_action(mut self, next_action: Option<String>) -> Self {
|
||
self.next_action = next_action;
|
||
self
|
||
}
|
||
}
|
||
|
||
impl HistoryCell for ThreadRecapHistoryCell {
|
||
fn display_lines(&self, width: u16) -> Vec<Line<'static>> {
|
||
visible_lines(self.display_hyperlink_lines(width))
|
||
}
|
||
|
||
fn display_hyperlink_lines(&self, width: u16) -> Vec<HyperlinkLine> {
|
||
if width == 0 {
|
||
return Vec::new();
|
||
}
|
||
|
||
let wrap_width = usize::from(width.saturating_sub(/*rhs*/ 2).max(/*other*/ 1));
|
||
let mut body = raw_lines_from_source(&self.recap);
|
||
if let Some(action) = &self.next_action {
|
||
body.extend(prefix_lines(
|
||
raw_lines_from_source(action),
|
||
"Next: ".bold().fg(accent_color()),
|
||
"".into(),
|
||
));
|
||
}
|
||
let mut body = body.into_iter().map(Line::italic).collect::<Vec<_>>();
|
||
let prefix = Line::from(vec![" ".into(), "↳ ".dim(), "Recap: ".bold()]).italic();
|
||
let mut options = if wrap_width <= prefix.width() {
|
||
// Keep the text readable when the terminal cannot fit the hanging indent.
|
||
body.insert(
|
||
/*index*/ 0,
|
||
Line::from(vec!["↳ ".dim(), "Recap:".bold()]).italic(),
|
||
);
|
||
RtOptions::new(wrap_width)
|
||
} else {
|
||
RtOptions::new(wrap_width)
|
||
.subsequent_indent(" ".repeat(prefix.width()).into())
|
||
.initial_indent(prefix)
|
||
};
|
||
let mut lines = Vec::new();
|
||
for line in body {
|
||
let line = HyperlinkLine::new(line);
|
||
let mut wrapped = remap_source_wrapped_line(
|
||
&line,
|
||
adaptive_wrap_line_to_width(&line.line, options.clone()),
|
||
);
|
||
for source in wrapped.iter_mut().filter_map(|line| line.source.as_mut()) {
|
||
source.wrap_policy = LineWrapPolicy::UrlAware;
|
||
source.continuation_indent = options.subsequent_indent.clone();
|
||
source.right_reserve = 2;
|
||
}
|
||
lines.extend(wrapped);
|
||
options.initial_indent = options.subsequent_indent.clone();
|
||
}
|
||
for line in &mut lines {
|
||
let style = line.line.style.dim();
|
||
*line = std::mem::take(line).style(style);
|
||
}
|
||
lines
|
||
}
|
||
|
||
fn transcript_hyperlink_lines(&self, width: u16) -> Vec<HyperlinkLine> {
|
||
self.display_hyperlink_lines(width)
|
||
}
|
||
|
||
fn raw_lines(&self) -> Vec<Line<'static>> {
|
||
let mut lines = vec![Line::from(RECAP_HEADING)];
|
||
lines.extend(raw_lines_from_source(&self.recap));
|
||
if let Some(action) = &self.next_action {
|
||
lines.extend(raw_lines_from_source(&format!("Next: {action}")));
|
||
}
|
||
lines
|
||
}
|
||
}
|