Systematic rename of all semantic anchors (#region, [DEF], @RELATION) across 1400+ files — backend Python, frontend Svelte/TS, specs, docs: - Flat anchors become Namespace.Module.Entity - @RELATION references updated to match new anchor paths - Zero business logic changes
75 lines
3.2 KiB
Python
75 lines
3.2 KiB
Python
# [DEF:Std.Ai.PluginExampleShot:Module]
|
|
# @COMPLEXITY: 3
|
|
# @SEMANTICS: Plugin, Core, Extension
|
|
# @PURPOSE: Reference implementation of a plugin following GRACE standards.
|
|
# @LAYER: Domain (Business Logic)
|
|
# @RELATION: [INHERITS] ->[Core.PluginBase]
|
|
|
|
from typing import Dict, Any, Optional
|
|
from ..core.plugin_base import PluginBase
|
|
from ..core.task_manager.context import TaskContext
|
|
# GRACE: Обязательный импорт семантического логгера
|
|
from ..core.logger import logger, belief_scope
|
|
|
|
# [DEF:Std.Ai.ExamplePlugin:Class]
|
|
# @PURPOSE: A sample plugin to demonstrate execution context and logging.
|
|
# @RELATION: [INHERITS] ->[Core.PluginBase]
|
|
class ExamplePlugin(PluginBase):
|
|
@property
|
|
def id(self) -> str:
|
|
return "example-plugin"
|
|
|
|
#[DEF:Std.Ai.GetSchema:Function]
|
|
# @PURPOSE: Defines input validation schema.
|
|
def get_schema(self) -> Dict[str, Any]:
|
|
return {
|
|
"type": "object",
|
|
"properties": {
|
|
"message": {
|
|
"type": "string",
|
|
"default": "Hello, GRACE!",
|
|
}
|
|
},
|
|
"required": ["message"],
|
|
}
|
|
#[/DEF:Std.Ai.GetSchema:Function]
|
|
|
|
# [DEF:Std.Ai.Execute:Function]
|
|
# @COMPLEXITY: 4
|
|
# @PURPOSE: Core plugin logic with structured logging and scope isolation.
|
|
# @RELATION: [BINDS_TO] ->[context.logger]
|
|
# @PRE: params must be validated against get_schema() before calling.
|
|
# @POST: Plugin payload is processed; progress is reported if context exists.
|
|
# @SIDE_EFFECT: Emits logs to centralized system and TaskContext.
|
|
async def execute(self, params: Dict, context: Optional[TaskContext] = None):
|
|
message = params.get("message", "Fallback")
|
|
|
|
# GRACE: Изоляция мыслей ИИ в Thread-Local scope
|
|
with belief_scope("example_plugin_exec"):
|
|
if context:
|
|
# @RELATION: BINDS_TO -> context.logger
|
|
log = context.logger.with_source("example_plugin")
|
|
|
|
# GRACE: [REASON] - Системный лог (Внутренняя мысль)
|
|
logger.reason("TaskContext provided. Binding task logger.", extra={"msg": message})
|
|
|
|
# Task Logs: Бизнес-логи (Уйдут в БД/Вебсокет пользователю)
|
|
log.info("Starting execution", extra={"msg": message})
|
|
log.progress("Processing...", percent=50)
|
|
log.info("Execution completed.")
|
|
|
|
# GRACE: [REFLECT] - Сверка успешного выхода
|
|
logger.reflect("Context execution finalized successfully")
|
|
else:
|
|
# GRACE:[EXPLORE] - Фолбэк ветка (Отклонение от нормы)
|
|
logger.explore("No TaskContext provided. Running standalone.")
|
|
|
|
# Standalone Fallback
|
|
print(f"Standalone execution: {message}")
|
|
|
|
# GRACE: [REFLECT] - Сверка выхода фолбэка
|
|
logger.reflect("Standalone execution finalized")
|
|
# [/DEF:Std.Ai.Execute:Function]
|
|
|
|
#[/DEF:Std.Ai.ExamplePlugin:Class]
|
|
# [/DEF:Std.Ai.PluginExampleShot:Module] |