Skip to content

Commit 3adad5e

Browse files
committed
move messages to constants
1 parent 3ed28dc commit 3adad5e

File tree

12 files changed

+204
-121
lines changed

12 files changed

+204
-121
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: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use crossterm::{
1111
};
1212

1313
use crate::cli::chat::consts::AGENT_FORMAT_HOOKS_DOC_URL;
14+
use crate::constants::help_text::{CONTEXT_DESCRIPTION, context_long_help};
1415
use crate::cli::chat::context::{
1516
ContextFilePath,
1617
calc_max_context_files_size,
@@ -22,23 +23,16 @@ use crate::cli::chat::{
2223
ChatSession,
2324
ChatState,
2425
};
26+
2527
use crate::os::Os;
2628

2729
#[deny(missing_docs)]
2830
#[derive(Debug, PartialEq, Subcommand)]
2931
#[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."
32+
about = CONTEXT_DESCRIPTION,
33+
before_long_help = context_long_help()
4034
)]
41-
/// Subcommands for managing context rules and files in Amazon Q chat sessions
35+
/// Context subcommands
4236
pub enum ContextSubcommand {
4337
/// Display the context rule configuration and matched files
4438
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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ use crate::cli::chat::{
4848
ChatError,
4949
ChatSession,
5050
ChatState,
51-
EXTRA_HELP,
5251
};
52+
use crate::constants::ui_text::EXTRA_HELP;
5353
use crate::cli::issue;
54+
5455
use crate::os::Os;
5556

5657
/// 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: 20 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ 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::{LIMIT_REACHED_TEXT, WELCOME_TEXT, RESUME_TEXT, SMALL_SCREEN_WELCOME, POPULAR_SHORTCUTS, SMALL_SCREEN_POPULAR_SHORTCUTS};
1617
#[cfg(unix)]
1718
mod skim_integration;
1819
mod token_counter;
@@ -144,6 +145,11 @@ use crate::api_client::{
144145
use crate::auth::AuthError;
145146
use crate::auth::builder_id::is_idc_user;
146147
use crate::cli::TodoListState;
148+
use crate::constants::{
149+
error_messages,
150+
tips,
151+
ui_text,
152+
};
147153
use crate::cli::agent::Agents;
148154
use crate::cli::chat::checkpoint::{
149155
CheckpointManager,
@@ -183,29 +189,6 @@ use crate::util::{
183189
ui,
184190
};
185191

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-
209192
#[derive(Copy, Clone, Debug, PartialEq, Eq, ValueEnum)]
210193
pub enum WrapMode {
211194
/// Always wrap at terminal width
@@ -453,72 +436,22 @@ impl ChatArgs {
453436
}
454437
}
455438

456-
const WELCOME_TEXT: &str = color_print::cstr! {"<cyan!>
457-
⢠⣶⣶⣦⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣤⣶⣿⣿⣿⣶⣦⡀⠀
458-
⠀⠀⠀⣾⡿⢻⣿⡆⠀⠀⠀⢀⣄⡄⢀⣠⣤⣤⡀⢀⣠⣤⣤⡀⠀⠀⢀⣠⣤⣤⣤⣄⠀⠀⢀⣤⣤⣤⣤⣤⣤⡀⠀⠀⣀⣤⣤⣤⣀⠀⠀⠀⢠⣤⡀⣀⣤⣤⣄⡀⠀⠀⠀⠀⠀⠀⢠⣿⣿⠋⠀⠀⠀⠙⣿⣿⡆
459-
⠀⠀⣼⣿⠇⠀⣿⣿⡄⠀⠀⢸⣿⣿⠛⠉⠻⣿⣿⠛⠉⠛⣿⣿⠀⠀⠘⠛⠉⠉⠻⣿⣧⠀⠈⠛⠛⠛⣻⣿⡿⠀⢀⣾⣿⠛⠉⠻⣿⣷⡀⠀⢸⣿⡟⠛⠉⢻⣿⣷⠀⠀⠀⠀⠀⠀⣼⣿⡏⠀⠀⠀⠀⠀⢸⣿⣿
460-
⠀⢰⣿⣿⣤⣤⣼⣿⣷⠀⠀⢸⣿⣿⠀⠀⠀⣿⣿⠀⠀⠀⣿⣿⠀⠀⢀⣴⣶⣶⣶⣿⣿⠀⠀⠀⣠⣾⡿⠋⠀⠀⢸⣿⣿⠀⠀⠀⣿⣿⡇⠀⢸⣿⡇⠀⠀⢸⣿⣿⠀⠀⠀⠀⠀⠀⢹⣿⣇⠀⠀⠀⠀⠀⢸⣿⡿
461-
⢀⣿⣿⠋⠉⠉⠉⢻⣿⣇⠀⢸⣿⣿⠀⠀⠀⣿⣿⠀⠀⠀⣿⣿⠀⠀⣿⣿⡀⠀⣠⣿⣿⠀⢀⣴⣿⣋⣀⣀⣀⡀⠘⣿⣿⣄⣀⣠⣿⣿⠃⠀⢸⣿⡇⠀⠀⢸⣿⣿⠀⠀⠀⠀⠀⠀⠈⢿⣿⣦⣀⣀⣀⣴⣿⡿⠃
462-
⠚⠛⠋⠀⠀⠀⠀⠘⠛⠛⠀⠘⠛⠛⠀⠀⠀⠛⠛⠀⠀⠀⠛⠛⠀⠀⠙⠻⠿⠟⠋⠛⠛⠀⠘⠛⠛⠛⠛⠛⠛⠃⠀⠈⠛⠿⠿⠿⠛⠁⠀⠀⠘⠛⠃⠀⠀⠘⠛⠛⠀⠀⠀⠀⠀⠀⠀⠀⠙⠛⠿⢿⣿⣿⣋⠀⠀
463-
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠛⠿⢿⡧</cyan!>"};
464439

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>"};
467440

468441
// Maximum number of times to show the changelog announcement per version
469442
const CHANGELOG_MAX_SHOW_COUNT: i64 = 2;
470443

471444
// 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-
];
445+
const ROTATING_TIPS: [&str; 20] = tips::ROTATING_TIPS;
509446

510447
const GREETING_BREAK_POINT: usize = 80;
511448

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!>"};
449+
517450

518451
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"};
452+
fn trust_all_text() -> String {
453+
ui_text::trust_all_warning()
454+
}
522455

523456
const TOOL_BULLET: &str = " ● ";
524457
const CONTINUATION_LINE: &str = " ⋮ ";
@@ -977,12 +910,13 @@ impl ChatSession {
977910
self.stderr,
978911
style::SetAttribute(Attribute::Bold),
979912
style::SetForegroundColor(Color::Red),
980-
style::Print(" ⚠️ Amazon Q rate limit reached:\n"),
913+
style::Print(error_messages::RATE_LIMIT_PREFIX),
914+
style::Print("\n"),
981915
style::Print(format!(" {}\n\n", err.clone())),
982916
style::SetAttribute(Attribute::Reset),
983917
style::SetForegroundColor(Color::Reset),
984918
)?;
985-
("Amazon Q is having trouble responding right now", eyre!(err), false)
919+
(error_messages::TROUBLE_RESPONDING, eyre!(err), false)
986920
},
987921
ApiClientError::ModelOverloadedError { request_id, .. } => {
988922
if self.interactive {
@@ -1022,12 +956,12 @@ impl ChatSession {
1022956
self.stderr,
1023957
style::SetAttribute(Attribute::Bold),
1024958
style::SetForegroundColor(Color::Red),
1025-
style::Print("Amazon Q is having trouble responding right now:\n"),
959+
style::Print(format!("{}:\n", error_messages::TROUBLE_RESPONDING)),
1026960
style::Print(format!(" {}\n", err.clone())),
1027961
style::SetAttribute(Attribute::Reset),
1028962
style::SetForegroundColor(Color::Reset),
1029963
)?;
1030-
("Amazon Q is having trouble responding right now", eyre!(err), false)
964+
(error_messages::TROUBLE_RESPONDING, eyre!(err), false)
1031965
},
1032966
ApiClientError::MonthlyLimitReached { .. } => {
1033967
let subscription_status = get_subscription_status(os).await;
@@ -1085,13 +1019,13 @@ impl ChatSession {
10851019
return Ok(());
10861020
},
10871021
_ => (
1088-
"Amazon Q is having trouble responding right now",
1022+
error_messages::TROUBLE_RESPONDING,
10891023
Report::from(err),
10901024
true,
10911025
),
10921026
},
10931027
_ => (
1094-
"Amazon Q is having trouble responding right now",
1028+
error_messages::TROUBLE_RESPONDING,
10951029
Report::from(err),
10961030
true,
10971031
),
@@ -1270,7 +1204,7 @@ impl ChatSession {
12701204
let welcome_text = match self.existing_conversation {
12711205
true => RESUME_TEXT,
12721206
false => match is_small_screen {
1273-
true => SMALL_SCREEN_WELCOME_TEXT,
1207+
true => SMALL_SCREEN_WELCOME,
12741208
false => WELCOME_TEXT,
12751209
},
12761210
};
@@ -1320,7 +1254,7 @@ impl ChatSession {
13201254
queue!(
13211255
self.stderr,
13221256
style::Print(format!(
1323-
"{}{TRUST_ALL_TEXT}\n\n",
1257+
"{}{}\n\n", trust_all_text(),
13241258
if !is_small_screen { "\n" } else { "" }
13251259
))
13261260
)?;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ use crate::util::spinner::{
4747
SpinnerComponent,
4848
};
4949
use crate::util::system_info::is_remote;
50+
use crate::constants::PRODUCT_NAME;
5051
use crate::util::{
5152
CLI_BINARY_NAME,
52-
PRODUCT_NAME,
5353
choose,
5454
input,
5555
};

0 commit comments

Comments
 (0)