Skip to content

Commit d62cf68

Browse files
Experiment manager enhancements (#3062)
* chore: Experiment Manager enhancements, centralizes commands configuration for experiments * fix: Fixes import --------- Co-authored-by: Kenneth S. <[email protected]>
1 parent 93094cd commit d62cf68

File tree

2 files changed

+48
-53
lines changed

2 files changed

+48
-53
lines changed

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

Lines changed: 3 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,7 @@ use super::tool_manager::{
4646
PromptQuery,
4747
PromptQueryResult,
4848
};
49-
use crate::cli::experiment::experiment_manager::{
50-
ExperimentManager,
51-
ExperimentName,
52-
};
49+
use crate::cli::experiment::experiment_manager::ExperimentManager;
5350
use crate::database::settings::Setting;
5451
use crate::os::Os;
5552
use crate::util::directories::chat_cli_bash_history_path;
@@ -106,55 +103,7 @@ pub const COMMANDS: &[&str] = &[
106103
/// Generate dynamic command list including experiment-based commands when enabled
107104
pub fn get_available_commands(os: &Os) -> Vec<&'static str> {
108105
let mut commands = COMMANDS.to_vec();
109-
110-
// Add knowledge commands if Knowledge experiment is enabled
111-
if ExperimentManager::is_enabled(os, ExperimentName::Knowledge) {
112-
commands.extend_from_slice(&[
113-
"/knowledge",
114-
"/knowledge help",
115-
"/knowledge show",
116-
"/knowledge add",
117-
"/knowledge remove",
118-
"/knowledge clear",
119-
"/knowledge search",
120-
"/knowledge update",
121-
"/knowledge status",
122-
"/knowledge cancel",
123-
]);
124-
}
125-
126-
// Add checkpoint commands if Checkpoint experiment is enabled
127-
if ExperimentManager::is_enabled(os, ExperimentName::Checkpoint) {
128-
commands.extend_from_slice(&[
129-
"/checkpoint",
130-
"/checkpoint help",
131-
"/checkpoint init",
132-
"/checkpoint list",
133-
"/checkpoint restore",
134-
"/checkpoint expand",
135-
"/checkpoint diff",
136-
"/checkpoint clean",
137-
]);
138-
}
139-
140-
// Add todos commands if TodoList experiment is enabled
141-
if ExperimentManager::is_enabled(os, ExperimentName::TodoList) {
142-
commands.extend_from_slice(&[
143-
"/todos",
144-
"/todos help",
145-
"/todos clear-finished",
146-
"/todos resume",
147-
"/todos view",
148-
"/todos delete",
149-
"/todos delete --all",
150-
]);
151-
}
152-
153-
// Add tangent commands if TangentMode experiment is enabled
154-
if ExperimentManager::is_enabled(os, ExperimentName::TangentMode) {
155-
commands.extend_from_slice(&["/tangent", "/tangent tail"]);
156-
}
157-
106+
commands.extend(ExperimentManager::get_commands(os));
158107
commands.sort();
159108
commands
160109
}
@@ -590,6 +539,7 @@ mod tests {
590539
use rustyline::history::DefaultHistory;
591540

592541
use super::*;
542+
use crate::cli::experiment::experiment_manager::ExperimentName;
593543

594544
#[tokio::test]
595545
async fn test_chat_completer_command_completion() {

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

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ pub struct Experiment {
3434
pub description: &'static str,
3535
pub setting_key: Setting,
3636
pub enabled: bool,
37+
pub commands: &'static [&'static str],
3738
}
3839

3940
static AVAILABLE_EXPERIMENTS: &[Experiment] = &[
@@ -42,36 +43,70 @@ static AVAILABLE_EXPERIMENTS: &[Experiment] = &[
4243
description: "Enables persistent context storage and retrieval across chat sessions (/knowledge)",
4344
setting_key: Setting::EnabledKnowledge,
4445
enabled: true,
46+
commands: &[
47+
"/knowledge",
48+
"/knowledge help",
49+
"/knowledge show",
50+
"/knowledge add",
51+
"/knowledge remove",
52+
"/knowledge clear",
53+
"/knowledge search",
54+
"/knowledge update",
55+
"/knowledge status",
56+
"/knowledge cancel",
57+
],
4558
},
4659
Experiment {
4760
experiment_name: ExperimentName::Thinking,
4861
description: "Enables complex reasoning with step-by-step thought processes",
4962
setting_key: Setting::EnabledThinking,
5063
enabled: true,
64+
commands: &[],
5165
},
5266
Experiment {
5367
experiment_name: ExperimentName::TangentMode,
5468
description: "Enables entering into a temporary mode for sending isolated conversations (/tangent)",
5569
setting_key: Setting::EnabledTangentMode,
5670
enabled: true,
71+
commands: &["/tangent", "/tangent tail"],
5772
},
5873
Experiment {
5974
experiment_name: ExperimentName::TodoList,
6075
description: "Enables Q to create todo lists that can be viewed and managed using /todos",
6176
setting_key: Setting::EnabledTodoList,
6277
enabled: true,
78+
commands: &[
79+
"/todos",
80+
"/todos help",
81+
"/todos clear-finished",
82+
"/todos resume",
83+
"/todos view",
84+
"/todos delete",
85+
"/todos delete --all",
86+
],
6387
},
6488
Experiment {
6589
experiment_name: ExperimentName::Checkpoint,
6690
description: "Enables workspace checkpoints to snapshot, list, expand, diff, and restore files (/checkpoint)\nNote: Cannot be used in tangent mode (to avoid mixing up conversation history)",
6791
setting_key: Setting::EnabledCheckpoint,
6892
enabled: true,
93+
commands: &[
94+
"/checkpoint",
95+
"/checkpoint help",
96+
"/checkpoint init",
97+
"/checkpoint list",
98+
"/checkpoint restore",
99+
"/checkpoint expand",
100+
"/checkpoint diff",
101+
"/checkpoint clean",
102+
],
69103
},
70104
Experiment {
71105
experiment_name: ExperimentName::ContextUsageIndicator,
72106
description: "Shows context usage percentage in the prompt (e.g., [rust-agent] 6% >)",
73107
setting_key: Setting::EnabledContextUsageIndicator,
74108
enabled: true,
109+
commands: &[],
75110
},
76111
];
77112

@@ -123,4 +158,14 @@ impl ExperimentManager {
123158
pub fn get_experiments() -> Vec<&'static Experiment> {
124159
AVAILABLE_EXPERIMENTS.iter().filter(|exp| exp.enabled).collect()
125160
}
161+
162+
/// Returns all commands from enabled experiments
163+
pub fn get_commands(os: &Os) -> Vec<&'static str> {
164+
AVAILABLE_EXPERIMENTS
165+
.iter()
166+
.filter(|exp| exp.enabled && Self::is_enabled(os, exp.experiment_name))
167+
.flat_map(|exp| exp.commands.iter())
168+
.copied()
169+
.collect()
170+
}
126171
}

0 commit comments

Comments
 (0)