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:
@@ -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);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user