-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Feat/hooks #1061
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Feat/hooks #1061
Conversation
- Add complete hook system with HookManager, HookService, and configuration - Implement 17 different hook types covering app lifecycle, tool execution, etc. - Enable Claude Code hook compatibility with event mapping - Add tool name mapping for Claude to Qwen tools - Allow hooks to execute any application via shell command execution - Add comprehensive documentation in README and docs/ - Include unit, integration, and error handling tests - Support both script file and inline hook definitions - Implement security measures for external script execution
… hook system - Add created_at and completed_at timestamp fields to TodoItem interface for Claude compatibility - Update todoWrite tool to properly handle Claude-compatible timestamp fields - Enhance todoWrite tests to cover timestamp functionality - Add Claude-compatible configuration files and adapter - Update hook manager tests with proper Config interface - Update alias creation script to support Claude compatibility adapter
…hook mapping functionality - Add created_at and completed_at fields to TodoItem interface for Claude compatibility - Update todoWrite tool to properly handle Claude-compatible timestamp fields - Enhance todoWrite tests to cover Claude-compatible functionality - Update HookService and ToolNameMapper with improved Claude compatibility - Update the claude adapter with proper help text and mappings - Add proper validation for Claude-compatible timestamp fields - Update documentation to reflect implemented features
…hooks documentation
- Fixed property access errors by using bracket notation for index signatures - Resolved type mismatches in HookService.ts and related test files - Fixed fs import inconsistencies in HookService.ts - Applied proper type assertions where needed - Removed unused imports and variables - Updated color theme definitions to use specified palette - Improved error handling and type safety in multiple modules - Restored original ASCII art and theme files as requested - Fixed syntax and structural issues in multiple files
- Fix all TypeScript compilation errors in HookService.ts by removing incorrect casting syntax - Correct malformed import statements and method calls - Fix property access issues with unknown types - Update hook-compatibility-claude.md with complete hook documentation including: - Additional Claude hook events like Notification - More complete tool mappings - Hook execution behavior and configuration options - Tool input format mapping configuration details Co-authored-by: Qwen-Coder <[email protected]>
- Implement timeoutMs functionality in HookExecutionOptions - Remove unused payload parameters from PayloadConverter methods - Use HookConfigLoader for all configuration loading in PayloadConverter - Add proper dependency injection of HookConfigLoader to PayloadConverter - Remove unused methods and fix architectural issues Co-authored-by: Qwen-Coder <[email protected]>
- Add HookConfigLoader for loading configuration mappings - Add HookExecutor for executing scripts with security validations - Add HookManager for managing hook lifecycle and execution - Add HookService as the main service interface - Add PayloadConverter for Claude-compatible format conversion - Add comprehensive tests for all hook system components - Include security features: path traversal prevention and timeout enforcement - Add integration tests for end-to-end functionality - Update .gitignore to include scripts/log/ directory
- Add appendSystemPrompt field to CliArgs interface - Add --append-system-prompt option to yargs configuration - Update ConfigParameters interface to include additionalSystemPrompt - Update Config class to store and provide additional system prompt - Modify getCoreSystemPrompt function to append additional prompt - Update all relevant calls to pass the additional system prompt - Add tests for append-system-prompt functionality in CLI and core - Extend existing tests to include the new functionality
- Add STREAM_JSON output format option to OutputFormat enum - Implement stream-json mode in nonInteractiveCli with Claude-compatible event structure - Add tests for stream-json output format covering content, tool calls, errors, and thoughts - Update CLI argument parser to accept 'stream-json' as output format choice - Update claude-adapter.js help text to document new stream-json format - Create SPEC-STREAMING.md specification document for the feature
…prompt alias - Document qwen-alt Claude-compatible alias in README - Document --append-system-prompt argument with examples - Document streaming JSON output mode with examples - Remove incorrect --system-prompt parameter alias from claude adapter - Only --append-system-prompt is now allowed as per requirements Co-authored-by: Qwen-Coder <[email protected]>
|
Thanks for the contribution! We appreciate your ideas and feedback and will try to implement them as soon as we can, but this PR will not be merged for the time being. |
Hook System Implementation - PR
Hey! This is a DRAFT, just floating the idea around (while testing it).
Interested to see what you guys think!
Summary
This pull request introduces a comprehensive hook system to Qwen Code, enabling users to execute custom scripts at key points in the application lifecycle. The implementation includes:
TLDR
This PR adds a powerful hook system that allows executing custom scripts at 17 different lifecycle events in Qwen Code. The system maintains full compatibility with Claude Code hooks while adding enhanced functionality for Qwen-specific workflows.
Dive Deeper
The implementation adds several new components to support the hook system:
The system supports two types of hooks:
Security measures are maintained with path validation ensuring hooks run within the project directory, and configuration validation prevents insecure execution.
The Claude compatibility layer allows executing external commands that receive JSON payloads and can return responses that influence the Qwen workflow, including tool usage permissions and input modifications.
Reviewer Test Plan
npm run buildto ensure the project builds correctlypackages/core/src/hooks/.qwen/settings.json:{ "hooks": { "enabled": true, "hooks": [ { "type": "session.start", "inlineScript": "console.log('Hook executed with payload:', payload);" } ] } }npx vitest run packages/core/src/hooks/to ensure all tests passTesting Matrix
Successfully tested on Linux and MacOS (build and test execution). All tests pass including the comprehensive new hook-specific tests.
Linked issues / bugs
Resolves the need for a comprehensive hook system to enable custom automation and integration in Qwen Code, including Claude Code compatibility for easy workflow migration!
Additional Features
The PR also includes implementation and documentation for other important Claude-compatible features:
qwen-altCLI alias that supports Claude-style commands and arguments--append-system-promptargument--output-format stream-jsonfor real-time processing of responses