56 lines
1.9 KiB
Python
56 lines
1.9 KiB
Python
"""Small demo runner that certifies a plan and records the attestation to the ledger.
|
|
|
|
This demonstrates how the DSL, verifier, and ledger tie together and can be
|
|
used as a starting point for real adapters and HIL integrations.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
from typing import Dict, Any
|
|
|
|
from ..dsl import SafetyContract, LocalCapabilities, ResourceBudgets, DataSharingPolicy
|
|
from ..verification import VerificationEngine
|
|
from ..governance.ledger import Ledger
|
|
|
|
|
|
def run_demo(contract: SafetyContract, plan: Dict[str, Any]) -> Dict[str, Any]:
|
|
"""Run a deterministic demo: certify plan and add certificate to ledger.
|
|
|
|
Returns a dict with certificate and the ledger entry dict.
|
|
"""
|
|
engine = VerificationEngine()
|
|
ledger = Ledger()
|
|
|
|
cert = engine.certify(plan, contract)
|
|
|
|
# Record attestation in the ledger with minimal metadata
|
|
payload = {
|
|
"contract_id": getattr(contract, "contract_id", None),
|
|
"plan_hash": cert.get("plan_hash"),
|
|
"certificate_id": cert.get("certificate_id"),
|
|
"status": cert.get("status"),
|
|
}
|
|
entry = ledger.add_entry(payload)
|
|
|
|
return {"certificate": cert, "ledger_entry": entry.__dict__, "chain": ledger.get_chain()}
|
|
|
|
|
|
def demo_cli() -> None:
|
|
"""Create a sample contract/plan, run the demo and print JSON output."""
|
|
contract = SafetyContract(
|
|
contract_id="demo-contract-1",
|
|
local_capabilities=[LocalCapabilities(name="Planner", capabilities=["plan"])],
|
|
budgets=ResourceBudgets(cpu_cores=1.0, memory_gb=1.0, energy_wh=50.0, time_seconds=600),
|
|
data_policy=DataSharingPolicy(policy_id="demo-policy", allowed_data=["telemetry"]),
|
|
version="1.0",
|
|
)
|
|
|
|
plan = {"name": "demo-mission", "actions": ["scan", "navigate"], "budgets": {"cpu_cores": 0.5}}
|
|
|
|
out = run_demo(contract, plan)
|
|
print(json.dumps(out, indent=2))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
demo_cli()
|