fix: correct hooks JSON schema type definition#2280
fix: correct hooks JSON schema type definition#2280xuewenjie123 wants to merge 2 commits intoQwenLM:mainfrom
Conversation
The hooks array items were incorrectly typed as 'string' in the JSON schema, causing VS Code to show type errors when users configure HookDefinition objects. This fix adds proper schema support for complex array item types. - Add SettingItemDefinition interface for array item schema - Add items schema for UserPromptSubmit and Stop hooks - Update generate-settings-schema.ts to convert complex item types Fixes QwenLM#2246 Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
Extract common hook definition items schema into a reusable constant to avoid code duplication between UserPromptSubmit and Stop hooks. Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
📋 Review SummaryThis PR fixes an important JSON schema issue where VS Code was incorrectly showing type errors for hook configurations in 🔍 General Feedback
🎯 Specific Feedback🔴 Critical
🟡 High
🟢 Medium
🔵 Low
✅ Highlights
|
Source definition in settingsSchema.ts: Generated settings.schema.json: The additionalProperties is missing. Root cause: convertItemDefinitionToJsonSchema only processes additionalProperties when itemDef.type === 'object' && itemDef.properties. Since env has no properties, the entire block is skipped. Fix: move additionalProperties handling outside the if (itemDef.properties) block.
In HOOK_DEFINITION_ITEMS: The generator silently overrides the type to 'array' when items is present, so the output is correct. But the source definition is semantically misleading. Should be type: 'object' with a comment, or better yet, support an 'array' type in SettingItemDefinition.
CommandHookConfig has source?: HooksConfigSource (values: 'project' | 'user' | 'system' | 'extensions'), which is absent from the schema. Low priority since source is likely an internal field not user-configurable.
Only UserPromptSubmit and Stop get the items schema. Other events (PreToolUse, PostToolUse, etc.) aren't in settingsSchema.ts at all, so this is a pre-existing gap — not this PR's responsibility.
required: true is placed at the property level instead of standard JSON Schema's parent-level required array. The converter handles the mapping correctly, but this non-standard design may confuse developers familiar with JSON Schema conventions. |
Pull Request Description
English Version
Fix: Correct hooks JSON schema type definition
Issue: #2246
Problem
When configuring Hooks in
settings.json, VS Code shows type errors forHookDefinitionobjects underhooks.UserPromptSubmitandhooks.Stop:This is because
settings.schema.jsonincorrectly defines the array element type asstringfor these hook events, while the actual runtime expectsHookDefinitionobject structures.Impact
HookDefinitionobject configurations are marked as type errors, causing confusionSolution
This PR adds proper schema support for complex array item types:
New Interface: Added
SettingItemDefinitioninterface to define schema for array item types, supporting simple types (string, number, boolean) and complex object typesSchema Definition: Added complete
itemsschema forUserPromptSubmitandStophooks with fullHookDefinitionstructure:matcher: Optional matcher patternsequential: Whether to execute hooks sequentiallyhooks: Array of hook configurations (required)type: Hook type (required, currently only 'command')command: Command to execute (required)name,description,timeout,env: Optional fieldsGenerator Update: Updated
generate-settings-schema.tswithconvertItemDefinitionToJsonSchemafunction to convert complex item definitions to standard JSON Schema formatFiles Changed
packages/cli/src/config/settingsSchema.tsSettingItemDefinitioninterface and items schema for hookspackages/vscode-ide-companion/schemas/settings.schema.jsonstringto proper object schemascripts/generate-settings-schema.tsTesting
npm run generate-settings-schemagenerates correct schemaScreenshots
Before Fix