Decentralized Contract Architecture for Action Handlers#262
Decentralized Contract Architecture for Action Handlers#262ruzaqiarkan-eng wants to merge 2 commits into
Conversation
Refactored the monolithic 1440-line `contracts.py` into a decentralized system where each `ActionHandler` owns its metadata contract (UI definitions, operations, policies). Key changes: - Created `base_contract.py` with `ActionContract` and `OperationContract` data classes and reusable presets. - Created `contract_utils.py` for shared utility functions and constants. - Created `contract_dto.py` for standardized frontend API generation. - Enhanced `ActionHandler` base class with contract protocol methods. - Enhanced `HandlerRegistry` to aggregate and cache decentralized contracts. - Migrated all 13 built-in action handlers to implement the contract protocol. - Transformed `contracts.py` into a thin backward-compatible facade using module-level `__getattr__`. This improvement co-locates execution logic with metadata, adheres to the Single Responsibility and Open/Closed principles, and eliminates extensive duplication in operation contracts.
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
- Ran `ruff format` on all modified files to fix formatting issues. - Fixed mypy error in `ActionHandler.get_action_contract` by ensuring `action_type` is a string. - Cleaned up redundant imports and long lines in handlers for better readability and lint compliance.
This PR implements a robust, decentralized architecture for the FlexiRule contract system. Previously, all action metadata (CSS, required fields, operation overrides, policies) was managed in a single, monolithic 1440-line
contracts.pyfile. This created a maintenance bottleneck and violated the Single Responsibility Principle.In the new architecture:
get_action_contract()andget_operation_contracts().HandlerRegistrycollects contracts from all registered handlers, providing a unified API for the engine, validation service, and frontend.base_contract.py(likeaggregate_operation_overrides) that eliminate hundreds of lines of duplicated JSON-like structures.contracts.pyremains as a facade, ensuring existing backend services and third-party handlers continue to work without modification.Verified via golden-file comparison of
get_contract_dto()output and the full backend test suite.PR created automatically by Jules for task 11590012441252482169 started by @ruzaqiarkan-eng