Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions crates/forge_main/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ pub struct Cli {
#[arg(long)]
pub provider: Option<ProviderId>,

/// Additional context to include with the prompt.
///
/// This allows passing contextual information (e.g., the last shell command
/// executed) to help the agent understand the user's intent. This is
/// particularly useful when using the ZSH plugin's `:` command after
/// running shell commands.
#[arg(long)]
pub context: Option<String>,

/// Top-level subcommands.
#[command(subcommand)]
pub subcommands: Option<TopLevelCommand>,
Expand Down
6 changes: 6 additions & 0 deletions crates/forge_main/src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2955,6 +2955,12 @@ impl<A: API + ConsoleWriter + 'static, F: Fn() -> A + Send + Sync> UI<A, F> {
event = event.additional_context(piped);
}

// Add CLI --context as additional context if provided
// This allows the ZSH plugin to pass the last shell command as context
if let Some(ctx) = &self.cli.context {
event = event.additional_context(ctx.clone());
}

// Create the chat request with the event
let chat = ChatRequest::new(event, conversation_id);

Expand Down
12 changes: 10 additions & 2 deletions shell-plugin/lib/dispatcher.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,16 @@ function _forge_action_default() {
_FORGE_ACTIVE_AGENT="$user_action"
fi

# Execute the forge command directly with proper escaping
_forge_exec_interactive -p "$input_text" --cid "$_FORGE_CONVERSATION_ID"
# Capture last command from history for context
# This allows forge to understand what the user was doing before asking for help
local last_cmd=$(fc -ln -1 2>/dev/null || echo "")

# Execute the forge command with last command context
if [[ -n "$last_cmd" ]]; then
_forge_exec_interactive -p "$input_text" --cid "$_FORGE_CONVERSATION_ID" --context "Last command: $last_cmd"
else
_forge_exec_interactive -p "$input_text" --cid "$_FORGE_CONVERSATION_ID"
fi

# Start background sync job if enabled and not already running
_forge_start_background_sync
Expand Down
Loading