ed44466f33
The bundled createTodoDescriptionOverrideHook returns { 'tool.definition': fn }, but plugin-interface.ts never exposes 'tool.definition' as an OpenCode hook handler. Result: the hook is constructed by createToolGuardHooks (line 132-134 of src/plugin/hooks/create-tool-guard-hooks.ts) but the function is never invoked, so todowrite keeps using OpenCode's core 7 KB description instead of the 1.4 KB TODOWRITE_DESCRIPTION. User-defined plugins under ~/.config/opencode/plugin/*.js use the same hook contract and work fine, confirming the contract itself is functional in opencode 1.14.28+.
Fix: add src/plugin/tool-definition.ts (createToolDefinitionHandler) that forwards the OpenCode 'tool.definition' input/output pair into hooks.todoDescriptionOverride. Wire it into plugin-interface.ts alongside tool.execute.before/after.
Regression coverage: src/plugin/tool-definition.test.ts covers (a) todowrite override applied, (b) other tools left untouched, (c) null hook is a no-op.
89 lines
2.6 KiB
TypeScript
89 lines
2.6 KiB
TypeScript
import type { PluginContext, PluginInterface, ToolsRecord } from "./plugin/types"
|
|
import type { OhMyOpenCodeConfig } from "./config"
|
|
|
|
import { createChatParamsHandler } from "./plugin/chat-params"
|
|
import { createChatHeadersHandler } from "./plugin/chat-headers"
|
|
import { createChatMessageHandler } from "./plugin/chat-message"
|
|
import { createCommandExecuteBeforeHandler } from "./plugin/command-execute-before"
|
|
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"
|
|
|
|
import type { CreatedHooks } from "./create-hooks"
|
|
import type { Managers } from "./create-managers"
|
|
|
|
export function createPluginInterface(args: {
|
|
ctx: PluginContext
|
|
pluginConfig: OhMyOpenCodeConfig
|
|
firstMessageVariantGate: {
|
|
shouldOverride: (sessionID: string) => boolean
|
|
markApplied: (sessionID: string) => void
|
|
markSessionCreated: (sessionInfo: { id?: string; title?: string; parentID?: string } | undefined) => void
|
|
clear: (sessionID: string) => void
|
|
}
|
|
managers: Managers
|
|
hooks: CreatedHooks
|
|
tools: ToolsRecord
|
|
}): PluginInterface {
|
|
const { ctx, pluginConfig, firstMessageVariantGate, managers, hooks, tools } =
|
|
args
|
|
|
|
return {
|
|
tool: tools,
|
|
|
|
"chat.params": async (input: unknown, output: unknown) => {
|
|
const handler = createChatParamsHandler({
|
|
anthropicEffort: hooks.anthropicEffort,
|
|
client: ctx.client,
|
|
})
|
|
await handler(input, output)
|
|
},
|
|
|
|
"chat.headers": createChatHeadersHandler({ ctx }),
|
|
|
|
"command.execute.before": createCommandExecuteBeforeHandler({
|
|
hooks,
|
|
}),
|
|
|
|
"chat.message": createChatMessageHandler({
|
|
ctx,
|
|
pluginConfig,
|
|
firstMessageVariantGate,
|
|
hooks,
|
|
}),
|
|
|
|
"experimental.chat.messages.transform": createMessagesTransformHandler({
|
|
hooks,
|
|
}),
|
|
|
|
"experimental.chat.system.transform": createSystemTransformHandler(),
|
|
|
|
config: managers.configHandler,
|
|
|
|
event: createEventHandler({
|
|
ctx,
|
|
pluginConfig,
|
|
firstMessageVariantGate,
|
|
managers,
|
|
hooks,
|
|
}),
|
|
|
|
"tool.definition": createToolDefinitionHandler({
|
|
hooks,
|
|
}),
|
|
|
|
"tool.execute.before": createToolExecuteBeforeHandler({
|
|
ctx,
|
|
hooks,
|
|
}),
|
|
|
|
"tool.execute.after": createToolExecuteAfterHandler({
|
|
ctx,
|
|
hooks,
|
|
}),
|
|
}
|
|
}
|