- Reset master to upstream/main (16,697 commits) - Overlay 2,271 local-only files (skills, tools, workspace, configs, apps) - Restore IDENTITY.md and USER.md templates - Build verified, gateway running, Discord working Co-Authored-By: Claude Opus 4.6 <[email protected]>
47 lines
1.2 KiB
Python
47 lines
1.2 KiB
Python
#!/usr/bin/env python3
|
|
import argparse
|
|
import json
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
from james.lib.log import get_logger
|
|
|
|
log = get_logger("validate")
|
|
|
|
|
|
def load_json(path: Path | None) -> dict:
|
|
if path is None:
|
|
data = sys.stdin.read()
|
|
else:
|
|
data = path.read_text()
|
|
return json.loads(data)
|
|
|
|
|
|
def main() -> int:
|
|
parser = argparse.ArgumentParser(description="Validate a James event against the JSON schema")
|
|
parser.add_argument("--schema", default="james/schemas/event.json")
|
|
parser.add_argument("--file", help="Event JSON file (defaults to stdin)")
|
|
args = parser.parse_args()
|
|
|
|
try:
|
|
import jsonschema
|
|
except Exception as exc: # pragma: no cover - runtime guard
|
|
log.error("jsonschema is required", exc_info=True)
|
|
return 2
|
|
|
|
schema = json.loads(Path(args.schema).read_text())
|
|
event = load_json(Path(args.file) if args.file else None)
|
|
|
|
try:
|
|
jsonschema.validate(instance=event, schema=schema)
|
|
except jsonschema.ValidationError as exc:
|
|
log.error("invalid event", error=exc.message)
|
|
return 1
|
|
|
|
log.info("valid")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|