Skip to content

Commit b8ade15

Browse files
authored
chore: move messages to constants (#3080)
* move messages to constants * formatting * fix clippy * fix windows
1 parent 3ed28dc commit b8ade15

File tree

13 files changed

+212
-136
lines changed

13 files changed

+212
-136
lines changed

crates/chat-cli/src/auth/consts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use aws_types::region::Region;
22

3-
pub(crate) const CLIENT_NAME: &str = "Amazon Q Developer for command line";
3+
pub(crate) use crate::constants::CLIENT_NAME;
44

55
pub(crate) const OIDC_BUILDER_ID_REGION: Region = Region::from_static("us-east-1");
66

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

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,19 @@ use crate::cli::chat::{
2222
ChatSession,
2323
ChatState,
2424
};
25+
use crate::constants::help_text::{
26+
CONTEXT_DESCRIPTION,
27+
context_long_help,
28+
};
2529
use crate::os::Os;
2630

2731
#[deny(missing_docs)]
2832
#[derive(Debug, PartialEq, Subcommand)]
2933
#[command(
30-
before_long_help = "Context rules determine which files are included in your Amazon Q session.
31-
They are derived from the current active agent.
32-
The files matched by these rules provide Amazon Q with additional information
33-
about your project or environment. Adding relevant files helps Q generate
34-
more accurate and helpful responses.
35-
36-
Notes:
37-
• You can add specific files or use glob patterns (e.g., \"*.py\", \"src/**/*.js\")
38-
• Agent rules apply only to the current agent
39-
• Context changes are NOT preserved between chat sessions. To make these changes permanent, edit the agent config file."
34+
about = CONTEXT_DESCRIPTION,
35+
before_long_help = context_long_help()
4036
)]
41-
/// Subcommands for managing context rules and files in Amazon Q chat sessions
37+
/// Context subcommands
4238
pub enum ContextSubcommand {
4339
/// Display the context rule configuration and matched files
4440
Show {

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

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ use crate::cli::chat::{
4545
ChatSession,
4646
ChatState,
4747
};
48+
use crate::constants::help_text::hooks_long_help;
4849
use crate::util::MCP_SERVER_TOOL_DELIMITER;
4950
use crate::util::pattern_matching::matches_any_pattern;
5051

@@ -388,15 +389,7 @@ fn sanitize_user_prompt(input: &str) -> String {
388389
#[deny(missing_docs)]
389390
#[derive(Debug, PartialEq, Args)]
390391
#[command(
391-
before_long_help = "Use context hooks to specify shell commands to run. The output from these
392-
commands will be appended to the prompt to Amazon Q.
393-
394-
Refer to the documentation for how to configure hooks with your agent: https://github.com/aws/amazon-q-developer-cli/blob/main/docs/agent-format.md#hooks-field
395-
396-
Notes:
397-
• Hooks are executed in parallel
398-
• 'conversation_start' hooks run on the first user prompt and are attached once to the conversation history sent to Amazon Q
399-
• 'per_prompt' hooks run on each user prompt and are attached to the prompt, but are not stored in conversation history"
392+
before_long_help = hooks_long_help()
400393
)]
401394
/// Arguments for the hooks command that displays configured context hooks
402395
pub struct HooksArgs;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ use crate::cli::chat::{
4848
ChatError,
4949
ChatSession,
5050
ChatState,
51-
EXTRA_HELP,
5251
};
5352
use crate::cli::issue;
53+
use crate::constants::ui_text::EXTRA_HELP;
5454
use crate::os::Os;
5555

5656
/// q (Amazon Q Chat)

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ use crate::cli::chat::{
3131
ChatError,
3232
ChatSession,
3333
ChatState,
34-
TRUST_ALL_TEXT,
34+
trust_all_text,
3535
};
36+
use crate::constants::help_text::tools_long_help;
3637
use crate::util::consts::MCP_SERVER_TOOL_DELIMITER;
3738

3839
/// Command-line arguments for managing tools in the chat session
@@ -197,10 +198,7 @@ impl ToolsArgs {
197198
#[deny(missing_docs)]
198199
#[derive(Debug, PartialEq, Subcommand)]
199200
#[command(
200-
before_long_help = "By default, Amazon Q will ask for your permission to use certain tools. You can control which tools you
201-
trust so that no confirmation is required.
202-
203-
Refer to the documentation for how to configure tools with your agent: https://github.com/aws/amazon-q-developer-cli/blob/main/docs/agent-format.md#tools-field"
201+
before_long_help = tools_long_help()
204202
)]
205203
/// Subcommands for managing tool permissions and configurations
206204
pub enum ToolsSubcommand {
@@ -369,7 +367,7 @@ impl ToolsSubcommand {
369367
},
370368
Self::TrustAll => {
371369
session.conversation.agents.trust_all_tools = true;
372-
queue!(session.stderr, style::Print(TRUST_ALL_TEXT))?;
370+
queue!(session.stderr, style::Print(trust_all_text()))?;
373371
},
374372
Self::Reset => {
375373
session.conversation.agents.trust_all_tools = false;

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

Lines changed: 27 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ mod prompt;
1313
mod prompt_parser;
1414
pub mod server_messenger;
1515
use crate::cli::chat::checkpoint::CHECKPOINT_MESSAGE_MAX_LENGTH;
16+
use crate::constants::ui_text::{
17+
LIMIT_REACHED_TEXT,
18+
POPULAR_SHORTCUTS,
19+
RESUME_TEXT,
20+
SMALL_SCREEN_POPULAR_SHORTCUTS,
21+
SMALL_SCREEN_WELCOME,
22+
WELCOME_TEXT,
23+
};
1624
#[cfg(unix)]
1725
mod skim_integration;
1826
mod token_counter;
@@ -161,6 +169,11 @@ use crate::cli::experiment::experiment_manager::{
161169
ExperimentManager,
162170
ExperimentName,
163171
};
172+
use crate::constants::{
173+
error_messages,
174+
tips,
175+
ui_text,
176+
};
164177
use crate::database::settings::Setting;
165178
use crate::os::Os;
166179
use crate::telemetry::core::{
@@ -183,29 +196,6 @@ use crate::util::{
183196
ui,
184197
};
185198

186-
const LIMIT_REACHED_TEXT: &str = color_print::cstr! { "You've used all your free requests for this month. You have two options:
187-
1. Upgrade to a paid subscription for increased limits. See our Pricing page for what's included> <blue!>https://aws.amazon.com/q/developer/pricing/</blue!>
188-
2. Wait until next month when your limit automatically resets." };
189-
190-
pub const EXTRA_HELP: &str = color_print::cstr! {"
191-
<cyan,em>MCP:</cyan,em>
192-
<black!>You can now configure the Amazon Q CLI to use MCP servers. \nLearn how: https://docs.aws.amazon.com/amazonq/latest/qdeveloper-ug/qdev-mcp.html</black!>
193-
194-
<cyan,em>Tips:</cyan,em>
195-
<em>!{command}</em> <black!>Quickly execute a command in your current session</black!>
196-
<em>Ctrl(^) + j</em> <black!>Insert new-line to provide multi-line prompt</black!>
197-
<black!>Alternatively, [Alt(⌥) + Enter(⏎)]</black!>
198-
<em>Ctrl(^) + s</em> <black!>Fuzzy search commands and context files</black!>
199-
<black!>Use Tab to select multiple items</black!>
200-
<black!>Change the keybind using: q settings chat.skimCommandKey x</black!>
201-
<em>Ctrl(^) + t</em> <black!>Toggle tangent mode for isolated conversations</black!>
202-
<black!>Change the keybind using: q settings chat.tangentModeKey x</black!>
203-
<em>Ctrl(^) + d</em> <black!>Start delegate command for task delegation</black!>
204-
<black!>Change the keybind using: q settings chat.delegateModeKey x</black!>
205-
<em>chat.editMode</em> <black!>The prompt editing mode (vim or emacs)</black!>
206-
<black!>Change using: q settings chat.skimCommandKey x</black!>
207-
"};
208-
209199
#[derive(Copy, Clone, Debug, PartialEq, Eq, ValueEnum)]
210200
pub enum WrapMode {
211201
/// Always wrap at terminal width
@@ -453,72 +443,18 @@ impl ChatArgs {
453443
}
454444
}
455445

456-
const WELCOME_TEXT: &str = color_print::cstr! {"<cyan!>
457-
⢠⣶⣶⣦⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣤⣶⣿⣿⣿⣶⣦⡀⠀
458-
⠀⠀⠀⣾⡿⢻⣿⡆⠀⠀⠀⢀⣄⡄⢀⣠⣤⣤⡀⢀⣠⣤⣤⡀⠀⠀⢀⣠⣤⣤⣤⣄⠀⠀⢀⣤⣤⣤⣤⣤⣤⡀⠀⠀⣀⣤⣤⣤⣀⠀⠀⠀⢠⣤⡀⣀⣤⣤⣄⡀⠀⠀⠀⠀⠀⠀⢠⣿⣿⠋⠀⠀⠀⠙⣿⣿⡆
459-
⠀⠀⣼⣿⠇⠀⣿⣿⡄⠀⠀⢸⣿⣿⠛⠉⠻⣿⣿⠛⠉⠛⣿⣿⠀⠀⠘⠛⠉⠉⠻⣿⣧⠀⠈⠛⠛⠛⣻⣿⡿⠀⢀⣾⣿⠛⠉⠻⣿⣷⡀⠀⢸⣿⡟⠛⠉⢻⣿⣷⠀⠀⠀⠀⠀⠀⣼⣿⡏⠀⠀⠀⠀⠀⢸⣿⣿
460-
⠀⢰⣿⣿⣤⣤⣼⣿⣷⠀⠀⢸⣿⣿⠀⠀⠀⣿⣿⠀⠀⠀⣿⣿⠀⠀⢀⣴⣶⣶⣶⣿⣿⠀⠀⠀⣠⣾⡿⠋⠀⠀⢸⣿⣿⠀⠀⠀⣿⣿⡇⠀⢸⣿⡇⠀⠀⢸⣿⣿⠀⠀⠀⠀⠀⠀⢹⣿⣇⠀⠀⠀⠀⠀⢸⣿⡿
461-
⢀⣿⣿⠋⠉⠉⠉⢻⣿⣇⠀⢸⣿⣿⠀⠀⠀⣿⣿⠀⠀⠀⣿⣿⠀⠀⣿⣿⡀⠀⣠⣿⣿⠀⢀⣴⣿⣋⣀⣀⣀⡀⠘⣿⣿⣄⣀⣠⣿⣿⠃⠀⢸⣿⡇⠀⠀⢸⣿⣿⠀⠀⠀⠀⠀⠀⠈⢿⣿⣦⣀⣀⣀⣴⣿⡿⠃
462-
⠚⠛⠋⠀⠀⠀⠀⠘⠛⠛⠀⠘⠛⠛⠀⠀⠀⠛⠛⠀⠀⠀⠛⠛⠀⠀⠙⠻⠿⠟⠋⠛⠛⠀⠘⠛⠛⠛⠛⠛⠛⠃⠀⠈⠛⠿⠿⠿⠛⠁⠀⠀⠘⠛⠃⠀⠀⠘⠛⠛⠀⠀⠀⠀⠀⠀⠀⠀⠙⠛⠿⢿⣿⣿⣋⠀⠀
463-
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠛⠿⢿⡧</cyan!>"};
464-
465-
const SMALL_SCREEN_WELCOME_TEXT: &str = color_print::cstr! {"<em>Welcome to <cyan!>Amazon Q</cyan!>!</em>"};
466-
const RESUME_TEXT: &str = color_print::cstr! {"<em>Picking up where we left off...</em>"};
467-
468446
// Maximum number of times to show the changelog announcement per version
469447
const CHANGELOG_MAX_SHOW_COUNT: i64 = 2;
470448

471449
// Only show the model-related tip for now to make users aware of this feature.
472-
const ROTATING_TIPS: [&str; 20] = [
473-
color_print::cstr! {"You can resume the last conversation from your current directory by launching with
474-
<green!>q chat --resume</green!>"},
475-
color_print::cstr! {"Get notified whenever Q CLI finishes responding.
476-
Just run <green!>q settings chat.enableNotifications true</green!>"},
477-
color_print::cstr! {"You can use
478-
<green!>/editor</green!> to edit your prompt with a vim-like experience"},
479-
color_print::cstr! {"<green!>/usage</green!> shows you a visual breakdown of your current context window usage"},
480-
color_print::cstr! {"Get notified whenever Q CLI finishes responding. Just run <green!>q settings
481-
chat.enableNotifications true</green!>"},
482-
color_print::cstr! {"You can execute bash commands by typing
483-
<green!>!</green!> followed by the command"},
484-
color_print::cstr! {"Q can use tools without asking for
485-
confirmation every time. Give <green!>/tools trust</green!> a try"},
486-
color_print::cstr! {"You can
487-
programmatically inject context to your prompts by using hooks. Check out <green!>/context hooks
488-
help</green!>"},
489-
color_print::cstr! {"You can use <green!>/compact</green!> to replace the conversation
490-
history with its summary to free up the context space"},
491-
color_print::cstr! {"If you want to file an issue
492-
to the Q CLI team, just tell me, or run <green!>q issue</green!>"},
493-
color_print::cstr! {"You can enable
494-
custom tools with <green!>MCP servers</green!>. Learn more with /help"},
495-
color_print::cstr! {"You can
496-
specify wait time (in ms) for mcp server loading with <green!>q settings mcp.initTimeout {timeout in
497-
int}</green!>. Servers that takes longer than the specified time will continue to load in the background. Use
498-
/tools to see pending servers."},
499-
color_print::cstr! {"You can see the server load status as well as any
500-
warnings or errors associated with <green!>/mcp</green!>"},
501-
color_print::cstr! {"Use <green!>/model</green!> to select the model to use for this conversation"},
502-
color_print::cstr! {"Set a default model by running <green!>q settings chat.defaultModel MODEL</green!>. Run <green!>/model</green!> to learn more."},
503-
color_print::cstr! {"Run <green!>/prompts</green!> to learn how to build & run repeatable workflows"},
504-
color_print::cstr! {"Use <green!>/tangent</green!> or <green!>ctrl + t</green!> (customizable) to start isolated conversations ( ↯ ) that don't affect your main chat history"},
505-
color_print::cstr! {"Ask me directly about my capabilities! Try questions like <green!>\"What can you do?\"</green!> or <green!>\"Can you save conversations?\"</green!>"},
506-
color_print::cstr! {"Stay up to date with the latest features and improvements! Use <green!>/changelog</green!> to see what's new in Amazon Q CLI"},
507-
color_print::cstr! {"Enable workspace checkpoints to snapshot & restore changes. Just run <green!>q</green!> <green!>settings chat.enableCheckpoint true</green!>"},
508-
];
450+
const ROTATING_TIPS: [&str; 20] = tips::ROTATING_TIPS;
509451

510452
const GREETING_BREAK_POINT: usize = 80;
511453

512-
const POPULAR_SHORTCUTS: &str = color_print::cstr! {"<black!><green!>/help</green!> all commands <em>•</em> <green!>ctrl + j</green!> new lines <em>•</em> <green!>ctrl + s</green!> fuzzy search</black!>"};
513-
const SMALL_SCREEN_POPULAR_SHORTCUTS: &str = color_print::cstr! {"<black!><green!>/help</green!> all commands
514-
<green!>ctrl + j</green!> new lines
515-
<green!>ctrl + s</green!> fuzzy search
516-
</black!>"};
517-
518454
const RESPONSE_TIMEOUT_CONTENT: &str = "Response timed out - message took too long to generate";
519-
const TRUST_ALL_TEXT: &str = color_print::cstr! {"<green!>All tools are now trusted (<red!>!</red!>). Amazon Q will execute tools <bold>without</bold> asking for confirmation.\
520-
\nAgents can sometimes do unexpected things so understand the risks.</green!>
521-
\nLearn more at https://docs.aws.amazon.com/amazonq/latest/qdeveloper-ug/command-line-chat-security.html#command-line-chat-trustall-safety"};
455+
fn trust_all_text() -> String {
456+
ui_text::trust_all_warning()
457+
}
522458

523459
const TOOL_BULLET: &str = " ● ";
524460
const CONTINUATION_LINE: &str = " ⋮ ";
@@ -977,12 +913,13 @@ impl ChatSession {
977913
self.stderr,
978914
style::SetAttribute(Attribute::Bold),
979915
style::SetForegroundColor(Color::Red),
980-
style::Print(" ⚠️ Amazon Q rate limit reached:\n"),
916+
style::Print(error_messages::RATE_LIMIT_PREFIX),
917+
style::Print("\n"),
981918
style::Print(format!(" {}\n\n", err.clone())),
982919
style::SetAttribute(Attribute::Reset),
983920
style::SetForegroundColor(Color::Reset),
984921
)?;
985-
("Amazon Q is having trouble responding right now", eyre!(err), false)
922+
(error_messages::TROUBLE_RESPONDING, eyre!(err), false)
986923
},
987924
ApiClientError::ModelOverloadedError { request_id, .. } => {
988925
if self.interactive {
@@ -1022,12 +959,12 @@ impl ChatSession {
1022959
self.stderr,
1023960
style::SetAttribute(Attribute::Bold),
1024961
style::SetForegroundColor(Color::Red),
1025-
style::Print("Amazon Q is having trouble responding right now:\n"),
962+
style::Print(format!("{}:\n", error_messages::TROUBLE_RESPONDING)),
1026963
style::Print(format!(" {}\n", err.clone())),
1027964
style::SetAttribute(Attribute::Reset),
1028965
style::SetForegroundColor(Color::Reset),
1029966
)?;
1030-
("Amazon Q is having trouble responding right now", eyre!(err), false)
967+
(error_messages::TROUBLE_RESPONDING, eyre!(err), false)
1031968
},
1032969
ApiClientError::MonthlyLimitReached { .. } => {
1033970
let subscription_status = get_subscription_status(os).await;
@@ -1084,17 +1021,9 @@ impl ChatSession {
10841021

10851022
return Ok(());
10861023
},
1087-
_ => (
1088-
"Amazon Q is having trouble responding right now",
1089-
Report::from(err),
1090-
true,
1091-
),
1024+
_ => (error_messages::TROUBLE_RESPONDING, Report::from(err), true),
10921025
},
1093-
_ => (
1094-
"Amazon Q is having trouble responding right now",
1095-
Report::from(err),
1096-
true,
1097-
),
1026+
_ => (error_messages::TROUBLE_RESPONDING, Report::from(err), true),
10981027
};
10991028

11001029
if display_err_message {
@@ -1270,7 +1199,7 @@ impl ChatSession {
12701199
let welcome_text = match self.existing_conversation {
12711200
true => RESUME_TEXT,
12721201
false => match is_small_screen {
1273-
true => SMALL_SCREEN_WELCOME_TEXT,
1202+
true => SMALL_SCREEN_WELCOME,
12741203
false => WELCOME_TEXT,
12751204
},
12761205
};
@@ -1320,7 +1249,8 @@ impl ChatSession {
13201249
queue!(
13211250
self.stderr,
13221251
style::Print(format!(
1323-
"{}{TRUST_ALL_TEXT}\n\n",
1252+
"{}{}\n\n",
1253+
trust_all_text(),
13241254
if !is_small_screen { "\n" } else { "" }
13251255
))
13261256
)?;

crates/chat-cli/src/cli/chat/tools/delegate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,7 @@ pub async fn status_all_agents(os: &Os) -> Result<String> {
455455
}
456456
}
457457

458+
#[allow(unused_variables)]
458459
fn is_process_alive(pid: u32) -> bool {
459460
#[cfg(unix)]
460461
{

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ use crate::auth::builder_id::{
3737
start_device_authorization,
3838
};
3939
use crate::auth::pkce::start_pkce_authorization;
40+
use crate::constants::PRODUCT_NAME;
4041
use crate::os::Os;
4142
use crate::telemetry::{
4243
QProfileSwitchIntent,
@@ -49,7 +50,6 @@ use crate::util::spinner::{
4950
use crate::util::system_info::is_remote;
5051
use crate::util::{
5152
CLI_BINARY_NAME,
52-
PRODUCT_NAME,
5353
choose,
5454
input,
5555
};

0 commit comments

Comments
 (0)