Merge pull request #4154 from MoerAI/fix/todo-description-override-fires
fix(plugin): wire tool.definition handler so todo-description-override actually fires (fixes #3705)
This commit is contained in:
@@ -8,6 +8,7 @@ import { createCommandExecuteBeforeHandler } from "./plugin/command-execute-befo
|
||||
import { createMessagesTransformHandler } from "./plugin/messages-transform"
|
||||
import { createSystemTransformHandler } from "./plugin/system-transform"
|
||||
import { createEventHandler } from "./plugin/event"
|
||||
import { createToolDefinitionHandler } from "./plugin/tool-definition"
|
||||
import { createToolExecuteAfterHandler } from "./plugin/tool-execute-after"
|
||||
import { createToolExecuteBeforeHandler } from "./plugin/tool-execute-before"
|
||||
|
||||
@@ -70,6 +71,10 @@ export function createPluginInterface(args: {
|
||||
hooks,
|
||||
}),
|
||||
|
||||
"tool.definition": createToolDefinitionHandler({
|
||||
hooks,
|
||||
}),
|
||||
|
||||
"tool.execute.before": createToolExecuteBeforeHandler({
|
||||
ctx,
|
||||
hooks,
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
import { describe, it, expect } from "bun:test"
|
||||
import { createToolDefinitionHandler } from "./tool-definition"
|
||||
import { createTodoDescriptionOverrideHook } from "../hooks/todo-description-override/hook"
|
||||
import { TODOWRITE_DESCRIPTION } from "../hooks/todo-description-override/description"
|
||||
import type { CreatedHooks } from "../create-hooks"
|
||||
|
||||
function buildHooks(overrides: Partial<CreatedHooks> = {}): CreatedHooks {
|
||||
return overrides as CreatedHooks
|
||||
}
|
||||
|
||||
describe("createToolDefinitionHandler (regression for #3705)", () => {
|
||||
describe("#given todoDescriptionOverride hook is registered", () => {
|
||||
describe("#when the tool.definition handler runs for the todowrite tool", () => {
|
||||
it("#then forwards to the hook and rewrites the description", async () => {
|
||||
//#given
|
||||
const handler = createToolDefinitionHandler({
|
||||
hooks: buildHooks({ todoDescriptionOverride: createTodoDescriptionOverrideHook() }),
|
||||
})
|
||||
const output = { description: "opencode core default", parameters: {} }
|
||||
|
||||
//#when
|
||||
await handler({ toolID: "todowrite" }, output)
|
||||
|
||||
//#then
|
||||
expect(output.description).toBe(TODOWRITE_DESCRIPTION)
|
||||
})
|
||||
})
|
||||
|
||||
describe("#when the tool.definition handler runs for any other tool", () => {
|
||||
it("#then leaves the description untouched", async () => {
|
||||
//#given
|
||||
const handler = createToolDefinitionHandler({
|
||||
hooks: buildHooks({ todoDescriptionOverride: createTodoDescriptionOverrideHook() }),
|
||||
})
|
||||
const output = { description: "bash native description", parameters: {} }
|
||||
|
||||
//#when
|
||||
await handler({ toolID: "bash" }, output)
|
||||
|
||||
//#then
|
||||
expect(output.description).toBe("bash native description")
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe("#given todoDescriptionOverride hook is disabled (null)", () => {
|
||||
describe("#when the tool.definition handler runs for todowrite", () => {
|
||||
it("#then is a no-op", async () => {
|
||||
//#given
|
||||
const handler = createToolDefinitionHandler({
|
||||
hooks: buildHooks({ todoDescriptionOverride: null }),
|
||||
})
|
||||
const output = { description: "opencode default kept", parameters: {} }
|
||||
|
||||
//#when
|
||||
await handler({ toolID: "todowrite" }, output)
|
||||
|
||||
//#then
|
||||
expect(output.description).toBe("opencode default kept")
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,16 @@
|
||||
import type { CreatedHooks } from "../create-hooks"
|
||||
|
||||
export function createToolDefinitionHandler(args: {
|
||||
hooks: CreatedHooks
|
||||
}): (
|
||||
input: { toolID: string },
|
||||
output: { description: string; parameters: unknown },
|
||||
) => Promise<void> {
|
||||
const { hooks } = args
|
||||
return async (input, output) => {
|
||||
const overrideHook = hooks.todoDescriptionOverride
|
||||
if (overrideHook) {
|
||||
await overrideHook["tool.definition"](input, output)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user