def keys_allowed($allowed): type=="object" and ((keys-$allowed)|length)==0; def text: type=="string" and test("\\S"); def portable: text and (startswith("/")|not) and (contains("\\")|not) and (contains(":")|not) and ([split("/")[]|select(.=="" or .=="." or .=="..")] | length)==0; def strings: type=="array" and length>0 and all(.[];text); def block: keys_allowed(["type","text","items","title","kind","content"]) and if .type=="text" or .type=="code" then keys_allowed(["type","text"]) and (.text|text) elif .type=="bullets" or .type=="steps" then keys_allowed(["type","items"]) and (.items|strings) elif .type=="callout" then . as $b | keys_allowed(["type","title","kind","text"]) and (.text|text) and ((.title//"x")|text) and (["info","low","medium","high","critical","warning","ok","success","unanalysed"]|index($b.kind//"info")!=null) elif .type=="subsection" then keys_allowed(["type","title","content"]) and (.title|text) and (.content|type=="array" and length>0 and all(.[];block)) else false end; def section: keys_allowed(["title","content"]) and (.title|text) and (.content|type=="array" and length>0 and all(.[];block)); def valid: keys_allowed(["schema_version","title","subtitle","id","report_type","status","severity","metadata","branding","summary","closing","timeline","findings","sections","appendices","actions_title","actions","provenance"]) and .schema_version==1 and (.title|text) and (.metadata|type=="object") and (.metadata.Date|type=="string" and test("^[0-9]{4}-[0-9]{2}-[0-9]{2}$")) and (.metadata.Author|text) and ((.report_type//"technical") as $v|["technical","briefing"]|index($v)!=null) and ((.severity//"info") as $v|["info","low","medium","high","critical","warning","ok","success","unanalysed"]|index($v)!=null) and ((.branding//{})|keys_allowed(["organization","logo","theme"]) and ((.organization//"x")|text) and ((.logo//"x")|portable) and ((.theme//{})|keys_allowed(["font","mono_font","ink","muted","line","paper_soft","accent","info","warning","critical","success"]) and all(to_entries[]; if (.key=="font" or .key=="mono_font") then (.value|text) else (.value|type=="string" and test("^#[0-9a-fA-F]{6}$")) end))) and ((.sections//[])|type=="array" and all(.[];section)) and ((.appendices//[])|type=="array" and all(.[];section)) and ((.findings//[]) as $f | ($f|type)=="array" and all($f[];keys_allowed(["id","title","severity","status","evidence","assessment","evidence_refs"]) and (.title|text)) and ([$f[]|select(.id).id]|length)==([$f[]|select(.id).id]|unique|length)); valid