Skip to content

Commit a85b37f

Browse files
authored
feat: add env command (#1829)
1 parent ec6f2d4 commit a85b37f

File tree

5 files changed

+46
-11
lines changed

5 files changed

+46
-11
lines changed

crates/forge_main/src/cli.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ pub enum TopLevelCommand {
102102
porcelain: bool,
103103
},
104104

105+
/// Display environment information
106+
///
107+
/// Example: forge env
108+
Env,
109+
105110
/// Configuration management commands
106111
Config(ConfigCommandGroup),
107112

crates/forge_main/src/info.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,13 @@ impl From<&Environment> for Info {
7575
None => "(not in a git repository)".to_string(),
7676
};
7777

78-
let mut info = Info::new().add_title("PATHS");
78+
let mut info = Info::new()
79+
.add_title("ENVIRONMENT")
80+
.add_key_value("Version", VERSION)
81+
.add_key_value("Working Directory", format_path_for_display(env, &env.cwd))
82+
.add_key_value("Shell", &env.shell)
83+
.add_key_value("Git Branch", branch_info)
84+
.add_title("PATHS");
7985

8086
// Only show logs path if the directory exists
8187
let log_path = env.log_path();
@@ -84,9 +90,8 @@ impl From<&Environment> for Info {
8490
}
8591

8692
let agent_path = env.agent_path();
87-
info = info.add_key_value("Agents", format_path_for_display(env, &agent_path));
88-
8993
info = info
94+
.add_key_value("Agents", format_path_for_display(env, &agent_path))
9095
.add_key_value("History", format_path_for_display(env, &env.history_path()))
9196
.add_key_value(
9297
"Checkpoints",
@@ -95,12 +100,7 @@ impl From<&Environment> for Info {
95100
.add_key_value(
96101
"Policies",
97102
format_path_for_display(env, &env.permissions_path()),
98-
)
99-
.add_title("ENVIRONMENT")
100-
.add_key_value("Version", VERSION)
101-
.add_key_value("Working Directory", format_path_for_display(env, &env.cwd))
102-
.add_key_value("Shell", &env.shell)
103-
.add_key_value("Git Branch", branch_info);
103+
);
104104

105105
info
106106
}
@@ -215,7 +215,7 @@ impl fmt::Display for Info {
215215
}
216216
} else {
217217
// Show value-only items
218-
writeln!(f, " ⦿ {}", value)?;
218+
writeln!(f, " {} {}", "⦿".cyan(), value)?;
219219
}
220220
}
221221
}

crates/forge_main/src/model.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ impl ForgeCommandManager {
329329
"/compact" => Ok(SlashCommand::Compact),
330330
"/new" => Ok(SlashCommand::New),
331331
"/info" => Ok(SlashCommand::Info),
332+
"/env" => Ok(SlashCommand::Env),
332333
"/usage" => Ok(SlashCommand::Usage),
333334
"/exit" => Ok(SlashCommand::Exit),
334335
"/update" => Ok(SlashCommand::Update),
@@ -417,6 +418,9 @@ pub enum SlashCommand {
417418
/// Display usage information (tokens & requests).
418419
#[strum(props(usage = "Shows usage information (tokens & requests)"))]
419420
Usage,
421+
/// Display environment information.
422+
#[strum(props(usage = "Display environment information"))]
423+
Env,
420424
/// Exit the application without any further action.
421425
#[strum(props(usage = "Exit the application"))]
422426
Exit,
@@ -495,6 +499,7 @@ impl SlashCommand {
495499
SlashCommand::Message(_) => "message",
496500
SlashCommand::Update => "update",
497501
SlashCommand::Info => "info",
502+
SlashCommand::Env => "env",
498503
SlashCommand::Usage => "usage",
499504
SlashCommand::Exit => "exit",
500505
SlashCommand::Forge => "forge",

crates/forge_main/src/ui.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,10 @@ impl<A: API + 'static, F: Fn() -> A> UI<A, F> {
400400
self.on_info(porcelain, conversation_id).await?;
401401
return Ok(());
402402
}
403+
TopLevelCommand::Env => {
404+
self.on_env().await?;
405+
return Ok(());
406+
}
403407
TopLevelCommand::Banner => {
404408
banner::display(true)?;
405409
return Ok(());
@@ -663,6 +667,7 @@ impl<A: API + 'static, F: Fn() -> A> UI<A, F> {
663667
// Define base commands with their descriptions
664668
info = info
665669
.add_key_value("info", "Print session information")
670+
.add_key_value("env", "Display environment information")
666671
.add_key_value("provider", "Switch the providers")
667672
.add_key_value("model", "Switch the models")
668673
.add_key_value("new", "Start new conversation")
@@ -793,7 +798,7 @@ impl<A: API + 'static, F: Fn() -> A> UI<A, F> {
793798
porcelain: bool,
794799
conversation_id: Option<ConversationId>,
795800
) -> anyhow::Result<()> {
796-
let mut info = Info::from(&self.api.environment());
801+
let mut info = Info::new();
797802

798803
// Fetch conversation
799804
let conversation = match conversation_id {
@@ -876,6 +881,13 @@ impl<A: API + 'static, F: Fn() -> A> UI<A, F> {
876881
Ok(())
877882
}
878883

884+
async fn on_env(&mut self) -> anyhow::Result<()> {
885+
let env = self.api.environment();
886+
let info = Info::from(&env);
887+
self.writeln(info)?;
888+
Ok(())
889+
}
890+
879891
async fn on_zsh_prompt(&self) -> anyhow::Result<()> {
880892
println!("{}", include_str!("../../../shell-plugin/forge.plugin.zsh"));
881893
Ok(())
@@ -981,6 +993,9 @@ impl<A: API + 'static, F: Fn() -> A> UI<A, F> {
981993
SlashCommand::Info => {
982994
self.on_info(false, None).await?;
983995
}
996+
SlashCommand::Env => {
997+
self.on_env().await?;
998+
}
984999
SlashCommand::Usage => {
9851000
self.on_usage().await?;
9861001
}

shell-plugin/forge.plugin.zsh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,13 @@ function _forge_action_info() {
237237
_forge_reset
238238
}
239239

240+
# Action handler: Show environment info
241+
function _forge_action_env() {
242+
echo
243+
_forge_exec env
244+
_forge_reset
245+
}
246+
240247
# Action handler: Dump conversation
241248
function _forge_action_dump() {
242249
local input_text="$1"
@@ -428,6 +435,9 @@ function forge-accept-line() {
428435
info|i)
429436
_forge_action_info
430437
;;
438+
env|e)
439+
_forge_action_env
440+
;;
431441
dump)
432442
_forge_action_dump "$input_text"
433443
;;

0 commit comments

Comments
 (0)