#!/usr/bin/env bash set -euo pipefail root="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)" source_dir="$root/docs/contracts" target_dir="$root/management/contracts" mkdir -p "$target_dir" files=(sip-management.openapi.yaml cell-agent.openapi.yaml) if [[ "${1:-}" == "--check" ]]; then for file in "${files[@]}"; do cmp -s "$source_dir/$file" "$target_dir/$file" || { echo "contract snapshot is stale: $file" >&2 exit 1 } done echo "contract snapshots match docs/contracts" exit 0 fi for file in "${files[@]}"; do cp "$source_dir/$file" "$target_dir/$file"; done python3 - "$source_dir" "$target_dir" "${files[@]}" <<'PY' import hashlib, json, pathlib, sys source = pathlib.Path(sys.argv[1]) target = pathlib.Path(sys.argv[2]) files = sys.argv[3:] manifest = {"source": "docs/contracts", "files": {}} for name in files: data = (target / name).read_bytes() manifest["files"][name] = {"source_path": f"docs/contracts/{name}", "sha256": hashlib.sha256(data).hexdigest()} (target / "manifest.json").write_text(json.dumps(manifest, indent=2, ensure_ascii=False) + "\n") PY echo "contract snapshots synchronized"