/** Bounded model views. Full task records/evidence remain owned by the desktop. */ const short=(text,limit=600)=>typeof text==='string'?text.slice(0,limit):text; const fields=(value,keys)=>Object.fromEntries(keys.filter(k=>value?.[k]!==undefined).map(k=>[k,value[k]])); const run=row=>({...fields(row,['run_id','queue_id','status','task_ids','remaining_task_ids','counters','blockers','resume_ready','started_utc']), diff:row.diff?fields(row.diff,['safe','changed','completed','remaining','plan_changes','evidence_changes','blockers']):undefined, result:row.result?fields(row.result,['status','tasks','message','cad_verification']):undefined}); const schedule=row=>fields(row,['schedule_id','title','task_ids','priority','not_before','due_at','dependencies','auto_start','status','ready','requires_confirmation','dispatchable','dispatch_authority','blockers','run_id']); const experience=row=>({...fields(row,['incident_id','issue_code','verified','verification','evidence','evidence_refs','evidence_references','status']), attempts:row.attempts,analyses:row.analyses?.slice(0,2),outcome:row.outcome, summary:short(row.summary,1200),message:short(row.message)}); const ticket=row=>({...fields(row,['incident_id','number','url','state','status','last_sync_at','last_attempt_at','error','reason']), comments:row.comments?.slice(-3).map(c=>({...fields(c,['id','created_at','updated_at','author']),body:short(c.body)}))}); const health=row=>({...fields(row,['status','checked_utc']),checks:(row.checks||[]).slice(0,10).map(check=>fields(check,['name','status','code','message','updated_utc']))}); const decision=row=>fields(row,['sequence','at_utc','previous_hash','record_hash','incident_id','trigger','evidence_refs','gates','candidate_action','authorized_scope','outcome','human_takeover']); function impact(report){ if(!report||typeof report!=='object')return report; const rows=report.rows||[]; return {...fields(report,['coverage','task_ids','component_count','known_component_count','enabled_scope','total_rows','omitted_row_count','truncated','tasks']), rows:rows.slice(0,20),model_omitted_rows:Math.max(0,rows.length-20)}; } export function compactResult(value){ if(!value||typeof value!=='object')return value; const result={...value}; delete result.plan_hashes;delete result.fingerprint;delete result.full_fingerprint; if(result.rows)Object.assign(result,impact(result)); if(result.impact)result.impact=impact(result.impact); if(result.tasks?.length>50){result.model_omitted_tasks=result.tasks.length-50;result.tasks=result.tasks.slice(0,50);} if(result.tasks)result.tasks=result.tasks.map(t=>({...t,...t.note?{note:short(t.note,300)}:{}})); if(result.runs)result.runs=result.runs.slice(0,5).map(run); if(result.schedules)result.schedules=result.schedules.slice(0,10).map(schedule); if(result.schedule_audit)result.schedule_audit=fields(result.schedule_audit,['status','live_events','archived_events','retained_limit']); if(result.schedule_events)result.schedule_events=result.schedule_events.slice(0,10).map(row=>({ ...fields(row,['sequence','schedule_id','at_utc','event','run_id']), payload:{...fields(row.payload,['automatic','authority','status']), receipt:row.payload?.receipt?fields(row.payload.receipt,['status','run_id','tasks','reporting_errors']):undefined}})); if(result.schedule)result.schedule=schedule(result.schedule); if(result.experiences)result.experiences=result.experiences.slice(0,5).map(experience); if(result.tickets)result.tickets=result.tickets.slice(0,5).map(ticket); if(result.ticket)result.ticket=ticket(result.ticket); if(result.health)result.health=health(result.health); if(result.decision_audit)result.decision_audit=fields(result.decision_audit,['status','code','checked','message']); if(result.decisions)result.decisions=result.decisions.slice(0,10).map(decision); return JSON.parse(JSON.stringify(result)); } export function modelSnapshot(value){ const result=fields(value,['task_id','revision','task_name','status','progress','rules_count','issue','issue_code','events','action_result']); const ops=value.operations||{}; result.operations=compactResult({busy:ops.busy===true,live_run:ops.live_run,last_execution:ops.last_execution, runs:ops.runs||[],schedules:ops.schedules||[],experiences:ops.experiences||[],tickets:ops.tickets||[],health:ops.health, decision_audit:ops.decision_audit,decisions:ops.decisions||[], section_errors:ops.section_errors||[],schedule_events:ops.schedule_events||[],schedule_audit:ops.schedule_audit}); if(value.automation?.incident_id)result.automation=fields(value.automation,['incident_id','task_id','issue_code','status','attempts','verification']); if(value.lifecycle?.status)result.lifecycle=fields(value.lifecycle,['request_id','status','task_ids','run_id']); return result; }