import json,os,subprocess
from pathlib import Path
os.umask(0o077)
R=Path(__file__).parent;runner='/root/.local/bin/codex-git-closeout';job='contextra-fire-api-runtime-20260914-113200'
def run(args):return subprocess.check_output(args,text=True,timeout=45)
def prepare(repo,expected_head,label,title,messages,verify,count):
    assert run(['git','-C',repo,'rev-parse','HEAD']).strip()==expected_head
    assert not run(['git','-C',repo,'diff','--cached','--name-only']).strip()
    paths=sorted(set(run(['git','-C',repo,'diff','--name-only']).splitlines()+run(['git','-C',repo,'ls-files','--others','--exclude-standard']).splitlines()))
    assert len(paths)==count
    run(['git','-C',repo,'diff','--check'])
    args=[runner,'prepare','--repository',repo,'--output',str(R/(label+'-final-manifest.json')),'--job-id',job if label=='contextra' else job+'-'+label,'--profile','ltb1021','--session-alias','work-session','--title',title,'--verify',verify]
    for m in messages:args+=['--message',m]
    for p in paths:args+=['--path',p]
    return json.loads(run(args))
source=prepare('/workspace/contextra-analytics-runtime-lifecycle-refactor','7a51cb97269ae535e412e88fc2383ea5cbc5ef55','contextra',
 'ops(fire): HTTP 교정 image와 실제 Metadata 연결 검증 기록',[
 'Why=직전 요청 schema 누락 교정을 실제 image와 서비스 전달 경계까지 검증한다.',
 'What=source/image import 동일성 및 HTTP 회귀, 기존 SDK 재사용, 고유 image와 제한 Fire Runtime 결과를 Owner에 기록했다.',
 'Impact=새 image와 Fire 모델 준비 유지. camera 설정과 정상 restart 정책 복원, healthy/Stream stopped이며 비대상은 보존했다.',
 'Verify=source/image HTTP 각2 tests PASS, Native binary3 동일. Start1/Stop1에서 Redis31Frame과 동일 JSON3개, cleanup0.331초 PASS. 짧은 구간 약10FPS이며 지속 성능과 자연 EOF는 미검증이다.',
 'Rollback=기록은 후속 evidence로 보정하며 배포는 private CAS 원장의 이전 image/env/설정으로 필요한 부분만 복원한다. 기존 모델과 산출물은 삭제하지 않는다.'
 ],'source/image HTTP2 each PASS; Native3 hashes equal; build1 Start1 Stop1 failures0; Redis31 same-frame3; cleanup PASS; original camera/restart restored; no reconversion or quality replay',2)
portfolio=prepare('/workspace/users/root/codex-ops-docs','77c4923deec71f2c4abf136788163c4f59479b0b','portfolio',
 'docs(portfolio): Fire 실제 전달과 제어 경계 완료 기록',[
 'Why=검증된 Fire 통합 결과를 코드와 별도의 기술 성과로 기록한다.',
 'What=source-image import 정합과 실제 Metadata 전달 및 cleanup milestone1건을 안전 append했다.',
 'Impact=Portfolio shard와 track/catalog만 갱신하며 historical evidence와 공용 지침은 변경하지 않았다.',
 'Verify=append dry-run과 content safety PASS, 실제 Runtime evidence 및 문서2파일과 대응 확인.',
 'Rollback=문제가 있으면 해당 신규 entry와 track/catalog 갱신만 기존 안전 절차로 보정하며 application Runtime은 건드리지 않는다.'
 ],'HIGH milestone append dry-run PASS; runtime evidence verified; new entry1 and catalog/track correspondence checked',3)
args=[runner,'batch-prepare','--output',str(R/'git-batch-final.json'),'--batch-id',job,'--profile','ltb1021','--session-alias','work-session','--expected-group-count','2']
for label,p in [('contextra',source),('portfolio',portfolio)]:args+=['--repository-label',label,'--manifest',str(R/(label+'-final-manifest.json')),'--expect-plan-hash',p['plan_hash']]
print(run(args))
