# [DEF:PluginExampleShot:Module] # @TIER: STANDARD # @SEMANTICS: Plugin, Core, Extension # @PURPOSE: Reference implementation of a plugin following GRACE standards. # @LAYER: Domain (Business Logic) # @RELATION: INHERITS -> PluginBase # @INVARIANT: get_schema must return valid JSON Schema. from typing import Dict, Any, Optional from ..core.plugin_base import PluginBase from ..core.task_manager.context import TaskContext class ExamplePlugin(PluginBase): @property def id(self) -> str: return "example-plugin" # [DEF:get_schema:Function] # @PURPOSE: Defines input validation schema. # @POST: Returns dict compliant with JSON Schema draft 7. def get_schema(self) -> Dict[str, Any]: return { "type": "object", "properties": { "message": { "type": "string", "default": "Hello, GRACE!", } }, "required": ["message"], } # [/DEF:get_schema:Function] # [DEF:execute:Function] # @PURPOSE: Core plugin logic with structured logging and scope isolation. # @PARAM: params (Dict) - Validated input parameters. # @PARAM: context (TaskContext) - Execution tools (log, progress). # @SIDE_EFFECT: Emits logs to centralized system. async def execute(self, params: Dict, context: Optional = None): message = params # 1. Action: System-level tracing (Rule VI) with belief_scope("example_plugin_exec") as b_scope: if context: # Task Logs: Пишем в пользовательский контекст выполнения задачи # @RELATION: BINDS_TO -> context.logger log = context.logger.with_source("example_plugin") b_scope.logger.info("Using provided TaskContext") # System log log.info("Starting execution", data={"msg": message}) # Task log # 2. Action: Progress Reporting log.progress("Processing...", percent=50) # 3. Action: Finalize log.info("Execution completed.") else: # Standalone Fallback: Замыкаемся на системный scope b_scope.logger.warning("No TaskContext provided. Running standalone.") b_scope.logger.info("Standalone execution", data={"msg": message}) print(f"Standalone: {message}") # [/DEF:execute:Function] # [/DEF:PluginExampleShot:Module]