state-hub/scripts/generate_custodian_brief.py
tegwick 39b51a21a5
All checks were successful
CI Smoke / host-smoke (push) Successful in 0s
CI Smoke / container-smoke (push) Successful in 1s
Build and Publish Multi-Context Image / build-and-push (push) Successful in 28s
Keep generated orientation briefs local without Git writeback
Assistant: codex
Assistant-Model: gpt-6-astra
Assistant-Session: 01a15374-f59f-7a31-86d2-d23b5d2ed181
2026-10-19 13:46:45 +02:00

34 lines
1.4 KiB
Python

#!/usr/bin/env python3
"""Render a current State Hub orientation brief without Git operations or hub writes."""
import argparse
import json
from pathlib import Path
import re
from consistency_check import _write_custodian_brief
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('--repo-path', type=Path, required=True)
parser.add_argument('--repo-slug', required=True)
parser.add_argument('--api-base', default='http://127.0.0.1:8000')
parser.add_argument('--check', action='store_true')
args = parser.parse_args()
try:
if not re.fullmatch(r'[a-z0-9]+(?:-[a-z0-9]+)*', args.repo_slug):
raise ValueError('canonical repository slug required')
if not args.repo_path.is_dir():
raise ValueError('repository path must exist')
if (args.repo_path / '.custodian-brief.md').is_symlink():
raise ValueError('refuse redirected brief')
changed = _write_custodian_brief(args.api_base, args.repo_slug, str(args.repo_path),
strict=True, check=args.check)
except (OSError, ValueError, KeyError, TypeError) as exc:
parser.exit(1, f'Brief generation refused: {exc}\n')
print(json.dumps({'repo': args.repo_slug, 'status': 'updated' if changed else 'current',
'source': 'state-hub-read-model', 'git_operations': False}))
if __name__ == '__main__':
main()