from research import *
rows=[r for r in json.loads((ROOT/'journal.json').read_text()) if r['step']<=1126]
s=begin(1127,'Audit sequential reassessment and record integrity','Is each completed action connected to its own finding and a subsequent reassessment?',{'prefix_last':1126},['journal.json','evidence/research.py'])
chain=True;times=True
for i,r in enumerate(rows):
 copy=dict(r);h=copy.pop('sha256');chain=chain and hashlib.sha256(json.dumps(copy,sort_keys=True).encode()).hexdigest()==h
 if i:chain=chain and r['predecessor_sha256']==rows[i-1]['sha256'];times=times and r['opened_utc']>=rows[i-1]['closed_utc']
 times=times and r['closed_utc']>=r['opened_utc']
checks={'contiguous195':len(rows)==195 and [r['step'] for r in rows]==list(range(932,1127)),'hash_chain':chain,'sequential_timestamps':times,'questions_and_reassessments':all(r['question'].strip() and r['finding'].strip() and r['reassessment'].strip() for r in rows),'all_step_checks':all(all(r['checks'].values()) for r in rows)}
a=artifact('model/sequential_reassessment_audit.json',json.dumps({'through':1126,'actions':len(rows),'checks':checks,'interpretation':'Records demonstrate sequential questions, findings and reassessments; parallel agents supplied bounded reviews and drafts, not retroactively numbered independent discoveries.'},indent=2)+'\n')
finish(s,{'sequential_audit':a},'All 195 preceding actions have ordered timestamps, intact predecessor hashes, passing checks, and explicit questions, findings and reassessments. Parallel contributions enter only through the sequential adoption records.','Summarize the new explanatory gains and their remaining limits for the reader.',checks)
