367 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
60 lines
5.1 KiB
Python
60 lines
5.1 KiB
Python
#!/usr/bin/env python3
|
|
"""Saved, local, read-only REA contract jobs; no client input or publication."""
|
|
import argparse,fcntl,json,os,subprocess,time
|
|
from pathlib import Path
|
|
ROOT=Path(__file__).resolve().parents[1]
|
|
def save(p,v):
|
|
p.parent.mkdir(parents=True,exist_ok=True)
|
|
tmp=p.with_suffix(p.suffix+'.tmp');tmp.write_text(json.dumps(v,indent=2)+'\n');tmp.replace(p)
|
|
def unwrap(v):
|
|
return v.get('data',v) if isinstance(v,dict) else {}
|
|
def main():
|
|
ap=argparse.ArgumentParser();ap.add_argument('--job-directory',type=Path,required=True);args=ap.parse_args()
|
|
out=args.job_directory.resolve();plan=json.loads((out/'job-scope.json').read_text())
|
|
lock=(out/'runner.lock').open('a+');fcntl.flock(lock,fcntl.LOCK_EX|fcntl.LOCK_NB)
|
|
(out/'runner.pid').write_text(str(os.getpid())+'\n')
|
|
cli=ROOT/'runtime/rea-cli-evaluation/node_modules/.bin/rea'
|
|
status={'phase':'running','pid':os.getpid(),'started':time.time(),'scope':plan['scope'],'units':[],'catalogue_complete':False,'runtime_fixes_verified':False}
|
|
save(out/'status.json',status)
|
|
print('REA system job running; full output is saved in its job directory.',flush=True)
|
|
for unit in plan['units']:
|
|
dest=out/unit['output'];dest.mkdir(exist_ok=True)
|
|
receipts=[];reusable={};missing=[]
|
|
for rel in unit['prior_evidence']:
|
|
p=ROOT/rel
|
|
if not p.exists():missing.append(rel);continue
|
|
paths=[p] if p.is_file() else sorted(p.rglob('*.json'))
|
|
for f in paths:
|
|
if f.name in {'status.json','evidence-index.json','comparison-handoff.json'} or f.stat().st_size>8*1024*1024:continue
|
|
try:v=json.loads(f.read_text());d=unwrap(v)
|
|
except (ValueError,UnicodeError,OSError):continue
|
|
receipts.append({'path':str(f.relative_to(ROOT)),'evidence_id':d.get('evidence_id'),'operation':d.get('operation'),'authority':d.get('authority')})
|
|
params=d.get('parameters') or {};subject=d.get('subject') or {}
|
|
query=params.get('query')
|
|
if d.get('evidence_id') and query and subject.get('local_path'):reusable[(subject['local_path'],query)]=str(f)
|
|
save(dest/'evidence-index.json',{'receipts':receipts,'missing_pinned_paths':missing,'reexported_existing_evidence':False})
|
|
previous_handoff=dest/'comparison-handoff.json'
|
|
traces=json.loads(previous_handoff.read_text()).get('traces',[]) if previous_handoff.exists() else []
|
|
for target,path in plan['targets'].items():
|
|
for query in unit['queries']:
|
|
name=target+'-'+query;result=dest/(name+'.json');log=dest/(name+'.stderr.log')
|
|
previous=reusable.get((path,query))
|
|
if previous:traces.append({'target':target,'query':query,'status':'reused','evidence':previous});continue
|
|
if result.exists():traces.append({'target':target,'query':query,'status':'saved-result-preserved','evidence':str(result)});continue
|
|
if not Path(path).is_file():traces.append({'target':target,'query':query,'status':'held-missing-target'});continue
|
|
command=[str(cli),'trace',path,'--query',query,'--format','json']
|
|
started=time.time()
|
|
try:
|
|
with result.open('w') as f,log.open('w') as err:r=subprocess.run(command,cwd=ROOT,stdout=f,stderr=err,timeout=180)
|
|
data=unwrap(json.loads(result.read_text())) if result.stat().st_size else {}
|
|
ok=r.returncode==0 and bool(data.get('evidence_id'))
|
|
traces.append({'target':target,'query':query,'status':'decoded-entry-point' if ok else 'held-provider-result','returncode':r.returncode,'evidence':str(result),'elapsed_seconds':round(time.time()-started,2),'catalogue_coverage_established':False})
|
|
except subprocess.TimeoutExpired:traces.append({'target':target,'query':query,'status':'held-bounded-analysis-timeout','evidence':str(result)})
|
|
except (ValueError,OSError) as e:traces.append({'target':target,'query':query,'status':'held-'+type(e).__name__,'evidence':str(result)})
|
|
handoff={'system':unit['system'],'scope':unit['coverage'],'prior_receipt_count':len(receipts),'traces':traces,'comparison_status':'Join the saved protocol-correlation source/native field and flag matrix with pinned original consumer/handler receipts and complete catalogue exports. Static references and API traces do not prove mappings.','implementation_status':'No live client or data package changed by this job.','completed_regression_only':plan['completed_regression_only']}
|
|
save(dest/'comparison-handoff.json',handoff)
|
|
status['units'].append({'system':unit['system'],'prior_receipts':len(receipts),'traces':len(traces),'handoff':str(dest/'comparison-handoff.json')});save(out/'status.json',status)
|
|
status.update(phase='contract-pass-finished',finished=time.time(),next='Apply and validate complete catalogue relationship exports; unresolved consumers remain held.');save(out/'status.json',status)
|
|
print('REA contract pass finished; saved handoffs distinguish decoded evidence, holds and pending catalogue coverage.',flush=True)
|
|
if __name__=='__main__':main()
|