cargo fmt
This commit is contained in:
+13
-12
@@ -136,19 +136,14 @@ impl App {
|
||||
}
|
||||
}
|
||||
}
|
||||
Event::ToolCallDone {
|
||||
id, arguments, ..
|
||||
} => {
|
||||
Event::ToolCallDone { id, arguments, .. } => {
|
||||
self.current_tool = None;
|
||||
if let Some(b) = self.find_tool_call_mut(&id) {
|
||||
b.arguments = Some(arguments);
|
||||
// Only advance the state when it's still in-flight.
|
||||
// If a ToolResult arrived out of order and already
|
||||
// transitioned us to Done/Error, keep that.
|
||||
if matches!(
|
||||
b.state,
|
||||
ToolCallState::Pending | ToolCallState::Streaming
|
||||
) {
|
||||
if matches!(b.state, ToolCallState::Pending | ToolCallState::Streaming) {
|
||||
b.state = ToolCallState::Executing;
|
||||
}
|
||||
}
|
||||
@@ -191,7 +186,12 @@ impl App {
|
||||
}
|
||||
};
|
||||
if !is_error {
|
||||
apply_cache_update(&mut self.cache, &name, args.as_deref(), output.as_deref());
|
||||
apply_cache_update(
|
||||
&mut self.cache,
|
||||
&name,
|
||||
args.as_deref(),
|
||||
output.as_deref(),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// Result for an unknown tool call. Surface it as an
|
||||
@@ -291,9 +291,7 @@ impl App {
|
||||
if let Block::ToolCall(tc) = b {
|
||||
if matches!(
|
||||
tc.state,
|
||||
ToolCallState::Pending
|
||||
| ToolCallState::Streaming
|
||||
| ToolCallState::Executing
|
||||
ToolCallState::Pending | ToolCallState::Streaming | ToolCallState::Executing
|
||||
) {
|
||||
tc.state = ToolCallState::Incomplete;
|
||||
} else {
|
||||
@@ -450,7 +448,10 @@ impl App {
|
||||
// Incomplete so the replay matches live semantics.
|
||||
for b in self.blocks.iter_mut() {
|
||||
if let Block::ToolCall(tc) = b
|
||||
&& matches!(tc.state, ToolCallState::Executing | ToolCallState::Pending | ToolCallState::Streaming)
|
||||
&& matches!(
|
||||
tc.state,
|
||||
ToolCallState::Executing | ToolCallState::Pending | ToolCallState::Streaming
|
||||
)
|
||||
{
|
||||
tc.state = ToolCallState::Incomplete;
|
||||
}
|
||||
|
||||
@@ -63,9 +63,15 @@ pub enum ToolCallState {
|
||||
/// `ToolCallDone` received, waiting on the tool result.
|
||||
Executing,
|
||||
/// `ToolResult { is_error: false, .. }` received.
|
||||
Done { summary: String, output: Option<String> },
|
||||
Done {
|
||||
summary: String,
|
||||
output: Option<String>,
|
||||
},
|
||||
/// `ToolResult { is_error: true, .. }` received.
|
||||
Error { summary: String, output: Option<String> },
|
||||
Error {
|
||||
summary: String,
|
||||
output: Option<String>,
|
||||
},
|
||||
/// Turn ended before a matching `ToolResult` arrived.
|
||||
Incomplete,
|
||||
}
|
||||
|
||||
+10
-3
@@ -33,8 +33,12 @@ fn resolve_socket(pod_name: &str, override_path: Option<PathBuf>) -> PathBuf {
|
||||
if let Some(p) = override_path {
|
||||
return p;
|
||||
}
|
||||
manifest::paths::pod_socket_path(pod_name)
|
||||
.unwrap_or_else(|| PathBuf::from("/tmp").join("insomnia").join(pod_name).join("sock"))
|
||||
manifest::paths::pod_socket_path(pod_name).unwrap_or_else(|| {
|
||||
PathBuf::from("/tmp")
|
||||
.join("insomnia")
|
||||
.join(pod_name)
|
||||
.join("sock")
|
||||
})
|
||||
}
|
||||
|
||||
enum Mode {
|
||||
@@ -172,7 +176,10 @@ async fn run(
|
||||
run_loop(terminal, &mut app, client, shutdown_pod_on_exit).await?;
|
||||
}
|
||||
Err(e) => {
|
||||
app.push_error(format!("Failed to connect to {}: {e}", socket_path.display()));
|
||||
app.push_error(format!(
|
||||
"Failed to connect to {}: {e}",
|
||||
socket_path.display()
|
||||
));
|
||||
terminal.draw(|f| ui::draw(f, &mut app))?;
|
||||
run_disconnected(&mut app)?;
|
||||
}
|
||||
|
||||
+14
-12
@@ -17,12 +17,8 @@ use std::path::PathBuf;
|
||||
use std::process::Stdio;
|
||||
use std::time::Duration;
|
||||
|
||||
use crossterm::event::{
|
||||
self, Event as TermEvent, KeyCode, KeyEventKind, KeyModifiers,
|
||||
};
|
||||
use manifest::{
|
||||
PodManifestConfig, find_project_manifest_from, load_layer, user_manifest_path,
|
||||
};
|
||||
use crossterm::event::{self, Event as TermEvent, KeyCode, KeyEventKind, KeyModifiers};
|
||||
use manifest::{PodManifestConfig, find_project_manifest_from, load_layer, user_manifest_path};
|
||||
use ratatui::Terminal;
|
||||
use ratatui::backend::CrosstermBackend;
|
||||
use ratatui::layout::{Constraint, Layout};
|
||||
@@ -103,7 +99,10 @@ pub async fn run() -> Result<SpawnOutcome, SpawnError> {
|
||||
let project_layer = find_project_manifest_from(&cwd).and_then(|p| load_layer(&p).ok());
|
||||
|
||||
let mut cascade = PodManifestConfig::builtin_defaults();
|
||||
for layer in [user_layer.as_ref(), project_layer.as_ref()].into_iter().flatten() {
|
||||
for layer in [user_layer.as_ref(), project_layer.as_ref()]
|
||||
.into_iter()
|
||||
.flatten()
|
||||
{
|
||||
cascade = cascade.merge(layer.clone());
|
||||
}
|
||||
let cascade_has_scope = !cascade.scope.allow.is_empty();
|
||||
@@ -147,8 +146,7 @@ pub async fn run() -> Result<SpawnOutcome, SpawnError> {
|
||||
None => continue,
|
||||
Some(Action::Submit) => {
|
||||
if form.name.trim().is_empty() {
|
||||
form.message =
|
||||
Some(("name is required".to_string(), MessageKind::Error));
|
||||
form.message = Some(("name is required".to_string(), MessageKind::Error));
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
@@ -358,7 +356,10 @@ fn build_overlay_toml(form: &Form) -> String {
|
||||
);
|
||||
rule.insert("permission".into(), toml::Value::String("write".into()));
|
||||
let mut scope = toml::value::Table::new();
|
||||
scope.insert("allow".into(), toml::Value::Array(vec![toml::Value::Table(rule)]));
|
||||
scope.insert(
|
||||
"allow".into(),
|
||||
toml::Value::Array(vec![toml::Value::Table(rule)]),
|
||||
);
|
||||
root.insert("scope".into(), toml::Value::Table(scope));
|
||||
}
|
||||
|
||||
@@ -382,7 +383,6 @@ fn resolve_pod_command() -> PathBuf {
|
||||
PathBuf::from("pod")
|
||||
}
|
||||
|
||||
|
||||
struct StderrTail {
|
||||
lines: std::collections::VecDeque<String>,
|
||||
}
|
||||
@@ -529,7 +529,9 @@ fn name_line(form: &Form) -> Line<'_> {
|
||||
Span::styled("name: ", Style::default().fg(Color::DarkGray)),
|
||||
Span::styled(
|
||||
form.name.as_str(),
|
||||
Style::default().fg(Color::Cyan).add_modifier(Modifier::BOLD),
|
||||
Style::default()
|
||||
.fg(Color::Cyan)
|
||||
.add_modifier(Modifier::BOLD),
|
||||
),
|
||||
])
|
||||
}
|
||||
|
||||
+36
-43
@@ -74,9 +74,12 @@ fn render_read_aggregate(blocks: &[Block], start: usize, mode: Mode) -> ToolRend
|
||||
})
|
||||
.collect();
|
||||
|
||||
let in_progress = group
|
||||
.iter()
|
||||
.any(|tc| !matches!(tc.state, ToolCallState::Done { .. } | ToolCallState::Error { .. } | ToolCallState::Incomplete));
|
||||
let in_progress = group.iter().any(|tc| {
|
||||
!matches!(
|
||||
tc.state,
|
||||
ToolCallState::Done { .. } | ToolCallState::Error { .. } | ToolCallState::Incomplete
|
||||
)
|
||||
});
|
||||
|
||||
let paths: Vec<String> = group.iter().map(|tc| read_path(tc)).collect();
|
||||
let count = paths.len();
|
||||
@@ -89,9 +92,7 @@ fn render_read_aggregate(blocks: &[Block], start: usize, mode: Mode) -> ToolRend
|
||||
} else {
|
||||
format!("Read — {count} file{} read", plural(count))
|
||||
};
|
||||
lines.push(Line::from(vec![
|
||||
Span::styled(header, tool_style),
|
||||
]));
|
||||
lines.push(Line::from(vec![Span::styled(header, tool_style)]));
|
||||
|
||||
if matches!(mode, Mode::Overview) {
|
||||
return ToolRenderOutput {
|
||||
@@ -169,17 +170,15 @@ fn render_write(cache: &FileCache, tc: &ToolCallBlock, mode: Mode) -> Vec<Line<'
|
||||
])];
|
||||
}
|
||||
|
||||
let mut lines = vec![
|
||||
Line::from(vec![
|
||||
Span::styled("Write — ".to_owned(), tool_style),
|
||||
Span::styled(format!("{label} "), label_style),
|
||||
Span::styled(path.clone(), Style::default().fg(Color::White)),
|
||||
Span::styled(
|
||||
format!(" ({})", state_suffix(&tc.state)),
|
||||
Style::default().fg(Color::DarkGray),
|
||||
),
|
||||
]),
|
||||
];
|
||||
let mut lines = vec![Line::from(vec![
|
||||
Span::styled("Write — ".to_owned(), tool_style),
|
||||
Span::styled(format!("{label} "), label_style),
|
||||
Span::styled(path.clone(), Style::default().fg(Color::White)),
|
||||
Span::styled(
|
||||
format!(" ({})", state_suffix(&tc.state)),
|
||||
Style::default().fg(Color::DarkGray),
|
||||
),
|
||||
])];
|
||||
|
||||
// Body preview.
|
||||
let cap = match mode {
|
||||
@@ -214,7 +213,12 @@ fn render_write(cache: &FileCache, tc: &ToolCallBlock, mode: Mode) -> Vec<Line<'
|
||||
// Edit
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
fn render_edit(cache: &FileCache, tc: &ToolCallBlock, width: u16, mode: Mode) -> Vec<Line<'static>> {
|
||||
fn render_edit(
|
||||
cache: &FileCache,
|
||||
tc: &ToolCallBlock,
|
||||
width: u16,
|
||||
mode: Mode,
|
||||
) -> Vec<Line<'static>> {
|
||||
let args = parsed_args(tc);
|
||||
let path = args
|
||||
.as_ref()
|
||||
@@ -296,9 +300,7 @@ fn build_edit_diff(content: &str, old: &str, new: &str, width: u16) -> Vec<Line<
|
||||
|
||||
// Width for the line-number gutter: fit the largest number we'll
|
||||
// print across either file's version of this hunk.
|
||||
let max_line = ctx_end
|
||||
.max(line_of_idx + new_line_count)
|
||||
.max(1);
|
||||
let max_line = ctx_end.max(line_of_idx + new_line_count).max(1);
|
||||
let num_w = max_line.to_string().len();
|
||||
|
||||
// BG-highlighted rows for -/+ so the change stripe extends full
|
||||
@@ -512,12 +514,10 @@ fn render_search(tc: &ToolCallBlock, mode: Mode, label: &str) -> Vec<Line<'stati
|
||||
])];
|
||||
}
|
||||
|
||||
let mut lines = vec![Line::from(vec![
|
||||
Span::styled(
|
||||
format!("{label} — {}", state_suffix(&tc.state)),
|
||||
tool_style,
|
||||
),
|
||||
])];
|
||||
let mut lines = vec![Line::from(vec![Span::styled(
|
||||
format!("{label} — {}", state_suffix(&tc.state)),
|
||||
tool_style,
|
||||
)])];
|
||||
|
||||
let cap = match mode {
|
||||
Mode::Normal => NORMAL_MAX_BODY,
|
||||
@@ -565,17 +565,13 @@ fn render_default(tc: &ToolCallBlock, mode: Mode) -> Vec<Line<'static>> {
|
||||
} else {
|
||||
format!("{} — {suffix}", tc.name)
|
||||
};
|
||||
return vec![Line::from(vec![
|
||||
Span::styled(label, tool_style),
|
||||
])];
|
||||
return vec![Line::from(vec![Span::styled(label, tool_style)])];
|
||||
}
|
||||
|
||||
let mut lines = vec![Line::from(vec![
|
||||
Span::styled(
|
||||
format!("{} — {}", tc.name, state_suffix(&tc.state)),
|
||||
tool_style,
|
||||
),
|
||||
])];
|
||||
let mut lines = vec![Line::from(vec![Span::styled(
|
||||
format!("{} — {}", tc.name, state_suffix(&tc.state)),
|
||||
tool_style,
|
||||
)])];
|
||||
|
||||
let args_pretty = parsed_args(tc)
|
||||
.and_then(|v| serde_json::to_string_pretty(&v).ok())
|
||||
@@ -589,7 +585,9 @@ fn render_default(tc: &ToolCallBlock, mode: Mode) -> Vec<Line<'static>> {
|
||||
&mut lines,
|
||||
&args_pretty,
|
||||
arg_cap,
|
||||
Style::default().fg(Color::DarkGray).add_modifier(Modifier::ITALIC),
|
||||
Style::default()
|
||||
.fg(Color::DarkGray)
|
||||
.add_modifier(Modifier::ITALIC),
|
||||
);
|
||||
|
||||
let summary_source: String = match &tc.state {
|
||||
@@ -660,12 +658,7 @@ fn maybe_error_line(lines: &mut Vec<Line<'static>>, state: &ToolCallState) {
|
||||
}
|
||||
}
|
||||
|
||||
fn emit_capped_lines(
|
||||
out: &mut Vec<Line<'static>>,
|
||||
text: &str,
|
||||
cap: usize,
|
||||
style: Style,
|
||||
) {
|
||||
fn emit_capped_lines(out: &mut Vec<Line<'static>>, text: &str, cap: usize, style: Style) {
|
||||
let all: Vec<&str> = text.lines().collect();
|
||||
let shown = all.len().min(cap);
|
||||
for l in &all[..shown] {
|
||||
|
||||
+29
-36
@@ -22,7 +22,7 @@ use unicode_width::{UnicodeWidthChar, UnicodeWidthStr};
|
||||
|
||||
use protocol::{AlertLevel, Greeting, Segment};
|
||||
|
||||
use crate::app::{App, fmt_tokens, alert_source_label};
|
||||
use crate::app::{App, alert_source_label, fmt_tokens};
|
||||
use crate::block::{Block, CompactEvent};
|
||||
|
||||
/// Display density for the history view.
|
||||
@@ -64,10 +64,10 @@ pub fn draw(frame: &mut Frame, app: &mut App) {
|
||||
let input_height = input_area_height(&input_render, area.height);
|
||||
|
||||
let chunks = Layout::vertical([
|
||||
Constraint::Min(0), // history view
|
||||
Constraint::Length(1), // separator
|
||||
Constraint::Length(1), // status
|
||||
Constraint::Length(input_height), // input area
|
||||
Constraint::Min(0), // history view
|
||||
Constraint::Length(1), // separator
|
||||
Constraint::Length(1), // status
|
||||
Constraint::Length(input_height), // input area
|
||||
])
|
||||
.split(area);
|
||||
|
||||
@@ -219,21 +219,20 @@ fn wrap_line_into(line: Line<'static>, width: u16, out: &mut Vec<Line<'static>>)
|
||||
*pending_width = 0;
|
||||
};
|
||||
|
||||
let push_row = |current: &mut Vec<Span<'static>>,
|
||||
row_width: &mut usize,
|
||||
out: &mut Vec<Line<'static>>| {
|
||||
if fill_to_width && *row_width < w {
|
||||
let pad = w - *row_width;
|
||||
current.push(Span::styled(" ".repeat(pad), line_style));
|
||||
*row_width = w;
|
||||
}
|
||||
let mut l = Line::from(std::mem::take(current)).style(line_style);
|
||||
if let Some(a) = alignment {
|
||||
l = l.alignment(a);
|
||||
}
|
||||
out.push(l);
|
||||
*row_width = 0;
|
||||
};
|
||||
let push_row =
|
||||
|current: &mut Vec<Span<'static>>, row_width: &mut usize, out: &mut Vec<Line<'static>>| {
|
||||
if fill_to_width && *row_width < w {
|
||||
let pad = w - *row_width;
|
||||
current.push(Span::styled(" ".repeat(pad), line_style));
|
||||
*row_width = w;
|
||||
}
|
||||
let mut l = Line::from(std::mem::take(current)).style(line_style);
|
||||
if let Some(a) = alignment {
|
||||
l = l.alignment(a);
|
||||
}
|
||||
out.push(l);
|
||||
*row_width = 0;
|
||||
};
|
||||
|
||||
for span in line.spans {
|
||||
if !pending.is_empty() && span.style != pending_style {
|
||||
@@ -276,12 +275,7 @@ fn wrap_line_into(line: Line<'static>, width: u16, out: &mut Vec<Line<'static>>)
|
||||
push_row(&mut current, &mut row_width, out);
|
||||
}
|
||||
|
||||
fn render_block_into(
|
||||
lines: &mut Vec<Line<'static>>,
|
||||
block: &Block,
|
||||
width: u16,
|
||||
mode: Mode,
|
||||
) {
|
||||
fn render_block_into(lines: &mut Vec<Line<'static>>, block: &Block, width: u16, mode: Mode) {
|
||||
match block {
|
||||
Block::Greeting(g) => match mode {
|
||||
Mode::Overview => {
|
||||
@@ -426,10 +420,7 @@ fn segment_display_text(seg: &Segment) -> String {
|
||||
match seg {
|
||||
Segment::Text { content } => content.replace('\n', " "),
|
||||
Segment::Paste {
|
||||
id,
|
||||
chars,
|
||||
lines,
|
||||
..
|
||||
id, chars, lines, ..
|
||||
} => format!("[Clipboard #{id} | {chars} chars, {lines} lines]"),
|
||||
Segment::FileRef { path } => format!("@{path}"),
|
||||
Segment::KnowledgeRef { slug } => format!("#{slug}"),
|
||||
@@ -554,16 +545,19 @@ fn render_compact(lines: &mut Vec<Line<'static>>, evt: &CompactEvent, width: u16
|
||||
let (text, kind) = match evt {
|
||||
CompactEvent::Start => ("[compact] starting".to_owned(), MessageKind::NoticeWarn),
|
||||
CompactEvent::Done { new_session_id } => {
|
||||
let short = new_session_id.to_string().chars().take(8).collect::<String>();
|
||||
let short = new_session_id
|
||||
.to_string()
|
||||
.chars()
|
||||
.take(8)
|
||||
.collect::<String>();
|
||||
(
|
||||
format!("[compact] done (new session {short})"),
|
||||
MessageKind::NoticeWarn,
|
||||
)
|
||||
}
|
||||
CompactEvent::Failed { error } => (
|
||||
format!("[compact error] {error}"),
|
||||
MessageKind::NoticeError,
|
||||
),
|
||||
CompactEvent::Failed { error } => {
|
||||
(format!("[compact error] {error}"), MessageKind::NoticeError)
|
||||
}
|
||||
};
|
||||
match mode {
|
||||
Mode::Overview => push_overview_line(lines, &text, width, kind, ""),
|
||||
@@ -772,4 +766,3 @@ pub fn kind_style(kind: MessageKind) -> Style {
|
||||
.add_modifier(Modifier::BOLD),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user