fix(question-label-truncator): fix type errors and add test coverage

- Remove invalid Pick<Plugin> type usage
- Add explicit input/output type annotations
- Add comprehensive test suite (5 tests)
- Tests verify truncation at 30 chars with '...' suffix
This commit is contained in:
justsisyphus
2026-01-24 16:07:08 +09:00
parent 04fb339622
commit ec32dd65c2
2 changed files with 143 additions and 9 deletions
+7 -9
View File
@@ -1,5 +1,3 @@
import type { Plugin } from "@opencode-ai/plugin";
const MAX_LABEL_LENGTH = 30;
interface QuestionOption {
@@ -42,20 +40,20 @@ function truncateQuestionLabels(args: AskUserQuestionArgs): AskUserQuestionArgs
};
}
export function createQuestionLabelTruncatorHook(): Pick<
Plugin,
"tool.execute.before"
> {
export function createQuestionLabelTruncatorHook() {
return {
"tool.execute.before": async (input, output) => {
"tool.execute.before": async (
input: { tool: string },
output: { args: Record<string, unknown> }
): Promise<void> => {
const toolName = input.tool?.toLowerCase();
if (toolName === "askuserquestion" || toolName === "ask_user_question") {
const args = output.args as AskUserQuestionArgs | undefined;
const args = output.args as unknown as AskUserQuestionArgs | undefined;
if (args?.questions) {
const truncatedArgs = truncateQuestionLabels(args);
Object.assign(output.args as object, truncatedArgs);
Object.assign(output.args, truncatedArgs);
}
}
},