Skip to content

Commit 3601482

Browse files
committed
allow both tangent & checkpoint enabled
1 parent e479178 commit 3601482

File tree

4 files changed

+79
-100
lines changed

4 files changed

+79
-100
lines changed

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

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -83,38 +83,33 @@ With --hard:
8383

8484
impl CheckpointSubcommand {
8585
pub async fn execute(self, os: &Os, session: &mut ChatSession) -> Result<ChatState, ChatError> {
86-
// Check if in tangent mode - captures are disabled during tangent mode
87-
if os
86+
// Check if checkpoint is enabled
87+
if !os
8888
.database
8989
.settings
90-
.get_bool(Setting::EnabledTangentMode)
90+
.get_bool(Setting::EnabledCheckpoint)
9191
.unwrap_or(false)
9292
{
9393
execute!(
9494
session.stderr,
95-
style::SetForegroundColor(Color::Yellow),
96-
style::Print(
97-
"⚠️ Checkpoint is disabled while in tangent mode. Disable tangent mode with: q settings -d chat.enableTangentMode.\n\n"
98-
),
99-
style::SetForegroundColor(Color::Reset),
95+
style::SetForegroundColor(Color::Red),
96+
style::Print("\nCheckpoint is disabled. Enable it with: q settings chat.enableCheckpoint true\n"),
97+
style::SetForegroundColor(Color::Reset)
10098
)?;
10199
return Ok(ChatState::PromptUser {
102100
skip_printing_tools: true,
103101
});
104102
}
105103

106-
// Check if checkpoint is enabled
107-
if !os
108-
.database
109-
.settings
110-
.get_bool(Setting::EnabledCheckpoint)
111-
.unwrap_or(false)
112-
{
104+
// Check if in tangent mode - captures are disabled during tangent mode
105+
if session.conversation.is_in_tangent_mode() {
113106
execute!(
114107
session.stderr,
115-
style::SetForegroundColor(Color::Red),
116-
style::Print("\nCheckpoint is disabled. Enable it with: q settings chat.enableCheckpoint true\n"),
117-
style::SetForegroundColor(Color::Reset)
108+
style::SetForegroundColor(Color::Yellow),
109+
style::Print(
110+
"⚠️ Checkpoint is disabled while in tangent mode. Disable tangent mode with: q settings -d chat.enableTangentMode.\n\n"
111+
),
112+
style::SetForegroundColor(Color::Reset),
118113
)?;
119114
return Ok(ChatState::PromptUser {
120115
skip_printing_tools: true,

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@ static AVAILABLE_EXPERIMENTS: &[Experiment] = &[
5252
},
5353
Experiment {
5454
name: "Checkpoint",
55-
description: "Enables workspace checkpoints to snapshot, list, expand, diff, and restore files (/checkpoint)",
55+
description: concat!(
56+
"Enables workspace checkpoints to snapshot, list, expand, diff, and restore files (/checkpoint)\n",
57+
" ",
58+
"Cannot be used in tangent mode (to avoid mixing up conversation history)"
59+
),
5660
setting_key: Setting::EnabledCheckpoint,
5761
},
5862
];

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

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -63,28 +63,24 @@ impl TangentArgs {
6363
});
6464
}
6565

66-
// Check if checkpoint is enabled
67-
if os
68-
.database
69-
.settings
70-
.get_bool(Setting::EnabledCheckpoint)
71-
.unwrap_or(false)
72-
{
73-
execute!(
74-
session.stderr,
75-
style::SetForegroundColor(Color::Yellow),
76-
style::Print(
77-
"⚠️ Tangent mode is disabled while using checkpoint. Disable checkpoint with: q settings -d chat.enableCheckpoint.\n"
78-
),
79-
style::SetForegroundColor(Color::Reset),
80-
)?;
81-
return Ok(ChatState::PromptUser {
82-
skip_printing_tools: true,
83-
});
84-
}
85-
8666
match self.subcommand {
8767
Some(TangentSubcommand::Tail) => {
68+
// Check if checkpoint is enabled
69+
if os
70+
.database
71+
.settings
72+
.get_bool(Setting::EnabledCheckpoint)
73+
.unwrap_or(false)
74+
{
75+
execute!(
76+
session.stderr,
77+
style::SetForegroundColor(Color::Yellow),
78+
style::Print(
79+
"⚠️ Checkpoint is disabled while in tangent mode. Please exit tangent mode if you want to use checkpoint.\n"
80+
),
81+
style::SetForegroundColor(Color::Reset),
82+
)?;
83+
}
8884
if session.conversation.is_in_tangent_mode() {
8985
let duration_seconds = session.conversation.get_tangent_duration_seconds().unwrap_or(0);
9086
session.conversation.exit_tangent_mode_with_tail();
@@ -126,6 +122,23 @@ impl TangentArgs {
126122
style::SetForegroundColor(Color::Reset)
127123
)?;
128124
} else {
125+
// Check if checkpoint is enabled
126+
if os
127+
.database
128+
.settings
129+
.get_bool(Setting::EnabledCheckpoint)
130+
.unwrap_or(false)
131+
{
132+
execute!(
133+
session.stderr,
134+
style::SetForegroundColor(Color::Yellow),
135+
style::Print(
136+
"⚠️ Checkpoint is disabled while in tangent mode. Please exit tangent mode if you want to use checkpoint.\n"
137+
),
138+
style::SetForegroundColor(Color::Reset),
139+
)?;
140+
}
141+
129142
session.conversation.enter_tangent_mode();
130143

131144
// Get the configured tangent mode key for display

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

Lines changed: 28 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ const RESUME_TEXT: &str = color_print::cstr! {"<em>Picking up where we left off.
462462
const CHANGELOG_MAX_SHOW_COUNT: i64 = 2;
463463

464464
// Only show the model-related tip for now to make users aware of this feature.
465-
const ROTATING_TIPS: [&str; 19] = [
465+
const ROTATING_TIPS: [&str; 20] = [
466466
color_print::cstr! {"You can resume the last conversation from your current directory by launching with
467467
<green!>q chat --resume</green!>"},
468468
color_print::cstr! {"Get notified whenever Q CLI finishes responding.
@@ -497,6 +497,7 @@ const ROTATING_TIPS: [&str; 19] = [
497497
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"},
498498
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!>"},
499499
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"},
500+
color_print::cstr! {"Enable workspace checkpoints to snapshot & restore changes. Just run <green!>q</green!> <green!>settings chat.enableCheckpoint true</green!>"},
500501
];
501502

502503
const GREETING_BREAK_POINT: usize = 80;
@@ -1336,46 +1337,29 @@ impl ChatSession {
13361337
.get_bool(Setting::EnabledCheckpoint)
13371338
.unwrap_or(false)
13381339
{
1339-
if os
1340-
.database
1341-
.settings
1342-
.get_bool(Setting::EnabledTangentMode)
1343-
.unwrap_or(false)
1344-
{
1345-
execute!(
1346-
self.stderr,
1347-
style::SetForegroundColor(Color::Yellow),
1348-
style::Print(
1349-
"⚠️ Checkpoint is disabled while in tangent mode. Disable tangent mode with: q settings -d chat.enableTangentMode.\n\n"
1350-
),
1351-
style::SetForegroundColor(Color::Reset),
1352-
)?;
1353-
} else {
1354-
let path = get_shadow_repo_dir(os, self.conversation.conversation_id().to_string())?;
1355-
let start = std::time::Instant::now();
1356-
let checkpoint_manager =
1357-
match CheckpointManager::auto_init(os, &path, self.conversation.history()).await {
1358-
Ok(manager) => {
1359-
execute!(
1360-
self.stderr,
1361-
style::Print(
1362-
format!(
1363-
"📷 Checkpoints are enabled! (took {:.2}s)\n\n",
1364-
start.elapsed().as_secs_f32()
1365-
)
1366-
.blue()
1367-
.bold()
1368-
)
1369-
)?;
1370-
Some(manager)
1371-
},
1372-
Err(e) => {
1373-
execute!(self.stderr, style::Print(format!("{e}\n\n").blue()))?;
1374-
None
1375-
},
1376-
};
1377-
self.conversation.checkpoint_manager = checkpoint_manager;
1378-
}
1340+
let path = get_shadow_repo_dir(os, self.conversation.conversation_id().to_string())?;
1341+
let start = std::time::Instant::now();
1342+
let checkpoint_manager = match CheckpointManager::auto_init(os, &path, self.conversation.history()).await {
1343+
Ok(manager) => {
1344+
execute!(
1345+
self.stderr,
1346+
style::Print(
1347+
format!(
1348+
"📷 Checkpoints are enabled! (took {:.2}s)\n\n",
1349+
start.elapsed().as_secs_f32()
1350+
)
1351+
.blue()
1352+
.bold()
1353+
)
1354+
)?;
1355+
Some(manager)
1356+
},
1357+
Err(e) => {
1358+
execute!(self.stderr, style::Print(format!("{e}\n\n").blue()))?;
1359+
None
1360+
},
1361+
};
1362+
self.conversation.checkpoint_manager = checkpoint_manager;
13791363
}
13801364

13811365
if let Some(user_input) = self.initial_input.take() {
@@ -2146,11 +2130,7 @@ impl ChatSession {
21462130
.settings
21472131
.get_bool(Setting::EnabledCheckpoint)
21482132
.unwrap_or(false)
2149-
&& !os
2150-
.database
2151-
.settings
2152-
.get_bool(Setting::EnabledTangentMode)
2153-
.unwrap_or(false)
2133+
&& !self.conversation.is_in_tangent_mode()
21542134
{
21552135
if let Some(manager) = self.conversation.checkpoint_manager.as_mut() {
21562136
if !manager.message_locked && self.pending_tool_index.is_none() {
@@ -2250,11 +2230,6 @@ impl ChatSession {
22502230
.settings
22512231
.get_bool(Setting::IntrospectTangentMode)
22522232
.unwrap_or(false)
2253-
&& !os
2254-
.database
2255-
.settings
2256-
.get_bool(Setting::EnabledCheckpoint)
2257-
.unwrap_or(false)
22582233
&& !self.conversation.is_in_tangent_mode()
22592234
&& self
22602235
.tool_uses
@@ -2394,11 +2369,7 @@ impl ChatSession {
23942369
.settings
23952370
.get_bool(Setting::EnabledCheckpoint)
23962371
.unwrap_or(false)
2397-
&& !os
2398-
.database
2399-
.settings
2400-
.get_bool(Setting::EnabledTangentMode)
2401-
.unwrap_or(false);
2372+
&& !self.conversation.is_in_tangent_mode();
24022373
if invoke_result.is_err() || !enabled {
24032374
None
24042375
}
@@ -2923,11 +2894,7 @@ impl ChatSession {
29232894
.settings
29242895
.get_bool(Setting::EnabledCheckpoint)
29252896
.unwrap_or(false)
2926-
&& !os
2927-
.database
2928-
.settings
2929-
.get_bool(Setting::EnabledTangentMode)
2930-
.unwrap_or(false)
2897+
&& !self.conversation.is_in_tangent_mode()
29312898
{
29322899
if let Some(mut manager) = self.conversation.checkpoint_manager.take() {
29332900
if manager.tools_in_turn > 0 {

0 commit comments

Comments
 (0)