mirror of
https://github.com/aljazceru/goose.git
synced 2025-12-19 07:04:21 +01:00
Add the ability to configure rustyline to use a different edit mode (e.g. vi) (#2769)
Co-authored-by: Jack Wright <jack.wright@nike.com> Co-authored-by: Michael Neale <michael.neale@gmail.com>
This commit is contained in:
@@ -7,6 +7,7 @@ use goose::recipe::{Response, SubRecipe};
|
||||
use goose::session;
|
||||
use goose::session::Identifier;
|
||||
use mcp_client::transport::Error as McpClientError;
|
||||
use rustyline::EditMode;
|
||||
use std::process;
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -136,6 +137,7 @@ async fn offer_extension_debugging_help(
|
||||
false,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
);
|
||||
|
||||
// Process the debugging request
|
||||
@@ -383,6 +385,19 @@ pub async fn build_session(session_config: SessionBuilderConfig) -> Session {
|
||||
}
|
||||
}
|
||||
|
||||
// Determine editor mode
|
||||
let edit_mode = config
|
||||
.get_param::<String>("EDIT_MODE")
|
||||
.ok()
|
||||
.and_then(|edit_mode| match edit_mode.to_lowercase().as_str() {
|
||||
"emacs" => Some(EditMode::Emacs),
|
||||
"vi" => Some(EditMode::Vi),
|
||||
_ => {
|
||||
eprintln!("Invalid EDIT_MODE specified, defaulting to Emacs");
|
||||
None
|
||||
}
|
||||
});
|
||||
|
||||
// Create new session
|
||||
let mut session = Session::new(
|
||||
agent,
|
||||
@@ -390,6 +405,7 @@ pub async fn build_session(session_config: SessionBuilderConfig) -> Session {
|
||||
session_config.debug,
|
||||
session_config.scheduled_job_id.clone(),
|
||||
session_config.max_turns,
|
||||
edit_mode,
|
||||
);
|
||||
|
||||
// Add extensions if provided
|
||||
|
||||
@@ -32,6 +32,7 @@ use mcp_core::protocol::JsonRpcMessage;
|
||||
use mcp_core::protocol::JsonRpcNotification;
|
||||
|
||||
use rand::{distributions::Alphanumeric, Rng};
|
||||
use rustyline::EditMode;
|
||||
use serde_json::Value;
|
||||
use std::collections::HashMap;
|
||||
use std::path::PathBuf;
|
||||
@@ -54,6 +55,7 @@ pub struct Session {
|
||||
run_mode: RunMode,
|
||||
scheduled_job_id: Option<String>, // ID of the scheduled job that triggered this session
|
||||
max_turns: Option<u32>,
|
||||
edit_mode: Option<EditMode>,
|
||||
}
|
||||
|
||||
// Cache structure for completion data
|
||||
@@ -116,6 +118,7 @@ impl Session {
|
||||
debug: bool,
|
||||
scheduled_job_id: Option<String>,
|
||||
max_turns: Option<u32>,
|
||||
edit_mode: Option<EditMode>,
|
||||
) -> Self {
|
||||
let messages = if let Some(session_file) = &session_file {
|
||||
match session::read_messages(session_file) {
|
||||
@@ -139,6 +142,7 @@ impl Session {
|
||||
run_mode: RunMode::Normal,
|
||||
scheduled_job_id,
|
||||
max_turns,
|
||||
edit_mode,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -399,9 +403,15 @@ impl Session {
|
||||
self.update_completion_cache().await?;
|
||||
|
||||
// Create a new editor with our custom completer
|
||||
let config = rustyline::Config::builder()
|
||||
.completion_type(rustyline::CompletionType::Circular)
|
||||
.build();
|
||||
let builder =
|
||||
rustyline::Config::builder().completion_type(rustyline::CompletionType::Circular);
|
||||
let builder = if let Some(edit_mode) = self.edit_mode {
|
||||
builder.edit_mode(edit_mode)
|
||||
} else {
|
||||
// Default to Emacs mode if no edit mode is set
|
||||
builder.edit_mode(EditMode::Emacs)
|
||||
};
|
||||
let config = builder.build();
|
||||
let mut editor =
|
||||
rustyline::Editor::<GooseCompleter, rustyline::history::DefaultHistory>::with_config(
|
||||
config,
|
||||
|
||||
Reference in New Issue
Block a user