Skip to content
Closed
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export GOOSE_EDITOR_MODEL="claude-3-5-sonnet-20241022"
```bash
export GOOSE_EDITOR_API_KEY="sk-..."
export GOOSE_EDITOR_HOST="https://api.morphllm.com/v1"
export GOOSE_EDITOR_MODEL="morph-v0"
export GOOSE_EDITOR_MODEL="morph-v3-large"
```

**Relace**
Expand Down
9 changes: 6 additions & 3 deletions crates/goose-mcp/src/developer/editor_models/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,23 @@ impl EditorModel {
original_code: &str,
old_str: &str,
update_snippet: &str,
instruction: &str,
) -> Result<String, String> {
match self {
EditorModel::MorphLLM(editor) => {
// Only MorphLLM uses the instruction parameter
editor
.edit_code(original_code, old_str, update_snippet)
.edit_code(original_code, old_str, update_snippet, instruction)
.await
}
EditorModel::OpenAICompatible(editor) => {
editor
.edit_code(original_code, old_str, update_snippet)
.edit_code(original_code, old_str, update_snippet, instruction)
.await
}
EditorModel::Relace(editor) => {
editor
.edit_code(original_code, old_str, update_snippet)
.edit_code(original_code, old_str, update_snippet, instruction)
.await
}
}
Expand All @@ -61,6 +63,7 @@ pub trait EditorModelImpl {
original_code: &str,
old_str: &str,
update_snippet: &str,
instruction: &str,
) -> Result<String, String>;

/// Get the description for the str_replace command when this editor is active
Expand Down
20 changes: 16 additions & 4 deletions crates/goose-mcp/src/developer/editor_models/morphllm_editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ impl EditorModelImpl for MorphLLMEditor {
original_code: &str,
_old_str: &str,
update_snippet: &str,
instruction: &str,
) -> Result<String, String> {
eprintln!("Calling MorphLLM Editor API");

Expand All @@ -42,10 +43,10 @@ impl EditorModelImpl for MorphLLMEditor {
// Create the client
let client = Client::new();

// Format the prompt as specified in the Python example
// Format the prompt according to MorphLLM's new format with instruction
let user_prompt = format!(
"<code>{}</code>\n<update>{}</update>",
original_code, update_snippet
"<instruction>{}</instruction>\n<code>{}</code>\n<update>{}</update>",
instruction, original_code, update_snippet
);

// Prepare the request body for OpenAI-compatible API
Expand Down Expand Up @@ -98,6 +99,7 @@ impl EditorModelImpl for MorphLLMEditor {

fn get_str_replace_description(&self) -> &'static str {
"Use the edit_file to propose an edit to an existing file.

This will be read by a less intelligent model, which will quickly apply the edit. You should make it clear what the edit is, while also minimizing the unchanged code you write.
When writing the edit, you should specify each edit in sequence, with the special comment // ... existing code ... to represent unchanged code in between edited lines.

Expand All @@ -113,7 +115,17 @@ impl EditorModelImpl for MorphLLMEditor {
You should bias towards repeating as few lines of the original file as possible to convey the change.
Each edit should contain sufficient context of unchanged lines around the code you're editing to resolve ambiguity.
If you plan on deleting a section, you must provide surrounding context to indicate the deletion.
DO NOT omit spans of pre-existing code without using the // ... existing code ... comment to indicate its absence.
DO NOT omit spans of pre-existing code without using the // ... existing code ... comment to indicate its absence.

**IMPORTANT**: You must also provide an `instruction` parameter - a single sentence written in the first person describing what you are going to do for the sketched edit. This instruction helps the less intelligent model understand and apply your edit correctly.

Examples of good instructions:
- \"I am adding error handling to the user authentication function and removing the old authentication method\"
- \"I am refactoring the database connection logic to use async/await\"
- \"I am fixing the bug in the validation logic by updating the regex pattern\"
- \"I am adding a new method to handle user preferences and updating the constructor\"

The instruction should be specific enough to disambiguate any uncertainty in your edit.
"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ impl EditorModelImpl for OpenAICompatibleEditor {
original_code: &str,
_old_str: &str,
update_snippet: &str,
_instruction: &str, // Not used by OpenAI compatible editor
) -> Result<String, String> {
eprintln!("Calling OpenAI-compatible Editor API");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ impl EditorModelImpl for RelaceEditor {
original_code: &str,
_old_str: &str,
update_snippet: &str,
_instruction: &str, // Not used by Relace editor
) -> Result<String, String> {
eprintln!("Calling Relace Editor API");

Expand Down
17 changes: 15 additions & 2 deletions crates/goose-mcp/src/developer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,10 @@ impl DeveloperRouter {
},
"old_str": {"type": "string"},
"new_str": {"type": "string"},
"instruction": {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hrm - I wonder if there is another way to do this, as it is a heavy change to always ask for this value (even if optional, isn't clear how we can make it clear) as it will trip up some LLMs... not sure of another way, need to somehow work out how we can switch this on and off only if needed?

if you look in the description for this tool it conditionally changes depending on if there is some editor (model) or not - can we do the same for this so it isn't there when not needed using tokens?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let me check

"type": "string",
"description": "A single sentence written in the first person describing what you are going to do for the sketched edit. Use it to disambiguate uncertainty in the edit."
},
"file_text": {"type": "string"}
}
}),
Expand Down Expand Up @@ -880,8 +884,13 @@ impl DeveloperRouter {
.ok_or_else(|| {
ToolError::InvalidParameters("Missing 'new_str' parameter".into())
})?;
let instruction = params
.get("instruction")
.and_then(|v| v.as_str())
.unwrap_or(""); // Empty string for backward compatibility

self.text_editor_replace(&path, old_str, new_str).await
self.text_editor_replace(&path, old_str, new_str, instruction)
.await
}
"insert" => {
let insert_line = params
Expand Down Expand Up @@ -1082,6 +1091,7 @@ impl DeveloperRouter {
path: &PathBuf,
old_str: &str,
new_str: &str,
instruction: &str,
) -> Result<Vec<Content>, ToolError> {
// Check if file exists and is active
if !path.exists() {
Expand All @@ -1100,7 +1110,10 @@ impl DeveloperRouter {
// Editor API path - save history then call API directly
self.save_file_history(path)?;

match editor.edit_code(&content, old_str, new_str).await {
match editor
.edit_code(&content, old_str, new_str, instruction)
.await
{
Ok(updated_content) => {
// Write the updated content directly
let normalized_content = normalize_line_endings(&updated_content);
Expand Down
2 changes: 1 addition & 1 deletion documentation/docs/guides/enhanced-code-editing.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export GOOSE_EDITOR_MODEL="claude-3-5-sonnet-20241022"
```bash
export GOOSE_EDITOR_API_KEY="sk-..."
export GOOSE_EDITOR_HOST="https://api.morphllm.com/v1"
export GOOSE_EDITOR_MODEL="morph-v0"
export GOOSE_EDITOR_MODEL="morph-v3-large"
```

**Relace:**
Expand Down
Loading