novaplan-decentralized-priv.../nova_plan/dsl.py

69 lines
1.7 KiB
Python

"""Minimal NovaPlan DSL scaffolding.
This module provides lightweight dataclasses to model a canonical signal/plan
DSL that can be used by adapters and bridge components to represent local
problems, signals, and planning hypotheses in a structured way.
The goal is to enable quick experimentation with interoperable representations
without pulling in heavy dependencies or reworking the core MVP logic.
"""
from __future__ import annotations
import json
from dataclasses import dataclass, asdict
from typing import List, Dict, Any
@dataclass
class SignalNode:
id: str
metadata: Dict[str, Any] # arbitrary per-signal metadata (venue, ts, confidence, etc.)
def to_json(self) -> str:
return json.dumps(asdict(self))
@dataclass
class Edge:
src: str
dst: str
weight: float = 1.0
def to_json(self) -> str:
return json.dumps(asdict(self))
@dataclass
class Scenario:
name: str
nodes: List[SignalNode]
edges: List[Edge]
def to_json(self) -> str:
data = {
"name": self.name,
"nodes": [asdict(n) for n in self.nodes],
"edges": [asdict(e) for e in self.edges],
}
return json.dumps(data)
@dataclass
class HedgePlan:
plan_id: str
scenario: Scenario
metadata: Dict[str, Any] # additional plan-level metadata
timestamp: float
def to_json(self) -> str:
data = {
"plan_id": self.plan_id,
"scenario": json.loads(self.scenario.to_json()),
"metadata": self.metadata,
"timestamp": self.timestamp,
}
return json.dumps(data)
__all__ = ["SignalNode", "Edge", "Scenario", "HedgePlan"]