Skip to content

Commit

Permalink
various improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
dlants committed Dec 30, 2024
1 parent c03fdd5 commit fa7c5e8
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 32 deletions.
4 changes: 3 additions & 1 deletion bun/anthropic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,10 @@ class AnthropicClientImpl implements AnthropicClient {
messages,
model: "claude-3-5-sonnet-20241022",
max_tokens: 4096,
system: `You are a coding assistant to a software engineer, inside a neovim plugin called magenta.nvim .
system: `\
You are a coding assistant to a software engineer, inside a neovim plugin called magenta.nvim .
Be concise.
Do not narrate tool use.
You can use multiple tools at once, so try to minimize round trips.
First understand what’s already working - do not change or delete or break existing functionality.
Look for the simplest possible fix.
Expand Down
13 changes: 0 additions & 13 deletions bun/magenta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import { pos } from "./tea/view.ts";
import type { Nvim } from "bunvim";
import { Lsp } from "./lsp.ts";

import { delay } from "./utils/async.ts";

// these constants should match lua/magenta/init.lua
const MAGENTA_COMMAND = "magentaCommand";
const MAGENTA_ON_WINDOW_CLOSED = "magentaWindowClosed";
Expand All @@ -32,17 +30,6 @@ export class Magenta {
update: chatModel.update,
View: chatModel.view,
});

this.animate();
}

async animate() {
while (true) {
if (this.mountedChatApp) {
this.mountedChatApp.render();
}
await delay(333);
}
}

async command(command: string): Promise<void> {
Expand Down
8 changes: 6 additions & 2 deletions bun/tea/tea.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,11 @@ export function createApp<Model, Msg>({
});
}

render();

currentState = { status: "running", model: nextModel };

render();

if (onUpdate) {
onUpdate(msg, currentState.model);
}
Expand All @@ -109,10 +110,13 @@ export function createApp<Model, Msg>({
};

function render() {
nvim.logger?.info(`render`)
if (renderPromise) {
reRender = true;
nvim.logger?.info(`re-render scheduled`)
} else {
if (root) {
nvim.logger?.info(`init renderPromise of state ${JSON.stringify(currentState, null, 2)}`)
renderPromise = root
.render({ currentState, dispatch })
.catch((err) => {
Expand All @@ -123,7 +127,7 @@ export function createApp<Model, Msg>({
renderPromise = undefined;
if (reRender) {
reRender = false;
nvim.logger?.debug(`scheduling followup render`);
nvim.logger?.debug(`followup render triggered`);
render();
}
});
Expand Down
6 changes: 3 additions & 3 deletions bun/tools/diff.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { withDriver } from "../test/preamble";
import type { ToolRequestId } from "./toolManager";
import * as path from "path";

describe("tea/diff.spec.ts", () => {
describe("bun/tools/diff.spec.ts", () => {
it("insert into new file", async () => {
await withDriver(async (driver) => {
await driver.showSidebar();
Expand Down Expand Up @@ -66,7 +66,7 @@ describe("tea/diff.spec.ts", () => {
});
});

it.only("replace in existing file", async () => {
it("replace in existing file", async () => {
await withDriver(async (driver) => {
await driver.showSidebar();
await driver.inputMagentaText(
Expand Down Expand Up @@ -138,7 +138,7 @@ Paints its colors in the light.`,
});
});

it.only("multiple messages editing same file", async () => {
it("multiple messages editing same file", async () => {
await withDriver(async (driver) => {
await driver.showSidebar();
await driver.inputMagentaText(
Expand Down
6 changes: 2 additions & 4 deletions bun/tools/getFile.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ describe("tea/getFile.spec.ts", () => {

assert.equal(
(await buffer.getLines({ start: 0, end: -1 })).join("\n"),
`⚙️ Reading file ./file.txt`,
"initialRender is as expected",
`⚙️ Reading file ./file.txt`
);
app.dispatch({
type: "finish",
Expand All @@ -57,8 +56,7 @@ describe("tea/getFile.spec.ts", () => {
await mountedApp.waitForRender();
assert.equal(
(await buffer.getLines({ start: 0, end: -1 })).join("\n"),
`✅ Finished reading file ./file.txt`,
"initialRender is as expected",
`✅ Finished reading file ./file.txt`
);
});
});
Expand Down
2 changes: 0 additions & 2 deletions bun/tools/insert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { type Result } from "../utils/result.ts";

export type Model = {
type: "insert";
autoRespond: boolean;
request: InsertToolUseRequest;
state: {
state: "done";
Expand Down Expand Up @@ -40,7 +39,6 @@ export const update: Update<Msg, Model> = (msg, model) => {
export function initModel(request: InsertToolUseRequest): [Model] {
const model: Model = {
type: "insert",
autoRespond: true,
request,
state: {
state: "done",
Expand Down
8 changes: 3 additions & 5 deletions bun/tools/listBuffers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { pos } from "../tea/view.ts";
import { NvimBuffer } from "../nvim/buffer.ts";
import { withNvimClient } from "../test/preamble.ts";

describe("tea/listBuffers.spec.ts", () => {
it("render the getFile tool.", async () => {
describe("bun/tools/listBuffers.spec.ts", () => {
it("render the listBuffers tool.", async () => {
await withNvimClient(async (nvim) => {
const buffer = await NvimBuffer.create(false, true, nvim);
await buffer.setOption("modifiable", false);
Expand Down Expand Up @@ -42,7 +42,6 @@ describe("tea/listBuffers.spec.ts", () => {

expect(
content,
// "initial render of list buffers tool is as expected",
).toBe(`⚙️ Grabbing buffers...`);

app.dispatch({
Expand All @@ -56,8 +55,7 @@ describe("tea/listBuffers.spec.ts", () => {

await mountedApp.waitForRender();
expect(
(await buffer.getLines({ start: 0, end: -1 })).join("\n"),
"initialRender is as expected",
(await buffer.getLines({ start: 0, end: -1 })).join("\n")
).toBe(`✅ Finished getting buffers.`);
});
});
Expand Down
2 changes: 0 additions & 2 deletions bun/tools/listBuffers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import type { Nvim } from "bunvim";

export type Model = {
type: "list_buffers";
autoRespond: boolean;
request: ListBuffersToolRequest;
state:
| {
Expand Down Expand Up @@ -50,7 +49,6 @@ export function initModel(
): [Model, Thunk<Msg>] {
const model: Model = {
type: "list_buffers",
autoRespond: true,
request,
state: {
state: "processing",
Expand Down

0 comments on commit fa7c5e8

Please sign in to comment.