build(agent): new-agents-4#58ba63 iteration

This commit is contained in:
agent-58ba63c88b4c9625 2026-04-20 16:48:23 +02:00
parent 1e5f4179ec
commit 6ac709a18d
2 changed files with 42 additions and 23 deletions

View File

@ -1,37 +1,56 @@
"""Lightweight Graph-of-Contracts (GoC) registry scaffold. """Lightweight Graph-of-Contracts (GoC) scaffolding.
Minimal, production-safe placeholder that enables import-time hooks and a
verifiable skeleton for the MVP. This module provides a minimal in-process registry for contracts/adapters
and a factory to produce a skeleton GoC structure embedded in the IR.
The goal is to enable the core DSL -> IR path to be testable and
extensible without introducing heavy dependencies.
""" """
from __future__ import annotations from __future__ import annotations
from typing import Dict from typing import Dict, List
import hashlib
import time import time
class GoCRegistry: class GoCRegistry:
"""Very small in-process registry for adapters and contracts.""" """A tiny in-memory registry for Graph-of-Contracts (GoC).
def __init__(self):
self.adapters = {}
self.contracts = {}
def register_adapter(self, name: str, details: Dict[str, object]): This is intentionally lightweight for MVP usage. It stores contracts by
self.adapters[name] = details name and allows listing and registering new ones. It does not persist to disk
return name in this MVP, but it provides a spot to hook in real registries later.
"""
def register_contract(self, contract_id: str, details: Dict[str, object]): def __init__(self) -> None:
self.contracts[contract_id] = details self._contracts: List[Dict[str, object]] = []
return contract_id
def build_minimal_goC_skeleton(registry_digest: str, timestamp: str) -> Dict[str, object]: def register_contract(self, name: str, contract: Dict[str, object]) -> None:
"""Return a minimal, reproducible GoC skeleton.""" """Register a new contract descriptor under the given name."""
# Simple, deterministic hash to seed the GoC's identity entry = {"name": name, "contract": contract, "registered_at": int(time.time())}
seed = hashlib.sha256(f"{registry_digest}:{timestamp}".encode("utf-8")).hexdigest() self._contracts.append(entry)
return {
def list_contracts(self) -> List[Dict[str, object]]:
return list(self._contracts)
def __repr__(self) -> str:
return f"GoCRegistry(contracts={len(self._contracts)})"
def build_minimal_goC_skeleton(registry_digest: str, generated_at: str) -> Dict[str, object]:
"""Produce a minimal, self-contained GoC skeleton.
The skeleton is deliberately small but structured to support extension as
adapters are added. It includes a registry digest, a timestamp, and an empty
contracts list that can be populated by future integrations.
"""
skeleton: Dict[str, object] = {
"version": "0.1", "version": "0.1",
"contracts": [], "contracts": [],
"metadata": {
"generated_at": generated_at,
"registry_digest": registry_digest, "registry_digest": registry_digest,
"generated_at": timestamp, },
"registry_seed": seed,
} }
return skeleton
__all__ = ["GoCRegistry", "build_minimal_goC_skeleton"] __all__ = ["GoCRegistry", "build_minimal_goC_skeleton"]

0
test.sh Normal file → Executable file
View File