Files
BEHAVE/BEHAVE-SHELL/scripts/generate_schema.py
anti 41f54cb30b feat(shell): initial decnet_behave_shell spec + tests
Shell-session behavioral observation registry layered on core.
SPDX: GPL-3.0-or-later (code) / CC-BY-SA-4.0 (attribution-recipes.md).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-10 06:17:28 -04:00

43 lines
1.3 KiB
Python

# SPDX-License-Identifier: GPL-3.0-or-later
"""Regenerate ``json/observation.schema.json`` from the Pydantic source of truth.
Idempotent. CI can gate on ``git diff --quiet json/observation.schema.json`` after
running this — a non-empty diff means someone changed the model without
regenerating the JSON Schema artifact.
"""
from __future__ import annotations
import json
import sys
from pathlib import Path
# Allow running this script directly without installing the package.
_REPO_ROOT = Path(__file__).resolve().parent.parent
if str(_REPO_ROOT) not in sys.path:
sys.path.insert(0, str(_REPO_ROOT))
from decnet_behave_shell.spec.envelope import OBSERVATION_SCHEMA_VERSION, Observation # noqa: E402
def build_schema() -> dict:
schema = Observation.model_json_schema()
schema["$id"] = (
f"https://behave.local/schema/observation/v{OBSERVATION_SCHEMA_VERSION}.json"
)
schema["$schema"] = "https://json-schema.org/draft/2020-12/schema"
return schema
def main() -> int:
schema = build_schema()
out = _REPO_ROOT / "json" / "observation.schema.json"
out.parent.mkdir(parents=True, exist_ok=True)
out.write_text(json.dumps(schema, indent=2, sort_keys=True) + "\n")
print(f"wrote {out}")
return 0
if __name__ == "__main__":
raise SystemExit(main())