"""Base abstractions for stateful closed-loop/fault plugins and task evaluators.""" from __future__ import annotations from abc import ABC, abstractmethod from dataclasses import dataclass, field from typing import Any @dataclass class VerifiedCall: """One SHA-384 verified and fresh-recomputed engine call recovered from `call_ledger.jsonl`.""" submitted_seal: str model_id: str tool: str args: dict[str, Any] answer: dict[str, Any] raw_text: str answer_sha384: str receipt_sha384: str primary_seal: str @dataclass class TaskEvaluatorContext: """Runtime context handed to each per-task `evaluator.py:grade(submission, ctx)`.""" task_id: str task_dir: str task_spec: dict[str, Any] pack_dir: str client: Any seal_bin: str | None = None vault: dict[str, Any] = field(default_factory=dict) ledger_records: list[dict[str, Any]] = field(default_factory=list) ledger_audit: dict[str, Any] | None = None resolved_seals: list[VerifiedCall] = field(default_factory=list) verified_by_model: dict[str, list[VerifiedCall]] = field(default_factory=dict) plugin_episodes: list[dict[str, Any]] = field(default_factory=list) class StatefulPlantPlugin(ABC): """Base class for stateful `CLC` / `FLT` plugins executed inside root `core/daemon.py`.""" def __init__(self, task_spec: dict[str, Any], engine_client: Any, vault: dict[str, Any] | None = None): self.task_spec = task_spec self.client = engine_client self.vault = vault or {} @abstractmethod def tool_definitions(self) -> list[dict[str, Any]]: """Return MCP JSON tool schemas exposed to the unprivileged agent.""" @abstractmethod def tool_category(self, tool_name: str) -> str | None: """Return `'discovery'`, `'sim'`, `'exempt'`, or `None` if not handled by this plugin.""" @abstractmethod def handle_tool(self, tool_name: str, args: dict[str, Any]) -> dict[str, Any]: """Execute a plugin tool call. Returns a dict: - `text`: JSON string returned to the agent - `isError`: bool - `step_call_records`: optional list of `{"tool": ..., "model_id": ..., "args": ..., "raw_text": ...}` for daemon ledger recording & post-run cryptographic recomputation. - `episode_record`: optional snapshot stored on finalize or step. """ def budget_extras(self) -> dict[str, Any]: """Optional status counters injected into `budget_status`.""" return {} def close(self) -> None: """Optional cleanup hook called when daemon shuts down.""" return None