Skip to content

Commit

Permalink
fixup replace tool
Browse files Browse the repository at this point in the history
  • Loading branch information
dlants committed Dec 18, 2024
1 parent 786024c commit 6ab17f1
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
5 changes: 4 additions & 1 deletion rplugin/node/magenta/src/tools/diff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ export async function displayDiffs(
edits: Edit[],
dispatch: Dispatch<Msg>,
) {
const { nvim } = context;
const { nvim, logger } = context;
logger.trace(
`Attempting to displayDiff for edits ${JSON.stringify(edits, null, 2)}`,
);

// first, check to see if any windows *other than* the magenta plugin windows are open, and close them.
const windows = await nvim.windows;
Expand Down
2 changes: 2 additions & 0 deletions rplugin/node/magenta/src/tools/insert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Dispatch, Update } from "../tea/tea.ts";
import { d, VDOMNode, withBindings } from "../tea/view.ts";
import { ToolRequestId } from "./toolManager.ts";
import { displayDiffs } from "./diff.ts";
import { context } from "../context.ts";

export type Model = {
type: "insert";
Expand Down Expand Up @@ -97,6 +98,7 @@ export function insertThunk(model: Model) {
}),
);
} catch (error) {
context.logger.error(error as Error);
dispatch({
type: "finish",
result: {
Expand Down
16 changes: 11 additions & 5 deletions rplugin/node/magenta/src/tools/replace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Dispatch, Update } from "../tea/tea.ts";
import { d, VDOMNode, withBindings } from "../tea/view.ts";
import { ToolRequestId } from "./toolManager.ts";
import { displayDiffs } from "./diff.ts";
import { context } from "../context.ts";

export type Model = {
type: "replace";
Expand Down Expand Up @@ -98,6 +99,7 @@ export function insertThunk(model: Model) {
}),
);
} catch (error) {
context.logger.error(error as Error);
dispatch({
type: "finish",
result: {
Expand Down Expand Up @@ -142,7 +144,11 @@ function toolStatusView({
case "editing-diff":
return d`Editing diff`;
case "done":
return d`Done`;
if (model.state.result.is_error) {
return d`Error: ${JSON.stringify(model.state.result.content, null, 2)}`;
} else {
return d`Done`;
}
}
}

Expand All @@ -168,7 +174,7 @@ export function getToolResult(model: Model): ToolResultBlockParam {
}

export const spec: Anthropic.Anthropic.Tool = {
name: "insert",
name: "replace",
description: "Replace text between two strings in a file.",
input_schema: {
type: "object",
Expand All @@ -180,16 +186,16 @@ export const spec: Anthropic.Anthropic.Tool = {
start: {
type: "string",
description:
"We will replace text starting with this string. This string is included in the text that is replaced. Please provide a minimal string that uniquely identifies a location in the file.",
"Replace content starting with this text. This text is included in what will be replaced. Please provide just enough text to uniquely identify a location in the file.",
},
end: {
type: "string",
description:
"We will replace text until we encounter this string. This string is included in the text that is replaced. Please provide a minimal string that uniquely identifies a location in the file.",
"Replace content until we encounter this text. This text is included in what will be replaced. Please provide just enough text to uniquely identify a location in the file.",
},
content: {
type: "string",
description: "Content to insert",
description: "New content that will replace the existing text.",
},
},
required: ["filePath", "start", "end", "content"],
Expand Down
2 changes: 1 addition & 1 deletion rplugin/node/magenta/src/tools/toolManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export function renderTool(model: ToolModel, dispatch: Dispatch<Msg>) {
dispatch({
type: "tool-msg",
id: model.request.id,
msg: { type: "insert", msg },
msg: { type: "replace", msg },
}),
});

Expand Down

0 comments on commit 6ab17f1

Please sign in to comment.