Skip to content

Commit 3f26b1f

Browse files
Apply cargo +nightly fmt formatting (#2664)
Co-authored-by: Kenneth S. <[email protected]>
1 parent 967ce49 commit 3f26b1f

File tree

7 files changed

+205
-76
lines changed

7 files changed

+205
-76
lines changed

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,12 @@ use tools::ToolsArgs;
3232
use crate::cli::chat::cli::subscribe::SubscribeArgs;
3333
use crate::cli::chat::cli::usage::UsageArgs;
3434
use crate::cli::chat::consts::AGENT_MIGRATION_DOC_URL;
35-
use crate::cli::chat::{ChatError, ChatSession, ChatState, EXTRA_HELP};
35+
use crate::cli::chat::{
36+
ChatError,
37+
ChatSession,
38+
ChatState,
39+
EXTRA_HELP,
40+
};
3641
use crate::cli::issue;
3742
use crate::os::Os;
3843

@@ -93,7 +98,10 @@ impl SlashCommand {
9398
Self::Clear(args) => args.execute(session).await,
9499
Self::Agent(subcommand) => subcommand.execute(os, session).await,
95100
Self::Profile => {
96-
use crossterm::{execute, style};
101+
use crossterm::{
102+
execute,
103+
style,
104+
};
97105
execute!(
98106
session.stderr,
99107
style::SetForegroundColor(style::Color::Yellow),

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
use clap::Args;
22
use crossterm::execute;
3-
use crossterm::style::{self, Color};
3+
use crossterm::style::{
4+
self,
5+
Color,
6+
};
47

5-
use crate::cli::chat::{ChatError, ChatSession, ChatState};
8+
use crate::cli::chat::{
9+
ChatError,
10+
ChatSession,
11+
ChatState,
12+
};
613
use crate::os::Os;
714

815
#[derive(Debug, PartialEq, Args)]
@@ -52,9 +59,7 @@ impl TangentArgs {
5259
style::Print("/tangent"),
5360
style::SetForegroundColor(Color::DarkGrey),
5461
style::Print(" to restore the conversation later.\n"),
55-
style::Print(
56-
"Note: this functionality is experimental and may change or be removed in the future.\n"
57-
),
62+
style::Print("Note: this functionality is experimental and may change or be removed in the future.\n"),
5863
style::SetForegroundColor(Color::Reset)
5964
)?;
6065
}

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,8 +1360,14 @@ mod tests {
13601360
assert!(!conversation.is_in_tangent_mode());
13611361

13621362
// Add some main conversation history
1363-
conversation.set_next_user_message("main conversation".to_string()).await;
1364-
conversation.push_assistant_message(&mut os, AssistantMessage::new_response(None, "main response".to_string()), None);
1363+
conversation
1364+
.set_next_user_message("main conversation".to_string())
1365+
.await;
1366+
conversation.push_assistant_message(
1367+
&mut os,
1368+
AssistantMessage::new_response(None, "main response".to_string()),
1369+
None,
1370+
);
13651371
conversation.transcript.push_back("main transcript".to_string());
13661372

13671373
let main_history_len = conversation.history.len();
@@ -1377,8 +1383,14 @@ mod tests {
13771383
assert!(conversation.next_message.is_none());
13781384

13791385
// Add tangent conversation
1380-
conversation.set_next_user_message("tangent conversation".to_string()).await;
1381-
conversation.push_assistant_message(&mut os, AssistantMessage::new_response(None, "tangent response".to_string()), None);
1386+
conversation
1387+
.set_next_user_message("tangent conversation".to_string())
1388+
.await;
1389+
conversation.push_assistant_message(
1390+
&mut os,
1391+
AssistantMessage::new_response(None, "tangent response".to_string()),
1392+
None,
1393+
);
13821394

13831395
// During tangent mode, history should have grown
13841396
assert_eq!(conversation.history.len(), main_history_len + 1);

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

Lines changed: 132 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -19,40 +19,109 @@ pub mod tool_manager;
1919
pub mod tools;
2020
pub mod util;
2121
use std::borrow::Cow;
22-
use std::collections::{HashMap, VecDeque};
23-
use std::io::{IsTerminal, Read, Write};
22+
use std::collections::{
23+
HashMap,
24+
VecDeque,
25+
};
26+
use std::io::{
27+
IsTerminal,
28+
Read,
29+
Write,
30+
};
2431
use std::process::ExitCode;
2532
use std::sync::Arc;
26-
use std::time::{Duration, Instant};
33+
use std::time::{
34+
Duration,
35+
Instant,
36+
};
2737

2838
use amzn_codewhisperer_client::types::SubscriptionStatus;
29-
use clap::{Args, CommandFactory, Parser};
39+
use clap::{
40+
Args,
41+
CommandFactory,
42+
Parser,
43+
};
3044
use cli::compact::CompactStrategy;
31-
use cli::model::{get_available_models, select_model};
45+
use cli::model::{
46+
get_available_models,
47+
select_model,
48+
};
3249
pub use conversation::ConversationState;
3350
use conversation::TokenWarningLevel;
34-
use crossterm::style::{Attribute, Color, Stylize};
35-
use crossterm::{cursor, execute, queue, style, terminal};
36-
use tool_manager::{PromptQuery, PromptQueryResult};
37-
use eyre::{Report, Result, bail, eyre};
51+
use crossterm::style::{
52+
Attribute,
53+
Color,
54+
Stylize,
55+
};
56+
use crossterm::{
57+
cursor,
58+
execute,
59+
queue,
60+
style,
61+
terminal,
62+
};
63+
use eyre::{
64+
Report,
65+
Result,
66+
bail,
67+
eyre,
68+
};
3869
use input_source::InputSource;
39-
use message::{AssistantMessage, AssistantToolUse, ToolUseResult, ToolUseResultBlock};
40-
use parse::{ParseState, interpret_markdown};
41-
use parser::{RecvErrorKind, RequestMetadata, SendMessageStream};
70+
use message::{
71+
AssistantMessage,
72+
AssistantToolUse,
73+
ToolUseResult,
74+
ToolUseResultBlock,
75+
};
76+
use parse::{
77+
ParseState,
78+
interpret_markdown,
79+
};
80+
use parser::{
81+
RecvErrorKind,
82+
RequestMetadata,
83+
SendMessageStream,
84+
};
4285
use regex::Regex;
43-
use spinners::{Spinner, Spinners};
86+
use spinners::{
87+
Spinner,
88+
Spinners,
89+
};
4490
use thiserror::Error;
4591
use time::OffsetDateTime;
4692
use token_counter::TokenCounter;
4793
use tokio::signal::ctrl_c;
48-
use tokio::sync::{Mutex, broadcast};
49-
use tool_manager::{ToolManager, ToolManagerBuilder};
94+
use tokio::sync::{
95+
Mutex,
96+
broadcast,
97+
};
98+
use tool_manager::{
99+
PromptQuery,
100+
PromptQueryResult,
101+
ToolManager,
102+
ToolManagerBuilder,
103+
};
50104
use tools::gh_issue::GhIssueContext;
51-
use tools::{NATIVE_TOOLS, OutputKind, QueuedTool, Tool, ToolSpec};
52-
use tracing::{debug, error, info, trace, warn};
105+
use tools::{
106+
NATIVE_TOOLS,
107+
OutputKind,
108+
QueuedTool,
109+
Tool,
110+
ToolSpec,
111+
};
112+
use tracing::{
113+
debug,
114+
error,
115+
info,
116+
trace,
117+
warn,
118+
};
53119
use util::images::RichImageBlock;
54120
use util::ui::draw_box;
55-
use util::{animate_output, play_notification_bell};
121+
use util::{
122+
animate_output,
123+
play_notification_bell,
124+
};
56125
use winnow::Partial;
57126
use winnow::stream::Offset;
58127

@@ -61,22 +130,36 @@ use super::agent::{
61130
PermissionEvalResult,
62131
};
63132
use crate::api_client::model::ToolResultStatus;
64-
use crate::api_client::{self, ApiClientError};
133+
use crate::api_client::{
134+
self,
135+
ApiClientError,
136+
};
65137
use crate::auth::AuthError;
66138
use crate::auth::builder_id::is_idc_user;
67139
use crate::cli::agent::Agents;
68140
use crate::cli::chat::cli::SlashCommand;
69141
use crate::cli::chat::cli::model::find_model;
70-
use crate::cli::chat::cli::prompts::{GetPromptError, PromptsSubcommand};
142+
use crate::cli::chat::cli::prompts::{
143+
GetPromptError,
144+
PromptsSubcommand,
145+
};
71146
use crate::cli::chat::util::sanitize_unicode_tags;
72147
use crate::database::settings::Setting;
73148
use crate::mcp_client::Prompt;
74149
use crate::os::Os;
75150
use crate::telemetry::core::{
76-
AgentConfigInitArgs, ChatAddedMessageParams, ChatConversationType, MessageMetaTag, RecordUserTurnCompletionArgs,
151+
AgentConfigInitArgs,
152+
ChatAddedMessageParams,
153+
ChatConversationType,
154+
MessageMetaTag,
155+
RecordUserTurnCompletionArgs,
77156
ToolUseEventBuilder,
78157
};
79-
use crate::telemetry::{ReasonCode, TelemetryResult, get_error_reason};
158+
use crate::telemetry::{
159+
ReasonCode,
160+
TelemetryResult,
161+
get_error_reason,
162+
};
80163
use crate::util::MCP_SERVER_TOOL_DELIMITER;
81164

82165
const LIMIT_REACHED_TEXT: &str = color_print::cstr! { "You've used all your free requests for this month. You have two options:
@@ -189,17 +272,13 @@ impl ChatArgs {
189272
agents.trust_all_tools = self.trust_all_tools;
190273

191274
os.telemetry
192-
.send_agent_config_init(
193-
&os.database,
194-
conversation_id.clone(),
195-
AgentConfigInitArgs {
196-
agents_loaded_count: md.load_count as i64,
197-
agents_loaded_failed_count: md.load_failed_count as i64,
198-
legacy_profile_migration_executed: md.migration_performed,
199-
legacy_profile_migrated_count: md.migrated_count as i64,
200-
launched_agent: md.launched_agent,
201-
},
202-
)
275+
.send_agent_config_init(&os.database, conversation_id.clone(), AgentConfigInitArgs {
276+
agents_loaded_count: md.load_count as i64,
277+
agents_loaded_failed_count: md.load_failed_count as i64,
278+
legacy_profile_migration_executed: md.migration_performed,
279+
legacy_profile_migrated_count: md.migrated_count as i64,
280+
launched_agent: md.launched_agent,
281+
})
203282
.await
204283
.map_err(|err| error!(?err, "failed to send agent config init telemetry"))
205284
.ok();
@@ -2693,31 +2772,26 @@ impl ChatSession {
26932772
};
26942773

26952774
os.telemetry
2696-
.send_record_user_turn_completion(
2697-
&os.database,
2698-
conversation_id,
2699-
result,
2700-
RecordUserTurnCompletionArgs {
2701-
message_ids: mds.iter().map(|md| md.message_id.clone()).collect::<_>(),
2702-
request_ids: mds.iter().map(|md| md.request_id.clone()).collect::<_>(),
2703-
reason,
2704-
reason_desc,
2705-
status_code,
2706-
time_to_first_chunks_ms: mds
2707-
.iter()
2708-
.map(|md| md.time_to_first_chunk.map(|d| d.as_secs_f64() * 1000.0))
2709-
.collect::<_>(),
2710-
chat_conversation_type: md.and_then(|md| md.chat_conversation_type),
2711-
assistant_response_length: mds.iter().map(|md| md.response_size as i64).sum(),
2712-
message_meta_tags: mds.last().map(|md| md.message_meta_tags.clone()).unwrap_or_default(),
2713-
user_prompt_length: mds.first().map(|md| md.user_prompt_length).unwrap_or_default() as i64,
2714-
user_turn_duration_seconds,
2715-
follow_up_count: mds
2716-
.iter()
2717-
.filter(|md| matches!(md.chat_conversation_type, Some(ChatConversationType::ToolUse)))
2718-
.count() as i64,
2719-
},
2720-
)
2775+
.send_record_user_turn_completion(&os.database, conversation_id, result, RecordUserTurnCompletionArgs {
2776+
message_ids: mds.iter().map(|md| md.message_id.clone()).collect::<_>(),
2777+
request_ids: mds.iter().map(|md| md.request_id.clone()).collect::<_>(),
2778+
reason,
2779+
reason_desc,
2780+
status_code,
2781+
time_to_first_chunks_ms: mds
2782+
.iter()
2783+
.map(|md| md.time_to_first_chunk.map(|d| d.as_secs_f64() * 1000.0))
2784+
.collect::<_>(),
2785+
chat_conversation_type: md.and_then(|md| md.chat_conversation_type),
2786+
assistant_response_length: mds.iter().map(|md| md.response_size as i64).sum(),
2787+
message_meta_tags: mds.last().map(|md| md.message_meta_tags.clone()).unwrap_or_default(),
2788+
user_prompt_length: mds.first().map(|md| md.user_prompt_length).unwrap_or_default() as i64,
2789+
user_turn_duration_seconds,
2790+
follow_up_count: mds
2791+
.iter()
2792+
.filter(|md| matches!(md.chat_conversation_type, Some(ChatConversationType::ToolUse)))
2793+
.count() as i64,
2794+
})
27212795
.await
27222796
.ok();
27232797
}

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

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,36 @@ use std::borrow::Cow;
22
use std::cell::RefCell;
33

44
use eyre::Result;
5-
use rustyline::completion::{Completer, FilenameCompleter, extract_word};
5+
use rustyline::completion::{
6+
Completer,
7+
FilenameCompleter,
8+
extract_word,
9+
};
610
use rustyline::error::ReadlineError;
7-
use rustyline::highlight::{CmdKind, Highlighter};
11+
use rustyline::highlight::{
12+
CmdKind,
13+
Highlighter,
14+
};
815
use rustyline::hint::Hinter as RustylineHinter;
916
use rustyline::history::DefaultHistory;
10-
use rustyline::validate::{ValidationContext, ValidationResult, Validator};
17+
use rustyline::validate::{
18+
ValidationContext,
19+
ValidationResult,
20+
Validator,
21+
};
1122
use rustyline::{
12-
Cmd, Completer, CompletionType, Config, Context, EditMode, Editor, EventHandler, Helper, Hinter, KeyCode, KeyEvent,
23+
Cmd,
24+
Completer,
25+
CompletionType,
26+
Config,
27+
Context,
28+
EditMode,
29+
Editor,
30+
EventHandler,
31+
Helper,
32+
Hinter,
33+
KeyCode,
34+
KeyEvent,
1335
Modifiers,
1436
};
1537
use winnow::stream::AsChar;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ pub struct PromptComponents {
1010

1111
/// Parse prompt components from a plain text prompt
1212
pub fn parse_prompt_components(prompt: &str) -> Option<PromptComponents> {
13-
// Expected format: "[agent] !> " or "> " or "!> " or "[agent] ↯ > " or "↯ > " or "[agent] ↯ !> " etc.
13+
// Expected format: "[agent] !> " or "> " or "!> " or "[agent] ↯ > " or "↯ > " or "[agent] ↯ !> "
14+
// etc.
1415
let mut profile = None;
1516
let mut warning = false;
1617
let mut tangent_mode = false;

0 commit comments

Comments
 (0)